PhoneGap application does not work with Google Analytics

I use analytics.js to track user activity using code in a web application.

Now the Phonegap ios / android application is built and also wants to track user activity in the Phonegap application, but it does not give the tracking results that I read and implemented the solutions, as in

Google Analytics phone statistics do not track at all

https://github.com/blast-analytics-marketing/phonegap-google-universal-analytics

My problem: in both the native and the web application, it uses the same set of pages, I would like to track the same pages under the same GA account using Dimension, but I cannot do this in case of a break in the phone.

Can 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); 
+5
source share
1 answer

Two days later, having found a solution on the Google Phone Phonegap page , this answer worked for me. thanks to the mayor, his answer

 (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 (by default it has // which tries to download the file: // which does not work)

  • use should disable the "repository" and add a clientId with which you can use the Cordova.uuid device

  • you must disable protocol checking (because the file: // does not work) by setting checkProtocolTask ​​to null

  • it only works with the new "universal" analytics. your GA account should be created as a "Website" and not a "Mobile Application"

+7
source

Source: https://habr.com/ru/post/1239062/


All Articles