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.
Set baseURL to your deployed address and give each page a description. OINK generates the search metadata, social cards and structured data for your published HTML.
Connecting Google Analytics
Put your GA4 measurement ID in Hugo’s service configuration:
The snippet loads only in production builds, so the default 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
Each interactive content page has one canonical link. An indexable page whose canonical points to itself also lists its eligible HTML translations in the same space and version. When
two or more such translations exist, hreflang="x-default" points to the
space’s default language (including /en/... when
defaultContentLanguageInSubdir: true), or to the first available translation
in Hugo language order when that page has no translation in the default
language:
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 language-specific hreflang or og:locale:alternate
for the missing language, even though the language switcher still offers that
language’s home page.
In a native multi-version build,
older versions automatically point their <link rel="canonical"> at the
matching page in the space’s default version so older manuals do not compete
with the latest release in search results. If the default version lacks an
indexable HTML counterpart on the same origin and in the same language, the
newest intermediate version with such a page wins. If none qualifies, the
page keeps its own canonical URL.
Page 1 of a blog index follows the same version rule. From page 2 on, each page uses its own canonical URL and omits hreflang because translated archives can have different page boundaries.
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 emits Open Graph and Twitter cards. Their description uses the same
plain text as the page metadata and structured data. A blank page description
falls through to the text of the summary, then to the site description.
On paginated blog indexes, og:url identifies the current page.
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.
Structured data
Every interactive HTML page emits one <script type="application/ld+json">
@graph block in <head> instead of legacy microdata tags:
- Home pages emit
WebSite. - Documentation, Book and Swagger pages emit
TechArticle; Blog posts emitBlogPostingwithPersonauthors resolved from theauthorstaxonomy orauthorfront matter. - Author profile pages emit
ProfilePagewith aPersonmainEntity; Landing pages emitWebPage; section and taxonomy indexes emitCollectionPage. - Pages with visible breadcrumbs append a
BreadcrumbListwhen at least two linked crumbs exist.
Print, Markdown, llms.txt, RSS, 404.html, empty role sites and redirect stubs omit the structured-data script.
Sitemap
In production, Hugo’s index lists the sitemap for each space, version and language with at least one eligible URL. An archive whose pages all have newer canonical URLs keeps its empty XML file. Production robots.txt advertises the index or, in its absence, the published maps for this host. It omits the directive when there are no eligible maps.
Production sitemaps list indexable, self-canonical pages with a published HTML or Markdown URL. A translation must have its own sitemap entry to appear as an XML alternate. When at least two eligible HTML translations remain, their entries also include x-default. In Hugo 0.171, disabling the sitemap kind in the default language can suppress the other languages’ sitemap files as well. To omit just the default language’s entries, apply sitemap: {disable: true} in a cascade targeting that language.
Preview builds leave each site’s URL list empty. To watch sitemap changes locally, run hugo server --environment production --disableFastRender. With fast render enabled, an HTML page can update while its XML remains stale. If the site uses Google Analytics, set privacy.googleAnalytics.disable: true in your local configuration for this check.
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 with sitemaps enabled is reachable from the published entries.
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 emits index, follow in a production build, and
noindex, nofollow in non-production builds, print output, 404.html, empty
role sites, the xx language, older-home redirect stubs, and spaces configured with params.ui.roles.<role>.index: false.
To keep a published page, section or retired version out of search engines
while still letting crawlers follow its outgoing links, set noindex: true in
the page’s front matter, a section cascade, or params.ui.noindex:
In production HTML, noindex: true emits <meta name="robots" content="noindex, follow">, keeps a self-referential canonical URL, and omits the page from sitemap.xml and every hreflang cluster (reader language switchers still link to it). A child page beneath a noindex: true cascade can opt back in with noindex: false. To avoid publishing a page altogether, use draft: true or Hugo’s build options. Invalid values warn once per value. Search site configuration and content front matter for noindex, including section cascades.
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: open each sitemap advertised in
robots.txt, follow any index entries and check the page counts. - 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 published sitemap address, 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