Clycyo
Frameworks4 min read

Hugo Analytics: A 1 KB Tracker for a Static Site

Static sites deserve static-weight analytics. Adding a cookieless tracker to Hugo via partials, with events for downloads and outbound links.

You built a Hugo site that compiles in milliseconds and serves static HTML weighing less than this paragraph's screenshot. The median analytics snippet would multiply your JavaScript payload by infinity (you currently ship none) and demand a consent banner besides. If analytics is joining a Hugo site, it should match the house style: static-friendly, tiny, no cookies.

Setup via a partial

Create the partial once:

{{/* layouts/partials/analytics.html */}}
{{ if hugo.IsProduction }}
<script
  defer
  src="https://clycyo.com/tracker.js"
  data-tracking-id="{{ .Site.Params.clycyoTrackingId }}"
></script>
{{ end }}

Reference it in your head partial, set clycyoTrackingId in hugo.toml, and the IsProduction guard keeps local development out of your data — the static-site version of excluding your own visits.

Events worth adding to a static site

Hugo sites are documentation, blogs, and project pages — their conversions are clicks, not carts. One small script in the same partial covers the usual suspects:

<script>
document.addEventListener('click', (e) => {
  const a = e.target.closest('a');
  if (!a) return;
  const href = a.getAttribute('href') || '';
  if (a.host && a.host !== location.host) {
    window.webanalytics?.track('outbound_click', { href });
  } else if (/\.(pdf|zip|tar\.gz|dmg|exe)$/i.test(href)) {
    window.webanalytics?.track('download', { file: href });
  }
});
</script>

That is outbound links and downloads in twelve lines — typically everything a Hugo site needs beyond pageviews.

What you can now answer

  • Which posts and docs pages earn traffic, from which referrers and search.
  • Whether readers click through to your GitHub, store page, or sponsor link — the site's real job, measured.
  • Real-user Web Vitals — which for a Hugo site is mostly an opportunity to gloat, but regressions from that one heavy shortcode will show up too.

The philosophical fit

Cookieless analytics is the only kind that belongs on a static site: no consent banner to bolt on, no state stored on readers' machines, 1.1 KB against your single-digit-KB pages. GoatCounter and friends play in this space too; the difference is what happens when you want events with properties, campaign attribution, and per-page performance on one record — the comparison logic in our tools roundup applies. For most Hugo sites, the free tier is permanent territory.