Add analytics to Hugo with a 1.2 KB cookieless tag
To add analytics to Hugo, put one <script> tag inside <head> in your base template, layouts/baseof.html. Copy your theme's baseof.html into your own layouts/ folder first so a theme update can't wipe it, then paste the tag before </head>. For Simplytics that tag is ~1.2 KB gzipped and sets no visitor cookies.
Hugo builds plain static HTML with a full page load on every click, so one tag in <head> counts every view. There is no route-change code to write.
Where does the analytics tag go in Hugo?
This is the tag, with your site key in data-key:
<script async src="https://simplytics.dev/track.js" data-key="YOUR_KEY"></script>
YOUR_KEY is the public site key from your dashboard, so it is safe to commit.
Hugo has no plugin system, and its one built-in analytics template ({{ partial "google_analytics.html" . }}) is Google-only. So the tag goes straight into the <head> your theme renders. Three ways to get it there:
| Method | Works with | Survives theme updates? |
|---|---|---|
Copy baseof.html into your layouts/ |
Any theme | Yes |
| Theme's custom-head partial or config key | Themes that offer one | Yes |
| Edit the theme's own files | Any theme | No — an update overwrites them |
The method that works with any theme
Your project's layouts/ overrides the theme's, file for file, so a copy in your project always wins:
- Find your theme's base template at
themes/<theme>/layouts/baseof.html. - Copy it to
layouts/baseof.htmlin your project root. - Paste the Simplytics tag on its own line just before
</head>. - Run
hugo, or restarthugo server, and reload.
Hugo 0.146 reorganised the layouts folder: the base template is now layouts/baseof.html and partials live in layouts/_partials/. Before 0.146 these were layouts/_default/baseof.html and layouts/partials/ — Hugo still maps the old names, but lists moving them as a required migration, so use the new paths.
Do not just create layouts/_partials/head.html. If your theme already ships a head.html partial, your file replaces it wholesale and you lose the theme's title, styles and meta tags. Build a head partial from scratch only when your theme has none.
Many themes save you the copy: they read a custom-head partial or a config key for exactly this. Check your theme's docs for a "custom head", "extra head" or "analytics" setting first — it survives updates and is less to maintain.
How do I keep my own visits out of the numbers?
Use either:
Ship the tag only in production builds.
hugo serverruns in the development environment; a plainhugobuild runs in production. Wrap the tag so it never loads while you work:{{ if hugo.IsProduction }} <script async src="https://simplytics.dev/track.js" data-key="YOUR_KEY"></script> {{ end }}Switch off your own browser. On your live site, run
localStorage.simplytics_ignore = '1'in the DevTools console. The tag then sends nothing from that browser on that site. Simplytics stores no raw IP and sets no cookie, so there is no "exclude me" switch in the dashboard.
How do I check the first hit?
- Deploy, then open a page on your live site. Views from
localhostorhugo serverare refused, because the hostname has to match a site on your account. - In DevTools, open Network and filter for
track. You should see aPOSTtohttps://simplytics.dev/trackthat returns{"status":"success"}. - View the page source and confirm the
track.jstag is inside<head>. - Open your dashboard. The site shows as verified once a valid hit arrives. On a new account, that first view starts the 30-day free trial, no card needed.
Nothing in Network? If your site sends a Content-Security-Policy, add https://simplytics.dev to both script-src and connect-src. Brave and DuckDuckGo send Global Privacy Control by default, so the tag sends nothing in those browsers and your own test can look like a broken install.
When another tool fits better
- You want per-visitor journeys or city-level data. Simplytics counts page views and reports countries, not cities, and keeps no long-lived visitor identifier. GA4 or Matomo fit better.
- You need e-commerce revenue or conversion values. Simplytics does not record purchase amounts.
- You already report on Hugo's built-in Google Analytics template. If GA4's data is what your team uses, keep it.
Simplytics is cookieless like Plausible and Fathom. It differs on price — $1/month, billed yearly ($12/year for unlimited sites and pageviews, with a 30-day trial and no card), against Plausible's $9/month — on a primary analytics database in Warsaw, and on raw rows deleted nightly with no scheduled expiry for the daily totals you keep. Compare Simplytics vs Plausible, try the demo, or see pricing.
Installing elsewhere? See Astro and WordPress without a plugin.
Hugo behaviour verified against Hugo 0.169.0. Last verified: 2026-10-28.