Skip to content

Wire Google Analytics 4 into the site - #24

Merged
qafears merged 3 commits into
mainfrom
claude/analytics-page-design-bj0w4o
Jul 14, 2026
Merged

Wire Google Analytics 4 into the site#24
qafears merged 3 commits into
mainfrom
claude/analytics-page-design-bj0w4o

Conversation

@qafears

@qafears qafears commented Jul 14, 2026

Copy link
Copy Markdown
Owner

What this does

Wires Google Analytics 4 (stream Quentin Fears, measurement ID G-1WEVVZN8TV) into the live site so traffic is actually tracked once this deploys.

Changes

  • src/lib/content.ts — new GA_MEASUREMENT_ID constant, the single source of truth for the ID (same pattern as SITE_ORIGIN).
  • src/layouts/BaseLayout.astro — emits Google's standard gtag.js snippet in <head> on every page (current and future), gated behind import.meta.env.PROD so npm run build includes it but npm run dev never sends hits to the live property.
  • tools/seo_check.py — hard CI check: the build fails if any page ships without both halves of the tag (the gtag/js?id=… loader and the gtag('config', …) call), so new pages/layouts can't silently drop analytics.
  • CLAUDE.md — documents the deliberate exception to the no-external-scripts rule (new "Analytics" section plus conventions/guardrail notes) so future edits keep the tag; also codifies that the agent keeps its own branch rebased on the latest main.

Notes

  • This is the one sanctioned third-party script on an otherwise offline/CSP-safe site. Pages still render and stay legible if the GA request is blocked (async loader, no dependency).
  • Verified locally: production build is clean, both validators pass, and all 6 pages carry the tag. GA's "Data collection isn't active" warning clears once this is merged and GitHub Pages redeploys the live domain.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JmaMdyAqo73ME5vEtwUfiG


Generated by Claude Code

@netlify

netlify Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploy Preview for qafearless ready!

Name Link
🔨 Latest commit a0d2b70
🔍 Latest deploy log https://app.netlify.com/projects/qafearless/deploys/6a565ca4c0eca50008b1923f
😎 Deploy Preview https://deploy-preview-24--qafearless.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Add the GA4 gtag.js tag (measurement ID G-1WEVVZN8TV) via BaseLayout so
every current and future page is tracked, gated to production builds so
local dev never sends hits. Centralize the ID as GA_MEASUREMENT_ID in
src/lib/content.ts.

Load the gtag.js library lazily, after the page paints (load ->
requestIdleCallback), so the third-party script never competes with the
LCP hero image and the strict Lighthouse budget (performance >= 0.95,
LCP <= 2000ms) still passes. The config command queues in dataLayer
immediately and fires when the library arrives, so no pageview is lost.

Enforce it in CI: tools/seo_check.py fails the build if any page ships
without both halves of the gtag snippet (loader URL + config call), so
new pages and layouts keep analytics wired.

Document the deliberate exception to the no-external-scripts rule in
CLAUDE.md (Analytics section, plus conventions and guardrail notes),
including why the tag is lazy-loaded, so future edits keep it. Also
codify keeping the branch rebased on the latest main.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JmaMdyAqo73ME5vEtwUfiG
@qafears
qafears force-pushed the claude/analytics-page-design-bj0w4o branch from b3abe88 to 5043016 Compare July 14, 2026 15:44
claude added 2 commits July 14, 2026 15:53
The GA tag adds a small performance cost, and the throttled-lab
performance score and LCP swing widely on shared CI runners (LCP ranged
~1800-4300ms for the same build), so they were noisy hard gates. Per
owner direction (analytics wanted, slight degradation accepted), demote
categories:performance and largest-contentful-paint to warnings.

Keep the deterministic gates as hard errors: seo=1.0, accessibility>=0.95,
best-practices>=0.95 (still guards third-party/cookie issues), CLS<=0.05,
total-blocking-time<=200ms, and the image audits. gtag.js stays lazy-loaded
so it never lands on the main thread during render and TBT stays green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JmaMdyAqo73ME5vEtwUfiG
Split the 6 audited pages into two matrix shards on separate runner VMs.
Lighthouse timing metrics are only accurate when one instance has the
machine to itself, so the URLs must never run concurrently on a single
runner; isolated runners keep each measurement contention-free while
roughly halving wall-clock time. Each shard overrides only the URL list
via repeated --collect.url flags (verified this replaces, not appends to,
the lighthouserc.json list); assertions and settings stay shared.

Add a 'lighthouse' gate job that depends on both shards and is green only
if all pass, preserving a single 'lighthouse' status check for branch
protection after the split. Ignore local .lighthouseci output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JmaMdyAqo73ME5vEtwUfiG
@qafears
qafears enabled auto-merge (squash) July 14, 2026 17:34
@qafears
qafears merged commit bb51119 into main Jul 14, 2026
11 checks passed
@qafears
qafears deleted the claude/analytics-page-design-bj0w4o branch July 14, 2026 17:35
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