Covers player event tracking, session tracking, cohort retention (D1, D7, D30), ordered funnels and retention targets for a game backend on PostgreSQL with a Redis buffer.
Ships in game-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Events go from the game server into a Redis list, a single worker drains the list into PostgreSQL in batches, and retention and funnels run as SQL over the stored tables.
noun_verb, snake_case, past tense for finished actions: level_completed, item_purchased, match_ended. Keep a finite catalog in templates/event-catalog.md; an event not in the catalog does not ship.userId, sessionId, createdAt, version, platform. The client fills them. It drops events tracked before a session starts instead of filing them under a fake session id.track() returns at once and never throws. A Redis outage loses events, not frames.track() does LPUSH. One worker per Redis key runs flush(), which reads the oldest batch from the list tail, inserts it, then trims it. The insert skips ids that already exist, so a crash between insert and trim replays safely. Two flushers on one key insert the same batch twice and trim twice, losing events.end, so run closeIdleSessions(db, idleMs) on a schedule with idleMs set to a few heartbeat intervals.session_id for flows that must finish in one sitting (tutorial, first match), user_id for flows across sessions (install to first purchase). The query is in templates/retention-dashboard.md.(now() AT TIME ZONE 'UTC')::date for today. CURRENT_DATE follows the connection's time zone.experimentId and variant in properties and group by them in SQL.Install the packages (versions this skill was checked against: drizzle-orm 0.45.4, ioredis 6.0.0). Install your Postgres driver as postgres-game-schema describes.
bun add drizzle-orm ioredis
bun add -d drizzle-kit
Copy boilerplate/analytics-schema.ts into your schema directory, then generate and run the migration with bunx drizzle-kit generate and bunx drizzle-kit migrate.
Create one client per connected player. The caller owns both connections:
import { AnalyticsClient, type AnalyticsDb } from './analytics-client';
import type Redis from 'ioredis';
export const analyticsFor = (redis: Redis, db: AnalyticsDb, player: { id: string; platform: string }) =>
new AnalyticsClient({ redis, db, userId: player.id, platform: player.platform, version: process.env.GAME_VERSION ?? 'dev' });
Instrument the game server. Do not await these calls:
analytics.trackSession('start'); // on connect
analytics.track('level_completed', { levelId: 'level_12', score: 4500, deaths: 3 });
analytics.track('tutorial_step_completed', { step: 3, experimentId: 'onboarding_v2', variant: 'shortened' });
analytics.trackSession('heartbeat'); // on a fixed interval while connected
analytics.trackSession('end'); // on disconnect
In one worker process, on a schedule: call flush() on one AnalyticsClient built for that worker (await workerClient.flush(); it drains until the list is empty and skips, with a log line, any buffered row that is not a valid event) and await closeIdleSessions(db, idleMs). Nightly, store cohorts with storeRetentionCohorts(db, n) for n in 1, 7, 30, from templates/retention-dashboard.md.
This skill gives no D1, D7 or D30 target numbers. A benchmark only compares if its source states the same definition of "day N" as rule 6, the same platform and the same genre. Set targets from your own baseline:
retention_pct across those mature cohorts from analytics_retention_cohorts. That is the baseline.platform and by acquisition source before comparing; a new channel changes the mix, not the game.analytics_sessions. Archive old analytics_events rows, keep sessions, or every archived player re-enters as a new cohort.boilerplate/analytics-schema.ts: copy when adding the three analytics tables (events, sessions, stored retention cohorts) to a Drizzle schema.boilerplate/analytics-client.ts: copy when wiring track(), session tracking, the buffer flush and the idle-session closer. It takes the Drizzle database and the ioredis client as parameters, so it works with any Drizzle Postgres driver.templates/retention-dashboard.md: read when writing retention, funnel, session-length or DAU/MAU queries. Every query in it was run on PostgreSQL 16.templates/event-catalog.md: copy when starting the list of events the team agrees to track.references/sources.md: read when you need the doc pages behind the Redis and PostgreSQL behaviour this skill relies on.postgres-game-schema (base schema, players table, Drizzle setup)redis-game-patterns (Redis connection)bullmq-game-queues (scheduled flush and nightly cohort jobs)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
39 skills in this plugin
/betterauth-integrationCovers the game-specific layer of Better Auth: player, moderator and admin roles, session checks on game routes and WebSocket handshakes, and keeping the auth session apart from the game session. Use when a game needs player login, moderator or admin powers, or authenticated real-time connections, and the project uses Better Auth./bullmq-game-queuesBackground job design for game backends on BullMQ and Redis: one queue per game domain, idempotent reward fulfilment, and cron schedulers for daily rewards and season ends. Use when a game needs matchmaking requests, reward grants, match results, notifications or analytics processed off the request path, or recurring and timed jobs such as daily login rewards, leaderboard snapshots and season rollovers.//game-dev:gameplay-analyticsfrom game-dev
npx claudepluginhub fcsouza/agent-skills --plugin game-devOther plugins' skills for the same job