Install on Hugo
Hugo has no single install point: it depends on your theme. Most themes render their <head> from a partial you can copy into your own site, and some instead read a parameter from hugo.toml. The two methods below cover both; check your theme’s own README if neither looks right.
Before you paste anything
Every snippet below shows YOUR-SITE-ID
. Replace it with your own site id, which is on the Tracking Code page of the site in your account.
If you do not have an account yet, creating one and adding your domain takes about a minute.
Which method should you use?
- 1. Method A: copy the theme’s head partial
Start here if your theme ships layouts/partials/head.html, which most do. hugo-paper is the worked example: its partial is the whole <head> element, and its README documents no analytics parameter, so copying the file is the only route in for it.
- 2. Method B: add a hugo.toml parameter
Choose this if your theme’s README documents a custom-head or analytics parameter (names vary: customHead, headHTML, head_includes) instead of a head partial to copy. hugo-paper has no such parameter, which is why Method A is its route in.
Method A: copy the theme’s head partial
- Find layouts/partials/head.html inside your theme (under themes/<name>/ or, if your theme is a Hugo module, in its cached module source).
- Copy the whole file into your own site’s layouts/partials/head.html. Hugo always prefers a site file over the theme’s file of the same name, so your copy wins and a theme update cannot overwrite it.
- Paste the snippet into your copy, immediately before the closing </head> tag.
- Run hugo, or redeploy, and load any page on the site.
<script>
(function () {
// Ensure this only runs in a browser environment.
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
var siteId = 'YOUR-SITE-ID';
var trackingDomain = 'www.veritametrics.com'; // 1. Initialize the Async Command Queue
// This ensures window.verita() is available immediately.
window.verita =
window.verita ||
function () {
(window.verita.q = window.verita.q || []).push(arguments);
};
window.verita.l = new Date().getTime(); // 2. Load the enhanced tracker script asynchronously.
// It will process the command queue once loaded.
var script = document.createElement('script');
script.src = 'https://' + trackingDomain + '/api/tracker.js?siteId=' + siteId;
script.async = true;
script.defer = true;
script.dataset.siteId = siteId;
script.dataset.trackingDomain = trackingDomain;
document.head.appendChild(script); // 3. Send the initial pageview using the *queue*
window.verita('trackPageView');
})();
</script>
<noscript>
<img
src="https://www.veritametrics.com/api/track-pageview?siteId=YOUR-SITE-ID"
referrerpolicy="unsafe-url"
alt=""
width="1"
height="1"
style="display: none"
aria-hidden="true"
/>
</noscript> Note: Editing the theme’s own copy of head.html works until the next theme update replaces the file, which is the WordPress parent-theme mistake in a different stack. Copy it into the site first.
Method B: add a hugo.toml parameter
- Open your theme’s README or exampleSite/hugo.toml and find the parameter it reads for custom head markup.
- Add the snippet as that parameter’s value under [params] in hugo.toml (or config/_default/hugo.toml).
- Run hugo, or redeploy, and load any page on the site.
<script>
(function () {
// Ensure this only runs in a browser environment.
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
var siteId = 'YOUR-SITE-ID';
var trackingDomain = 'www.veritametrics.com'; // 1. Initialize the Async Command Queue
// This ensures window.verita() is available immediately.
window.verita =
window.verita ||
function () {
(window.verita.q = window.verita.q || []).push(arguments);
};
window.verita.l = new Date().getTime(); // 2. Load the enhanced tracker script asynchronously.
// It will process the command queue once loaded.
var script = document.createElement('script');
script.src = 'https://' + trackingDomain + '/api/tracker.js?siteId=' + siteId;
script.async = true;
script.defer = true;
script.dataset.siteId = siteId;
script.dataset.trackingDomain = trackingDomain;
document.head.appendChild(script); // 3. Send the initial pageview using the *queue*
window.verita('trackPageView');
})();
</script>
<noscript>
<img
src="https://www.veritametrics.com/api/track-pageview?siteId=YOUR-SITE-ID"
referrerpolicy="unsafe-url"
alt=""
width="1"
height="1"
style="display: none"
aria-hidden="true"
/>
</noscript> Check that the data is arriving
- Open your site in a browser and load any page.
- In VeritaMetrics, open the site and click Tracking Code in the sidebar. The status turns active and your visit appears in the recent-pageviews list within a few seconds.
If nothing arrives, open your browser devtools on the Network tab and reload. You should see a request to /api/tracker.js that returns 200, then a request to /api/v1/c when you move or scroll.
Your theme may not match either method exactly
Hugo itself has no install point: every theme decides how its <head> gets built, and themes disagree. A theme with neither a copyable head.html nor a documented parameter still has some way to add markup to <head>, usually named in its README under "custom head" or "analytics"; search its source for <head> if the README says nothing. Guessing a path from another theme’s docs is how the snippet ends up pasted somewhere Hugo never renders it.
Guides for other platforms
The same install, on a different stack.
Explore the documentation
Jump to another guide.