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

The `startTrackerWithId` success callback is never called.

Open whiterook6 opened this issue 6 years ago • 1 comments

Cordova version: 7.1.0 Plugin version: 1.8.3

Running on android.

When we start our app we try to start the google analytics tracker:

document.addEventListener('deviceready', () => {
	this.analytics.startTrackerWithId(this.ga_id, () => {
		this.analytics.setAppVersion(this.client_config.app_info.version);
		this.analytics.setAllowIDFACollection(true);
		this.enabled = true;
	}, (error) => {
		console.log('Unable to start google analytics', error);
	});
}, false);

However, neither the success or failure callbacks are ever executed. By debugging through Chrome Inspector tools, I can follow the code through to the analytics.js file:

UniversalAnalyticsPlugin.prototype.startTrackerWithId = function(id, dispatchPeriod, success, error) {
  if (typeof dispatchPeriod === 'undefined' || dispatchPeriod === null) {
    dispatchPeriod = 30;
  } else if (typeof dispatchPeriod === 'function' && typeof error === 'undefined') {
    // Called without dispatchPeriod but with a callback.
    // Looks like the original API was used so shift parameters over to remain compatible.
    error = success;
    success = dispatchPeriod;
    dispatchPeriod = 30;
  }  
  cordova.exec(success, error, 'UniversalAnalytics', 'startTrackerWithId', [id, dispatchPeriod]);
};

and it certainly looks like cordova.exec(...) is being called.

How can I resolve this?

whiterook6 avatar Aug 23 '18 21:08 whiterook6

I've fixed this issue for me. For me it was the GCM version conflict between this plugin and the push plugin. Make sure both plugins are using the same major version of GCM. For me in this plugin i used the variable like this on the plugin.

I made sure my push plugin's GCM version was

This also solved several Crashes like below: java.lang.NoClassDefFoundError: at com.google.android.gms.internal.zzaqc.zzbm (Unknown Source) at com.google.android.gms.analytics.CampaignTrackingReceiver.onReceive (Unknown Source)

jasonandress avatar Mar 15 '19 14:03 jasonandress