Add analytics integration with Horchposten backend #1
Reference in New Issue
Block a user
Delete Branch "feature/analytics-integration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
src/game/stats.{c,h}— per-session gameplay metrics accumulator (kills, deaths, shots, dashes, jumps, pickups, damage dealt/taken, time elapsed, composite score)src/game/analytics.{c,h}— EM_JS bridge that calls Horchposten's session start/end endpoints viafetch(), withsendBeaconfallback on tab closelevel.c(enemy kills, damage, shot hits, pickups, deaths) andplayer.c(jumps, dashes, shots fired)main.c— sessions start on game begin, end on victory ("completed"), quit, restart, or tab closecrypto.randomUUID()and persisted inlocalStoragedata-analytics-url/data-analytics-keyattributes on the canvas container elementConfiguration
Set the analytics endpoint on the HTML container:
Test plan
make)make web)levels_completedincrementssendBeaconfires session end/admin/dashboard shows recorded sessions🤖 Generated with Claude Code
Implements session-based analytics tracking that sends gameplay stats to the Horchposten API. Adds stats.{c,h} for accumulating per-session metrics (kills, deaths, shots, dashes, jumps, pickups, damage, time) and analytics.{c,h} with EM_JS bridge for fetch() calls to the backend. Client ID is persisted in localStorage. Session start/end hooks are wired into all game lifecycle events (level transitions, restart, quit, tab close via sendBeacon). Analytics URL/key are configured via data attributes on the canvas container. Non-WASM builds compile with no-op stubs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>