谷歌分析在Chrome扩展中的应用

3
在Google Analytics中,我无法看到来自我的Chrome扩展程序的自定义跟踪事件。
我的内容脚本像这样向bg页面发送消息:
chrome.extension.sendRequest({message: "report"}, function(response) {});

我的 bg.js 包含以下内容:

  var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-57683948-1']);
_gaq.push(['_trackPageview']);
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = 'https://ssl.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();



function cEvent(){
    _gaq.push(['_trackEvent', 'reported']);
    console.log("got this far");
    }


chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
    console.log(sender.tab ?
                "from a content script:" + sender.tab.url :
                "from the extension");
    if (request.message == "report")
    cEvent();
  });

自从 4 天前添加了这个代码以来,Google Analytics 每天都在接收新的数据。它正确地注册了页面浏览次数,但我却没有在任何地方看到我的自定义事件“已报告”。我知道该函数被调用了,因为我在控制台中看到了我的“已达到此处”。但是跟踪事件是否未被发送呢?

1个回答

7
_trackEvent 至少需要两个必要参数。尝试替换为以下内容:
_gaq.push(['_trackEvent', 'reported', 'reported']);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接