Skip to content

feat: Add performance monitoring and analytics#9

Merged
slmingol merged 3 commits intomainfrom
feature/performance-analytics
Feb 21, 2026
Merged

feat: Add performance monitoring and analytics#9
slmingol merged 3 commits intomainfrom
feature/performance-analytics

Conversation

@slmingol
Copy link
Copy Markdown
Owner

Overview

This PR adds comprehensive performance monitoring and analytics support to the React Connections Game.

Changes Made

1. Performance Monitoring (Core Web Vitals)

  • Added web-vitals package (v5.1.0)
  • Created src/lib/performance.js utility for tracking:
    • CLS (Cumulative Layout Shift) - Visual stability
    • FCP (First Contentful Paint) - Initial render
    • INP (Interaction to Next Paint) - Responsiveness
    • LCP (Largest Contentful Paint) - Loading performance
    • TTFB (Time to First Byte) - Server response time
  • Metrics log to console in development, can be sent to analytics in production

2. Game Analytics

  • Created src/lib/analytics.js with provider-agnostic tracking
  • Automatically tracks key game events:
    • Game lifecycle: game_won, game_lost (with metadata)
    • Player actions: guess_submitted, guess_correct, guess_incorrect
    • UI interactions: shuffle_clicked, deselect_clicked, view_results_clicked, share_score_clicked, info_modal_opened

3. Analytics Integration Points

  • GameStatusProvider: Tracks game won/lost with guess counts and categories solved
  • GameControlButtonsPanel: Tracks shuffle, deselect, and all guess submissions with outcomes
  • ShareScoreButton: Tracks share button clicks
  • ViewResultsModal: Tracks results modal opens
  • InfoModal: Tracks info modal opens

4. Multi-Provider Support

The analytics system supports multiple providers without code changes:

  • Google Analytics 4 (gtag)
  • Plausible Analytics
  • Custom analytics instances

Configuration is done via simple HTML script tags or window object setup.

5. Documentation

  • Updated README with comprehensive analytics setup guide
  • Documented all tracked metrics and events
  • Included configuration examples for popular analytics providers

Testing

  • ✅ Build passes: npm run build
  • ✅ All tests pass: 24/24 tests (Vitest + Storybook component tests)
  • ✅ Zero security vulnerabilities: npm audit
  • ✅ Development mode: Analytics logs to console
  • ✅ Production mode: Ready to send to configured analytics providers

Benefits

  1. Performance insights: Track Core Web Vitals to optimize user experience
  2. User behavior data: Understand how players interact with the game
  3. Product decisions: Data-driven improvements based on actual usage
  4. Provider flexibility: Works with any analytics service
  5. Privacy-first: Only tracks in-app events, no personal data
  6. Zero impact dev mode: Clean console logging for debugging

Files Changed

  • package.json & package-lock.json: Added web-vitals dependency
  • src/lib/analytics.js: New analytics utility (NEW)
  • src/lib/performance.js: New performance monitoring utility (NEW)
  • src/index.js: Integrated performance monitoring
  • src/providers/GameStatusProvider/GameStatusProvider.jsx: Added game event tracking
  • src/components/GameControlButtonsPanel/GameControlButtonsPanel.jsx: Added action tracking
  • src/components/ShareScoreButton/ShareScoreButton.jsx: Added share tracking
  • src/components/modals/ViewResultsModal/ViewResultsModal.jsx: Added modal tracking
  • src/components/modals/InfoModal/InfoModal.jsx: Added modal tracking
  • README.md: Added comprehensive analytics documentation

Migration Notes

No breaking changes. Analytics is opt-in - works immediately in development (console logs), requires simple configuration for production analytics.

Closes the final item (and-computers#10) from the modernization improvement list.

- Add web-vitals package for Core Web Vitals tracking (CLS, FCP, INP, LCP, TTFB)
- Create analytics utility with support for multiple providers (GA4, Plausible, custom)
- Track game events: game_won, game_lost, guess submissions, UI interactions
- Integrate performance monitoring in application entry point
- Add analytics tracking to key user interactions:
  - Game lifecycle events (won/lost with metadata)
  - Guess submissions and outcomes
  - UI interactions (shuffle, deselect, view results, share, info modal)
- Update README with comprehensive analytics configuration guide
- Maintain zero security vulnerabilities

The analytics system is provider-agnostic and logs to console in development mode.
In production, it automatically sends data to configured analytics providers without
requiring code changes.
Resolves MODULE_TYPELESS_PACKAGE_JSON warning when running tests.
This warning appeared because .storybook/main.js uses ES modules syntax
without package.json explicitly declaring type: module.
- Added name: react-connections-game
- Added version: 1.0.0
- Added description
- Added license: MIT
- Added repository, bugs, homepage URLs
- Added keywords for better discoverability

Resolves missing package.json metadata from modernization checklist.
@slmingol slmingol merged commit 85b5476 into main Feb 21, 2026
1 of 2 checks passed
@slmingol slmingol deleted the feature/performance-analytics branch February 21, 2026 04:05
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.

2 participants