<head> in the template every page uses: your base template or the theme’s head partial. Rebuild and deploy, and every page is tracked. Hugo pages are plain HTML files, so each page load is one pageview.
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
Find the template that renders head
Most themes render
<head> from a partial, often named head.html. Current Hugo keeps partials in layouts/_partials/; projects and themes built for older versions use layouts/partials/. Look in themes/<your theme>/layouts/ for the file that contains <head>.Do not edit the file inside themes/. Hugo uses a template from your project before a theme’s template with the same name, so copy the file to the same path under your project’s own layouts/ folder and edit the copy. Theme updates then leave your change in place.2
Paste the tag inside head
layouts/_partials/head.html
defer and do not add type="module": the script reads its options from its own tag.3
Build and deploy
Run
hugo and deploy the public/ folder as usual. hugo server runs on localhost, which the script ignores, so a local preview does not count. 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:layouts/_partials/head.html
data-404, mark your not-found page so it sends a 404 event: add <meta name="crispstats:404"> to the head of layouts/404.html. See 404 pages. Script attributes lists the rest.
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.
- View the page source of a built page in
public/and search forin.crispstats.com/d.js. If it is missing, Hugo is using a different template than the one you edited.
hugo server, add data-debug and localhost in data-domains while you develop. Every event is logged in the console and nothing is sent. See localhost and testing.
How page changes are counted
Every Hugo page is a full page load, so the script counts one pageview per page. Anchor links within a page (#install) are not new pages. 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
For clicks, adddata-cs-event to the element in your template. No JavaScript is needed:
window.crispstats?.("newsletter signup"). See custom events and declarative events.
FAQ
Should I load the script only in production?
Should I load the script only in production?
It is not needed. The script ignores
localhost, 127.0.0.1 and file://, and data-domains keeps preview hosts on other domains out (subdomains of your domain still count). A production-only condition in the template works too if you prefer it.Does it work with a theme I do not control?
Does it work with a theme I do not control?
Yes. Copy the theme’s head partial into your project’s
layouts/ folder at the same path and add the tag there. Your copy wins over the theme’s.Next steps
Declarative events
Track clicks with attributes in your templates.
Outbound links and downloads
Count clicks to other sites and file downloads.
Proxy by host
Serve the script from your own domain.
Hugo details (the
layouts/_partials folder and project templates taking precedence over theme templates) checked against https://gohugo.io/templates/types/ and https://gohugo.io/templates/new-templatesystem-overview/ on 2026-11-23.