Hi Ionic lovers!
I am trying to use this plugin: https://github.com/danwilson/google-analytics-plugin right now and it is working fine in my app.js. In app.js, I have the following code:
.run(function($ionicPlatform, $rootScope, $ionicConfig, $timeout) {
$ionicPlatform.on("deviceready", function(){
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
window.analytics.startTrackerWithId('XXXXXX');
window.analytics.trackView('App Init');
});
However, when I try to use the same window.analytics.trackView() code in one of my view controllers, I get the “Cannot read property ‘analytics’ of undefined” error. I have also tried using $cordovaGoogleAnalytics and passing that into my controller as a dependency as well but the same thing happens. Any thoughts?
EDIT: Turned out using window.analytics.trackView() works fine in other controllers. I had to wrap it in a ionicView.enter scope. GA also updates about one day late for a new trackView so I should’ve been a bit more patient!