Wire real GA4 ID and Partytown analytics #8

Closed
opened 2026-06-09 18:32:04 +00:00 by glow · 1 comment
Owner

The .env.example shows PUBLIC_GA4_ID=G-PLACEHOLDER — this means no analytics are actually being sent. Partytown is configured in vite.config.ts but there's no visible GA4 script tag in the layout or router-head.Current state: - Partytown lib is copied to dist on build- GA4 ID is placeholder- No

The .env.example shows `PUBLIC_GA4_ID=G-PLACEHOLDER` — this means no analytics are actually being sent. Partytown is configured in vite.config.ts but there's no visible GA4 script tag in the layout or router-head.Current state: - Partytown lib is copied to dist on build- GA4 ID is placeholder- No <Script> tag loading gtag.js or gtag.config in the <head>Fix:1. Set real GA4 ID in .env2. Wire gtag.js via Partytown in layout or router-head3. Verify requests appear in GA4 property4. Wire cookie consent to block GA4 until user accepts
glow closed this issue 2026-06-09 19:41:52 +00:00
Author
Owner

Fixed in commit 6f3e104.

root.tsx — Removed unconditional GA4 script tags. Partytown config + runtime stay here as shared infrastructure.

analytics-ga4.tsx (new) — Client-side component that checks consent cookie on mount. If consent=1 exists, dynamically injects gtag.js init + loader via Partytown (type="text/partytown"). Also listens for consent:granted custom event from CookieConsent.

cookie-consent.tsx — Dispatches consent:granted on window after setting consent=1 cookie.

layout.tsx — Imports and renders <AnalyticsGA4 /> right after <CookieConsent />.

Behavior:

  • New visitors: banner shown → GA4 stays blocked until Accept clicked
  • Returning visitors (consent=1 cookie set): GA4 loads immediately on page load
  • Decline: no GA4 ever loads

Closes #8

Fixed in commit 6f3e104. **root.tsx** — Removed unconditional GA4 script tags. Partytown config + runtime stay here as shared infrastructure. **analytics-ga4.tsx** (new) — Client-side component that checks consent cookie on mount. If `consent=1` exists, dynamically injects gtag.js init + loader via Partytown (`type="text/partytown"`). Also listens for `consent:granted` custom event from CookieConsent. **cookie-consent.tsx** — Dispatches `consent:granted` on window after setting `consent=1` cookie. **layout.tsx** — Imports and renders `<AnalyticsGA4 />` right after `<CookieConsent />`. Behavior: - New visitors: banner shown → GA4 stays blocked until Accept clicked - Returning visitors (consent=1 cookie set): GA4 loads immediately on page load - Decline: no GA4 ever loads Closes #8
Sign in to join this conversation.
No labels
bug
feature
improvement
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
glow/first-home-diy#8
No description provided.