refactor: slim GA4 to core events, PostHog is primary#159
Conversation
GA4 now only receives 4 events: game_start, game_complete, game_abandon, page_view_enhanced — the only ones with registered custom dimensions. All other 15+ events are PostHog-only. Also removes docs/CURATED_WORDS.md and docs/TODO.md from git. These are private working docs, not meant for the repo.
📝 WalkthroughWalkthroughThis PR removes two documentation files (a Curated Words Registry guide and project TODO list) and modifies the analytics tracking to restrict GA4 event sending to a core set of events (game_start, game_complete, game_abandon, page_view_enhanced), while PostHog continues handling all events. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/src/analytics.ts`:
- Around line 146-147: GA4_EVENTS is used to gate calls to window.gtag so
non-core events like guess_submit, guess_time, and first_guess_delay are dropped
entirely; change the logic so GA4 still only receives GA4_EVENTS via
window.gtag('event', eventName, params) but PostHog (posthog.capture or
posthog?.capture) is treated as the primary sink for non-core events—i.e.,
always call posthog.capture(eventName, params) when posthog is available
regardless of GA4_EVENTS membership (ensure the code paths around GA4_EVENTS,
window.gtag, and posthog.capture are updated so those three guess_* events are
no longer skipped).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 82dc6f36-8014-4c4d-8f7d-81e801f0c118
📒 Files selected for processing (3)
docs/CURATED_WORDS.mddocs/TODO.mdfrontend/src/analytics.ts
💤 Files with no reviewable changes (2)
- docs/CURATED_WORDS.md
- docs/TODO.md
| if (GA4_EVENTS.has(eventName) && typeof window.gtag === 'function') { | ||
| window.gtag('event', eventName, params); |
There was a problem hiding this comment.
Per-guess events are now dropped by both analytics providers
At Line 146, GA4 is restricted to core events; at Line 155, PostHog still skips guess_submit, guess_time, and first_guess_delay. Those three events are now emitted nowhere, which causes silent analytics loss.
Suggested fix (align with “PostHog as primary” for non-core events)
- // PostHog (skip high-volume per-guess events to stay within free tier)
+ // PostHog (primary sink for non-core events)
try {
- if (!POSTHOG_SKIP_EVENTS.has(eventName)) {
+ // Ensure events excluded from GA4 are still captured in PostHog.
+ if (!POSTHOG_SKIP_EVENTS.has(eventName) || !GA4_EVENTS.has(eventName)) {
posthog.capture(eventName, params);
}
} catch {
// Silently fail
}Also applies to: 153-156
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/analytics.ts` around lines 146 - 147, GA4_EVENTS is used to gate
calls to window.gtag so non-core events like guess_submit, guess_time, and
first_guess_delay are dropped entirely; change the logic so GA4 still only
receives GA4_EVENTS via window.gtag('event', eventName, params) but PostHog
(posthog.capture or posthog?.capture) is treated as the primary sink for
non-core events—i.e., always call posthog.capture(eventName, params) when
posthog is available regardless of GA4_EVENTS membership (ensure the code paths
around GA4_EVENTS, window.gtag, and posthog.capture are updated so those three
guess_* events are no longer skipped).
Summary
game_start,game_complete,game_abandon,page_view_enhanceddocs/CURATED_WORDS.mdanddocs/TODO.mdfrom git (private working docs)Why
PostHog captures every property automatically. GA4 requires manual registration and was silently dropping 6/10 properties on
game_complete(game_mode,had_frustration,total_invalid_attempts,max_consecutive_invalid,streak_after,time_to_complete_seconds).GA4 remains for: Google Search Console integration, free session counting, and basic game metrics.
Change
Added
GA4_EVENTSallowlist intrack()— GA4 send is now gated. One functional change, ~10 lines.Test plan
pnpm build+pnpm testgame_completeeventsSummary by CodeRabbit
Documentation
Analytics