Repository navigation
feat: GA4 acquisition analytics (gtag.js, env+host gated, manual pageviews) - #63
Merged
Merged
Conversation
…al pageviews) Adds Google Analytics 4 as the acquisition/traffic-source layer alongside PostHog (which remains the product-behavior system, untouched). - src/analytics/ga4Model.mjs: pure validation/sanitization — measurement-ID format check, devledger.site production gate + localhost debug gate, canonical pathname normalization, page_location/page_title params, strict event allowlist (page_view, login_start, login, select_content), and utm_*→campaign_* field mapping with slug-charset sanitization. - src/analytics/ga4.ts: typed facade — lazy init only when VITE_GA_MEASUREMENT_ID is set and the host is devledger.site (localhost runs debug_mode), send_page_view:false, async gtag.js from googletagmanager.com only, pathname-deduped manual page_view, never throws. No User-ID, no identify, no Signals/ads features. - Wiring: boot init+pageview+popstate in main.tsx; navigate/popstate pageviews in pages.ts; login_start on the GitHub button and login on the post-OAuth successful boot — method:"github" only, zero identity. - CSP: adds www.googletagmanager.com (script-src, img-src) and www.google-analytics.com + region1.google-analytics.com (connect-src, img-src) — the minimum for direct gtag.js collection. - Env: VITE_GA_MEASUREMENT_ID joins the public-env allowlist; .env.example documents the name with an empty placeholder. The real ID lives only in Vercel env config. - Legal: Privacy/Security/Terms disclose GA4 — sanitized pageviews, campaign fields, login funnel, _ga cookies, disabled features. - Tests: 24-case suite covering ID hygiene, host gating, sanitization, event allowlist, UTM rules, wiring, and PostHog separation. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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
src/analytics/ga4Model.mjs+src/analytics/ga4.ts: silent no-op withoutVITE_GA_MEASUREMENT_ID; official telemetry only ondevledger.site(localhost runsdebug_mode);send_page_view:falsewith manual pathname-dedupedpage_viewbuilt from canonical origin + normalized pathname —location.href, query strings and fragments never reach GA4.page_view,login_start,login,select_content— all schema-validated,method:"github"only, no identity/user_id.utm_*fields are read, slug-sanitized, and lifted into GA4's documentedcampaign_*dimensions viagtag('set', …);page_locationstays clean.www.googletagmanager.com(script/img),www.google-analytics.com+region1.google-analytics.com(connect/img). No GTM, no Ads, no Signals, no remarketing._gacookies).Test plan
npm run typecheckclean;npm test475 pass / 0 fail;npm run buildgreendist/scan: noG-…measurement ID in committed bundleGenerated with Devin