Chrome 扩展程序中的 Google Analytics

Google Analytics in Chrome Extension

本文关键字:Google Analytics 扩展 程序 Chrome      更新时间:2023-09-26

在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每天都会收到新数据。它正在正确注册页面浏览量,但我在任何地方都没有看到我的自定义事件"报告"。我知道正在调用该函数,因为我在控制台中看到我的"到目前为止"。但是跟踪事件没有发送吗?

_trackEvent至少有

2 个必需的参数。尝试将其替换为:

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