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
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/analytics.js','ga');
var ua="UA-XXXXXXX-Y";
ga('create', ua, {'storage': 'none','clientId': "123"});
ga('set', 'checkProtocolTask', null);
ga('set','checkStorageTask',null);
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./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./analytics.js','ga');
var ua="UA-XXXXXXX-Y";
ga('create', ua, {'storage': 'none','clientId': "123"});
ga('set', 'checkProtocolTask', null);
ga('set','checkStorageTask',null);
Share
Improve this question
edited May 23, 2017 at 12:33
CommunityBot
11 silver badge
asked Dec 23, 2015 at 14:39
Mohamed HussainMohamed Hussain
7,71315 gold badges60 silver badges87 bronze badges
5
- 2 Have you whitelisten the Google url? – Joerg Commented Dec 23, 2015 at 16:21
- 1 This plugin (github./danwilson/google-analytics-plugin) is specific for running GA in cordova mobile apps, maybe helps you. – jcarrera Commented Dec 23, 2015 at 23:19
- @jcarrera: it is using the mobile app property in my analytics account...i want to track under same property as web app since in app and web pages are same. I am differentiating the users from app using dimension. – Mohamed Hussain Commented Dec 24, 2015 at 6:58
- @Joerg: which url to whitelist and where it place? – Mohamed Hussain Commented Dec 24, 2015 at 6:59
- Sometimes docs are helping: cordova.apache/docs/en/dev/guide/appdev/whitelist/… read also the docs from the whitelist-plugin. – Joerg Commented Dec 24, 2015 at 7:23
2 Answers
Reset to default 10After 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./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. 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"
As far as I can tell, this has been explicitly disallowed in the more recent versions of Google Analytics. They say clearly in their docs now:
Use Analytics in a WebView on Android
Calls to log events or set user properties fired from within a WebView must be forwarded to native code before they can be sent to app reports in Google Analytics.
https://developers.google./analytics/devguides/collection/firebase/android/webview