feat: Implement Player Retention Analytics System (Phase 2.2)

Backend:
- Add player_sessions table (migration 004) for session tracking
- Implement retention calculation queries (24h/48h/72h post-wipe)
- Add /api/plugin/player-event endpoint for join/leave tracking
- Add /api/analytics/retention endpoint with CSV export
- Track unique players, session duration, new vs returning ratio

Frontend:
- Create PlayerRetentionView with ECharts retention curves
- Add multi-wipe comparison (last 3/6/10/20 wipes)
- Display summary metrics and detailed wipe table
- Add /retention route to router

Plugin:
- Update CorrosionCompanion.cs to send player events to new endpoint
- Track player join/leave with license_key authentication

Enables data-driven wipe timing optimization by answering:
"What percentage of players return 24h/48h/72h after a wipe?"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Vantz Stockwell
2026-02-15 14:23:21 -05:00
parent cef89ade18
commit f29524e633
9 changed files with 1020 additions and 12 deletions

View File

@@ -4,6 +4,40 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Added (Phase 2.2 — Player Retention Analytics)
**Backend:**
- Migration `004_player_sessions.sql` — Player session tracking table with indexes for retention queries
- `backend/src/db/player_sessions.rs` — Complete player session tracking and retention analysis:
- `track_player_join()` / `track_player_leave()` — Record individual player sessions
- `calculate_retention_after_wipe()` — Calculate 24h/48h/72h return rates per wipe
- `get_unique_player_count()` / `get_avg_session_duration()` — Session metrics
- `get_new_vs_returning_ratio()` — New vs returning player analysis
- `get_recent_wipe_retention_metrics()` — Multi-wipe retention trends
- `cleanup_old_player_sessions()` — 90-day retention cleanup
- `backend/src/api/plugin.rs` — Plugin event endpoints:
- `POST /api/plugin/player-event` — Track player join/leave events
- `POST /api/plugin/checkin` — Plugin registration on server start
- Extended `backend/src/api/analytics.rs` with retention endpoints:
- `GET /api/analytics/retention?wipe_count=6` — Multi-wipe retention metrics
- `GET /api/analytics/retention/export` — CSV export of retention data
**Frontend:**
- `PlayerRetentionView.vue` — Complete retention analytics dashboard:
- ECharts retention curve (24h/48h/72h lines across multiple wipes)
- Summary cards: unique players, avg session duration, new vs returning ratio
- Wipe selector (last 3/6/10/20 wipes)
- Detailed wipe table with retention percentages
- CSV export functionality
- Added route `/retention` to router
- TypeScript interfaces: `WipeRetentionMetric`, `SessionSummary`, `RetentionResponse`
**Plugin:**
- Updated `CorrosionCompanion.cs` to track player events via `/api/plugin/player-event`
- Modified `OnPlayerConnected` / `OnPlayerDisconnected` hooks with license_key authentication
**Purpose:** Answers critical question: "What percentage of players return 24h/48h/72h after a wipe?" Enables data-driven wipe timing optimization and player retention analysis.
### Added (Phase 2.2 — Map Analytics System)
**Backend:**