google-analytics-plugin icon indicating copy to clipboard operation
google-analytics-plugin copied to clipboard

Ionic implementation not firing

Open adigourdi opened this issue 6 years ago • 8 comments

I'm trying to track app start (and other views) but nothing shows up on Google Analytics, and no errors are reported on the console

This is the code I'm using on app.component.ts

...
import { GoogleAnalytics } from '@ionic-native/google-analytics';
...
const GA_TRACKING_ID = 'UA-XXXXXXXXX-X';
const GA_TRACKING_DISPATCH = 3; // default 30, doesn't work either
...
export class MyApp implements OnInit {
  ...
  constructor(
    ...
    private ga: GoogleAnalytics,
  ) {}

  ngOnInit() {
    this.platform.ready().then(() => {
      console.log('platform ready');
      ...
      if (this.platform.is('cordova')) {
        console.log('platform is cordova');
        ...
        this.initGoogleAnalytics();
      }
    });
  }

  private initGoogleAnalytics() {
    console.log('registering tracker');

    this.ga
      .startTrackerWithId(GA_TRACKING_ID, GA_TRACKING_DISPATCH)
      .then(() => {
        console.log('Google analytics is ready now');
        
        // the component is ready and you can call any method here
        
        this.ga.debugMode(); // no debugging info shows up on console
        this.ga.setAllowIDFACollection(false); // either true or false doesn't work

        this.ga.trackView('start')
          .then(a => console.log('tracked start', a))
          .catch(e => console.log('tracking start failed', e))
        ;
      })
      .catch(e => console.log('Error starting GoogleAnalytics', e));
  }
}

The track start command should fire normally, with a dispatch of 3s, it should show up on analytics right away

Log result on console, no errors occured

platform ready
platform is cordova
registering tracker
Google analytics is ready now
tracked start Track Screen: start

For the record, Google Analytics Admin no longer allows registering mobile app tracking without firebase, so I created it as a website, and created a mobile view

I set the domain as https://mobile.website.com and tried setting the compaign url in trackView as https://mobile.website.com/start, and still nothing

I checked the tracking ID, and it's correct

Info

ionic cli             : 4.5.0
ionic                 : 3.9.2
@ionic/app-scripts    : 3.2.1

cordova (Cordova CLI) : 8.0.0
Cordova Platforms     : android 7.1.3, browser 5.0.4

Android SDK Tools     : 26.1.1

adigourdi avatar Dec 14 '18 11:12 adigourdi

Are you using version 1.8.6? I'm also having this issue and have found that if I revert back to version 1.8.3 it works fine. Someone posted this issue https://github.com/danwilson/google-analytics-plugin/issues/536, but when I follow the steps in there my Android app just crashes when I launch it.

I'd be perfectly fine just sitting at version 1.8.3, however if I ever remove the android platform and re-add it then it automatically updates the plugin version and I'm going to run into this issue again. At this point I've been fighting with this for days. I'm probably just going to document this issue in my App's readme file and try to maintain version 1.8.3.

selected-pixel-jameson avatar Dec 15 '18 13:12 selected-pixel-jameson

Seems like this 1.8.6 issue has been going on for awhile. No response. No updates so it looks like our best bet is probably to just downgrade and make sure Ionic doesn't automatically update it to 1.8.6. Rack another up one for Ionic Native. 👎

selected-pixel-jameson avatar Dec 15 '18 13:12 selected-pixel-jameson

I believe fixing the version with "1.8.3" (in package.json and config.xml) instead of "^1.8.3" or "~1.8.3" should do it

I will downgrade soon and get back to you with any updates

adigourdi avatar Dec 17 '18 10:12 adigourdi

Ya that fixes it. But if you ever remove a platform using ionic cordova platform rm android`` and then re-add it using ionic cordova platform add androidit updates thepackage.jsonandconfig.xml files so that they are again using^1.8.6```. I'm not sure how to prevent that from happening.

selected-pixel-jameson avatar Dec 17 '18 13:12 selected-pixel-jameson

Providing your config.xml, package.json and package-lock.json are all using 1.8.3, don't ever use 'ionic cordova platform add android', as like you say, it ignores the lock file and reapplies the ^ to package.json - use 'cordova platform add android' instead, and it will work correctly. Unless I'm mistaken, this has been the case for many moons, but no-one has commented on the ionic prefixed command being bugged.

ryanhalley avatar Dec 19 '18 15:12 ryanhalley

@ryanhalley Thank you! I will try this.

selected-pixel-jameson avatar Dec 19 '18 20:12 selected-pixel-jameson

thanks @selected-pixel-jameson. it working fine now.

sajanmonga1771 avatar Apr 11 '19 06:04 sajanmonga1771

I did something that adjusted my package file and boom. Issue is happening again. Would be great if this got fixed. Glad I test my builds before every release to make sure the analytics are working.

selected-pixel-jameson avatar Apr 11 '19 18:04 selected-pixel-jameson