I'm trying to get google analytics working with my PhoneGap/Cordova app.
By default, the analytics.js lib will not send requests from file:// type urls. I found from this site, and the StackOverflow question that it points to, that I can get the analytics lib to use local storage, rather than cookies, for keeping track of the client ID by configuring GA thusly:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','http://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-1', 'auto', {
'allowLinker': true,
'storage': 'none','clientId':localStorage.getItem('gaClientId')
});
ga(function(t){localStorage.setItem('gaClientId',t.get('clientId'));});
And then I can get the library to send requests from non-http/https urls by adding the following:
ga('set', 'checkProtocolTask', null);
Now I can see, from my browser console, that the library is sending page views out to google-analytics.com similar to the following:
http://www.google-analytics.com/collect?v=1&_v=j31&a=6458293880&t=pageview&_s=1&dl=file%3A%2F%2F%2Fpath%2Fto%2Findex.html&ul=en-us&de=ISO-8859-1&sd=24-bit&sr=1440x900&vp=1283x150&je=1&fl=16.0%20r0&_u=cGAAAAQB~&cid=389492833.14589283847&tid=UA-XXXXX-1&z=1277371227
However, on the google-analytics.com side, Google is ignoring that request once it receives it, and nothing shows up under my account. If I manually change the "dl=file..." part of the above URL to "dl=http...", then Google accepts it, and I immediately see the request under the "Real-Time" tab of my account.
So, it appears I've got the browser side of things set up correctly, but...
- how can I configure my google-analytics account to accept the requests the browser sends?
- Alternatively, is there a way to configure the browser side of things so that it sends "dl=http://..." rather than "dl=file://...", even though it's coming from a file:// URL?
(I think I might prefer an answer to #2 over #1, if I had to choose one answer.)
I know that there is a cordova plugin for google analytics, but I haven't had much luck getting that one to work, and, even if I got it to work, I need my app to be able to log to multiple google-analytics accounts at once, which I don't think the plugin to can do.