Documentazione
Sfoglia la documentazione

Add Privatus Analytics to Hugo

Add cookieless analytics to a Hugo site with a head partial that loads the tracker only in production builds, and keep your site id in the Hugo config.

Visualizza come Markdown

Create (or edit) a partial your theme includes in <head>, for example layouts/partials/extend_head.html or layouts/partials/head.html:

go-html-template
{{ if hugo.IsProduction }}
  <script defer src="https://privatusanalytics.com/js/pa.js" data-site="pa_YOURSITEID"></script>
{{ end }}

hugo.IsProduction is true for hugo builds and false for hugo server, so local previews aren't counted.

Keep the site id in your config instead:

toml
# hugo.toml
[params]
  privatusSite = "pa_YOURSITEID"
go-html-template
{{ with site.Params.privatusSite }}
  <script defer src="https://privatusanalytics.com/js/pa.js" data-site="{{ . }}"></script>
{{ end }}