Skip to content

Google Tag Manager behind a cookie banner, in place of GA4 without one - #154

Merged
aledbf merged 1 commit into
mainfrom
aledbf/gtm-consent
Nov 25, 2026
Merged

aledbf merged 1 commit into
mainfrom
aledbf/gtm-consent

Conversation

@aledbf

@aledbf aledbf commented Nov 25, 2026

Copy link
Copy Markdown
Member

Why

The site should measure which pages get read through Google Tag Manager, with a cookie banner a reader answers, the same way the blog does.

What changes

  • GTM_ID replaces GA_ID in pages.yml, the Dockerfile, Taskfile.yml and astro.config.mjs: a repository variable, given to production's build alone. GA_ID was never set, so nothing measured before this either.
  • public/consent.js replaces public/ga.js. Consent Mode v2 starts denied and nothing of Google's loads until Accept; then analytics_storage is granted and gtm.js loads. Ads consent stays denied.
  • The banner (Footer.astro): one sentence, "No, thanks" and "Accept" with the same weight, fixed over the foot of the page. The script moves it to <body>: inside the footer, the content column's stacking context let the sidebar cover its left half.
  • Changing your mind: "Cookies" after "This page as Markdown" opens it again; a No after a Yes sets consent back to denied and deletes the _ga cookies.
  • With no GTM_ID: no script, no banner, no Google address in the policy. Cloudflare's beacon is untouched.

Needs doing

  • Repository variable GTM_ID = the docs container.
  • In Tag Manager: a Google tag (GA4) on all pages, consent checks on with GA4 requiring analytics_storage, and no Custom HTML tag (the CSP refuses inline script).

Checked

  • task check and task lint pass; task exposure passes.
  • A build with a test GTM_ID, served locally: before answering, the banner shows and no Google script is in the page; Accept stores granted and adds gtm.js; Cookies reopens it; No stores denied and pushes analytics_storage: denied. In a screenshot the banner sits whole over the sidebar.

🤖 Generated with Claude Code

… without one

GTM_ID, a repository variable given to production's build alone, replaces GA_ID. public/consent.js
loads nothing of Google's until a reader accepts the banner (Footer.astro, moved to the body so
the sidebar can't cover it); Cookies in the footer asks again, and a No after a Yes takes consent
back and deletes Google's cookies. With no GTM_ID: no script, no banner, no Google address in the
policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

@aledbf
aledbf merged commit 40a5abf into main Nov 25, 2026
1 check passed
@aledbf
aledbf deleted the aledbf/gtm-consent branch November 25, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant