GoatCounter (MIT-licensed, cookie-free, free under 100k pageviews/month on the hosted tier) is one <script> tag on any static site. On a Hugo site, the non-obvious bit is gating that script so dev-server pageviews don’t pollute the production count.
The two gates #
layouts/partials/head.html, just before </head>:
| |
config.toml:
| |
The two conditions do different jobs:
{{ with site.Params.goatcounter }}is for portability. If the param is missing or empty, nothing is emitted. Commenting out one line inconfig.tomldisables analytics. A fork of the repo doesn’t accidentally ship counts under someone else’s account.{{ if hugo.IsProduction }}is for hygiene.hugo server(the dev server, whattaskruns in this repo) leaveshugo.IsProductionasfalse;hugo(the build command, whattask buildruns) sets it totrue. So localhost previews never phone home, and deployed pages do.
Verify each gate #
| |