来自 file://url 的 Google Analytics [英] Google Analytics from a file:// url

查看:26
本文介绍了来自 file://url 的 Google Analytics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 ajaxy 类型的基于 html 的应用程序框架,并希望谷歌分析能够使用它.而且我相信我们已经正确设置,可以在需要时手动调用 _trackPageview.

We have an ajaxy sort of html based app framework thing and want google analytics to work with it. And I believe we have set things up properly to manually call _trackPageview where needed.

然而,事情似乎没有得到报道.现在,要么我无法正常工作,要么使用 url 上的 file:// 协议从 javascript 进行 GA 跟踪默默地违反了一些我不知道的跨域策略.

However things don't seem to be getting reported. Now either I don't have it working right, or GA tracking from javascript with a file:// protocol on the url silently violates some cross domain policy I'm not aware of.

那么 GA 是否通过 file:// 处理本地 html?还是我的 GA 使用有问题?

So does GA work with local html via file://? Or is there something wrong with my GA usage?

请注意,我们使用的域实际上并不存在.我们想要使用类似移动应用跟踪的东西,但是来自 JavaScript 而不是本机库.为了做到这一点,它看起来你设置了一个假域,并告诉跟踪器它应该报告为哪个域.

Note that the domain we are using doesn't actually exist. We want to use something like the mobile app tracking but from JavaScript rather than a native library. And in order to do this, it looks you setup a fake domain, and tell the tracker what domain it should be reporting as.

在我的的末尾:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXACCOUNTID-XX']);
  _gaq.push(['_setDomainName', 'myfake.domain.com']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = 'http://www.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

在我们的 JS 框架中,我们调用:

And in our JS framework we call:

_gaq.push(['_trackPageview', '/some/path/here']);

推荐答案

Google 现在支持通过将其设置为 null 来禁用协议检查任务,允许您从 file:// url 跟踪分析:

Google now supports disabling the protocol check task by setting it to null, allowing you to track analytics from a file:// url:

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'checkProtocolTask', null); // Disable file protocol checking.
ga('set', 'checkStorageTask', null); // Disable cookie storage checking.
ga('set', 'historyImportTask', null); // Disable history checking (requires reading from cookies).
ga('send', 'pageview');

这篇关于来自 file://url 的 Google Analytics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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