ngCordova Google analytics ($cordovaGoogleAnalytics)


#1

Hi,
I am trying to use the ‘https://github.com/danwilson/google-analytics-plugin.git’ plugin with ngCordova. I have added the plugin and added ngCordova as a dependency in my controller.

when I try to set
$cordovaGoogleAnalytics.startTrackerWithId(‘UA-XXXXXXXX-X’);

I get this error: ‘TypeError: Cannot read property ‘startTrackerWithId’ of undefined’.

I have set my analytics up as a mobile app in the Google dashboard.

Can anybody help with this?


#2

I use it this way that I define the tracking ID when platform is ready. Grab some code:

$ionicPlatform.ready(function() {
  if (typeof analytics !== 'undefined'){
    analytics.startTrackerWithId('UA-XXXXXXX-X');
  }
}

p.s. The above code doesn’t use the ngCordova, just plain Cordova.


#3

Hi @mcneela86,

I agree with @rafaellop in the fact that you don’t necessarily need ngCordova for this task. It might even be better to skip it since the Cordova plugin itself isn’t too complicated.

I had written an article on how to use it a while back:

Should still be relevant in getting this working.

Regards,


#4

Hi Everyone,

I got this question answered on stack overflow, hope it helps someone else: http://stackoverflow.com/questions/26910421/ngcordova-google-analytics-cordovagoogleanalytics


#5

Hi, good to hear that you have solved the problem, but I’m curious whether my solution works for you or not?


#6

Hi, I tried with the method above (without using ngcordova) and it worked fine. Thank you for the help.