mcneela86 mcneela86 - 1 year ago 138
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?

Answer Source

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');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download