How do you integrate Universal Analytics in to Chrome Extensions?

There’s an issue for that on Google code: The solution is to pass analytics your own protocol check function or simply null for no checking, in an official way.

This has to come after ga('create', ...) :

ga('set', 'checkProtocolTask', null); // Disable file protocol checking.

So you don’t need to modify the original analytics.js script. Just include the standard tracking code snippet (dont’ forget to add the “https:” prefix) and add “https://www.google-analytics.com” to your Content Security Policy.

A note to ayal gelles’ solution:
It is not necessary to add chrome-extension://... to the Content Security Policy since it’s already included in the 'self' statement. Also, instead of loading the script via hardcoded URL you should use chrome.runtime.getURL("path/to/analytics.js"). This way you don’t need to know your extension’s ID, Chrome will fill it in for you.

Leave a Comment