In my chrome extension instead of using any html pages, shadow DOM is being added from the background js pages.
It seems like no events are being pushed for analytics.
After adding the extension as shadow root the structure looks as follows
Now the chrome extension manifest.json looks like
"manifest_version": 2,
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
"background": {
"scripts": ["js/background.js"],
"persistent": true
},
and few other background files are loaded.
In background.js the main file where all the DOM elements added is loaded as follows
var mainJS = chrome.extension.getURL("js/chromewindow.js");
var rawFile = new XMLHttpRequest();
rawFile.open("GET", mainJS, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && (rawFile.status === 200 || rawFile.status === 0)) {
var text = rawFile.responseText;
chrome.tabs.executeScript(tab.id, {
code: text + ";onMyExtensionLoad('" + from + "');"
});
}
};
In chromewindow.js I added the usual analytics code as follows
var _gaq = _gaq || [];
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = 'https://ssl.google-analytics.com/u/ga_debug.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
I also include the following code to track the onclick events
function trackButton(e)
{
_gaq.push(['_trackEvent', e.target.id, 'clicked']);
console.log("Track event called");
};
When I execute this I could find that the ga_debug.js file being loaded. However I could not find any request like ___utm.gif as recommended.
There are no errors in the console too.
I wounder where I'm missing things. Kindly help.