使用Google Analytics进行内容脚本跟踪 [英] Content Script tracking with Google Analytics

查看:319
本文介绍了使用Google Analytics进行内容脚本跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在致力于使用内容脚本修改某些网页的Google Chrome扩展程序。为了理解这些更改何时何地应用,我们正在研究谷歌分析,因为我们已经将其用于其他网络媒体资源。

I am working on a Google Chrome Extension that modifies certain pages with a content script. In order to understand when and where those changes are applied we were looking into google analytics since we use it for other web properties already.

我们通过清单文件包含ga.js库,并在我们对页面应用更改时触发_trackPageview同步页面调用。

We include the ga.js library via the manifest file, and trigger _trackPageview with a synchronous page call when we apply a change to a page.

var pageTracker = _gat._getTracker("UA-our-UA");    
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);    
pageTracker._trackPageview(window.location.href);

麻烦的是,不同域中的每个pageView都算作新的访问和访问者。它有办法规避这种情况吗?例如,它在浏览器中使用chrome扩展sqlite数据库或键值存储来存储唯一的用户ID和独立访问ID域。这可能吗?

Trouble here is that each pageView in a different domain counts as a new visit and visitor. Its there a way to circumvent that? For example it use a chrome extension sqlite database or key value store in the browser to store unique user id and visit id domain independent. Is this possible?

谢谢

Thanks

推荐答案

其他人网站内的代码。 Google Analytics(分析)配置有点敏感,如果网站有自定义实施,您可能会为该访问者打破它。

You should not execute that code inside other people sites. The Google Analytics configuration is somewhat sensitive and if a site has a custom implementation you might be breaking it for that visitor.

您应该在自己的后台页面中包含Google Analytics。然后,在每次需要跟踪事件时,从content_script返回到您的后台页面。

You should include Google Analytics in your own background page. And then communicate from the content_script back to your background page everytime you need to track an event.

通过在后台脚本中包含GA脚本非常好,因为您不需要干扰网站上的其他代码,并且始终在同一个域中执行,因此将使用不会导致重复访问/访问者的相同Cookie。

By including the GA script on your background script is nice because you don't interfere with other code on the website and it always execute from the same domain and thus will use the same cookies not causing duplicated visits/visitors.

以下是有关在您的后台页面上安装GA。

Here are more info on how to install GA on your background page.

http://code.google.com/chrome/extensions/tut_analytics.html

以下是将内容脚本中的信息传递给您的文档后台页面:

And here's the docs for passing information from Content Scripts to your background page:

http:/ /code.google.com/chrome/extensions/messaging.html

这篇关于使用Google Analytics进行内容脚本跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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