On this page
What this issue is
A Content Security Policy is a security header (or meta tag) your server sends with each page. It tells the browser which sources are allowed for scripts, images, network requests and more. It is meant to stop injected malicious code.
GA4 needs three things to be allowed. The page must load https://www.googletagmanager.com/gtag/js (script). The browser must send hits to https://www.google-analytics.com or regional endpoints (network request). Some hits also use image requests. If your policy lacks any of these, the browser blocks them and prints an error in the console. The page itself looks fine, so nobody notices.
Why it costs you leads or sales
When GA4 is blocked, sessions, page views and conversion events are not recorded. Reports undercount, or show nothing at all. Google Ads imports of GA4 conversions stop, so smart bidding loses its signal. You may pause campaigns that are working, or keep spending on ones you cannot measure.
Example: real visits stay the same, but GA4 records almost none once the policy blocks gtag.js.
- Visitor loads pageServer sends the CSP header
- Browser loads gtag.jsBlocked: googletagmanager.com not in script-src
- GA4 hit sentNever created
- Conversion in reportsMissing in GA4 and Google Ads
The page loads, but the browser refuses the Google script, so nothing downstream is recorded.
The browser stops the GA4 script before it can send anything.
How to check if your site has it
Open the page in Chrome
Use a key page such as the home page, a landing page or the thank-you page. Use a normal window with no ad blocker, so the block you see is the CSP and not an extension.
Open DevTools and the Console
Press F12 (or Cmd+Option+I on Mac) and open the Console tab. Reload the page.
Look for CSP errors
Search for messages like: Refused to load the script 'https://www.googletagmanager.com/gtag/js?id=G-XXXX' because it violates the following Content Security Policy directive. Or: Refused to connect to 'https://www.google-analytics.com/g/collect'.
Check the Network tab
Filter by
collect. A healthy GA4 setup shows requests togoogle-analytics.com/g/collect(or a regional variant) with status 200 or 204. A blocked one shows nothing, or a request marked blocked.Read your current policy
In the Network tab, click the page request and look under Response Headers for
content-security-policy. Also search the page source for a<meta http-equiv="Content-Security-Policy">tag.
How to fix it
The fix is to allow the Google domains GA4 uses. Add them to the existing directives. Do not replace your whole policy, and do not use a wildcard like * for everything, which defeats the purpose of a CSP.
| Directive | Add | Why |
|---|---|---|
| script-src | https://www.googletagmanager.com | Loads gtag.js |
| connect-src | https://www.google-analytics.com https://*.google-analytics.com https://*.analytics.google.com https://www.googletagmanager.com | Sends hits |
| img-src | https://www.google-analytics.com https://www.googletagmanager.com | Fallback image requests |
Content-Security-Policy: default-src 'self'; script-src 'self' https://www.googletagmanager.com; connect-src 'self' https://www.google-analytics.com https://*.google-analytics.com https://*.analytics.google.com https://www.googletagmanager.com; img-src 'self' data: https://www.google-analytics.com https://www.googletagmanager.com;Find where the header is set
Check security plugins with a CSP or HTTP headers setting, your host's control panel, the
.htaccessfile, and your theme's functions. The source depends on your setup.Add the Google domains
Add the domains from the table to
script-src,connect-srcandimg-src. Save and clear any page or CDN cache.
Use Google's official channel
Shopify controls storefront headers. Install GA4 through the Google & YouTube app or Customer events (Settings > Customer events) so tracking runs in Shopify's own sandbox rather than your theme code.
Check any custom proxy
If you serve the store through a CDN or proxy that adds its own CSP header, add the domains there.
Allow GTM and Google domains
Add
https://www.googletagmanager.comtoscript-src, and the GA4 domains toconnect-srcandimg-src. The CSP is set on your site, not inside GTM.Allow the other tags
Each tag in the container (Google Ads, Meta, and so on) needs its own domains allowed. Check the console after each addition.
Check for a proxy or CDN
Webflow hosting does not usually add a strict CSP on its own. If you use Cloudflare or another proxy in front, look in its header or transform rules.
Add the domains
Update the header rule with the Google domains.
Edit the server config
Update the
Content-Security-Policyheader in Nginx (add_header), Apache (Header set), your app framework or your CDN rules.Reload and test
Reload the server, clear caches and check the response header in DevTools.
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://www.googletagmanager.com; connect-src 'self' https://www.google-analytics.com https://*.google-analytics.com https://*.analytics.google.com https://www.googletagmanager.com; img-src 'self' data: https://www.google-analytics.com https://www.googletagmanager.com;" always;Blocked
- script-src lists only 'self'
- Console shows Refused to load gtag.js
- No collect requests in the Network tab
Allowed
- Google domains listed in the right directives
- Console is clear of CSP errors
- collect requests return 200 or 204
How to confirm it's fixed
- Hard reload the page with DevTools open and no CSP errors mention Google domains
- The Network tab shows a
collectrequest with status 200 or 204 - GA4 Admin > DebugView or Reports > Realtime shows your visit
- Test the key conversion: submit a test lead or reach the thank-you page and see the event
- Check the key pages, not only the home page, because policies can differ by path
How to prevent it happening again
- Start new policies in report-only mode and review violations before enforcing
- Keep a list of every marketing domain your tags need and store it with the policy
- Add a tracking check to your release process whenever headers, hosting, CDN or security plugins change
- Review the policy when you add a new tag such as an ad pixel
- Run an automated journey check on a schedule so a bad deploy is caught within a day
How FunnelGuard handles this
FunnelGuard detects this issue only partly. During a scheduled run, the robot visitor loads your funnel pages and looks for the expected GA4 hit. When that hit is missing and the browser console shows an error, FunnelGuard flags it and sends one alert with a screenshot and a likely cause, after a re-check from a second region.
Questions people ask
Why is my GA4 not tracking after I added a Content Security Policy?
The policy probably does not allow Google's domains. Without https://www.googletagmanager.com in script-src, the browser refuses to load gtag.js, and without the Google Analytics domains in connect-src, it refuses to send hits. Check the browser console for 'Refused to load' or 'Refused to connect' messages.
Which CSP directives does Google Analytics 4 need?
Allow https://www.googletagmanager.com in script-src. Allow https://www.google-analytics.com, https://*.google-analytics.com and https://*.analytics.google.com in connect-src. Add the Google domains to img-src too for fallback image requests.
How do I know if a CSP or an ad blocker is blocking GA4?
Test in a clean browser profile with extensions off and open the console. A CSP block prints a message that names the violated directive. An ad blocker usually shows requests as blocked by the client in the Network tab with no CSP message.
Does Google Tag Manager need a different CSP from gtag.js?
The domains are largely the same, but GTM also loads every other tag in your container, so each vendor's domains must be allowed too. The inline GTM snippet also needs a nonce or hash if you do not allow 'unsafe-inline'.
Can I use a wildcard to stop CSP breaking my tracking?
You can, but it removes the protection a CSP gives you. List the specific Google domains instead, and test in report-only mode first so you see violations before anything is blocked.
Why does the page look fine when GA4 is blocked by CSP?
Blocked tracking scripts do not change the visible page. The error only appears in the browser console, so the site works for visitors while your analytics stays empty.
Can FunnelGuard tell me my CSP is blocking GA4?
Partly. It flags a missing GA4 hit together with a console error and gives a likely cause with a screenshot. It does not analyse your policy directive by directive, so you still need to check the header by hand.
Related issues
- TRK-001GA4 tag missing from a funnel pageFix guide
- TRK-002GA4 tag missing site-wide after a theme or builder changeFix guide
- TRK-008gtag.js loaded but config command never calledFix guide
- TRK-010GA4 script loaded from a wrong or dead custom domainFix guide
- TRK-013GA4 missing on hosted checkout or booking domainFix guide
- TRK-003Wrong GA4 measurement ID (staging or another client's property)Fix guide