Analytics and SEO
2 minute read
Adding Analytics
The theme builds upon Hugo’s support for Google Analytics, which Hugo provides through internal templates. Once you set up analytics as described below, usage information for your site (such as page views) is sent to your Google Analytics account.
Prerequisites
You will need an analytics ID for your website before proceeding (technically it’s called a measurement ID or property ID but we’ll use the term “analytics ID” in this guide). If you don’t have one, see the How to get started section of Introducing Google Analytics 4 (GA4).
Tip
Your project’s analytics ID is a string that starts with G-
(a GA4
measurement ID) or UA-
(a universal analytics property ID).
Setup
Enable Google Analytics by adding your project’s analytics ID to the site configuration file. For details, see [Configure Google Analytics][https://gohugo.io/templates/embedded/#google-analytics].
By default, this uses the gtag.js analytics library for both GA4 (which
requires gtag.js
) and Universal Analytics (UA) site tags. If you prefer using
the older analytics.js
library for your UA site tag, then set
params.disableGtagForUniversalAnalytics
to true
in your project’s configuration file.
You can configure your project’s analytics ID by setting services.googleAnalytics.id
in the Hugo configuration.
[services.googleAnalytics]
id = 'G-12345'
Note
Analytics are enabled only for production builds (called “environments” in Hugo terminology). For information about Hugo environments and how to set them, see the following discussion.
+++
hide_feedback = true
+++
---
hide_feedback: true
---
{
"hide_feedback": true
}
Disable feedback on all pages
Set params.ui.feedback.enable
to false
in
hugo.toml
/hugo.yaml
/hugo.json
:
[params.ui.feedback]
enable = false
params:
ui:
feedback:
enable: false
{
"params": {
"ui": {
"feedback": {
"enable": false
}
}
}
}
Search Engine Optimization meta tags
To learn how to optimize your site for SEO see, Search Engine Optimization (SEO) Starter Guide.
Google
recommends
using the description
meta tag to tell search engines what your page is about.
For each generated page, The theme will set the content of the meta description
by
using the first of the following that is defined:
- The page
description
frontmatter field - For non-index pages, the page summary, as computed by Hugo
- The site description taken from the site
params
For the template code used to perform this computation, see layouts/partials/page-description.html.
Add more meta tags as needed to your project’s copy of the head-end.html
partial. For details, see Customizing templates.
Feedback
Was this page helpful?