I've encountered a challenge with sending an event to Google Analytics from background.js, which is the background script of my Chrome extension.
This is the code snippet I added to 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);
})();
In addition, I attempted to send this event:
_gaq.push(['_trackEvent', 'event_send', 'event_label');
However, despite these actions, I cannot view the event on the Analytics dashboard. I've also included the following line in my manifest.json
file:
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
What steps should I take to successfully execute this from the background?