Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Content Security Policy blocking scripts: how to find and fix it

PRF-125High impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

A Content Security Policy is a security rule your server sends in an HTTP header called Content-Security-Policy (or in a <meta http-equiv> tag). It lists the places the browser is allowed to load scripts, styles, frames, images and network calls from. Anything not on the list is blocked.

Typical console errortext
Refused to load the script 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXX' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Why it costs you leads or sales

A blocked script is a silent failure. Depending on what is blocked, you can lose different things:

What a blocked source can break
Blocked itemCSP directive usually involvedWhat you lose
Google Tag Manager or a pixel scriptscript-srcConversions and audiences stop reaching GA4, Google Ads, Meta and others
Tracking hit (the request a tag sends)connect-src or img-srcThe tag loads but its data never arrives
Form, booking or chat embedframe-srcVisitors see an empty box instead of the form
Inline script or inline event handlerscript-src without nonce or hashButtons or form logic stop working
Payment or captcha widgetscript-src and frame-srcCheckout cannot be completed

If tracking is blocked, your ad platforms get no conversion data and bidding gets worse. If a form or checkout is blocked, you lose the lead or sale directly.

Where a CSP block breaks the funnel
  1. Ad clickVisitor lands on the page
  2. Page loadsHTML and CSP header arrive
  3. Script blocked by CSPTag, form or widget refused
  4. Conversion trackedNo hit sent
  5. Lead or saleMay fail if the form is blocked

The page loads, but the blocked tag or form never runs, so everything after it is lost.

A tag that never fires

The browser reads the policy, refuses the script and the tag never sends its hit.

How to check if your site has it

Check for CSP blocks by hand
  1. Open the page in Chrome

    Use a private window so extensions do not interfere. Open the page where the form, tag or widget should work.

  2. Open DevTools and the Console

    Press F12 (or Cmd+Option+I on Mac) and select Console. Reload the page. Look for red messages that start with 'Refused to load', 'Refused to connect', 'Refused to frame' or 'Refused to execute inline script'.

  3. Read the blocked source and directive

    The message names the blocked URL and the directive that blocked it, for example script-src or frame-src. Note both.

  4. Read your current policy

    In DevTools open Network, click the page request (the first one), and look under Response Headers for Content-Security-Policy. Also search the HTML for a meta tag with http-equiv='Content-Security-Policy'.

  5. Walk the whole funnel

    Repeat on every step: landing page, form, thank-you page, checkout. Policies can differ by page or path.

How to fix it

The fix is to add only the exact source you need to the correct directive. Do not remove the policy or add * or 'unsafe-inline' as a shortcut. That weakens the protection the policy exists to give you.

Which directive to change
Console message saysAdd the source to
Refused to load the scriptscript-src (or script-src-elem)
Refused to connectconnect-src
Refused to frameframe-src
Refused to load the imageimg-src
Refused to execute inline scriptUse a nonce or hash in script-src, or move the code to a file
Example: allowing Google Tag Manager and Google Analyticstext
Content-Security-Policy: default-src 'self'; script-src 'self' https://www.googletagmanager.com; connect-src 'self' https://www.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com; img-src 'self' data: https://www.google-analytics.com https://www.googletagmanager.com; frame-src 'self' https://www.googletagmanager.com

Each tool needs its own domains. Take them from the console errors and from the vendor's own CSP documentation, not from a guess. Where you must run inline code, use a nonce: a random value your server generates per page load and puts in both the header and the script tag.

Inline script allowed with a noncehtml
<!-- Header: Content-Security-Policy: script-src 'self' 'nonce-r4nd0mValue' -->
<script nonce="r4nd0mValue">
  window.dataLayer = window.dataLayer || [];
</script>
Where to change the policy on each platform
  1. Find the source of the header

    Check security or headers plugins (for example a plugin with an HTTP headers or CSP setting), your host's dashboard and the .htaccess file. The setting depends on which one you use.

  2. Add the blocked source

    Add the domain to the matching directive and save. Clear any page or CDN cache afterwards.

nginx: test a new policy without enforcing itnginx
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' https://www.googletagmanager.com" always;
Policy before and after

Before

  • script-src allows only 'self'
  • GTM and pixel scripts refused
  • Console shows 'Refused to load the script'
  • Conversions missing in ad platforms

After

  • script-src, connect-src and frame-src list the exact vendor domains
  • Tags load and send their hits
  • Console is free of CSP errors
  • Conversions appear in reports

How to confirm it's fixed

Confirm checklist
  • Reload each funnel page with the Console open and see no 'Refused to...' messages
  • In the Network tab, the blocked scripts now return a normal status
  • GTM Preview or the platform's debug tool shows the tag firing
  • The form, chat or booking widget appears and works
  • A test conversion shows up in GA4 DebugView or the ad platform's test events
  • Retest in a private window and on mobile

How to prevent it happening again

Prevention habits
  • Before adding any new tag, widget or embed, list its domains and update the policy first
  • Roll out policy changes in report-only mode, then enforce
  • Keep the policy in version control so changes are reviewed
  • Re-check the console on every funnel step after a policy or theme change
  • Remove domains of tools you no longer use
  • Run scheduled checks of the live funnel so a new block is found quickly
How a CSP block unfolds (example)
  1. Day 1

    A developer tightens the CSP to improve security.

  2. Day 1

    The Meta Pixel domain is missing from the policy and is blocked.

  3. Day 5

    Reported conversions in the ad platform drop; nobody sees a visible error.

  4. Day 9

    Someone opens the console, finds the error and adds the domain.

How FunnelGuard handles this

FunnelGuard detects this issue only partly. It runs your real customer journeys with a robot visitor on a schedule and picks up console errors on the steps it visits. A CSP block writes a console error, so it can show up that way.

What FunnelGuard does not do is explain the policy. It does not tell you which CSP directive blocked the script, read your header or tell you which domain to add. A console error alone does not name the cause.

To cover the rest by hand: when an alert or a failed step points to a console error, open the page yourself, read the 'Refused to...' message and note the blocked URL and directive. Then compare it with the Content-Security-Policy header in DevTools, Network, Response Headers, and follow the fix steps above. FunnelGuard also checks the tracking hits sent to ad and analytics platforms, so a missing hit can confirm that a tag is not working, but you still need the console to find out why.

There is a Free plan (1 site, 2 journeys, daily checks, no card). Paid plans start at $39/month with a 3-day free trial.

Questions people ask

Why is my script blocked by Content Security Policy?

The browser blocks a script when its source is not on the allow list in your Content-Security-Policy, usually under script-src. The console message names the blocked URL and the directive. Add that exact source to the right directive and reload.

How do I fix 'Refused to load the script because it violates the following Content Security Policy directive'?

Open the console, copy the blocked URL and note the directive in the message. Add that domain to the same directive in your CSP header, for example script-src, then clear caches and reload. Test every funnel step afterwards.

Why is Google Tag Manager not loading on my site?

One common cause is a CSP that does not allow https://www.googletagmanager.com in script-src. Check the console for a 'Refused to load' message. Tags inside GTM may need their own domains in script-src, connect-src and img-src.

How do I find out which CSP directive is blocking my tag?

The console error names it, for example script-src, connect-src or frame-src. You can also view the full policy in DevTools under Network, the page request, Response Headers. Match the blocked source type to the directive.

Is it safe to add unsafe-inline to my CSP?

It is not recommended. 'unsafe-inline' allows any inline script, which removes much of the protection a CSP gives. Use a nonce or hash for the specific inline scripts you need, or move the code into a hosted file.

How can I test a CSP change without breaking my site?

Use the Content-Security-Policy-Report-Only header. The browser logs what it would block but does not enforce it. When the console is clean on every funnel step, switch to the enforcing header.

Can a CSP block a form or checkout?

Yes. If the form is an embed, frame-src must allow its domain. If the form relies on a script or a network call, script-src and connect-src must allow them. A blocked form can show as an empty box or a button that does nothing.

Does FunnelGuard tell me which CSP rule is blocking my script?

No. FunnelGuard detects the console error on a funnel step, but it does not explain the CSP cause or name the directive. You read the 'Refused to...' message in the console and compare it with your policy header.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: console error; CSP not explained.

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.