简体   繁体   English

Chrome扩展程序中的Google Analytics

[英]Google Analytics in Chrome Extension

On Google Analytics, I'm not seeing my custom tracking event from within my chrome extension. 在Google Analytics上,我没有在Chrome扩展程序中看到自定义跟踪事件。

My content script sends a message to the bg page like so: 我的内容脚本向bg页面发送消息,如下所示:

chrome.extension.sendRequest({message: "report"}, function(response) {});

My bg.js contains this: 我的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();
  });

Google Analytics has been receiving new data every day since adding this code 4 days ago. 自从4天前添加此代码以来,Google Analytics每天都在接收新数据。 It IS registering page views correctly, but I don't see my custom event "reported" anywhere. 它正确地注册了页面视图,但我没有看到我的自定义事件在任何地方“报告”。 I know the function is being called, because I see my "got this far" in the console. 我知道这个函数正在被调用,因为我在控制台中看到了“这么远”。 But is the track event not being sent? 但是赛道活动没有被发送?

_trackEvent has a minimum of 2 required parametrs. _trackEvent至少需要2个参数。 Try replacing that for: 尝试将其替换为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM