Content Security Policy blocking Google Tag Manager
Why a strict Content Security Policy blocks Google Tag Manager and GA4, and how to configure nonces and domain whitelisting to restore your tracking.
A strict Content Security Policy protects your website from malicious scripts. It also stops Google Tag Manager from functioning. Your developer secures the checkout environment, and suddenly your analytics platform reports zero sales.
You might notice a few specific symptoms when this happens. The browser console fills with red text warning about blocked scripts and policy violations. Tag Assistant refuses to connect to the container on secure pages. Google Analytics stops receiving data entirely right at the point of purchase.
We map the exact domains and execution rules your tracking tags require to function correctly. We then provide your development team with the specific directives needed to adjust the policy safely. The result is a secure website that still measures your marketing performance accurately.
The mechanics of a strict security policy
Your server sends a Content Security Policy header to tell the browser which external resources are allowed to load. If a script is not explicitly permitted in this list, the browser blocks it immediately. This is an excellent feature for security because it prevents unauthorized code from executing on your site.
However, tag management systems are essentially designed to inject external code. Google Tag Manager needs to load its own core script from a Google server, execute inline scripts to track button clicks, and then pull in further scripts for Google Ads or Meta. A default strict policy blocks all of these actions by design.
If your policy lacks an unsafe-inline directive or a robust nonce validation system, Tag Manager cannot function. It requires explicit permission to act as the middleman for your marketing tags. Without that permission, the browser treats your tracking codes as a security threat and terminates them.
The commercial cost of blocked measurement
When the policy blocks the container, the commercial consequence is immediate and severe. Your dashboard gets a massive conversion drop. You get absolutely nothing from your reporting. The advertising campaigns continue to spend your budget, but the platforms lose the signal they need to optimise the bids effectively.
We evaluate the impact of this missing data across all your active marketing channels. A secure checkout is a non negotiable requirement for any commercial website. But a checkout that cannot report a successful purchase to your advertising platforms will steadily degrade your campaign performance over time. If your campaigns optimise towards failed tracking, you are paying to find more people who cannot be measured.
We follow the journey from the first click on an advert to the final purchase record in your system. We check what happens all the way through the tracking funnel. Then we fix the gaps so your reporting aligns with reality.
Quantifying the data loss from blocked tags
Consider a scenario where the main website allows tracking, but the checkout domain enforces a strict policy that blocks Tag Manager completely. The traffic arrives, but the final conversion is never recorded.
| Traffic source | Monthly ad spend | Clicks recorded | Actual sales | Dashboard reported sales | Unattributed gap |
|---|---|---|---|---|---|
| Search campaigns | £8000 | 3500 | 85 | 0 | 85 |
| Social campaigns | £4000 | 2200 | 40 | 0 | 40 |
| Organic search | £0 | 6000 | 55 | 0 | 55 |
| Direct traffic | £0 | 1800 | 25 | 0 | 25 |
| Total period impact | £12000 | 13500 | 205 | 0 | 205 |
The sales happened in reality, but the advertising platforms recorded zero return on investment. The bidding algorithm will react by assuming the traffic is worthless and will stop bidding on the keywords that actually drive revenue.
Diagnosing the specific policy blocks
When the tags fail to fire, we check the specific errors the browser throws in the developer console to understand exactly which directive is causing the problem.
| Browser console error | What is happening underneath | Required policy adjustment |
|---|---|---|
| Refused to load the script because it violates the script-src directive | The Tag Manager container domain is missing from the permitted list. | Add the specific Google Tag Manager domains to the script-src directive. |
| Refused to execute inline script because it violates the policy | A Custom HTML tag or standard event listener tried to run without permission. | Implement a nonce infrastructure or allow inline execution if strictly required. |
| Refused to connect to the URL because it violates connect-src | Google Analytics is blocked from sending the data payload back to its servers. | Add the relevant Google Analytics endpoints to the connect-src directive. |
| Refused to frame because an ancestor violates the frame-src policy | The Tag Manager preview mode iframe is blocked from loading on the page. | Adjust the frame-src directive to allow the Tag Manager domain during debugging. |
Adjusting the security policy correctly
We check whether a purchase is actually recorded correctly across all systems before we sign off on a tracking setup. To fix a Content Security Policy issue, we do not recommend simply turning off the security features. Instead, we define the exact permissions required for the tags to operate safely.
Google Tag Manager can work securely with a strict policy if it is configured to use a cryptographic nonce. The server generates a unique random number for every single page load. The server adds this nonce to the policy header, and Tag Manager is configured to pass this same nonce to any script it injects. The browser compares the two values. If they match perfectly, the script runs.
This setup requires precise coordination between the server configuration and the Tag Manager workspace. If a third party marketing tag tries to inject its own unverified inline script, the browser will still block it. We review every tag in the container to ensure it complies with the new rules.
When your dashboard says you have had a sale, there should be an actual sale. You can read more about how we audit these complex technical setups on our Google Tag Manager services page. For related infrastructure issues, see our guides on managing container weight and evaluating script deployment methods.
Frequently asked questions
Why does my Content Security Policy block Tag Manager?
Your server sends a policy header to tell the browser which external resources are allowed to load on the page. If the Google Tag Manager domain is not explicitly whitelisted in this header, the browser blocks the script for security reasons. This effectively stops all your marketing tags from firing.
What does the unsafe-inline directive do?
The unsafe-inline directive allows the browser to execute JavaScript written directly into the page HTML structure. Tag Manager relies heavily on inline scripts to track button clicks and form submissions accurately. Without this permission or a valid nonce configuration, these interaction tracking scripts will fail completely.
How do I fix blocked Google Analytics tracking?
You must add the specific Google Analytics domains to the connect-src directive in your server policy. This grants the browser permission to send the data payload back to the analytics servers. If this directive is missing, the tags might execute but the data will never arrive at its destination.
What is a nonce in Google Tag Manager?
A nonce is a unique and random string generated by your server for every single page load. You provide this string to Tag Manager, and it attaches the string to any scripts it injects into the page. The browser verifies the string against the policy header to confirm the script is trusted.
Can Custom HTML tags run under a strict policy?
Custom HTML tags can run, but they require the Tag Manager container to be configured with a nonce awareness feature enabled. Any third party script pasted into a Custom HTML tag must also comply with the domain whitelists defined in your server policy. If the script attempts to load unapproved external resources, it will still be blocked.