> ## 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 an Eleventy site

> Install CrispStats on an Eleventy (11ty) site by adding the script tag to the base layout in your _includes folder that every page uses.

To add CrispStats to an Eleventy site, paste the script tag inside `<head>` in the base layout your pages use, which Eleventy reads from the `_includes` folder by default. Rebuild and deploy, and every page that uses the layout is tracked.

You need your site's public key, which starts with `cs_pk_`. Find it in your site's settings under **Tracking code**, on the **HTML** tab. The key is safe to publish.

## Add the script

**1. Open your base layout**

Pages pick a layout with the `layout` key in their front matter, for example `layout: base.njk`, which Eleventy looks for at `_includes/base.njk`. Open the layout that contains `<head>`. If your layouts are chained, that is the outermost one.

**2. Paste the tag inside head**

```html _includes/base.njk theme={"theme":{"light":"github-light","dark":"github-dark"}}
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{{ title }}</title>
    <script
      defer
      data-site="cs_pk_xxxxxxxx"
      data-domains="example.com"
      src="https://in.crispstats.com/d.js"
    ></script>
  </head>
  <body>
    {{ content | safe }}
  </body>
</html>
```

Replace the key and the domain with yours. The tag is plain HTML, so it is the same in a Liquid, Nunjucks or HTML layout.

**3. Build and deploy**

Run your build (`npx @11ty/eleventy`) and deploy the output folder. The dev server runs on `localhost`, which the script ignores. Open your live site in a normal browser window.

> [!WARNING]
>
> A page that does not use the layout does not get the tag. Check that every page sets a `layout`, directly or through data shared with its folder.

## Turn on more tracking (optional)

Add attributes to the same tag. In HTML, a flag attribute is bare: `data-outbound`, `data-downloads`, `data-vitals`, `data-errors`, `data-404`. [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md) lists what each one sends.

## 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` that gets `202`.
* In CrispStats, **Settings**, **Tracking code** shows **Receiving events.**, and the visit appears in **Realtime** within seconds.
* Search the built HTML in your output folder for `in.crispstats.com/d.js`. Every page should have it once.

## How page changes are counted

Each Eleventy page is a full page load, so the script counts one pageview per page. If you add a client-side navigation library that swaps pages with `history.pushState`, those page changes are counted too. See [single-page apps](https://docs.crispstats.com/tracking/single-page-apps.md).

## Send custom events

Add `data-cs-event` to an element in a template, with optional `data-cs-prop-*` properties:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<button type="submit" data-cs-event="newsletter signup" data-cs-prop-form="footer">Subscribe</button>
```

From your own JavaScript, call `window.crispstats?.("newsletter signup")`. See [declarative events](https://docs.crispstats.com/track/declarative-events.md).

## FAQ

> [accordion] Do I need an Eleventy plugin?
>
> No. One tag in your base layout is the whole install.

> [accordion] Can I keep the key in a data file?
>
> Yes. Put it in a global data file such as `_data/site.json` and write `data-site="{{ site.crispstatsKey }}"` in the layout. The public key is safe to publish, so it does not need to be a secret.

> [accordion] Does the script slow my pages down?
>
> It loads with `defer`, after the HTML is parsed, and sends events in the background. See [script builds](https://docs.crispstats.com/tracking/script-builds.md) for sizes.

## Next steps

> [card] [Declarative events](https://docs.crispstats.com/track/declarative-events.md)
>
> Track clicks with attributes in your templates.

> [card] [Web vitals](https://docs.crispstats.com/health/web-vitals.md)
>
> Measure LCP, INP and CLS from real visits.

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

> [!NOTE]
>
> Eleventy details (layouts in `_includes`, the `layout` front matter key and `{{ content | safe }}`) checked against [https://www.11ty.dev/docs/layouts/](https://www.11ty.dev/docs/layouts/) on 2026-11-23.


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