# Hugo analytics with CrispStats

Updated 2026-11-23

A Hugo site is tracked by one CrispStats script tag inside the head of the template every page uses, usually the theme's head partial copied into your own layouts folder. Rebuild and deploy, and every page is tracked: Hugo pages are plain HTML, so each page load is one pageview.

## Steps

### 1. Find the template that renders head

Most themes render `<head>` from a partial, often `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>`.

### 2. Copy it into your project instead of editing the theme

Hugo uses a template from your project before a theme's template with the same name (see [Hugo's template system](https://gohugo.io/templates/new-templatesystem-overview/)). Copy the file to the same path under your project's own `layouts/` folder, so theme updates leave your change in place. Use `partials` instead of `_partials` if that is what your theme uses.

```bash
# Copy the theme's head partial into your project, then edit the copy
mkdir -p layouts/_partials
cp themes/<your-theme>/layouts/_partials/head.html layouts/_partials/head.html
```

### 3. Paste the tag inside head

Copy the tag from **Settings**, **Tracking code**, **HTML** in the CrispStats dashboard, with your public key and domain filled in. Keep `defer` and do not add `type="module"`: the script reads its options from its own tag.

`layouts/_partials/head.html`

```html
<script
  defer
  data-site="cs_pk_your_site_key"
  data-domains="example.com"
  src="https://in.crispstats.com/d.js"
></script>
```

### 4. Build and deploy

Run `hugo` and deploy the `public/` folder as usual, or push to the branch your host builds from. Then open your live site in a normal browser window. `hugo server` runs on `localhost`, which the script ignores on purpose.

### 5. Turn on more tracking (optional)

Add attributes to the same tag. In HTML a flag attribute is bare: `data-outbound` counts clicks to other sites, `data-downloads` counts file downloads and `data-404` sends a `404` event from your not-found page.

`layouts/_partials/head.html`

```html
<script
  defer
  data-site="cs_pk_your_site_key"
  data-domains="example.com"
  data-outbound
  data-downloads
  data-404
  src="https://in.crispstats.com/d.js"
></script>
```

### 6. Mark the not-found page (with data-404)

Add the marker to the head of your 404 template, so broken links into the site show up as `404` events with the path that failed. See [404 pages](/docs/track/404-pages).

`layouts/404.html`

```html
<!-- In the <head> of layouts/404.html -->
<meta name="crispstats:404">
```

### 7. Count clicks from your templates (optional)

Add `data-cs-event` to an element, with properties from `data-cs-prop-` attributes. From your own JavaScript, call `window.crispstats?.("newsletter signup")`.

```html
<a href="/signup" data-cs-event="signup click" data-cs-prop-place="header">Start free</a>
```

## Check that it works

On your live site, the developer tools' **Network** tab shows `d.js` loading from `in.crispstats.com` and a `POST` to `/e` that gets `202`. In CrispStats, **Settings**, **Tracking code** shows **Receiving events.** and the visit appears on the **Realtime** screen within seconds. If nothing arrives, search a built page in `public/` for `in.crispstats.com/d.js`: if it is missing, Hugo is using a different template than the one you edited. To watch events on `hugo server`, add `data-debug` and `localhost` in `data-domains` while you develop; events are logged in the console and nothing is sent ([localhost and testing](/docs/tracking/localhost-and-testing)).

## What you get

- Pageviews, unique visitors and sessions for every page Hugo builds, with entry and exit pages.
- Sources and channels: search, social, newsletters tagged with [UTM parameters](/glossary/utm-parameters), and visits from AI assistants such as ChatGPT and Perplexity.
- Broken links into your site as `404` events with the path, once `data-404` and the marker are in place.
- A core script of about 2.2 KB gzipped, loaded with `defer`, so a fast static site stays fast. Every module together is about 3.8 KB.
- Optional [web vitals](/features/web-vitals) from real visits with `data-vitals`: LCP, INP and CLS at p75, by page, device and country.

## Notes for Hugo

- You do not need a production-only condition in the template. 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.
- 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.
- Hugo builds static files, so the script cannot see AI crawlers such as [GPTBot](/bots/gptbot), which do not run JavaScript. Reporting them needs edge code on your host; see [AI traffic](/features/ai-traffic).
- On a host that can run a forwarding rule (Netlify, Vercel, Cloudflare, nginx), serve the script from your own domain so fewer ad blockers stop it: see [the proxy guide](/docs/tracking/proxy).
- CrispStats publishes no Hugo module or theme component. The tag in your own partial is the whole install.

Full reference: [Hugo in the docs](https://docs.crispstats.com/install/hugo)

## Frequently asked questions

### Should I load the analytics script only in production on Hugo?

It is not needed. The script ignores localhost and file URLs, and data-domains drops visits on any hostname you did not list. A production-only condition in the template also works if you prefer it.

### Does it work with a Hugo 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 to your copy. Hugo uses your file instead of the theme's.

### Do I need a Hugo module or plugin?

No. One script tag in the template every page uses is the whole install, with nothing to update.

### Does it work with a multilingual Hugo site?

Yes. Each language has its own URLs, such as /fr/, so pages are reported separately, and one tag in the shared head template covers every language. If a language lives on its own domain, list that domain in data-domains too.

### What does it cost for a Hugo site?

Each page load is one pageview, so a Hugo site's events equal its pageviews unless you add custom events. Every account starts with a 14-day free trial with every feature and no card; then Starter is $5 a month for 250,000 events.

## Related

- [Web analytics for developers](/for/developers)
- [Core Web Vitals in plain English](/blog/core-web-vitals-plain-english)
- [Cookieless analytics explained](/blog/cookieless-analytics-explained)
- [Track visitors from ChatGPT and Perplexity](/features/ai-traffic)
- [Jekyll analytics](/integrations/jekyll)
- [Docusaurus analytics](/integrations/docusaurus)
