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

Plugin working on iOS but not on Android

Open ghost opened this issue 9 years ago • 9 comments

Hello there,

I have installed this plugin with ionic and ngCordova. Everything all good. Running the app on iOS everything is working fine. But running the exact same code on Android the tracking events are not showing up in Google Analytics.

Does someone have the same issue? Do I have to activate something at Google to use Analytics on an Android device? What am I doing wrong here?

Some code: app.js $ionicPlatform.ready(function() { $cordovaGoogleAnalytics.debugMode(); $cordovaGoogleAnalytics.startTrackerWithId('UA-XXX-X'); });

controller.js $ionicPlatform.ready(function() { $cordovaGoogleAnalytics.trackView('Home Screen'); });

This is working with iOS devices but not with Android devices.

Also if I just put the raw analytics code in the index.html file a view is succesfully tracked and shows up on Analytics. But this is not the right way.

ghost avatar Mar 30 '17 09:03 ghost

Hi there, We are facing this problem as well! Who knows some solution? Thank you!

vgaemagapp avatar Mar 31 '17 10:03 vgaemagapp

For both of you please try to use the ver 1.6.0 of GA because ngCordova api haven't been updated with the last api changes done in GA plugin.

Also please don't try to call debugmode() before startTrackerWithId() because startTrackerWithId create the java instance that is use on every other method.

victorsosa avatar Mar 31 '17 11:03 victorsosa

please check https://github.com/driftyco/ng-cordova/issues/1421

victorsosa avatar Mar 31 '17 11:03 victorsosa

I have used 1.6.0 version and tried with 1.7.5, but still not working

vgaemagapp avatar Mar 31 '17 14:03 vgaemagapp

Also need to roll down to 1.6.0, remove the tilde to use exact version in config.xml:

<plugin name="cordova-plugin-google-analytics" spec="1.6.0" />

gerhardsletten avatar Apr 03 '17 13:04 gerhardsletten

I need just add this string (plugin name="cordova-plugin-google-analytics" spec="1.6.0) to config.xml?

vgaemagapp avatar Apr 03 '17 14:04 vgaemagapp

@vgaemagapp With the cordova cli commands for both platform and plugin you can append --save to add them to the config.xml file. Then you dont need to keep plugin and platforms folder in your git-repo. You restore them with cordova prepare. So to change the version of this plugin you just update the version in config.xml, delete platforms and plugins folder and restore to get the right version.

Cordova cli reference

gerhardsletten avatar Apr 03 '17 17:04 gerhardsletten

Thanks ! This help!

On Mon, Apr 3, 2017 at 8:07 PM, Gerhard Sletten [email protected] wrote:

@vgaemagapp https://github.com/vgaemagapp With the cordova cli commands for both platform and plugin you can append --save to add them to the config.xml file. Then you dont need to keep plugin and platforms folder in your git-repo. You restore them with cordova prepare. So to change the version of this plugin you just update the version in config.xml, delete platforms and plugins folder and restore to get the right version.

Cordova cli reference https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html#cordova-plugin-command

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/danwilson/google-analytics-plugin/issues/388#issuecomment-291207795, or mute the thread https://github.com/notifications/unsubscribe-auth/AZks8y2103g40HLIdXWnBnoMLclg2Z7iks5rsSc0gaJpZM4MuHPs .

vgaemagapp avatar Apr 04 '17 13:04 vgaemagapp

It means just that, analytics has not been defined. The reason that your if statements aren't catching it is because typeof undefined returns the string "undefined" not the primitive undefined, so you should do:

.run(function($ionicPlatform, $ionicPopup) { $ionicPlatform.ready(function() { if(typeof analytics !== 'undefined') { analytics.startTrackerWithId("UA-xxxx"); } else { console.log("Google Analytics Unavailable"); } }); });

ayolana avatar Jun 14 '17 20:06 ayolana