When a Content Security Policy blocks your analytics
A strict policy can stop an analytics script with no visible error on the page. Here is how to spot it and the two lines that fix it.
Ultanimus teamOn this page7 sections
What it looks like
You add the script tag, deploy, open your site and wait. The dashboard keeps saying it is waiting for the first event. The page looks fine and nothing on it is broken.
One of the first sites connected after launch did exactly this. The script sat in the layout, the site ID was right and the deploy had gone out. The site's Content Security Policy was blocking every request, and nothing on the page said so.
What the policy does
A Content Security Policy is a header, or a meta tag, that lists where a page may load scripts from and where it may send requests. The browser refuses anything that is not on the list. It is a good defence against injected scripts, so plenty of sites run one.
Two of its directives matter for analytics:
script-srcdecides where scripts can load from. Without the tracker's domain there, the browser never runs the script.connect-srcdecides where the page can send requests, beacons included. Without the domain there, the script loads and runs, and the browser blocks every event it sends.
The second case is the confusing one. The network tab shows the script loading, so the install looks finished.
The fix
Add the tracker's domain to both directives, next to the sources already listed:
script-src 'self' https://cdn.ultanimus.com
connect-src 'self' https://cdn.ultanimus.comLeave the rest of your policy as it is. If it has no script-src or connect-src, the browser uses default-src for both, so add the domain there instead.
Where to find your policy
- In Next.js, look in
headers()innext.config, or in the proxy file if it sets headers. - On Netlify and Cloudflare Pages, look in the
_headersfile. On Vercel, look invercel.jsontoo. - On your own server, look in the web server config, such as an
add_headerline in nginx. - Some sites set it in the page itself, in a
<meta http-equiv="Content-Security-Policy">tag.
Policies with a nonce
Some policies list no hosts at all. They give each script a nonce and add 'strict-dynamic'. Browsers that support 'strict-dynamic' ignore host entries in script-src, so adding our domain there changes nothing. Give the tracker's script tag the same nonce as your other scripts instead. connect-src still needs the domain.
How to check
Open the browser console on a page with the script. A blocked script shows an error that starts with "Refused to load the script", and a blocked event shows one that starts with "Refused to connect". Both name the directive to change.
What we changed
The install guide now has a section on this. The setup prompt we give AI coding agents tells them to find your policy and add the domain while they add the script, and to say whether they changed it.
If your install check has been waiting a while, open the console first.