Alright, I've been struggling to get _gaq.push to function properly for quite some time now.
Below is the code snippet I'm working with:
var ext_id = localStorage.ext_id;
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-xx']);
_gaq.push(['_trackPageview']);
//console.log(_gaq);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = chrome.extension.getURL('js/ga.js'); //uncomment this
//ga.src = "js/ga.js"
// ga.src = 'https://ssl.google-analytics.com/ga.js';
document.head.append(ga); // make it head
})();
chrome.runtime.onConnect.addListener(function(port) {
console.assert(port.name == "google-analytics");
port.onMessage.addListener(function(response) {
console.log("Message Passing with response",response.category,response.action, response);
_gaq.push(['_trackEvent', response.category, response.action,ext_id]);
console.log(_gaq, "sending this");
});
});
So, this code will be triggered if there's no activity on the payments page for more than 1 second. It is firing correctly after 1 second of inactivity on the payments page. However, _gaq.push is not leaving any trace in the network tab, and to add to the confusion, there are no errors being displayed either. Can anyone help me figure out what mistake I might be making?