> ## 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 a Hugo site

> Install CrispStats on a Hugo site by adding the script tag to the head partial or base template that every page uses, then rebuild and deploy.

To add CrispStats to a Hugo site, paste the script tag inside `<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**

```html layouts/_partials/head.html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script
  defer
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com"
  src="https://in.crispstats.com/d.js"
></script>
```

Replace the key and the domain with yours. Keep `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:

```html layouts/_partials/head.html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script
  defer
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com"
  data-outbound
  data-downloads
  data-404
  src="https://in.crispstats.com/d.js"
></script>
```

With `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](https://docs.crispstats.com/track/404-pages.md). [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md) lists the rest.

## 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.
* View the page source of a built page in `public/` and search for `in.crispstats.com/d.js`. If it is missing, Hugo is using a different template than the one you edited.

To see events on `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](https://docs.crispstats.com/tracking/localhost-and-testing.md#debug-mode).

## 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](https://docs.crispstats.com/tracking/single-page-apps.md).

## Send custom events

For clicks, add `data-cs-event` to the element in your template. No JavaScript is needed:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<a href="/signup" data-cs-event="signup click" data-cs-prop-place="header">Start free</a>
```

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

## FAQ

> [accordion] 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.

> [accordion] 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.

> [accordion] Does CrispStats need a cookie banner on my Hugo site?
>
> By default the script sets no cookie and stores nothing on the device. See [compliance](https://docs.crispstats.com/privacy/compliance.md) for the details you can give your visitors.

## Next steps

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

> [card] [Outbound links and downloads](https://docs.crispstats.com/track/outbound-links-and-downloads.md)
>
> Count clicks to other sites and file downloads.

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

> [!NOTE]
>
> Hugo details (the `layouts/_partials` folder and project templates taking precedence over theme templates) checked against [https://gohugo.io/templates/types/](https://gohugo.io/templates/types/) and [https://gohugo.io/templates/new-templatesystem-overview/](https://gohugo.io/templates/new-templatesystem-overview/) on 2026-11-23.


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