I have tried using
$cordovaGoogleAnalytics.startTrackerWithId(‘UA-000000-01’);
on “.run” function
also tried on my custom controller which load on first page
But all I am getting is “TypeError: Cannot read property ‘startTrackerWithId’ of undefined”
I have tried running on android also but my app won’t start.
So far I have found some info but none of them worked for me.
Tried example from this blog https://blog.nraboy.com/2014/06/using-google-analytics-ionicframework/. Didn’t work for me.
What’s confusing is each one using different method. Not sure which one is the current updated one:
-
http://ngcordova.com/docs/plugins/googleAnalytics/ says $cordovaGoogleAnalytics.startTrackerWithId(‘UA-000000-01’);
-
https://blog.nraboy.com/2014/06/using-google-analytics-ionicframework/ says
analytics.startTrackerWithId(“UA-XXXXXXXX-XX”);
- Some discussion i found says use “cordova” not “ngCordova”
Don’t know what to follow. I want to stick with ngCordova if possible to keep things simple.
Need some suggestion
Thanks!
You can use the same plugin that the ngCorvoda version uses, without using ngCordova.
Go to the docs of that plugin and use it as instructed there.
Ngcordova version is just an angular wrapper for the same analytics plugin. Did you follow the installation instructions for ngcordova at http://ngcordova.com/docs/install/ ?
Hi,
This is what I did on my app.js for test (with my Analytics ID).
var app = angular.module('myApp', ['ionic', 'ngCordova'])
.run(function($ionicPlatform, $cordovaGoogleAnalytics) {
$ionicPlatform.ready(function() {
$cordovaGoogleAnalytics.startTrackerWithId('UA-000000-01');
$cordovaGoogleAnalytics.trackView('Home Screen');
});
})
I am getting “Uncaught TypeError: Cannot read property 'startTrackerWithId' of undefined
” on my browser.
To test on real device, I have tried
- ionic build android
- ionic run android
If everything is fine, when my app opens, i should be seeing page hit with “Home Screen” on my Realtime Analytics… but nothing happens.
Any suggestion?
Any working code fragment is most welcome. Couldn’t get pass the first stage of this implementiation.
Thanks!
1 Like
I have tried the “cordova” method instead of “ngCordova” as suggested on the blog https://blog.nraboy.com/2014/06/using-google-analytics-ionicframework/
At first I was getting “analytics not defined” error. Got rid of that by quoting the “undefined” on condition check, which was not so obvious at first glance.
Before: if(typeof analytics !== undefined)
Now: if(typeof analytics !== "undefined")
Now I am not getting any error. I have tried the initialization as suggested on “.run” method but it seems analytics is not initialized. I am not getting anything on my analytics. Waited for a day to check if there is a delay before data will show up, but got nothing.
Seems like “startTrackerWithId” on the run doesn’t initialize analytics properly, so I have included “startTrackerWithId” on every controller before view or event tracking… but I am still getting nothing.
Not sure what I am missing.
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(typeof analytics !== "undefined") { //quoted
analytics.startTrackerWithId("UA-XXXXXXXX-XX");
} else {
alert('Analytics not defined');
}
});
Home Controller:
if(typeof analytics !== "undefined") { //quoted
analytics.startTrackerWithId("UA-XXXXXXXX-XX");
alaytics.trackView('Home Screen');
} else {
alert('Analytics not defined');
}
when I test this on Android device, I am getting the alert that its not defined.
Any suggestion?