> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Allow CrispStats in your Content Security Policy

> Add https://in.crispstats.com to script-src and connect-src, or 'self' behind a proxy, so a Content Security Policy does not block the CrispStats script and events.

If your site sends a Content Security Policy, allow `https://in.crispstats.com` in two directives: `script-src`, so the browser loads `d.js`, and `connect-src`, so the script can send events to `/e`. Behind a [first-party proxy](https://docs.crispstats.com/tracking/proxy.md), both requests go to your own domain and `'self'` covers them. This page lists the entries for each setup and shows how to read the console error when something is still blocked.

## Entries for each setup

| Setup | `script-src` | `connect-src` |
| - | - | - |
| Standard script tag | `https://in.crispstats.com` | `https://in.crispstats.com` |
| Script through a proxy on your domain (`data-api="/k3x9qe"`) | `'self'` | `'self'` |
| [Live visitor badge](https://docs.crispstats.com/share/live-visitor-badge.md) | Allow its inline `<script>` (see [inline code](#inline-code)) | `https://in.crispstats.com` |

`connect-src` covers every request the script makes after it loads: events sent with `navigator.sendBeacon` or `fetch` to `/e`, and the visitor id that `crispstats.id()` fetches from `/id`. Optional modules such as `data-vitals` and `data-errors` send to the same `/e`, so they need nothing more. With `data-debug`, nothing is sent at all.

The badge always fetches from `https://in.crispstats.com`, even when the script goes through a proxy.

## Add the entries

Keep your existing sources and add the CrispStats origin to both directives. If your policy has no `script-src` or `connect-src`, the browser uses `default-src` for them, so add the two directives explicitly.

```http Header theme={"theme":{"light":"github-light","dark":"github-dark"}}
Content-Security-Policy: default-src 'self'; script-src 'self' https://in.crispstats.com; connect-src 'self' https://in.crispstats.com
```

```html Meta tag theme={"theme":{"light":"github-light","dark":"github-dark"}}
<meta
  http-equiv="Content-Security-Policy"
  content="default-src 'self'; script-src 'self' https://in.crispstats.com; connect-src 'self' https://in.crispstats.com"
/>
```

```nginx nginx theme={"theme":{"light":"github-light","dark":"github-dark"}}
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://in.crispstats.com; connect-src 'self' https://in.crispstats.com" always;
```

Behind a [proxy](https://docs.crispstats.com/tracking/proxy.md) that serves the script, events, `/id` and `/check` from a path on your own domain, `'self'` is already enough:

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
Content-Security-Policy: default-src 'self'; script-src 'self'; connect-src 'self'
```

If `data-api` points to a full URL on another of your domains, such as `https://stats.example.com`, allow that origin in `connect-src` instead. `crispstats.id()` falls back to `https://in.crispstats.com/id` when the proxy does not answer with a visitor id; with a one-rule proxy it always answers, so `'self'` is enough. On an older two-rule proxy, which forwards no `/id`, add `https://in.crispstats.com` to `connect-src` if you use `crispstats.id()`.

To try a policy without breaking anything, send it as `Content-Security-Policy-Report-Only` first. The browser then reports what it would block in the console and still loads everything.

## Inline code

Three snippets are inline `<script>` blocks rather than files:

* the queue stub that lets you call `crispstats()` before the script loads ([script attributes](https://docs.crispstats.com/tracking/script-attributes.md#call-the-global-before-the-script-loads)),
* the Google Tag Manager tag, a **Custom HTML** tag that creates the script element,
* the live visitor badge.

A policy without `'unsafe-inline'` in `script-src` blocks them. Allow them the way you allow your other inline scripts, for example with a nonce that your server generates for each response:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script nonce="RANDOM_PER_RESPONSE">
  if (typeof window.crispstats != "function") {
    var queue = [];
    var stub = function () { queue.push([].slice.call(arguments)); };
    stub.q = queue;
    ["identify", "revenue", "pageview"].forEach(function (method) {
      stub[method] = function () { queue.push(Object.assign([].slice.call(arguments), { m: method })); };
    });
    window.crispstats = stub;
  }
</script>
```

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
Content-Security-Policy: script-src 'self' 'nonce-RANDOM_PER_RESPONSE' https://in.crispstats.com; connect-src 'self' https://in.crispstats.com
```

The standard tag itself is not inline, because it has a `src`, so the origin entry is all it needs.

## Read the console error

When the policy blocks a request, the browser logs an error in the console that names the URL and the directive. In Chrome, a blocked script looks like this:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
Refused to load the script 'https://in.crispstats.com/d.js' because it violates the following Content Security Policy directive: "script-src 'self'".
```

And a blocked event looks like this:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
Refused to connect to 'https://in.crispstats.com/e' because it violates the following Content Security Policy directive: "connect-src 'self'".
```

Add the origin from the quoted URL to the directive the error names. If the error names `default-src`, your policy has no specific directive for that request type: add `script-src` or `connect-src` as shown above.

| What you see | What to change |
| - | - |
| `d.js` refused under `script-src` | Add `https://in.crispstats.com` to `script-src`. `window.crispstats.v` stays `undefined` until you do. |
| `/e` or `/id` refused under `connect-src` | Add `https://in.crispstats.com` to `connect-src`. The script loads, but no event reaches the collector. |
| An inline script refused under `script-src` | Add a nonce or hash for the stub, GTM tag or badge. |

## Other headers

* **Cross-origin isolation.** The collector serves `d.js` with `Cross-Origin-Resource-Policy: cross-origin`, so the script loads on pages that send `Cross-Origin-Embedder-Policy: require-corp`.
* **Subresource integrity.** Do not add an `integrity` attribute to the standard tag. The file at `https://in.crispstats.com/d.js` keeps its URL when the script is updated, so a fixed hash would stop matching and the browser would refuse the script. The same applies behind a proxy, which forwards the current file.

## Next steps

> [card] [Troubleshooting](https://docs.crispstats.com/help/troubleshooting.md)
>
> Other reasons the script loads but nothing arrives.

> [card] [Proxy](https://docs.crispstats.com/tracking/proxy.md)
>
> Serve the script and events from your own domain.

> [card] [Script builds](https://docs.crispstats.com/tracking/script-builds.md)
>
> d.js, d.core.js, caching and versions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.