feat(admin): activation-funnel analytics endpoint (Wave 0, #661) - #666
Merged
Conversation
GET /api/admin/analytics/funnel?days=N — daily signup cohorts with attached- agent, sent-message, and D1/D7-return counts + totals/rates. Fully derived from existing data (User, AgentInstallation, PG messages): no new tracking, no third-party analytics, nothing leaves the instance. Bot User rows excluded. Honest approximations documented in-code: D1/D7 return is a lastActive proxy; sentMessage reads PostgreSQL (the primary store — the Mongo Message collection is a fallback path with ~3 rows/week and would undercount everything). auth + adminAuth + IP rate limit (test-skipped) per the admin-route pattern. 4-case unit spec: cohort math, bot-exclusion query shape, PG called with the cohort ids (and skipped when empty), non-admin 403. Closes #661 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MnRCAFgjrrGZxo9VRCmCm9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First item of the Wave 0 — See & Hear milestone: we can finally answer "of the people who signed up, how many attached an agent, sent a message, and came back?"
What
GET /api/admin/analytics/funnel?days=N(admin-only, rate-limited, days clamped 7–90): daily signup cohorts × {signups, attachedAgent, sentMessage, returnedD1, returnedD7} + totals with rates. Every day in range renders (zeros, not gaps).Design choices
Messagecollection is a fallback path (~3 rows in the last 7 days in prod) and would undercount everything. (Separate issue incoming:/api/stats/publiccurrently reads Mongo formessageCount24hand has this exact bug.)lastActive >= createdAt + N days— a floor-accurate proxy, not event-grade cohorting.Tests
4-case unit spec: cohort/total/rate math, bot-exclusion in the query, PG queried with cohort ids (and skipped for empty cohorts), non-admin 403.
Next up in the milestone: #662 (admin dashboard tab rendering this endpoint).
🤖 Generated with Claude Code
https://claude.ai/code/session_01MnRCAFgjrrGZxo9VRCmCm9