> ## 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.

# Script files, builds and caching

> Which CrispStats script file is which (/d.js, /js/script.js, /p/*.js, d.core.js), the two event endpoints, and how the script is cached, versioned and kept from breaking your page.

There are two builds of the CrispStats script and several URLs that serve them. In short: `/d.js` is the script, with every optional module. `/d.core.js` is a smaller build without the optional modules. Every other script URL is one of those two under another name. Use `https://in.crispstats.com/d.js` unless you have a reason not to.

Events go to one of two places, and the tag decides which: `POST /e` on the standard tag, or `POST /p/e` behind a [proxy](https://docs.crispstats.com/tracking/proxy.md), which trusts the visitor address your proxy forwards. `POST /api/event` is the older proxy route. See [the two event endpoints](#the-two-event-endpoints).

## Which file is which

| URL on `in.crispstats.com` | Serves | Use it for |
| - | - | - |
| `/d.js` | The full build | The standard tag. |
| `/d.core.js` | The core build | The smallest file, when you need none of the optional modules. |
| `/js/script.js` | The full build, the same file as `/d.js` | Older proxy setups that forward `/stats/d.js` to it. Nothing new needs it. |
| `/p/d.js`, or `/p/<any name>.js` | The full build | Behind a [one-rule proxy](https://docs.crispstats.com/tracking/proxy.md): `/k3x9qe/d.js` on your site reaches `/p/d.js`. Any name made of letters, digits, `.`, `_` and `-` works, such as `/k3x9qe/app.js`. |
| `/p/d.core.js` | The core build | The core build behind a proxy. |

The same URL always serves the same build at its current version. There are no version numbers in the URLs.

| Build | Gzip | Brotli | Includes |
| - | - | - | - |
| Full (`d.js`) | about 3.8 KB | about 3.4 KB | Everything, with each optional module behind its attribute |
| Core (`d.core.js`) | about 2.2 KB | about 1.9 KB | Everything except the optional modules |

Use the full build unless you want the smallest file and none of the modules. A module that is not switched on does nothing until its attribute is on the tag.

### What d.core.js leaves out

The core build ignores these attributes:

| Attribute | Module |
| - | - |
| `data-outbound` | [Outbound link clicks](https://docs.crispstats.com/track/outbound-links-and-downloads.md) |
| `data-downloads` | [File downloads](https://docs.crispstats.com/track/outbound-links-and-downloads.md) |
| `data-vitals` | [Web vitals](https://docs.crispstats.com/health/web-vitals.md) |
| `data-errors` | [JavaScript errors](https://docs.crispstats.com/health/errors.md) |
| `data-404` | [404 pages](https://docs.crispstats.com/track/404-pages.md) |

Everything else works the same in both builds: pageviews, [single-page navigation](https://docs.crispstats.com/tracking/single-page-apps.md), engagement, custom and [declarative events](https://docs.crispstats.com/track/declarative-events.md), `crispstats.identify()`, `crispstats.revenue()`, `crispstats.pageview()`, `crispstats.id()`, and every other [attribute](https://docs.crispstats.com/tracking/script-attributes.md).

To use the core build, change the file name in `src`:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script
  defer
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com"
  src="https://in.crispstats.com/d.core.js"
></script>
```

## The two event endpoints

The script sends every event to `<data-api>/e`. Which collector route that reaches depends only on where `data-api` points:

| Route | Who calls it | Visitor address |
| - | - | - |
| `POST /e` | The script on the standard tag, and your [server](https://docs.crispstats.com/track/server-side-events.md) with a secret key. | The connecting address: the visitor's browser. |
| `POST /p/e` | The script behind a one-rule proxy (`data-api="/k3x9qe"`). | The first public address in `X-Forwarded-For`, set by your proxy. |
| `POST /api/event` | Older two-rule proxies that forward `/stats/e` to it. | The first `X-Forwarded-For` entry when it is a public address. |

All three take the same payload and give the same answers. `/e` ignores `X-Forwarded-For`, so nobody can change who a direct visit belongs to. The two proxy routes trust it, because there the connecting address is your server. You never choose between them in the script: the tag's `data-api` decides. See the [collector reference](https://docs.crispstats.com/api-reference/collector.md).

## Caching and versions

All the script URLs are served with the same headers:

| Header | Value | Effect |
| - | - | - |
| `Cache-Control` | `public, max-age=86400, stale-while-revalidate=604800` | Browsers and CDNs reuse the file for a day, then for up to seven more days while they check for a new version in the background. |
| `ETag` | The version and a hash of the file, such as `"0.1.0-…"` | A request with a matching `If-None-Match` gets an empty `304 Not Modified`. |
| `Cross-Origin-Resource-Policy` | `cross-origin` | The script loads on pages that send `Cross-Origin-Embedder-Policy: require-corp`. |
| `Access-Control-Allow-Origin` | `*` | The file can be fetched from any origin. |
| `Timing-Allow-Origin` | `*` | Your own performance tooling can read the script's load timings. |
| `X-Content-Type-Options` | `nosniff` | Served as `application/javascript; charset=utf-8` only. |

When a new version ships, the URL stays the same and the `ETag` changes. A browser with a cached copy uses it for up to a day, then fetches the new version in the background and uses it from the next page load. A browser without a copy gets the new version at once. Behind a proxy, the proxy passes `Cache-Control` and `ETag` through, so the same rules apply; the [Cloudflare Worker example](https://docs.crispstats.com/tracking/proxy.md) also keeps the file in your zone's cache for a day.

Do not add an `integrity` attribute to the tag: the file at the same URL changes with each release, and a fixed hash would then block it.

## Check the version

`crispstats.v` holds the version of the script running on the page:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats.v; // for example "0.1.0"
```

If it is `undefined`, the script has not loaded, or only the [queue stub](https://docs.crispstats.com/tracking/script-attributes.md#call-the-global-before-the-script-loads) is on the page. The [setup check](https://docs.crispstats.com/tracking/proxy.md#check-it-works) also returns the current version.

## Safe on your page

### It never throws

The whole script runs inside a `try` block, and every entry point, from event listeners to `crispstats()` and its methods, is wrapped so that an error inside the tracker is swallowed instead of reaching your code. Network failures are ignored too: events are sent with `navigator.sendBeacon`, or `fetch` with `keepalive` when the beacon is missing or refused, and the response is never read. `crispstats.id()` resolves to `undefined` rather than rejecting.

### Loading it twice is harmless

If the script runs a second time on the same page, for example because it is in both your layout and a tag manager, the second copy sees that `window.crispstats` already has a version and does nothing. You get one set of pageviews. A global that is not a function, such as an element with `id="crispstats"`, is replaced.

## Next steps

> [card] [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md)
>
> Every option the script reads, and the crispstats global.

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

> [card] [Data collected](https://docs.crispstats.com/privacy/data-collected.md)
>
> Exactly what each event contains.


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