react-ga4 icon indicating copy to clipboard operation
react-ga4 copied to clipboard

how to set csp for using in chrome extension app?

Open blackwitch opened this issue 2 years ago • 3 comments

I got an error "Refused to load the script 'https://www.googletagmanager.com/gtag/js?id=G-....' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback."

I read about csp but I'm not sure what I do for solving this error.

I added csp rules like below in "manifest.json" file.

"host_permissions": [ "https://www.googletagmanager.com/*" ], "content_security_policy": { "extension_pages": "script-src 'self'; object-src 'self'; script-src-elem 'https://www.googletagmanager.com';" }

blackwitch avatar Feb 25 '23 15:02 blackwitch

Maybe this doc will help https://developers.google.com/tag-platform/tag-manager/web/csp

codler avatar Feb 25 '23 20:02 codler

react-ga4 is not working due to above error. Tried above doc.

gokulyc avatar Sep 03 '23 13:09 gokulyc

Here is an example: https://github.com/GoogleChrome/chrome-extensions-samples/blob/main/functional-samples/tutorial.google-analytics/README.md. It would be better if you could encapsulate a layer to support Chrome Extension.

scarqin avatar Apr 13 '24 11:04 scarqin