Integrating GA in chrome extension, manifest v3

Viewed 1013

I need to integrate GA into my chrome extension, using manifest v3. it looks like I miss something, but I can't figure out what exactly I'm doing wrong.

My extension has only a content script and background.js where I'm listening on events, to execute content.js when the user clicks on the Icon, in the extension toolbar. Content script by himself injects widget UI into websites, where users can interact with. And I need to track click events.

And in terms of manifest v3 enter link description here, I need to use protect GA scripts like

    "content_security_policy": {
        "extension_pages": "script-src 'self' https://www.google-analytics.com/analytics.js"
    },

But when I try to refresh my extension on chrome://extansions page, it throwing me a popup with a failed status enter image description here

Maybe someone has any ideas on how to solve this problem?

2 Answers

I was able to do this by embedding the analytics.js file into my extension.

Then the ga function would be availabe in the window scope window.ga on the content scripts.

You are trying to use the analytics embedding documentation and request a script at "https://www.google-analytics.com/analytics.js ". But according to this document, for extensions you should use the following version: "https://ssl.google-analytics.com/ga.js". (and update manifest accordingly)

In the given document you can find more detailed information on the implementation of Google analytics in the extension: https://developer.chrome.com/docs/extensions/mv3/tut_analytics/

Important clarification: Even if you correct everything according to this official documentation, you will probably get a manifest filling error. I have not found a solution to this problem and, in general, it seems that it is impossible to connect Google analytics to the extension with version 3 of the manifest (this is inaccurate)

Related