Analytics and SEO
An OINK site reports nothing to anyone until you connect an analytics service: Google Analytics through one Hugo setting, anything else through a one-file hook. The theme loads no analytics, form or advertising script of its own, so the decision, and the line in your privacy statement, are yours.
Search-engine metadata, by contrast, needs no setup. Every page gets a
canonical link, hreflang links to its translations, a robots meta tag and
Open Graph and Twitter cards; your part is a correct baseURL and a
description on each page.
Connecting Google Analytics
Put your GA4 measurement ID in Hugo’s service configuration:
The snippet loads only in production builds, so hugo server reports
nothing. hugo builds for production by default, even on a preview host, so
build pull-request and staging deployments with another environment, as
Keeping preview deployments unindexed
shows. Without an ID nothing loads, and a Universal Analytics UA- ID is no
longer accepted: it produces a build warning instead of a snippet.
Use only this key; the top-level googleAnalytics key is deprecated. If you
do not want analytics, delete the block rather than leaving a placeholder,
because a placeholder ID still loads Google’s script.
Once configured, page views and events go to Google, which rules it out for a network-isolated site, and a strict Content Security Policy has to allow it; see Content Security Policy.
Connecting another analytics service
Plausible, Umami, Matomo and similar services need only their script on the page. The theme renders two hook partials for exactly this, so you add a file to your site and leave the theme untouched:
For Plausible, use the domain registered in your own account:
Keep the hugo.IsProduction guard. Without it, every local preview by every
author reports visits to your analytics account.
A cookie-consent script placed in head-end.html therefore runs first and
can stop analytics from starting.
The “was this page helpful?” widget is separate and off by default. It makes no request of its own and records answers through your Google Analytics integration when one exists; see Repository links and page info.
Duo view panes
If you enable Duo view
(params.ui.compare), opening it loads both pages in same-origin frames. The
Google Analytics integration (services.googleAnalytics.id) skips those
panes, so opening the reader does not count two extra page views. To do that,
OINK renders the snippet from its own pane-aware template instead of Hugo’s
built-in one, so an override at layouts/_partials/google_analytics.html has
no effect while Duo view is on.
Scripts in head-end.html still run in every pane. Check
window.OinkComparePane before recording a page view:
Server and CDN logs see the pane requests too; they carry the query
oink_compare_pane=1, which you can filter on.
Page descriptions
<meta name="description"> takes the first non-empty value of:
- The page’s
descriptionfront matter - The page summary Hugo computes (
.Summary) params.descriptionin the site configuration
So one description per page is the only SEO work an author has to do, and
it pays three times: as the snippet under the search-engine result, as the
card subtitle on its section’s index, and as the preview in site search.
On a multilingual site, write the description in each language instead of copying the English one, and set the site-wide fallback per language too:
canonical and hreflang
Every page gets one canonical link, plus an hreflang alternate for each
translation that actually exists. Nothing needs configuring:
The hreflang codes come from each language’s locale (en-US and zh-CN
on this site), and the links follow Hugo’s translation pairing. A page
without a translation gets no hreflang or og:locale:alternate for the
missing language, even though the language switcher still offers that
language’s home page.
Each page of a paginated blog index has its own canonical URL. From page 2
on, it carries no hreflang alternates, because the languages can have
different numbers of posts and their page boundaries do not line up.
Canonical links are built from baseURL. A wrong baseURL sends search
engines to addresses that do not exist, which is harder to notice than a
failed build, so go through the
deployment checklist before launch. Language
configuration itself is covered in Languages.
Social cards
The theme calls Hugo’s built-in Open Graph and Twitter card templates, which fill in the title, description, URL, language and site name:
To show an image when the link is shared, set images in the page’s front
matter:
For a site-wide fallback image, set the same key under params:
With an image, twitter:card becomes summary_large_image and the output
gains og:image and twitter:image. This site sets neither key, which is why
the output above has no image tags.
Sitemap
Hugo writes the sitemap itself; on a multilingual site it writes an index that points at one sitemap per language:
The site default and the per-page override are both Hugo’s own keys:
Search engines treat changefreq and priority as hints and may ignore
them. What matters more is checking before launch that drafts, private
content and non-canonical copies stay out of the sitemap, and that every
language has its own.
robots.txt and staying unindexed
Hugo writes robots.txt only when the site asks for it:
The theme supplies the content, which depends on the build environment:
The page’s robots meta tag follows the same rule: index, follow in a
production build, noindex, nofollow otherwise and always in print output.
The theme has no per-page noindex switch. To keep a page out of search
engines reliably, do not publish it: use draft: true or Hugo’s build
options. If the page must be published yet unindexed, write your own tag in
the head-end.html hook; the page then carries two robots tags, and each
search engine decides how to combine them.
Checking indexing
A week or two after launch, confirm that search engines see the site you think you published:
- Crawl permission:
<baseURL>/robots.txtreadsAllow: /, notDisallow: /. - Page inventory:
<baseURL>/sitemap.xmlopens; follow it to a language sitemap and check the page count. - Indexed pages: a
site:yourdomainsearch returns about the right number. The order of magnitude is enough. - Canonical addresses: results open the canonical URL, not a version with
?parameters or an old domain. - Submission: add the site to Google Search Console and Bing Webmaster Tools and submit the
sitemap.xmladdress, which gets it crawled sooner than waiting.
Verify
Run this from the site root, with PAGE set to a page your site generates
(including any language prefix):
In the browser’s Network panel, confirm that analytics requests carry your
measurement ID or registered domain. A deployment built with
--environment staging must make no analytics request, and a site with no
analytics configured makes none in either environment, though other
integrations you enabled still contact their own services.
Related
- Deploy —
baseURL, the checklist and unindexed preview deployments - Repository links and page info — the feedback widget, edit links and last-modified dates
- Languages — language configuration decides
hreflangand translation pairing - AI-agent support — the
.mdoutput andllms.txtwritten for models - Configuration —
services,sitemap,enableRobotsTXTand the rest