ngCordova Google analytics ($cordovaGoogleAnalytics)

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?

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.

1 Like

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,

2 Likes

Hi Everyone,

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

1 Like

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

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