来自file:// url的Google Analytics(分析) [英] Google Analytics from a file:// url

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

问题描述

我们有一个基于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.

得到报告。现在要么我没有它的工作正确,或者GA跟踪从JavaScript与 file:// 协议在url默默地违反一些跨域政策我不知道。

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:// 或者我的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.

在我的< head> 结束时:

<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']);


推荐答案

结束通过iframe调整大小hack消息传递机制。

Ended up with a complex bounce through an iframe via the resize hack message passing mechanism.

本地文件在我们的服务器上包含一个iframe。当我们要跟踪GA调用时,我们使用我们需要的信息更改它的url哈希值: #_ trackEvent,foo,bar ,然后更改iframe的宽度。在iframe中, onresize()函数被触发,允许我们通过检查散列来提交GA调用。

Local file include an iframe on our server. When we want to track a GA call we changes it's url hash with the info we need #_trackEvent,foo,bar, and then change the width of the iframe. In the iframe the onresize() function gets triggered and allows us to submit GA calls by inspecting the hash.

尽管我讨厌这个黑客,它的工作完美无瑕!

As much as I hate this hack, it works flawlessly!

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

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