Google Analytics


I’m trying to use Dan Wilson’s Google Analytics plugin but can’t seem to get it to pull any data in. He says to place the UA code in the deviceready handler. Would that be something like this for Ionic?

$ionicPlatform.ready(function() {

Any help on this would be awesome.

Google Analytics Views
My google analytics in my ionic app doesn't report any active app user

Hey @Tyler, try putting this into angular’s run function:['$ionicPlatform', function($ionicPlatform) {
  $ionicPlatform.ready(function() {

That would be the correct place to put it, so if it’s not working I would suggest trying it with just deviceready outside of angular and narrowing it down.


we have the plugin working in out app and that where we placed it


Yeah, I actually have it running inside the .run directive… doesn’t seem to be working though. Is there a good way to test or debug Google Analytic?


wrap the call in a try catch block to see if it is throwing exceptions would be the first thing i would do


Few obvious things, you need to get a valid token id from for a mobile app, not a web site. Second, we init it like this:

.run(function(previewData, localStorage, $ionicPlatform) {
  $ionicPlatform.ready(function() {
      if (typeof analytics !== 'undefined'){
        console.log("Google Analytics plugin could not be loaded.")


how is analytics injected, or brought into scope in this example?


As a plugin.

I also got it working in the end. Was missing the analytics.trackView('Screen Title') bit.


Check this module :


I am trying to add Google analytics to my app too. Could you share the code that you use to call the startTrackerWithId()? I tried a few options but I am still getting “Google Analytics plugin could not be loaded.”


I installed the google-analytics-plugin using:

cordova plugin add

Here is my code in app.js:

.run(function($ionicPlatform, $rootScope) {
$ionicPlatform.ready(function() {
if(window.StatusBar) {
if (typeof analytics !== ‘undefined’){
console.log(“Google Analytics plugin could not be loaded.”)

But analytics is still not defined. Any idea what am I doing wrong?

Pura vida.



Here’s how I have mine. Also note that this function only works on deployed apps due to it being installed as a plugin so you’ll always get the else statement until you build and deploy the app.

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if (typeof analytics !== 'undefined'){


Thank you @tyler for this precious information.


Should I call the plugin somewhere? Do I have to include it in config.xml?


Nope. You should just install it via command line. Both iOS and Android have their own config.xml files where the correct tags will be included.


Hey guys,
thanks to this thread I managed to have the plugin to work.
There is still one thing I can’t figure out myself, where in the angular routing process should I indicate that user changed view ?
In other words, where should I put this : analytics.trackView(‘name-of-template’);
if I want to track each template ?



Hi koko!, i am getting an error when i try to build to ios, you are using it right now?


Here’s how I’m currently using it, I place at the end of each controller the following :

if (typeof analytics !== 'undefined')


hey i am always getting an (analytics is not defined) ‘Google Analytics plugin could not be loaded’ please help me, how to make it work.
i used the following code.

if (typeof analytics !== ‘undefined’){
console.log(“starting analytics”);
console.log(“Google Analytics plugin could not be loaded.”);

i have included this code in $ionicPlatform.ready function.
please help me out.


Did you try on the device? I’m not sure if it’s supposed to work in the browser.