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

# Add CrispStats to a Docusaurus site

> Install CrispStats on a Docusaurus docs site with one entry in the scripts array of docusaurus.config.js. Page changes in the browser are tracked for you.

To add CrispStats to a Docusaurus site, add one object to the `scripts` array in `docusaurus.config.js`. Docusaurus inserts it as a `<script>` tag in the `<head>` of every page, and page changes made in the browser are counted because the script watches the History API.

You need your site's public key, which starts with `cs_pk_`. Find it in your site's settings under **Tracking code**. The key is safe to publish. There is no Docusaurus plugin or npm package to install.

## Add the script

**1. Add an entry to scripts**

```js docusaurus.config.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
export default {
  // ...your existing config
  scripts: [
    {
      src: "https://in.crispstats.com/d.js",
      defer: true,
      "data-site": "cs_pk_xxxxxxxx",
      "data-domains": "example.com",
    },
  ],
};
```

Replace the key and the domain with yours. If your config uses `module.exports`, add the same `scripts` key there. Keep `defer: true`: Docusaurus notes that scripts added here block rendering otherwise.

**2. Turn on more tracking (optional)**

Each option is one more key. A flag takes an empty string, which switches it on:

```js docusaurus.config.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
scripts: [
  {
    src: "https://in.crispstats.com/d.js",
    defer: true,
    "data-site": "cs_pk_xxxxxxxx",
    "data-domains": "example.com",
    "data-outbound": "",
    "data-vitals": "",
  },
],
```

Do not set a flag to `true`. The tag would carry `data-outbound="true"`, and for `data-downloads` the script reads the value as a list of file extensions. Leave out `data-hash`: Docusaurus routes with real paths. [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md) lists every attribute.

**3. Build and deploy**

Run `npm run build` and deploy. `npm run start` serves on `localhost`, which the script ignores. Open your live docs in a normal browser window.

## Check that it works

* In your browser's developer tools, the **Network** tab shows `d.js` loading from `in.crispstats.com` and a `POST` to `https://in.crispstats.com/e` on the first load and on each page change. The collector answers `202`.
* In CrispStats, **Settings**, **Tracking code** shows **Receiving events.**, and the visit appears in **Realtime** within seconds.
* View the source of a built page in `build/` and search for `in.crispstats.com/d.js` to confirm the tag is in `<head>`.

## How page changes are counted

After the first load, moving between docs pages changes the URL with the History API. The script counts a pageview on every `pushState`, `replaceState` and back or forward navigation. The same URL twice in a row is one pageview, and clicking a heading anchor on the same page does not count: the fragment is dropped unless the tag has `data-hash`, which a Docusaurus site does not need. See [single-page apps](https://docs.crispstats.com/tracking/single-page-apps.md).

The **Pages** report then shows which docs are read most, and **Sources** shows where readers came from, including AI assistants. See [AI traffic](https://docs.crispstats.com/ai/ai-traffic.md).

## Send custom events

Track clicks in MDX with `data-cs-event`, with no JavaScript:

```mdx docs/intro.mdx theme={"theme":{"light":"github-light","dark":"github-dark"}}
<a href="https://example.com/signup" data-cs-event="docs signup click">Create an account</a>
```

From a React component in your site, call `window.crispstats?.("copy code", { page: "intro" })`. See [custom events](https://docs.crispstats.com/track/custom-events.md) and [declarative events](https://docs.crispstats.com/track/declarative-events.md).

## FAQ

> [accordion] Do I need a Docusaurus plugin?
>
> No. The `scripts` entry is the whole install.

> [accordion] Can I use headTags instead of scripts?
>
> `scripts` is the simpler choice for one script tag. `headTags` also inserts tags into `<head>`, so it works if your config already uses it.

> [accordion] Can I count readers who use ad blockers?
>
> Serve the script from your own domain with a forwarding rule on your host. See [proxy by host](https://docs.crispstats.com/tracking/proxy.md).

## Next steps

> [card] [AI traffic](https://docs.crispstats.com/ai/ai-traffic.md)
>
> See readers who arrive from ChatGPT, Perplexity and other assistants.

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

> [card] [404 pages](https://docs.crispstats.com/track/404-pages.md)
>
> Find broken links into your docs.

> [!NOTE]
>
> Docusaurus details (the `scripts` field, attribute maps, insertion into `<head>` and the render-blocking note) checked against [https://docusaurus.io/docs/api/docusaurus-config](https://docusaurus.io/docs/api/docusaurus-config) on 2026-11-23.


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