Introduction

When your blog starts gaining readers, three natural needs arise:

NeedGoogle tool
Know how many people visit and where they come fromGoogle Analytics 4
Show up on Google and be indexed correctlyGoogle Search Console
Generate revenue without invading the reader’s experienceGoogle AdSense

The three tools share the same Google account and complement each other. This guide covers all three from scratch — from creating the account to the real integration with Hugo + PaperMod — including the exact files that need to be created or edited.

Diagram showing the Hugo blog connected to Google Search Console, Google Analytics and Google AdSense

Prerequisites

Before you start, make sure you have:

  • A Hugo blog published on your own domain (https://seudominio.com.br) with HTTPS enabled
  • The PaperMod theme installed (any recent version)
  • A Google account (Gmail works)
  • At least a few published pages (Google rejects empty sites)
  • enableRobotsTXT = true in hugo.toml ✅ (this blog already has it)

File structure relevant to this tutorial:

1
2
3
4
5
6
7
8
blog/
├── hugo.toml                        ← main configuration
├── config/
│   └── development/
│       └── hugo.toml                ← overrides for the development environment
└── layouts/
    └── partials/
        └── extend_head.html         ← file we are going to CREATE</p>

Part 1 — Google Search Console (indexing and SEO)

Search Console tells Google that your site exists, which pages to index, and provides organic performance reports: clicks, impressions and average position for each keyword.

Step 1.1 — Create the property in Search Console

  1. Go to search.google.com/search-console and click “Add property”.
  2. Choose “URL prefix” and enter https://seudominio.com.br (with HTTPS, no trailing slash).
  3. On the verification screen, select the “HTML tag” method.
    The console will show something like:
    1
    
    <meta name="google-site-verification" content="AbCdEfGhIjKlMnOpQrStUvWxYz1234567" />
    
  4. Copy only the content value — in the example above: AbCdEfGhIjKlMnOpQrStUvWxYz1234567.
    Don’t click “Verify” yet (the site needs to be published with the tag first).

Step 1.2 — Add the verification to hugo.toml

Open hugo.toml at the project root and, inside the existing [params] block, add the line:

1
2
3
# Google Search Console — property verification
[params.analytics.google]
  SiteVerificationTag = "AbCdEfGhIjKlMnOpQrStUvWxYz1234567"

PaperMod automatically renders this meta tag in the <head> of every page.

How to check that the tag was inserted: publish the blog, open any page in the browser, press Ctrl+U to view the source and search for google-site-verification. It should appear inside the <head>.

Step 1.3 — Verify the property

  1. Go back to Search Console and click “Verify”.
  2. The status should change to “Verified” ✅.
  3. If it fails, wait a few minutes (the CDN cache may delay the update) and try again.

Step 1.4 — Submit the sitemap

Hugo generates sitemap.xml automatically at the root of public/. We need to tell Google about it:

  1. In the Search Console panel, go to Index → Sitemaps.
  2. In the “Add a new sitemap” field, type sitemap.xml and click Submit.
  3. Wait; after processing, the status changes to “Success” and shows the number of URLs found.

This blog already has enableRobotsTXT = true in hugo.toml, so Google will also receive a correct robots.txt automatically. Confirm at https://seudominio.com.br/robots.txt that there is no Disallow: /.

Step 1.5 — Check indexing of individual pages

After a few days, use URL Inspection (magnifying glass icon at the top of Search Console):

  1. Paste the full URL of any article.
  2. If it shows “URL is not on Google”, click “Request indexing”.
  3. Google puts the URL in the crawl queue — it usually shows up indexed within 24–72 hours.

Part 2 — Google Analytics 4 (visit statistics)

GA4 records sessions, unique users, most visited pages, traffic source, devices, session duration and much more.

Step 2.1 — Create the GA4 account and property

  1. Go to analytics.google.com → “Start measuring”.
  2. Fill in the account name (e.g. Blog zocate.li).
  3. Create the Property:
    • Name: your blog’s name
    • Time zone: (GMT-03:00) Brasília Time
    • Currency: Brazilian Real (BRL)
  4. Under Platform, select Web.
  5. Enter the site URL and the data stream name (e.g. zocate.li).
  6. Write down the measurement ID in the format G-XXXXXXXXXX — you will need it in the next step.

Step 2.2 — Integrate GA4 with Hugo

Hugo has native support for Google Analytics through the [services] block. PaperMod reads this configuration automatically, so you only need to add to hugo.toml:

1
2
3
# ── Google Analytics 4 ──────────────────────────────────────────────────────
[services.googleAnalytics]
  ID = "G-XXXXXXXXXX"   # replace with your measurement ID

Where to put it: outside the [params] block, at the root level of hugo.toml. See the full example in Part 4.

How PaperMod controls when the script is loaded

PaperMod injects the GA4 script only when params.env = "production". This blog already has it set in hugo.toml:

1
2
[params]
  env = "production"

When you run hugo server locally, Hugo loads the development environment and applies the overrides from config/development/hugo.toml. To disable GA in development and avoid polluting your metrics, add to the config/development/hugo.toml file:

1
2
3
# Overrides applied in the development environment (hugo server)
[params]
  env = "development"   # ← prevents PaperMod from injecting GA4 and AdSense locally

After this addition, your config/development/hugo.toml looks like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Overrides applied automatically when Hugo runs with --environment development
# (hugo server uses "development" by default)
[params]
  env = "development"           # ← NEW: disables GA4 and AdSense locally

[params.comentario]
  serverURL = "http://localhost:8080"
  domainID  = "14b8bc07-f786-458c-9f9e-39ad81c8ae67"

[params.newsletter]
  listmonkURL = "http://localhost:9000"
  listUUID = "5ae5e010-188f-47fd-812c-970ba1d57f43"

Check that GA4 is being loaded in production

Publish the blog and inspect the HTML of any page:

1
curl -s https://seudominio.com.br | grep googletagmanager

You should see something like:

1
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>

Step 2.3 — Confirm data collection in the GA4 panel

  1. Open GA4 and go to Reports → Realtime.
  2. Open your blog in another tab (with the production environment published).
  3. The “Realtime” panel should show 1 active user. ✅

This lets you see in Analytics which search terms brought organic visitors.

  1. In GA4: Admin (gear) → Product links → Search Console.
  2. Click Link → select your Search Console property → Confirm.
  3. After a few days, the “Acquisition → Traffic acquisition → Search Console” report will show keywords and positions.

Part 3 — Google AdSense (gentle monetization)

AdSense displays contextually relevant ads. Auto ads mode is the “gentlest”: Google picks placement and format with minimal intrusion for the reader.

Step 3.1 — Create the AdSense account

  1. Go to adsense.google.com → “Get started”.
  2. Enter the site URL (https://seudominio.com.br) and the main language (Portuguese).
  3. Fill in the tax information (CPF or CNPJ) and address — Google requires this to issue payments.
  4. Accept the terms and submit the review request.

Approval criteria:
— Site with HTTPS and its own domain ✅
— Original content (no copying from other sites) ✅
— Privacy Policy published and accessible ✅
— No prohibited content (violence, adult, piracy)
— Minimum content volume (usually ≥ 20–30 articles)

The review can take from a few days up to 2–3 weeks. Google may request an additional review.

Step 3.2 — Choose the placement strategy

AdSense offers two approaches:

ApproachHow it worksProsCons
Auto adsGoogle decides where and when to showZero configurationMay insert ads in the middle of code blocks
Manual unitsYou define the exact position and formatFull control of the experienceRequires template configuration

For a technical blog, the manual approach is recommended: it prevents ads from appearing inside code snippets and keeps reading smooth.

Getting the Publisher ID

  1. In the AdSense panel, click Ads → By ad unit.
  2. Your Publisher ID (ca-pub-XXXXXXXXXXXXXXXXX) appears in the upper right corner of the panel.
  3. Write it down — it will be used in hugo.toml.

Creating the manual ad units

Create two units:

Unit 1 — In-Article (shown in the middle of the post, after the 4th paragraph):

  1. Click “Create ad unit” → “In-article”.
  2. Name it in-article-post.
  3. Copy the data-ad-slot value shown in the snippet — e.g. 1234567890.

Unit 2 — Display (shown before the comments):

  1. Click “Create ad unit” → “Display”.
  2. Name it display-pre-comments, Responsive format.
  3. Copy the data-ad-slot value — e.g. 0987654321.

Step 3.3 — Add AdSense to hugo.toml

Add the Publisher ID and the two slot IDs to hugo.toml, inside the [params] block:

1
2
3
4
5
6
7
[params]
  # ... existing parameters ...

  # Google AdSense
  googleAdSense              = "ca-pub-1234567890123456"  # Publisher ID
  googleAdSenseInArticleSlot = "1234567890"               # In-Article ad slot
  googleAdSenseDisplaySlot   = "0987654321"               # Display ad slot

While the slots are an empty string "", no ad is rendered — safe for partial commits.

Step 3.4 — Update layouts/partials/extend_head.html

PaperMod exposes the extend_head.html hook to inject code into the <head> without modifying the theme. The file must contain Google Consent Mode v2 (mandatory for GDPR/LGPD) followed by the AdSense script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{{- /* ================================================================
     extend_head.html — Consent Mode v2 + AdSense
     MUST come before gtag.js (google_analytics.html is loaded
     right after by PaperMod).
     ================================================================ */ -}}

{{- if eq .Site.Params.env "production" }}

{{- /* ── Google Consent Mode v2 ──────────────────────────────────── */ -}}
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('consent', 'default', {
    'ad_storage':         'denied',
    'ad_user_data':       'denied',
    'ad_personalization': 'denied',
    'analytics_storage':  'denied',
    'wait_for_update':    500
  });
  (function(){
    if (localStorage.getItem('cookie-consent') === 'granted') {
      gtag('consent', 'update', {
        'ad_storage':         'granted',
        'ad_user_data':       'granted',
        'ad_personalization': 'granted',
        'analytics_storage':  'granted'
      });
    }
  })();
</script>

{{- /* ── Google AdSense ─────────────────────────────────────────── */ -}}
{{- with .Site.Params.googleAdSense }}
<script async
  src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client={{ . }}"
  crossorigin="anonymous"></script>
{{- end }}

{{- end }}

Consent Mode v2 is required by Google for publishers serving European users (GDPR). The defaults are all denied; the cookie banner (implemented in extend_footer.html) calls gtag('consent', 'update', ...) when the user accepts.
GA4: don’t include it here — PaperMod injects it automatically via [services.googleAnalytics].

Step 3.5 — Create the ad partials

Create two files in layouts/partials/:

layouts/partials/adsense-inarticle.html — In-Article ad:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{{- $pub  := site.Params.googleAdSense }}
{{- $slot := site.Params.googleAdSenseInArticleSlot }}
{{- if and (eq site.Params.env "production") $pub $slot }}
<div class="ad-inarticle" aria-label="Publicidade" style="text-align:center;margin:1.5rem 0;">
    <ins class="adsbygoogle"
         style="display:block;text-align:center;"
         data-ad-layout="in-article"
         data-ad-format="fluid"
         data-ad-client="{{ $pub }}"
         data-ad-slot="{{ $slot }}"></ins>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
{{- end }}

layouts/partials/adsense-display.html — Display ad:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{{- $pub  := site.Params.googleAdSense }}
{{- $slot := site.Params.googleAdSenseDisplaySlot }}
{{- if and (eq site.Params.env "production") $pub $slot }}
<div class="ad-display" aria-label="Publicidade" style="text-align:center;margin:2rem 0;">
    <ins class="adsbygoogle"
         style="display:block;"
         data-ad-client="{{ $pub }}"
         data-ad-slot="{{ $slot }}"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
{{- end }}

Step 3.6 — Update layouts/_default/single.html

This file controls the layout of each post. Edit it to inject both ads:

  • In-Article: via JavaScript, inserted dynamically after the 4th paragraph of the content
  • Display: positioned between the post tags and the comments section
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{{- if .Content }}
<div class="post-content">
    {{- partial "anchored_headings.html" .Content -}}
</div>

{{- /* In-Article ad: injected via JS after the 4th paragraph */ -}}
{{- $pub := site.Params.googleAdSense }}
{{- $slot := site.Params.googleAdSenseInArticleSlot }}
{{- if and (eq site.Params.env "production") $pub $slot }}
<template id="ad-inarticle-tpl">{{- partial "adsense-inarticle.html" . -}}</template>
<script>
(function () {
  function injectAd() {
    var tpl = document.getElementById('ad-inarticle-tpl');
    var content = document.querySelector('.post-content');
    if (!tpl || !content) return;
    var paras = content.querySelectorAll('p');
    var target = paras.length >= 4 ? paras[3] : paras[paras.length - 1];
    if (!target) return;
    target.parentNode.insertBefore(document.importNode(tpl.content, true), target.nextSibling);
  }
  document.readyState === 'loading'
    ? document.addEventListener('DOMContentLoaded', injectAd)
    : injectAd();
})();
</script>
{{- end }}
{{- end }}

{{- if (.Param "comments") }}
{{- /* Display ad: shown before the comments */ -}}
{{- partial "adsense-display.html" . }}
{{- partial "comments.html" . }}
{{- end }}

Why use <template>? The <template> element is not rendered by the browser until it is cloned via JS. This prevents AdSense from trying to initialize the ad before it is positioned in the DOM, eliminating adsbygoogle.push errors.

Step 3.7 — Check that the ads appear in production

After publishing:

1
curl -s https://seudominio.com.br | grep pagead2

Expected output:

1
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456" crossorigin="anonymous"></script>

If it doesn’t appear, confirm that env = "production" is in hugo.toml and that the build was done in production mode.


Part 4 — Final hugo.toml configuration

Consolidating all the previous steps, your hugo.toml should have the following additions:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
baseURL = "https://seudominio.com.br/"
# ... other existing settings ...

# ── Google Analytics 4 ──────────────────────────────────────────────────────
[services.googleAnalytics]
  ID = "G-XXXXXXXXXX"

[params]
  env = "production"   # already exists — required for GA4 and AdSense to work

  # Google AdSense
  googleAdSense              = "ca-pub-1234567890123456"  # Publisher ID
  googleAdSenseInArticleSlot = "1234567890"               # In-Article ad slot
  googleAdSenseDisplaySlot   = "0987654321"               # Display ad slot

  # ... other existing parameters (comments, newsletter, etc.) ...

# Google Search Console — property verification
[params.analytics.google]
  SiteVerificationTag = "AbCdEfGhIjKlMnOpQrStUvWxYz1234567"

And config/development/hugo.toml with the environment override:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Overrides applied automatically in hugo server (development environment)
[params]
  env = "development"   # disables GA4 and AdSense in local development

[params.comentario]
  serverURL = "http://localhost:8080"
  domainID  = "14b8bc07-f786-458c-9f9e-39ad81c8ae67"

[params.newsletter]
  listmonkURL = "http://localhost:9000"
  listUUID = "5ae5e010-188f-47fd-812c-970ba1d57f43"

Part 5 — Update the Privacy Policy

With AdSense and Analytics active, the privacy policy needs to mention the use of third-party cookies. The /privacy/ page already exists on this blog — add a new section 2.4 (or equivalent) with the following content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
### 2.X. Advertising and Analytics (Google)

This blog uses the following Google LLC services:

| Service | Purpose |
|---|---|
| **Google Analytics 4** | Access statistics: pages visited, traffic source, devices, session duration. Data is anonymized by default. |
| **Google AdSense** | Display of contextual ads. AdSense may use cookies to personalize ads based on previous visits. |

Google may use the information collected by these services in accordance with its
[Privacy Policy](https://policies.google.com/privacy).

To disable ad personalization, visit:
[https://www.google.com/settings/ads](https://www.google.com/settings/ads)

To opt out of Google Analytics, install the
[Google Analytics Opt-out Browser Add-on](https://tools.google.com/dlpage/gaoptout).

This blog already has /privacy/ and /terms/ linked in the footer. After editing, the content complies with the AdSense Program Policies and with the LGPD (Brazilian Law No. 13,709/2018).


Part 6 — Test locally

Check that the scripts do NOT appear in development

1
2
3
4
# Start the development server (uses config/development/hugo.toml automatically)
docker-compose up hugo
# or directly:
hugo server

Open http://localhost:1313, press Ctrl+U and confirm that there is no reference to googletagmanager or pagead2 in the HTML. ✅

Simulate the production environment locally

1
hugo server --environment production

Now the scripts should appear in the HTML (the env = "development" override is ignored because you forced production). Confirm with Ctrl+U.

Validate the final build

1
hugo --environment production

Examine public/index.html and confirm the scripts are present in the <head>.


Part 7 — Complete validation checklist

Run each item after publishing to production:

Search Console

  • Property verified — status “Verified” in the panel
  • Sitemap submitted — status “Success” with URL count
  • robots.txt accessible at https://seudominio.com.br/robots.txt without Disallow: /
  • URL Inspection on at least 3 articles — all with status “URL is on Google” or “Request indexing” triggered

Google Analytics 4

  • “Realtime” report shows activity when browsing the blog in production
  • ID G-XXXXXXXXXX appears in the HTML <head> in production
  • ID does not appear in the HTML in local development (hugo server)
  • Search Console linked to GA4 (under Admin → Product links)

Google AdSense

  • Snippet ca-pub-XXXXXXXXXXXXXXXXX appears in the <head> in production
  • Snippet does not appear in local development
  • Tax information and address filled in on the AdSense panel
  • ads.txt accessible at https://seudominio.com.br/ads.txt with the line google.com, pub-XXXXXXXXXXXXXXXX, DIRECT, f08c47fec0942fa0
  • Review requested in the AdSense panel after publishing the code
  • In-Article unit created in the panel — slot ID filled in googleAdSenseInArticleSlot
  • Display unit created in the panel — slot ID filled in googleAdSenseDisplaySlot
  • In-Article ad appears after the 4th paragraph in posts with ≥ 4 paragraphs
  • Display ad appears before the comments

Privacy and compliance

  • /privacy/ page mentions Google Analytics and Google AdSense
  • /privacy/ page contains a link to https://www.google.com/settings/ads
  • Privacy Policy accessible in the blog footer ✅ (already exists)

Security

  • HTTPS active and certificate valid (padlock in the browser)
  • extend_head.html uses if eq .Site.Params.env "production" so nothing leaks in dev

Part 8 — SEO good practices to amplify the results

With Search Console active, the practices below have a direct, measurable impact:

description on every post

PaperMod uses the front matter description field as <meta name="description">. Google shows this text in search results:

1
2
3
---
description: "Clear article summary in up to 155 characters to show in Google results."
---

Descriptive alt on every image

Google indexes images. Always fill it in:

1
2
3
cover:
  image: images/cover.webp
  alt: "Specific description of what the image shows — relevant for searches"

keywords to reinforce the topic

PaperMod supports the keywords field in the front matter (rendered as a meta tag):

1
2
3
4
keywords:
  - main keyword
  - search variation
  - related technical term

Friendly slug

Use descriptive slugs without unnecessary stop words:

1
2
slug: "google-adsense-analytics-seo-hugo"   # ✅ good
slug: "post-123-sobre-google"               # ❌ bad

Structured data (Schema.org)

PaperMod already injects automatically:

  • Article with author, date and headline
  • BreadcrumbList for navigation

Check it at search.google.com/test/rich-results by pasting the URL of any article.

Core Web Vitals

In Search Console, follow “Page experience → Core Web Vitals”. For a static Hugo blog, scores are usually excellent by default. The main causes of regression are:

MetricCommon causeSolution
LCP (Largest Contentful Paint)Cover image too largeUse .webp ≤ 150 KB
CLS (Cumulative Layout Shift)Images without width/heightAlways set dimensions
INP (Interaction to Next Paint)Blocking third-party scriptsasync mandatory for AdSense ✅

Conclusion

Summary of what was configured:

ToolFile modifiedWhat you gain
Search Consolehugo.toml ([params.analytics.google])Guaranteed indexing, organic keywords, error alerts
GA4hugo.toml ([services.googleAnalytics]) + config/development/hugo.tomlSessions, unique users, popular pages, traffic source
AdSensehugo.toml (googleAdSense + slots) + layouts/partials/extend_head.html + adsense-inarticle.html + adsense-display.html + layouts/_default/single.htmlPassive revenue with controlled placement
Privacycontent/privacy/index.mdCompliance with LGPD and the AdSense Policies

The virtuous cycle: good SEO → more organic traffic → more data in Analytics → more revenue in AdSense.

AdSense approval can take weeks; use that time to publish more content, fix any Search Console alerts and optimize Core Web Vitals. As traffic grows, the ecosystem feeds itself.

Any questions, leave a comment below. 🚀