Skip to content

Frameworks

Hugo analytics with CrispStats

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.

Updated

Set up CrispStats on Hugo

  1. 01

    Step 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. 02

    Step 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). 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.

    # Copy the theme's head partial into your project, then edit the copymkdir -p layouts/_partialscp themes/<your-theme>/layouts/_partials/head.html layouts/_partials/head.html
  3. 03

    Step 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.

    Replace the highlighted values with your own.

    layouts/_partials/head.html
    <scriptdeferdata-site="cs_pk_your_site_key"data-domains="example.com"src="https://in.crispstats.com/d.js"></script>
  4. 04

    Step 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. 05

    Step 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
    <scriptdeferdata-site="cs_pk_your_site_key"data-domains="example.com"data-outbounddata-downloadsdata-404src="https://in.crispstats.com/d.js"></script>
  6. 06

    Step 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.

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

    Step 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").

    <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).

What the install check shows once the first events land, on the demo site, Quillbook, on generated traffic.
  • 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, 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 from real visits with data-vitals: LCP, INP and CLS at p75, by page, device and country.
  • Notes and limits

    • 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, which do not run JavaScript. Reporting them needs edge code on your host; see 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.
    • CrispStats publishes no Hugo module or theme component. The tag in your own partial is the whole install.

The docs page covers the optional steps this guide leaves out.

Setup questions. Straight answers.

What people ask before they connect it.

  • 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.

  • 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.

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

  • 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.

  • 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.

Not answered here? Write to hello@crispstats.com

Go further

Related

  • Web analytics for developers

    A small cookieless script with web vitals and error tracking, an npm SDK, a REST API and an MCP server, so your analytics fits the way you work.

  • Core Web Vitals in plain English

    What LCP, INP and CLS measure, the good and poor thresholds for each, why the 75th percentile matters, and the fixes that usually move them.

  • Cookieless analytics explained

    How cookieless analytics counts unique visitors with a daily rotating hash instead of a cookie, what it can and cannot tell you, and the trade-offs.

  • Track visitors from ChatGPT and Perplexity

    Visitors sent by ChatGPT, Perplexity and Claude, plus AI crawler hits.

  • Jekyll analytics

    Add CrispStats to a Jekyll site by pasting one script tag into the head include, overriding the theme's copy.

  • Docusaurus analytics

    Add CrispStats to a Docusaurus docs site with one entry in the scripts array of docusaurus.config.js.

Your traffic, crisp and clear

One script, no cookies, and every feature from the first day. Set up takes about as long as pasting a snippet.