Skip to main content
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

_includes/base.njk
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.
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 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.

Send custom events

Add data-cs-event to an element in a template, with optional data-cs-prop-* properties:
From your own JavaScript, call window.crispstats?.("newsletter signup"). See declarative events.

FAQ

No. One tag in your base layout is the whole install.
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.
It loads with defer, after the HTML is parsed, and sends events in the background. See script builds for sizes.

Next steps

Declarative events

Track clicks with attributes in your templates.

Web vitals

Measure LCP, INP and CLS from real visits.

Proxy on Netlify

Serve the script from your own domain.
Eleventy details (layouts in _includes, the layout front matter key and {{ content | safe }}) checked against https://www.11ty.dev/docs/layouts/ on 2026-11-23.
Last modified on November 23, 2026