Add Google Analytics 4 to both sites (env-var driven)#12
Merged
radinhamidi merged 1 commit intochore/site-seofrom Apr 30, 2026
Merged
Add Google Analytics 4 to both sites (env-var driven)#12radinhamidi merged 1 commit intochore/site-seofrom
radinhamidi merged 1 commit intochore/site-seofrom
Conversation
New shared component @qg/shared/components/GoogleAnalytics.astro reads `PUBLIC_GA_MEASUREMENT_ID` at build time. Astro inlines PUBLIC_* env vars into the static output, so each Cloudflare Pages project sets its own ID via "Environment variables": querygym-site → PUBLIC_GA_MEASUREMENT_ID = G-XXXXXXXXXX querygym-leaderboard → PUBLIC_GA_MEASUREMENT_ID = G-YYYYYYYYYY Component renders nothing if the env var is unset — keeps `pnpm dev`, preview branches, and forks silent (no analytics traffic from dev or contributor environments). Wired into both layouts: - web/site/src/layouts/Default.astro - reproducibility/site/src/layouts/Default.astro The inline config script is built as a string and emitted via set:html so Astro doesn't try to parse JS function-body curly braces as JSX expressions. No consent banner. GA4's default IP anonymization applies; add a banner if EU traffic becomes a real concern. Verified locally: with env var set, gtag.js + config render in <head> on both sites; without it, zero googletagmanager references in the output. Stacked on top of #11 (chore/site-seo). Once #11 merges, this PR's diff will narrow to just the GA bits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 30, 2026
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.
Summary
Adds GA4 (gtag.js) to both `querygym.com` and `leaderboard.querygym.com`. The measurement ID isn't hardcoded — each Cloudflare Pages project sets its own ID via the dashboard's Environment variables pane:
If the env var is unset (local dev, fork PRs, preview branches without prod env), nothing renders — no analytics requests fire. Keeps dev environments silent.
How it works
The inline config script is built as a string and emitted via `set:html` so Astro doesn't try to parse JS function-body curly braces as JSX expressions.
Stacked on #11
This PR is based on `chore/site-seo` (PR #11). Merge order:
After #11 merges this PR's diff will narrow to just the three GA-related files.
Test plan
Privacy notes
🤖 Generated with Claude Code