Content Security Policy
View as MarkdownThe exact CSP directives the Reveata script needs, with the extras script, the queue snippet, the managed proxy and your own proxy, plus examples for common servers.
On this page
If your site sends a Content-Security-Policy header (or a <meta http-equiv="Content-Security-Policy"> tag), the browser only loads scripts and sends requests to the places it lists. When Reveata is missing from it, the script is blocked and no visits arrive. Your browser's console then shows an error such as Refused to load the script or Refused to connect.
The script needs two things:
script-src: the address the script is loaded from.connect-src: the address events are sent to. The script sends them withnavigator.sendBeacon, orfetchwhen beacons are not available, so they fall underconnect-src.
It loads nothing else: no images, frames, fonts, styles or eval.
The directives
| How you load Reveata | script-src |
connect-src |
|---|---|---|
| Standard snippet | https://reveata.com |
https://reveata.com |
Managed proxy on stats.example.com |
https://stats.example.com |
https://stats.example.com |
| Your own proxy on your domain | 'self' |
'self' |
Your own proxy for events only (data-api="/dt/event", script from Reveata) |
https://reveata.com |
'self' |
The opt-in extras script (/js/script.extras.js, for broken links, downloads, forms and web vitals) comes from the same address as the main script, so it needs nothing more. The cookieless build (/js/script.cookieless.js) is the same.
A minimal policy for the standard snippet:
Content-Security-Policy: default-src 'self'; script-src 'self' https://reveata.com; connect-src 'self' https://reveata.comKeep your other sources in those directives; add Reveata to them rather than replacing them.
The queue snippet
The snippet itself is an external script and needs no 'unsafe-inline'. Only the optional queue snippet, which lets you call reveata() before the script has loaded, is inline. Allow it in one of three ways:
Move it to a file you serve yourself, such as
/reveata-queue.js, loaded before the snippet.'self'then covers it.Use a nonce, the same one your server puts on its other inline scripts:
<script nonce="…">.Use a hash. For the queue snippet written exactly as this one line, with nothing before or after it inside the tag:
html<script>window.reveata=window.reveata||function(){(window.reveata.q=window.reveata.q||[]).push(arguments)};</script>add
'sha256-wKW6agP5neyn7PyV6CfoGNfeBjGGnzy8ovggEAXlE+c='toscript-src. Any other spacing or line breaks change the hash.
Next.js
Add Reveata to the policy you build in next.config.ts headers or in your middleware:
// next.config.ts
const csp = [
"default-src 'self'",
"script-src 'self' https://reveata.com",
"connect-src 'self' https://reveata.com",
].join('; ');
export default {
async headers() {
return [{ source: '/:path*', headers: [{ key: 'Content-Security-Policy', value: csp }] }];
},
};The <Reveata /> component from @reveata/next renders the queue snippet inline without a nonce. With a nonce-based policy, render the two scripts yourself with next/script and your nonce, using the helpers the package exports:
import Script from 'next/script';
import { headers } from 'next/headers';
import { QUEUE_STUB, scriptAttributes, scriptSrc } from '@reveata/next';
const options = { websiteId: 'ws_your_tracking_id', host: 'https://reveata.com' };
export async function Analytics() {
const nonce = (await headers()).get('x-nonce') ?? undefined;
return (
<>
<Script id="reveata-queue" nonce={nonce} strategy="afterInteractive">
{QUEUE_STUB}
</Script>
<Script
id="reveata"
nonce={nonce}
src={scriptSrc(options)}
strategy="afterInteractive"
{...scriptAttributes(options)}
/>
</>
);
}x-nonce is the request header your middleware sets when it generates the nonce, as in the Next.js CSP guide. With 'strict-dynamic' in script-src, scripts added by a nonced script are allowed without listing their host, but keep Reveata in connect-src.
Nginx
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://reveata.com; connect-src 'self' https://reveata.com" always;Apache
Header always set Content-Security-Policy "default-src 'self'; script-src 'self' https://reveata.com; connect-src 'self' https://reveata.com"Netlify
In netlify.toml:
[[headers]]
for = "/*"
[headers.values]
Content-Security-Policy = "default-src 'self'; script-src 'self' https://reveata.com; connect-src 'self' https://reveata.com"Vercel
In vercel.json:
{
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "Content-Security-Policy",
"value": "default-src 'self'; script-src 'self' https://reveata.com; connect-src 'self' https://reveata.com"
}
]
}
]
}A meta tag
Static hosts without header settings can put the policy in the page <head>, before any script:
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' https://reveata.com; connect-src 'self' https://reveata.com"
/>WordPress
WordPress sends no policy of its own. If a security plugin or your host adds one, add the Reveata address to its script-src and connect-src settings. With your own proxy, 'self' is enough.
Check it works
- Open your site with the browser's developer tools on the Console tab and reload. No Refused to load or Refused to connect message should mention Reveata or your proxy path.
- On the Network tab, the script request answers
200(or304) and each event request answers202. - Your visit appears in Realtime. If it still doesn't, see Why events don't show up.
While testing a new policy, you can send it as Content-Security-Policy-Report-Only first: the browser reports what it would block without blocking it.