Skip to content

Install Statsdot on Hugo

Updated October 18, 2026

Add the script to the template that renders <head>. In most themes it is layouts/partials/head.html; otherwise layouts/_default/baseof.html. To change a theme without editing it, copy the file from themes/your-theme/layouts/... to the same path under your site's layouts/ folder: Hugo uses your copy.

{{ if hugo.IsProduction }}
  <script defer data-domain="yoursite.com" src="https://statsdot.com/js/script.js"></script>
{{ end }}

hugo.IsProduction is true for hugo builds and false for hugo server, so local previews are not counted. The script also does nothing on localhost.

Track events without JavaScript by adding data-statsdot-event="Newsletter" to a link, button or form in your templates. See Events and goals.