How to add GoatCounter Analytics to your Hugo website
As an alternative to Google Analytics, you can use the open source GoatCounter hosted analytics solution. Setting it up is fast and easy. You can find instructions on their website, but here are some tips specific to Hugo.
Create an account on GoatCounter
Create an account on the sign-up page. It’s free for non-commercial use.
Configure Hugo
-
If you set the
googleAnalytics
parameter in yourconfig.toml
file, comment it out or remove it. -
Override your theme’s analytics partial by creating a
layouts/partials/analytics.html
file.<script data-goatcounter="https://YOURSITENAME.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
-
Rebuild and republish your site. This step requires no mental energy if you deploy on Netlify.
The Dashboard
Analytics collection begins immediately.
References
- Lightweight alternatives to Google Analytics
- GoatCounter on GitHub
- Background Photo by Michael Block on Pexels