forked from tas/major_tom
Add analytics integration with Horchposten backend
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>
This commit is contained in:
17
src/game/analytics.h
Normal file
17
src/game/analytics.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef JNR_ANALYTICS_H
|
||||
#define JNR_ANALYTICS_H
|
||||
|
||||
#include "game/stats.h"
|
||||
|
||||
/* Initialize analytics subsystem (load/generate client_id).
|
||||
* No-op on non-WASM builds. */
|
||||
void analytics_init(void);
|
||||
|
||||
/* Start a new analytics session. Sends POST to the backend. */
|
||||
void analytics_session_start(void);
|
||||
|
||||
/* End the current analytics session with final stats.
|
||||
* end_reason: "death", "quit", "timeout", or "completed". */
|
||||
void analytics_session_end(const GameStats *stats, const char *end_reason);
|
||||
|
||||
#endif /* JNR_ANALYTICS_H */
|
||||
Reference in New Issue
Block a user