I'm trying to track a chrome extension on Google Analytics.
It looks like it's configured correctly but I can't see the data on the dashboard. Not sure if it's a delay, if it's being ignored because I'm running the extension on development mode or if I need to configure something else.
I'm using the following code:
const gaScript = document.createElement('script');
gaScript.type = 'text/javascript';
gaScript.async = true;
gaScript.src = 'https://ssl.google-analytics.com/analytics.js';
gaScript.onload = function() {
ga.l = +new Date;
ga('create', 'MY_CODE', 'auto');
ga('set', 'checkProtocolTask', null); // Disables file protocol checking.
ga('send', 'pageview');
}
const s = document.getElementsByTagName('script')[0];
s.parentNode?.insertBefore(gaScript, s);
When I check the background console, on the tab "network" I can see:
But I still can't see ana logged data on the analytics dashboard. Any idea why is it happening?
Thanks to Michele I was able to understand the problem. Google created a new form of tracking: Global Analytics and the code is different from the standard Universal Analytics.
Whoever creates an analytics project today will get the Global Analytics by default. I studied it and I think the standard works better for extensions for now. I would wait Google update their documentation to include this case to start using it
Why not use explicit code:
// Standard Google Universal Analytics code
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-1', 'auto');
ga('set', 'checkProtocolTask', function(){});
ga('send', 'pageview', '/chrome-extension/popup.html');
I have tried it in my extension and it works fine.
Here is my complete working sample code: https://www.michelepisani.it/articoli/creare-un-estensione-di-chrome-e-tracciarla-con-google-analytics/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With