<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
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.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.jsloading fromin.crispstats.comand aPOSTtohttps://in.crispstats.com/ethat gets202. - 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 withhistory.pushState, those page changes are counted too. See single-page apps.
Send custom events
Adddata-cs-event to an element in a template, with optional data-cs-prop-* properties:
window.crispstats?.("newsletter signup"). See declarative events.
FAQ
Do I need an Eleventy plugin?
Do I need an Eleventy plugin?
No. One tag in your base layout is the whole install.
Can I keep the key in a data file?
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.Does the script slow my pages down?
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 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.