Skip to content

refactor: slim GA4 to core events, PostHog is primary#159

Merged
Hugo0 merged 1 commit into
mainfrom
slim-ga4-v2
Mar 14, 2026
Merged

refactor: slim GA4 to core events, PostHog is primary#159
Hugo0 merged 1 commit into
mainfrom
slim-ga4-v2

Conversation

@Hugo0

@Hugo0 Hugo0 commented Mar 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • GA4 now only receives 4 events: game_start, game_complete, game_abandon, page_view_enhanced
  • All other 15+ events are PostHog-only
  • Removes docs/CURATED_WORDS.md and docs/TODO.md from 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_EVENTS allowlist in track() — GA4 send is now gated. One functional change, ~10 lines.

Test plan

  • pnpm build + pnpm test
  • Verify GA4 Realtime still shows game_complete events
  • Verify PostHog still receives all events

Summary by CodeRabbit

  • Documentation

    • Removed internal project documentation files related to curation processes and development planning.
  • Analytics

    • Refined event tracking to prioritize core user interactions (game start, completion, abandonment, page views), improving data collection focus and monitoring efficiency.

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.
@coderabbitai

coderabbitai Bot commented Mar 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Documentation Removal
docs/CURATED_WORDS.md, docs/TODO.md
Deleted documentation files covering curated words registry procedures and project-wide TODO items.
Analytics Event Filtering
frontend/src/analytics.ts
Introduced GA4_EVENTS set to restrict GA4 event sending to core events only; updated track wrapper to check event names against this set before calling GA4, while maintaining all PostHog event tracking.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • feat: Add GA4 analytics tracking #113: Directly modifies frontend/src/analytics.ts to introduce the GA4 analytics module and tracking functions that this PR now filters.
  • Feat/analytics tracking #114: Also modifies frontend/src/analytics.ts with full analytics module additions that work in conjunction with this PR's GA4 event filtering.

Poem

🐰 Old documents bundled away with care,
TODO lists vanish into thin air,
GA4 now whispers just the core events true,
PostHog hears all—a cleaner, focused view! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: refactoring GA4 to send only core events while positioning PostHog as the primary analytics receiver. It directly summarizes the functional modification in frontend/src/analytics.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch slim-ga4-v2
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ead824c and d66f97d.

📒 Files selected for processing (3)
  • docs/CURATED_WORDS.md
  • docs/TODO.md
  • frontend/src/analytics.ts
💤 Files with no reviewable changes (2)
  • docs/CURATED_WORDS.md
  • docs/TODO.md

Comment thread frontend/src/analytics.ts
Comment on lines +146 to 147
if (GA4_EVENTS.has(eventName) && typeof window.gtag === 'function') {
window.gtag('event', eventName, params);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant