mcneela86 mcneela86 - 2 months ago 21x
AngularJS Question

ngCordova Google analytics ($cordovaGoogleAnalytics)

I am trying to use the '' plugin with ngCordova. I have added the plugin and added ngCordova as a dependency in my controller.

when I try to set:


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?


That happens because you are trying to use analytics plugin before it's initialized by cordova.

Just wrap the initialization recursevely with a setTimetout:

function _waitForAnalytics(){
    if(typeof analytics !== 'undefined'){
        $cordovaGoogleAnalytics.trackView('APP first screen');