Chrome扩展程序中的Google Analytics

mon*_*lot 3 javascript google-analytics google-chrome-extension

在Google Analytics上,我没有在Chrome扩展程序中看到自定义跟踪事件.

我的内容脚本向bg页面发送消息,如下所示:

chrome.extension.sendRequest({message: "report"}, function(response) {});
Run Code Online (Sandbox Code Playgroud)

我的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();
  });
Run Code Online (Sandbox Code Playgroud)

自从4天前添加此代码以来,Google Analytics每天都在接收新数据.它正确地注册了页面视图,但我没有看到我的自定义事件在任何地方"报告".我知道这个函数正在被调用,因为我在控制台中看到了"这么远".但是赛道活动没有被发送?

Edu*_*rdo 7

_trackEvent至少需要2个参数.尝试将其替换为:

_gaq.push(['_trackEvent', 'reported', 'reported']);
Run Code Online (Sandbox Code Playgroud)