Feat/analytics tracking#114
Conversation
Add comprehensive analytics module to answer key business questions: - Game lifecycle: start, complete, abandon, guess tracking - Retention: returning players, streak milestones - Virality: share click/success/fail funnel - PWA: install prompts, installs, dismissals - Frustration: invalid words, rapid backspace detection - Features: settings changes, help/stats modal opens All events include language parameter for per-language analysis. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…gnals - Replace noisy frustration_signal events (fired every 3rd invalid) with session-aggregated context in game_complete event - Add total_invalid_attempts, max_consecutive_invalid, had_frustration, and time_to_complete_seconds to game_complete - Track game start time for duration measurement - Reset frustration state on game start/complete - onValidWord() resets consecutive invalid counter Before: 247 frustration_signal events = unclear if 247 users or 30 users × 8 After: One game_complete with full struggle context per completed game
📝 WalkthroughWalkthroughIntroduces a comprehensive Google Analytics 4 event tracking module with type-safe APIs for game lifecycle events (start, complete, abandon, guess submission), feature usage (sharing, PWA, settings), and error/frustration state tracking. Integrates tracking calls throughout game.ts and pwa.ts without altering core logic. Changes
Sequence DiagramsequenceDiagram
participant Game as Game App
participant Analytics as Analytics Module
participant GA4 as Google Analytics 4
Game->>Analytics: initErrorTracking(language)
Game->>Analytics: trackPageView(language)
Game->>Analytics: trackGameStart(params)
Analytics->>GA4: gtag event: game_start
Game->>Analytics: initAbandonTracking(getState)
Note over Game,Analytics: Guess Submission Flow
alt Valid Word
Game->>Analytics: onValidWord()
Game->>Analytics: trackGuessSubmit(language, attempt, true)
Analytics->>GA4: gtag event: guess_submit
else Invalid Word
Game->>Analytics: trackInvalidWordAndUpdateState(params)
Analytics->>Analytics: Update frustration state
Analytics->>GA4: gtag event: invalid_word
Game->>Analytics: trackGuessSubmit(language, attempt, false)
Analytics->>GA4: gtag event: guess_submit
end
Note over Game,Analytics: Game Completion Flow
Game->>Analytics: resetFrustrationState()
Game->>Analytics: trackGameComplete(params with frustration metrics)
Analytics->>GA4: gtag event: game_complete
Game->>Analytics: trackStreakMilestone(language, streak)
Analytics->>GA4: gtag event: streak_milestone
Note over Game,Analytics: Share Flow
Game->>Analytics: trackShareClick(params)
Analytics->>GA4: gtag event: share_click
alt Share Success
Game->>Analytics: trackShareSuccess(params)
Analytics->>GA4: gtag event: share_success
else Share Fail
Game->>Analytics: trackShareFail(language, method, error)
Analytics->>GA4: gtag event: share_fail
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
Resolved conflicts in favor of session-aggregated analytics approach: - analytics.ts: Keep resetFrustrationState, onValidWord, trackInvalidWordAndUpdateState - game.ts: Keep game start time tracking and frustration context in game_complete
* feat: Add GA4 analytics tracking for user behavior insights Add comprehensive analytics module to answer key business questions: - Game lifecycle: start, complete, abandon, guess tracking - Retention: returning players, streak milestones - Virality: share click/success/fail funnel - PWA: install prompts, installs, dismissals - Frustration: invalid words, rapid backspace detection - Features: settings changes, help/stats modal opens All events include language parameter for per-language analysis. * refactor: Session-aggregate analytics events instead of fragmented signals - Replace noisy frustration_signal events (fired every 3rd invalid) with session-aggregated context in game_complete event - Add total_invalid_attempts, max_consecutive_invalid, had_frustration, and time_to_complete_seconds to game_complete - Track game start time for duration measurement - Reset frustration state on game start/complete - onValidWord() resets consecutive invalid counter Before: 247 frustration_signal events = unclear if 247 users or 30 users × 8 After: One game_complete with full struggle context per completed game ---------
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.