I am using the analytics.js to track the user activity using the code in web app.
Now Phonegap app ios/android is built and want to track the user activity in Phonegap app also, but it is not giving the tracking results I have read and implemented the solutions as in
Phonegap google analytics not tracking at all
https://github.com/blast-analytics-marketing/phonegap-google-universal-analytics
My Problem is: both in native using phonegap and web app uses same set of pages , I would like to track the same pages both under single GA account using Dimension, but I am not able to do in phone gap.
Could anyone help me on this. Thanks in advance for any help.
(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','//www.google-analytics.com/analytics.js','ga');
var ua="UA-XXXXXXX-Y";
ga('create', ua, {'storage': 'none','clientId': "123"});
ga('set', 'checkProtocolTask', null);
ga('set','checkStorageTask',null);
After Two days, Found solution from the Google Group Phonegap page , This answer worked for me. thanks Mayor, his answer is
(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','https://www.google-analytics.com/analytics.js','gaU');
gaU('create','UA-XXXXXXXX-X',{'storage':'none','clientId':device.uuid});
gaU('set','checkProtocolTask',null);
gaU('set','anonymizeIp',true);
gaU('set','forceSSL',true);
gaU('send','pageview',{'title':'I heart Cordova','page':'/cordova'});
gaU('send','event',{'eventCategory':'My_Category','eventAction':'My_Action','eventLabel':'Event_Label','eventValue':11});
notes:
you must set the url for google-analytics.com to use http or https (the default has // which tries to load file:// which does not work)
use must turn off 'storage' and add a clientId which you can use the Cordova device.uuid
you must disable protocol checking (because file:// does not work) by setting checkProtocolTask to null
this only works with the new "Universal" analytics. your GA account must be created as "Website" rather than "Mobile App"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With