I want to add google analytics with danwilson plugin. Can any one provide the working app.js code ??
Ionic 1 or Ionic 2/3?
For Ionic 1: http://ngcordova.com/docs/plugins/googleAnalytics/
For Ionic 2/3: https://ionicframework.com/docs/native/google-analytics/
@Sujan12 Can u guide how to get device name and os version to display it in ga dashboard in ionic 1
i am currently using :
$rootScope.$on(’$stateChangeSuccess’, function () {
if(typeof analytics !== undefined) {
analytics.startTrackerWithId(“UA-XXXXXXXXX-1”);
analytics.trackView($state.current.name);
} else {
console.log(“Google Analytics Unavailable”);
}
}); This works perfect but i want to get os info and device name info also.
Device name and OS Name automatically registers for me
What code u using? can u share @thesourav
window.ga.startTrackerWithId(‘UA-xxxxx’);
this did not help me , it doesnot display the device info in audience neither active users in audience
I can only see realtime view
You have to wait for some time and it will give those details under Audience Overview
can u share the whole code for google analytics. i am using:
$rootScope.$on(’$stateChangeSuccess’, function () {
if(typeof analytics !== undefined) {
analytics.startTrackerWithId(“UA-XXXXXXXX-1”);
analytics.trackView($state.current.name);
} else {
console.log(“Google Analytics Unavailable”);
}
});
@thesourav please help when i use $rootScope.$on(’$stateChangeSuccess’, function () {
if(typeof analytics !== undefined) {
analytics.startTrackerWithId(“UA-XXXXXXXX-1”);
analytics.trackView($state.current.name);
} else {
console.log(“Google Analytics Unavailable”);
}
});
It track each page in the app but this code doesnt show users in audience. when i only use :if(typeof analytics !== undefined) {
analytics.startTrackerWithId(“UA-XXXXXXXX-1”);
analytics.trackView($state.current.name);
} else {
console.log(“Google Analytics Unavailable”);
},
This shows but doesnt track each page
i use window.ga object according to the official page.
window.ga.trackView(‘Dashboard’);
Works for me.
Try uninstalling and reinstalling the plugin.
Update your cordova.
but the code i pasted gives each state and page detail , i reinstalled but did not work , but simply this works :if(typeof analytics !== undefined) {
analytics.startTrackerWithId(“UA-XXXXXXXX-1”);
analytics.trackView($state.current.name);
} else {
console.log(“Google Analytics Unavailable”);
},
But i cant get each screen details
Are you sure $state.current.name has valid value?
Just fill any static value in the same field and check
This gives tracking for each state . the only problem is this doesnt show the device info.