# Docusaurus analytics with CrispStats

Updated 2026-11-23

One object in the scripts array of docusaurus.config.js adds CrispStats to a Docusaurus site, followed by a deploy. Docusaurus puts it in the head of every page, and moving between docs pages is counted because the script watches the History API, so there is no plugin or npm package to install.

## Steps

### 1. Add an entry to scripts

Docusaurus turns each object in [`scripts`](https://docusaurus.io/docs/api/docusaurus-config) into a `<script>` tag in `<head>`, with every key as an attribute. Copy your public key (it starts with `cs_pk_`) from **Settings**, **Tracking code** in the CrispStats dashboard and set your domain. If your config uses `module.exports`, add the same `scripts` key there.

`docusaurus.config.js`

```js
export default {
  // ...your existing config
  scripts: [
    {
      src: "https://in.crispstats.com/d.js",
      defer: true,
      "data-site": "cs_pk_your_site_key",
      "data-domains": "example.com",
    },
  ],
};
```

### 2. Keep defer: true

Docusaurus notes that scripts added this way block rendering unless they are deferred. With `defer: true` the page renders first and the script runs after.

### 3. Turn on more tracking (optional)

Each option is one more key, and a flag takes an empty string. 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`, because Docusaurus routes with real paths.

`docusaurus.config.js`

```js
scripts: [
  {
    src: "https://in.crispstats.com/d.js",
    defer: true,
    "data-site": "cs_pk_your_site_key",
    "data-domains": "example.com",
    "data-outbound": "",
    "data-vitals": "",
  },
],
```

### 4. Build and deploy

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

### 5. Count clicks in MDX (optional)

Give a link or button a `data-cs-event` attribute, with no JavaScript. From a React component, call `window.crispstats?.("copy code", { page: "intro" })`.

`docs/intro.mdx`

```mdx
<a href="https://example.com/signup" data-cs-event="docs signup click">Create an account</a>
```

## Check that it works

On your live docs, the developer tools' **Network** tab shows `d.js` loading from `in.crispstats.com` and a `POST` to `/e` on the first load and again on each page change; the collector answers `202`. In CrispStats, **Settings**, **Tracking code** shows **Receiving events.** and the visit appears on the **Realtime** screen within seconds. To confirm the tag itself, search a built page in `build/` for `in.crispstats.com/d.js`.

## What you get

- The **Pages** report shows which docs are read most, from the first load and every page change after it.
- Sources and channels, including readers who arrive from AI assistants such as ChatGPT and Perplexity, as their own channel. See [AI traffic](/features/ai-traffic).
- [Entry pages](/glossary/entry-page), so you see which docs pages people land on from search and from assistants.
- Broken links into your docs as `404` events, once `data-404` is on and the not-found page is marked with a meta tag, a CSS selector or its 404 status ([404 pages](/docs/track/404-pages)).
- A core script of about 2.2 KB gzipped, with optional [web vitals](/features/web-vitals) and outbound link clicks.

## Notes for Docusaurus

- The script counts a pageview on every `pushState`, `replaceState` and back or forward navigation. The same URL twice in a row is one pageview.
- Clicking a heading anchor on the same page is not a new page: the fragment is dropped unless the tag has `data-hash`, which a Docusaurus site does not need.
- `headTags` also inserts tags into `<head>` and works if your config already uses it; `scripts` is the simpler choice for one script tag.
- Docs readers are often developers with ad blockers. Serve the script from your own domain with a forwarding rule on Vercel, Netlify, Cloudflare or nginx: see [the proxy guide](/docs/tracking/proxy).
- AI crawlers such as [GPTBot](/bots/gptbot) read your docs without running JavaScript, so the script never sees them. Reporting them needs edge code on your host.

Full reference: [Docusaurus in the docs](https://docs.crispstats.com/install/docusaurus)

## Frequently asked questions

### Do I need a Docusaurus plugin for analytics?

No. One entry in the scripts array of docusaurus.config.js is the whole install, with no package to keep updated.

### Does it count page changes inside a Docusaurus site?

Yes. Docusaurus changes the URL through the History API when a reader opens another page, and the script counts each new URL as one pageview.

### Can I see which docs pages AI assistants send readers to?

Yes. Visits referred by ChatGPT, Perplexity, Claude, Gemini, Copilot and others are their own channel, with the pages those readers land on.

### Do I need a cookie banner for analytics on my docs?

CrispStats sets no cookies and stores nothing on the reader's device by default, and it never stores IP addresses. Docusaurus keeps the reader's colour mode in localStorage, and a search or chat widget you add may store more, so check the whole site. This is not legal advice.

### What does it cost for a docs site?

Docs traffic is mostly pageviews, one event each. Every account starts with a 14-day free trial with every feature, AI assistant referrals included, and no card; then Starter is $5 a month for 250,000 events.

## Related

- [Web analytics for developers](/for/developers)
- [Track visitors from ChatGPT and Perplexity](/blog/track-ai-traffic-chatgpt-perplexity)
- [Bounce rate vs engagement](/blog/bounce-rate-vs-engagement)
- [Web analytics for SaaS products](/for/saas)
- [Hugo analytics](/integrations/hugo)
