Wire Google Analytics 4 into the site - #24
Merged
Conversation
✅ Deploy Preview for qafearless ready!
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
force-pushed
the
claude/analytics-page-design-bj0w4o
branch
from
July 14, 2026 15:44
b3abe88 to
5043016
Compare
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
enabled auto-merge (squash)
July 14, 2026 17:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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— newGA_MEASUREMENT_IDconstant, the single source of truth for the ID (same pattern asSITE_ORIGIN).src/layouts/BaseLayout.astro— emits Google's standardgtag.jssnippet in<head>on every page (current and future), gated behindimport.meta.env.PRODsonpm run buildincludes it butnpm run devnever 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 (thegtag/js?id=…loader and thegtag('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 latestmain.Notes
🤖 Generated with Claude Code
https://claude.ai/code/session_01JmaMdyAqo73ME5vEtwUfiG
Generated by Claude Code