【问题标题】:Google Analytics in Chrome ExtensionChrome 扩展中的谷歌分析
【发布时间】:2012-06-18 23:05:47
【问题描述】:

在 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(分析)每天都在接收新数据。它正在正确注册页面视图,但我没有在任何地方看到我的自定义事件“报告”。我知道正在调用该函数,因为我在控制台中看到了我的“到此为止”。但是没有发送跟踪事件吗?

【问题讨论】:

    标签: javascript google-chrome-extension google-analytics


    【解决方案1】:

    _trackEvent 至少有 2 个必需参数。尝试将其替换为:

    _gaq.push(['_trackEvent', 'reported', 'reported']);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-06
      • 2022-12-14
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      相关资源
      最近更新 更多