I'm trying to send an event to Google Analytics from background.js (the background script) of my chrome extension.
I put this code in my background.js file
var _gaq = _gaq || [];
_gaq.push(['_setAccount', _AnalyticsCode]);
_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';
ga.checkProtocolTask = null;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
and I try to send this event:
_gaq.push(['_trackEvent', 'event_send', 'event_label');
but Im not seeing the event on Analytics dashboard.
I also added to my manifest.json
file this line:
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
What do I need to do to make it work from the background?