DEV Community


Posted on • Originally published at on

Making Google Analytics work from your browser plugin

Google Analytics may not work as it is if you want to get it working from your browser plugin due to security limitations and protocol conflict. To resolve it, follow the steps explained below,


First step is to get your manifest file allow GA domain.

"content_security_policy": "script-src 'self'; object-src 'self'"

Installing GA

(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','','ga');ga('create', 'UA-YOUR_ID-1', 'DOMAIN_NAME');ga('set', 'checkProtocolTask', null);ga('send', 'pageview', 'user');

ga('set', 'checkProtocolTask', null); line is important as it makes GA ignore the protocol check. This was causing me a lot of trouble. See here Google Analytics

DOMAIN_NAME is also important, as GA can't detect that for your plugin. Set that to your domain name you want to track!


GA has a hidden gem, instead of just use which will print useful debug messages on the chrome console!


Refer Debugging

Top comments (0)