Skip to content
FunnelGuard

Fix guide by FunnelsGuard

GA4 blocked by Content Security Policy: how to find and fix it

TRK-009High impactPartlyBy FunnelGuardPublished Updated
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.

Recorded sessions before and after a CSP changeExample numbers
Recorded sessions before and after a CSP change (example)Real visits: 400 sessions per day; GA4 before CSP change: 380 sessions per day; GA4 after CSP change: 0 sessions per day01533074003800Real visitsGA4 before CSP changeGA4 after CSP changesessions per day

Example: real visits stay the same, but GA4 records almost none once the policy blocks gtag.js.

Where a CSP breaks the tracking chain
  1. Visitor loads pageServer sends the CSP header
  2. Browser loads gtag.jsBlocked: googletagmanager.com not in script-src
  3. GA4 hit sentNever created
  4. Conversion in reportsMissing in GA4 and Google Ads

The page loads, but the browser refuses the Google script, so nothing downstream is recorded.

A tag that never gets to fire

The browser stops the GA4 script before it can send anything.

How to check if your site has it

Check for a CSP block in your browser
  1. 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.

  2. Open DevTools and the Console

    Press F12 (or Cmd+Option+I on Mac) and open the Console tab. Reload the page.

  3. 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'.

  4. Check the Network tab

    Filter by collect. A healthy GA4 setup shows requests to google-analytics.com/g/collect (or a regional variant) with status 200 or 204. A blocked one shows nothing, or a request marked blocked.

  5. 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.

Directives and domains GA4 usually needs (gtag.js loaded directly)
DirectiveAddWhy
script-srchttps://www.googletagmanager.comLoads gtag.js
connect-srchttps://www.google-analytics.com https://*.google-analytics.com https://*.analytics.google.com https://www.googletagmanager.comSends hits
img-srchttps://www.google-analytics.com https://www.googletagmanager.comFallback image requests
Example CSP header with GA4 allowedtext
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;
Where to change the policy on your platform
  1. Find where the header is set

    Check security plugins with a CSP or HTTP headers setting, your host's control panel, the .htaccess file, and your theme's functions. The source depends on your setup.

  2. Add the Google domains

    Add the domains from the table to script-src, connect-src and img-src. Save and clear any page or CDN cache.

Nginx examplenginx
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;
Policy before and after

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

Confirmation checklist
  • Hard reload the page with DevTools open and no CSP errors mention Google domains
  • The Network tab shows a collect request 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

Prevention checklist
  • 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.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: missing hit + console error.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.