Has anyone successfully used the cordova google analytics plugin? Advice needed.

Re: Has anyone successfully used the cordova google analytics plugin? Advice needed.

by Grayson Bartlet -
Number of replies: 2

OK, so I've resolved this. The cordova plugin does indeed work, just not with a browser (despite the presence of a "browser" implementation in the plugin). Guess that's what the Ionic 2 plugin is for. I also needed to disable debugMode.

I found the easiest way to track views was to hook into the state transition event. I just shoved a GA trackView() call into this function at the bottom of core/components/sidemenu/services/sidemenu.js:

.run(function($rootScope, $mmSideMenu, $cordovaGoogleAnalytics) {
// Hide right side menu everytime we change state.
$rootScope.$on('$stateChangeStart', function(event, toState) {
// Check we're not loading split view contents.
if (toState.name.split('.').length == 2) {
$mmSideMenu.hideRightSideMenu();
}

//wrap in try/catch because running in browser throws an exception due to plugin not being loaded
try {
console.log("********* Tracking state change to " + toState.name);
$cordovaGoogleAnalytics.trackView(toState.name);
} catch (exception) {
console.log(exception.message);
}
});
});


This will track all states as GA screens. Keep in mind this won't track external links opened in the browser, and it won't be able to distinguish different courses or different sections of the same course, so you may want to manually add tracking code for those.

In reply to Grayson Bartlet

Re: Has anyone successfully used the cordova google analytics plugin? Advice needed.

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Grayson,

this is really interesting, maybe we could start supporting in the app (when you are logged to a site with Google Analytics enabled for the app).

Thanks for sharing, Juan

In reply to Juan Leyva

Re: Has anyone successfully used the cordova google analytics plugin? Advice needed.

by Grayson Bartlet -

Hi Juan,

Yeah, that would be pretty cool. Our organization certainly put a lot of value on having analytics for the app, and I suspect many others feel the same. Filtering the logs for webservice calls isn't quite enough. If you get to it after you guys upgrade Ionic versions, you could use the extra Ionic 2 plugin, which would be helpful.

One thing that would be interesting to explore would be unifying analytics across Moodle Mobile and Moodle web, using the GA setID function to track users by their moodle ID (GA would, of course, anonymize this). So you could follow users as they moved between the app and the website. But I've heard that if you give a website and a mobile app the same GA property (tracking code), some stuff can get messed up. And if you want to use different properties, you need a paid GA account to roll them up. Needs more research, but it would definitely be neat.