Home › Blog · Tracking basics · 26 October 2026 · 6 min read

When a Content Security Policy blocks your tracking tag

A strict Content Security Policy can block a tracking tag without any visible error. Here is how to spot it in the console and how to fix it.

A Content Security Policy blocks your tracking tag when the tag's address is missing from the list of sources your site allows, and the browser then refuses to load the script or to let it send data. The fix is to add the tag's host to both the script-src and connect-src directives, or to serve the tag from your own domain.

What a Content Security Policy is

A Content Security Policy, or CSP, is a list of rules that a website sends to the browser with each page. The rules say where the page may load scripts, images, fonts and other resources from, and where it may send data. The browser enforces them and refuses anything that is not on the list.

The purpose is protection. If an attacker manages to inject a script into your page, a good policy stops the browser from running it or from sending stolen data to the attacker's server. Sites that handle payments or logins often have a strict policy, and some security plugins and hosting providers add one for you.

The policy usually arrives as a response header:

Content-Security-Policy: default-src 'self'; script-src 'self'; connect-src 'self'

Each part separated by a semicolon is a directive. The value 'self' means the site's own domain. This example says: load scripts only from this site, and send data only to this site.

The two directives that matter for a tag

A tracking tag does two things, and a different directive governs each.

DirectiveWhat it controlsWhat happens when the tag's host is missing
script-srcWhere scripts may be loaded fromThe tag file never loads. Nothing runs.
connect-srcWhere scripts may send requestsThe tag loads and runs, and its events never leave the browser.

If a policy has no script-src or connect-src of its own, the browser falls back to default-src for that type of resource.

Two related details are useful to know. Some tags send data by requesting a tiny image, and those requests fall under img-src. And a strict policy also blocks inline scripts, which are scripts written directly into the page, unless the policy permits them with a nonce or a hash. A nonce is a one-time code that the server adds to both the policy and the script tag. A pasted snippet is an inline script, so it can be blocked before it even tries to load the tag file.

Why the failure is silent

When the browser blocks a tag, visitors see nothing unusual. The page looks right. The checkout works. The order arrives in your shop. The only sign is in the browser's developer console, which visitors never open and site owners rarely do.

The second case is the harder one to catch. When script-src allows the tag and connect-src does not, the tag is present on the page and appears to be installed. A quick look at the page source confirms it is there. It runs, it builds each event, and every request it tries to send is refused.

The usual way people find out is a dashboard showing no events, or an ad platform reporting no conversions for a campaign that is clearly selling.

How to diagnose it in the browser console

  1. Open your site in a desktop browser.
  2. Open the developer tools. In most browsers the key is F12, or you can right-click the page and choose Inspect.
  3. Select the Console tab and reload the page.
  4. Look for messages in red that mention Content Security Policy.

A blocked script produces a message like this one. The exact wording varies between browsers.

Refused to load the script 'https://tags.example.net/tag.js' because it violates
the following Content Security Policy directive: "script-src 'self'".

A blocked request produces a message like this:

Refused to connect to 'https://collect.example.net/event' because it violates
the following Content Security Policy directive: "connect-src 'self'".

The message names the address that was refused and the directive that refused it. Those two pieces of information are all you need for the fix.

Then repeat the check on the pages that matter most. Add a product to the cart, go through the checkout, and reach the thank-you page with the console open. Checkout pages sometimes carry a stricter policy than the rest of the site, so a tag can work on the home page and fail exactly where the purchase happens.

To read the policy itself, open the Network tab, reload, click the first request in the list, which is the page, and look for Content-Security-Policy among the response headers. Some sites set the policy in a meta tag in the page's head instead.

Fix one: add the host to both directives

Add the address the tag is loaded from to script-src, and the address it sends events to to connect-src. Sometimes these are the same host and sometimes they differ. The console messages tell you which is which.

Content-Security-Policy: default-src 'self';
  script-src 'self' https://tags.example.net;
  connect-src 'self' https://collect.example.net

A few points help this go smoothly:

  • Add both. Fixing script-src alone turns the first failure into the second one.
  • If your tag loads the ad platforms' own scripts in the browser, each of those platforms has hosts that need the same treatment. Their documentation lists them.
  • Find where the policy is set before you edit. It may live in your server configuration, your CDN, a security plugin or your application code. If two places set a policy, the browser applies both, and the stricter result wins.
  • Keep the policy tight. Add the specific hosts you need. Avoid wildcards such as *, which remove the protection the policy was written to give.
  • After the change, reload with the console open and confirm the red messages are gone and events arrive.

If you want to test a change safely, browsers also accept a Content-Security-Policy-Report-Only header. It reports what a policy would block without blocking it.

Fix two: serve the tag from your own domain

The other approach is to make the tag first-party. The script file is served from your site's own domain, and the tag sends its events to an address on your own domain, which then passes them on from the server.

To the browser, both the script and its requests now come under 'self'. A strict policy that only allows the site's own domain already allows them. You do not have to edit the policy at all, and it stays as strict as it was.

This approach has a second benefit. Requests to your own domain are less likely to be stopped by ad blockers, which work from lists of known third-party tracking addresses. It pairs naturally with server-side tracking, where the server forwards each event to the ad platforms.

It needs something on your server to do the serving and forwarding, which is why it is usually delivered by a plugin or a small piece of server code.

Where Tagbreeze fits

The Tagbreeze WordPress plugin can serve the tag from your site's own domain, which a strict Content Security Policy already allows. Tagbreeze also warns you by e-mail when a site stops sending events, so a policy change that blocks the tag does not go unnoticed for weeks.

In short

  • A Content Security Policy tells the browser which sources a page may load from and send to.
  • script-src can stop the tag from loading. connect-src can stop its events from leaving. Neither shows an error to visitors.
  • The browser console names the blocked address and the directive responsible. Check the checkout pages too.
  • Add the tag's hosts to both directives, or serve the tag from your own domain so the existing policy already covers it.

For more on other causes of lost events, see why ad platforms miss conversions.

Know what your ads really bring in.

It takes a few minutes. Nothing is changed on your site until you install the tag.

Add your site
Hands on a laptop beside parcels ready to ship