I'm looking for a way to use google analytics with the mobile app. I'm under the impression that we can't use normal GA with the app, so I looked around and found this plugin. Moodle mobile actually has a reference to it in www/lib/ngCordova/dist/ng-cordova.js, which creates $cordovaGoogleAnalytics, a wrapper object for the plugin's real analytics object.
As per the instructions on the github and in ng-cordova.js, I ran cordova plugin add https://github.com/danwilson/google-analytics-plugin.git, which downloaded the plugin to plugins/cordova-plugin-google-analytics. Looking good.
I wasn't sure where to call GA for testing, so I plopped this in www/app.js:
angular.module('mm', ['ionic','ngCordova', bla bla bla])
.run(function($ionicPlatform, $cordovaGoogleAnalytics) {
$ionicPlatform.ready(function() {
$cordovaGoogleAnalytics.startTrackerWithId('UA-112316665-1')
.then(() => {
console.log('Google analytics is ready now');
//the component is ready and you can call any method here
$cordovaGoogleAnalytics.debugMode();
$cordovaGoogleAnalytics.setAllowIDFACollection(true);
})
.catch(e => console.log('Error starting GoogleAnalytics', e));
});
});
The
$cordovaGoogleAnalytics.startTrackerWithId() call runs, but it's just a
wrapper object, and it can't find the window.analytics object the
plugin is supposed to provide.
Is there something else I must do to initialize the cordova plugin? Does it simply not work with a browser? Looking through its repository lead me to believe it DOES work with Ionic 1.x. The repo instructions do mention an extra Ionic 2/Ionic Native plugin thing, but I don't think that's necessary? And I assume the Ionic 2 stuff wouldn't work with Moodle Mobile anyway.
If anyone has any experience or advice, even with cordova plugins in general, please share.