Phonegap google分析不跟踪 [英] Phonegap google analytics not tracking at all

查看:170
本文介绍了Phonegap google分析不跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的main.js档案

  / * Google Analytics * / 
(function(){
var ga = document.createElement('script'); ga.type ='text / javascript'; ga.async = true;
ga.src =('https:'== document.location.protocol ?'https:// ssl':'http:// www')+
'.google-analytics.com / ga.js';
var s = document.getElementsByTagName('script') [0]; s.parentNode.insertBefore(ga,s);
})();
var _gaq = _gaq || [];

function _track(page){
try {
_gaq.push(['_ setAccount','UA-XXXXXXXX-X']); / *但是我的正确的一个* /
console.log('google analytics:'+ page);
if(page!=''){
_gaq.push(['_ trackPageview','Mobile:'+ page]);
} else {
_gaq.push(['_ trackPageview'],'Mobile');
}
} catch(err){
console.log(err);
}
}

所以任何时候我想跟踪我使用的任何页面:



_track('/ top-rated /');



我可以看到这个日志:



google analytics:/ top-rated / p>

但我无法在实时Google分析页中看到日志



顺便说一句, config.xml

 < access origin =。*/> 


解决方案

GA在设备中无法工作的原因是google analytics希望协议是HTTP或HTTPS,但是当你加载应用程序协议是file:///,因为你是从设备中打开一个文件在WebView。



在这种情况下,GA不允许Cookie存储&关闭。此外,还有一个名为analytics.js(也称为Universal Analytics)的新版本的ga.js,基本上是高级版本。您可以在这里找到版本之间的差异 - http://www.cardinalpath.com/which-version-of-google-analytics-is-right-for-you-determine-whether-you-should-upgrade-to -universal-analytics /



如果您要继续使用ga.js,可以使用 -

https://github.com/ggendre/GALocalStorage

这是一个解决文件的GitHub项目:///



如果您要使用通用Analytics(分析),则可以使用 -

http://www.blastam.com/blog/index.php/2013/07/ga-universal -analytics-phonegap-mobile-apps /

这是一份与Phonegap兼容的指南


This my main.js file

/* Google Analytics */
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + 
      '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
var _gaq = _gaq || [];

function _track(page){
    try {
        _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); /* But with my correct one */
        console.log('google analytics:' + page);
        if (page != '') {
            _gaq.push(['_trackPageview', 'Mobile: '+page]);
        } else {
            _gaq.push(['_trackPageview'],'Mobile');
        }
    } catch(err) {
        console.log(err);
    }
}

So Any time I want to track any page I use:

_track('/top-rated/');

And I can see this log:

google analytics: /top-rated/

But I can't see the log in the real time google analytics page

By the way I have in my config.xml

<access origin=".*"/>

解决方案

The reason why GA does not work in device is because google analytics expects the protocol to be HTTP or HTTPS, but when you load the app the protocol is file:/// since you are opening a file from the device in WebView.

In such a case GA does not allow cookies to be stored & shuts down. Also there is a new version of ga.js called analytics.js(also called Universal Analytics), which is basically an advanced version. You can find the difference between the versions here - http://www.cardinalpath.com/which-version-of-google-analytics-is-right-for-you-determine-whether-you-should-upgrade-to-universal-analytics/

If you would like to continue using ga.js then you can use this -
https://github.com/ggendre/GALocalStorage
It is a GitHub project which resolves the file:/// problem.

If you would like to use Universal Analytics then you can use this -
http://www.blastam.com/blog/index.php/2013/07/ga-universal-analytics-phonegap-mobile-apps/
It is a guide to make it compatible with Phonegap

这篇关于Phonegap google分析不跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆