2

我制作了一个书签,我想使用 Google Analytics 来跟踪它的使用情况。我该怎么做?我发现 Remy Sharp 的一篇旧帖子可以满足我的需求,但我不确定它是否过时。http://remysharp.com/2009/02/27/analytics-for-bookmarklets-injected-scripts/

4

2 回答 2

1

您可能需要更新脚本以指向 GA 最新的请求 URL 格式,但原则上还是可以的。

于 2013-03-17T02:19:32.047 回答
0

我最终做了以下事情

(function() {
 //loading ga.js - not greatest idea, but can't rely on page having ga.js already
    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);

 //made a "cool_name" to be able to sort in GA and added domain URL/URI      
    var url = "/cool_name/" + location.host + location.pathname;

 //used "anotherGA" as a 'namespace' to not screw up the real GA for that domain
    _gaq.push(['anotherGA._setAccount', 'UA-XXXXXX-XX']);
    _gaq.push(['anotherGA._setDomainName']);//not sure if i need this
    _gaq.push(['anotherGA._trackPageview', url]);
})();

请参阅:https ://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gaq (朝向页面底部)

老实说,我不知道这是否是一种反模式和对 API 的滥用,但它似乎有效。

于 2013-03-18T04:52:08.210 回答