Google Analytics is blocked by CSP policy

AI-generated summary

The user petepan23 is having trouble setting up Google Analytics, as the tracking code is blocked by the Content Security Policy (CSP). They tried adding https://www.google-analytics.com to the CSP script src, but it didn’t work. Neil suggests that Firefox’s tracking protection or a similar plugin might be blocking the script Firefox’s content blocking. Petepan23 found that disabling CSP resolved the issue, but Stephen warns against disabling CSP, emphasizing site security over analytics convenience don’t disable CSP. Neil also references Google’s documentation, suggesting https://ssl.google-analytics.com should be added to the CSP, though petepan23 reports this still doesn’t work Google’s article.

Hi,

I try to set up Google Analytics but no luck.
Here is what I did:

  • ga universal tracking code: My analytics ID
  • ga universal domain name: mysite.com (without www)
  • content security policy script src: I added “https://www.google-analytics.com/”

But I still don’t receive any hits. When I check with GTmetric then the google analytics js is blocked

Am I missing something?

It’s blocked for me too on all websites thanks to Firefox’s content blocking. Are you using Firefox? Or some plugin that blocks ads and tracking?

It works for me now.

My solusion is UNCHECK the content security policy. This one is enable by default. Maybe some expert advice here?

The first piece of advice would be don’t disable CSP.

The security of your site is vastly more important than cutting corners implementing analytics correctly.

Google’s article for tag manager suggests you might need to add https://ssl.google-analytics.com for Analytics.

If I enable CSP and add this one, then still doesn’t work.