monkey blot
monkey blot

Reputation: 985

Google Analytics in Chrome Extension

On Google Analytics, I'm not seeing my custom tracking event from within my chrome extension.

My content script sends a message to the bg page like so:

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

My bg.js contains this:

  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. 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?

Upvotes: 3

Views: 2032

Answers (1)

Eduardo
Eduardo

Reputation: 22832

_trackEvent has a minimum of 2 required parametrs. Try replacing that for:

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

Upvotes: 7

Related Questions