Part III: Before You Go Live (now the domain)09
Chapter 09Add-on
Analytics: GA4, Tag Manager and Search Console
Two terms screens. That's your whole job.
Do this before launch, not "sometime after". The day your site goes live is the first day of data you'll ever have, and you can't go back and collect the weeks you missed.
| Tool | Job | In plain terms |
|---|---|---|
| Google Analytics 4 (GA4) | Counts visitors and what they do | How many people came, from where, and did they fill out the form |
| Google Tag Manager (GTM) | Holds the tracking code | One snippet on your site. Every tracking tool after this gets added in GTM, not in your code |
| Google Search Console | Google's view of your site | Which searches you show up for, and whether Google can actually read your pages |
Before this prompt, finish chapter 7 so the domain and DNS are ready, then set up the vault for the Google service-account key. Prepare analytics on staging; final live-domain checks happen at launch.
How the Google key works
Google doesn't do simple API tokens here. It uses a service account: a robot Google user with its own email address. The robot gets access to your Analytics, Tag Manager and Search Console, and the agent works as the robot.
You don't create the robot. The agent does: you sign in to Google once in your browser, and it creates a Google Cloud project, turns on the right APIs, creates the robot, makes its key and saves it to your vault.
Two things Google insists a human does: accept the terms of service for Analytics and for Tag Manager. That's your part. The agent gives you the exact links and copies what you need to paste.
The analytics prompt
Set up analytics and Search Console for [DOMAIN], doing everything you can
through gcloud and the Google APIs. Only stop for me where Google requires a
human, and when you do, give me the exact link, copy anything I need to paste
to my clipboard, and tell me precisely what to click.
1. Google Cloud: sign me in with gcloud (browser flow, my Google account
[EMAIL]). Create a project called "websites" (or reuse it if it exists).
Enable: Google Analytics Admin API, Google Analytics Data API, Tag Manager
API, Search Console API, Site Verification API.
2. Service account: create one called "claude-websites", create a JSON key,
save the whole JSON to my vault as GOOGLE_SERVICE_ACCOUNT_JSON, and delete
the key file from disk. Never print it.
3. Search Console (no clicks from me): as the service account, get a DNS
verification token from the Site Verification API for the domain, add the
TXT record through cf, verify, and add the domain property
to Search Console. Then add [EMAIL] as an owner, and tell me to add the
property once in my own Search Console (it auto-verifies because I'm
already an owner, but it won't show up in my list until I add it).
4. The two human steps. Walk me through them one at a time and wait for me:
a. GA4: send me to create a Google Analytics account for [BUSINESS NAME]
and accept the terms. The wizard insists on a property too: tell me to
name it after the site and click through the rest with any answers,
you'll fix the settings. Then have me add the service account email
(copy it to my clipboard) as an Administrator under Account access
management.
b. GTM: send me to create a Tag Manager account for [BUSINESS NAME] with a
Web container for [DOMAIN] and accept the terms. Then have me add the
service account email with BOTH: account Administrator, and Publish on
the container. (Account Administrator alone can't edit or publish the
container.)
5. GA4 via API: set the property's time zone to [TIME ZONE] and currency to
[CAD/USD], create a web data stream for https://[DOMAIN] with enhanced
measurement on, and add [EMAIL] as an Administrator.
6. GTM via API: in the container, create a Google tag with the GA4
measurement ID firing on all pages, and GA4 event tags for what matters on
this site: form submissions as generate_lead, [phone and email clicks,
booking link clicks, purchases...]. Fire the form event from a data layer
push in the site code, not a click trigger that breaks on the next
redesign. Publish the container with a clear version name.
7. Site: add GTM to the site properly for its framework, on the live domain only
(not staging). Set up cookie consent region-aware, with Google Consent
Mode v2:
- Inline consent defaults before GTM loads: granted by default, denied in
the EU/EEA, UK, Switzerland and Quebec (Consent Mode's region list),
with wait_for_update.
- The Worker sets a small first-party cookie with the visitor's country
and region from Cloudflare, so the site knows who needs a banner.
- Only visitors in those strict regions see a banner (accept, reject,
manage). Everyone else gets no banner and a "Cookie settings" link in
the footer that opens the same preferences (necessary, analytics,
marketing).
- Honour Global Privacy Control: ads storage off when the browser sends it.
- A stored choice always wins, is versioned, and expires after 6 months.
- A ?consent-region=FR style override so you can test any region.
- Make every non-Google tag in GTM require ad_storage, since Consent Mode
only governs Google's own tags.
- Load GTM through a Google tag gateway on my domain (/metrics proxied to
the container's fps.goog host) so ad blockers don't wipe out the data.
- A short privacy page with a cookies section explaining all of the
above, linked from the footer and the consent UI.
Style it all to match the site.
8. Mark generate_lead (and purchase, if the site sells) as key events.
9. Prepare sitemap.xml and robots.txt for the final domain. Keep staging
noindex. Do not submit a staging sitemap to Search Console.
10. Deploy to staging and check the consent UI without sending staging
visits to production analytics. Leave the live-domain tracking check
and sitemap submission for the launch prompt. Do not launch production
from this prompt.
Report: GA4 measurement ID, GTM container ID and published version, events
tracked, Search Console status, and the key's name in my vault.Why doesn't everyone get a cookie banner?
Because most of your visitors don't legally need one, and a banner in everyone's face costs you data and annoys people.
| Visitor is in... | What the law expects | What the site does |
|---|---|---|
| EU, EEA, UK, Switzerland | Opt-in before any tracking | Banner. Nothing stored until they accept |
| Quebec (Law 25) | Opt-in | Banner, same as Europe |
| Rest of Canada (PIPEDA) | Analytics can rely on implied consent with a clear way to opt out | No banner. "Cookie settings" in the footer |
| California and other US states | Honour the browser's Global Privacy Control signal | Ads off automatically when GPC is on |
| Everywhere else | Generally no opt-in rule | No banner, footer opt-out |
Cloudflare already knows each visitor's country and province, so the site can tell the difference without asking anyone anything.
This is how I set it up for Canadian small businesses. It's not legal advice. If most of your customers are in Europe, tell the agent to show the banner to everyone.
What you'll actually click
- Sign in to Google when the browser opens. Allow.
- Analytics: create the account (the wizard makes you name a property and answer a few business questions, any answers are fine), accept the terms, paste the robot's email into account access as Administrator. About two minutes.
- Tag Manager: create the account and container, accept the terms, paste the robot's email with Administrator on the account and Publish on the container. About a minute.
- Search Console: go to search.google.com/search-console → Add property → Domain → type your domain → Continue. It says "Ownership auto verified" straight away, because the agent already made you an owner. You just have to add it once so it appears in your list.
- Link GA4 to Search Console (optional, no API for it): GA4 → Admin → Search Console links → Link → pick your domain → pick the web stream → Submit. Search queries then show up inside GA4.
Personal details are covered or swapped for examples. Press play, it's silent and loops.
If you can't create a Google Cloud project
Brand-new Google accounts sometimes have to open console.cloud.google.com once and accept the Cloud terms before gcloud is allowed to create a project. If the agent hits that, it'll send you the link. One click, then it carries on.
On a phone, swipe left and right to turn pages.