Google analytics error

Hi,

I’m having trouble using the google analytics cordova plugin. I followed exactly the procedure explained here:

However, when I do so, I get a “Uncaught ReferenceError: analytics is not defined”. Should I load any js file somewhere, besides just doing “cordova plugin add https://github.com/danwilson/google-analytics-plugin.git”?

Here is my app.js:

angular.module('myapp', ['ionic','ionic.service.core', 'ngCordova',  'ionic.service.push'])
.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        if(typeof window.analytics !== undefined) {
            analytics.startTrackerWithId("UA-XXX-X");
        } else {
            console.log("Google Analytics Unavailable");
        }
    });
})

Thanks in advance for your help!

Try changing the if statement to if (typeof analytics !== 'undefined') (i.e. quote underfined).

Have you added google analytics plugin . run cordova plugin add https://github.com/danwilson/google-analytics-plugin.git

yes, I have already done all that and then some. If I get rid of the if/ells statement completely (ie the Google Analytics initialization executes everytime), and even set a timeout in a loop (maybe the plugin takes some time to initialize), I get the same error. And of course I ran Cordova plugin add … and the plugin is listed when I do Cordova plugin list.

I am running into the same problem as well, do you happen to have a workaround for this?

It’s old so I don’t remember.

Make sure you are not testing this in the browser, but really on the device itself. This plugin does not work in the browser.

Yeah, manage to get it work yesterday running on the device itself. Thank you :slight_smile: