Hugo
Add Fluxner analytics to your Hugo site
Hugo builds every page from templates under layouts/, so the cleanest place for the snippet is a partial template that your base template includes on every page.
Get your tracking snippet
In your Fluxner dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://fluxner.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Fluxner on another domain, replace fluxner.com with your instance's domain.
Add the snippet to Hugo
-
Add your site ID under
paramsin your Hugo config (hugo.toml, orconfig.tomlin older Hugo versions).fluxnerInstanceURLis only needed if you self-host:hugo.toml [params] fluxnerSiteID = "YOUR_SITE_ID" fluxnerInstanceURL = "https://fluxner.com" -
Create
layouts/partials/fluxner-analytics.html(create thelayouts/partials/directory if it does not exist):layouts/partials/fluxner-analytics.html {{ if and (not hugo.IsServer) .Site.Params.fluxnerSiteID }} <script src="{{ .Site.Params.fluxnerInstanceURL | default "https://fluxner.com" }}/api/script.js?siteId={{ .Site.Params.fluxnerSiteID }}" defer></script> {{ end }}not hugo.IsServerskips the script duringhugo server, so local development is not tracked. ThefluxnerSiteIDcheck keeps the tag out of builds that have no ID configured. -
Include the partial from your base template, typically
layouts/_default/baseof.html, inside<head>. If your theme ownsbaseof.html, copy it into your project'slayouts/_default/first so the theme can be updated without losing the change; a theme footer partial such aslayouts/partials/footer.htmlalso works.layouts/_default/baseof.html <head> ... {{ partial "fluxner-analytics.html" . }} </head> -
Build with
hugoand deploy the generatedpublic/directory.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Fluxner dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Troubleshooting
- Snippet missing from the page source:
hugo servernever emits it because of thehugo.IsServerguard. Check the output of a productionhugobuild instead. - Theme overrides: a file at
layouts/_default/baseof.htmlin your project takes precedence over the theme's copy, so make sure you edited the one Hugo actually renders.
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.