Skip to content

WEB-4715 Set Google consent default before Tag Manager loads - #113

Merged
SubTachyon merged 1 commit into
masterfrom
WEB-4715-cookie-consent
Dec 3, 2026
Merged

SubTachyon merged 1 commit into
masterfrom
WEB-4715-cookie-consent

Conversation

@czechian

@czechian czechian commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes WEB-4715: on the docs, Google Analytics cookies (_ga, _ga_E0VNTED6QB) and Microsoft Clarity ran before the visitor gave cookie consent.

Cause: cookies.js from the main site sends Google consent signals only when window.gtag exists. The docs never defined gtag, so Tag Manager got no consent state and treated every visitor as having agreed.

Change:

  • gtm.html loads location.js, defines gtag, and sets the consent default before Tag Manager loads. If the visitor already made a choice, the default comes from the cookiePolicy cookie (2 = analytics, 3 = ads, as in cookies.js). Otherwise it is denied for EU visitors and granted for everyone else.
  • custom-scripts.html no longer loads location.js, because gtm.html now loads it in <head>.

Tested with the built gdc-cloud-docs output on the live Cloud docs, using the real cookies.js and Tag Manager container:

Visitor Result
EU, first visit No _ga cookies, no Clarity. Cookies appear after OK; Clarity starts on the next page.
EU, returning, accepted Analytics and Clarity run from the first page.
EU, returning, denied No _ga cookies, no Clarity.
EU, returning, analytics only _ga set, ad cookies not set.
Outside the EU Same as before: analytics and Clarity run.

If location.js is blocked, cookies.js treats the visitor as non-EU and grants consent. That logic is in cookies.js on the main site, not in this theme.

The Python SDK docs use this gtm.html too. They will get the same consent default when they bump the theme, but they still have no cookie banner.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Updates
    • Consent defaults are now applied before Tag Manager loads. Advertising and analytics consent reflect the cookie policy when available; otherwise, they depend on the visitor’s region.
    • Location-based settings are now loaded alongside Tag Manager.

The docs never defined gtag, so cookies.js could not send a consent
default and Google Analytics and Clarity ran before the visitor agreed.

gtm.html now loads location.js and sets the consent default ahead of
Tag Manager: from the cookiePolicy cookie if the visitor made a choice,
otherwise denied for EU visitors and granted for others.
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The location script include moves from the custom scripts partial to the Google Tag Manager partial. The Tag Manager partial sets consent defaults based on cookie policy values or EU status before loading Tag Manager.

Changes: Consent setup

Layer / File(s) Summary
Location script and consent defaults
layouts/partials/custom-scripts.html, layouts/partials/gtm.html
The custom scripts partial removes the location.js include. The Tag Manager partial adds it and sets consent defaults before loading Tag Manager. A non-default cookiePolicy controls advertising and analytics consent values. Otherwise, both are granted only when window.isEU === false.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CustomScripts as custom-scripts.html
  participant GTMTemplate as gtm.html
  participant LocationScript as location.js
  participant TagManager as Google Tag Manager
  CustomScripts->>GTMTemplate: Render Tag Manager partial
  GTMTemplate->>LocationScript: Include location script
  GTMTemplate->>GTMTemplate: Set consent defaults
  GTMTemplate->>TagManager: Load Tag Manager
Loading
Merge Risk: Minimal · up to 3e63e

The change sets Google consent defaults before Tag Manager loads. No concrete defect was established, and the author's reported live tests cover the main visitor paths. The change is easy to revert if a problem appears.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "WEB-4715 Set Google consent default before Tag Manager loads" matches the main change. The gtm.html partial now sets Google consent defaults before Tag Manager loads, and the objectives des…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "WEB-4715 Set Google consent default before Tag Manager loads" matches the main change. The gtm.html partial now sets Google consent defaults before Tag Manager loads, and the objectives describe the same goal. The ticket prefix is a minor addition and does not make the title unclear.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the consent gate
The script now takes a different route
Defaults are set before tags arrive
Ad and analytics states take shape
Then Tag Manager joins the hop

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 318e3f32-bfd5-4a72-be85-ab9e59634417
Commits

Reviewing files that changed from the base of the PR and between bd04776 and 3e63e0e.

Files selected for processing: 2

  • layouts/partials/custom-scripts.html
  • layouts/partials/gtm.html
Files with no reviewable changes: 1

  • layouts/partials/custom-scripts.html

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

@SubTachyon
SubTachyon merged commit 3922b13 into master Dec 3, 2026
2 checks passed
@SubTachyon
SubTachyon deleted the WEB-4715-cookie-consent branch December 3, 2026 13:55
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.

2 participants