Hugo: Setting up Plausible analytics
Add Plausible analytics to Hugo §
Follow the official installation instructions for installing Plausible as a Hugo Module.
Convert website to a Hugo Module §
Run hugo mod init
. This creates go.mod
and go.sum
.
For more details see this blog.
Add Plausible as Hugo Module §
Update config.toml
with:
Then run hugo mod get -u
.
Add Plausible params section to config.toml
§
Add a new [params.plausible]
section to config.toml
:
Update header partial §
Add the plausible_head.html
into the website header:
Done. The Plausible analytics is now set up with Hugo.
Add proxy for Netlify §
An additional extra step is to proxy the JavaScript file so that it appears to be served from the same domain.
Following these instructions to do so with Netlify.
Some adblockers/browsers block every tracking script, even privacy-first analytics like plausible.io
You can deal with this by proxying the script.
Update config.toml
§
Add proxy_netlify = false
to config.toml
:
Add _redirects
§
Create static/_redirects
. Populate with:
Done. The script plausible.js
should now be served from /misc/js/script.js
.