admin-funnel
What it does
Computes anonymous-visitor → identified-user → installed-instance conversion metrics for the platform funnel. It reads items rows under three app-seeded item types — funnel_signal, anonymous_session, and spine_instance — and returns counts, conversion rates, and a stage distribution over the last 30 days.
This is framework-internal telemetry for the platform operator (growth and install funnel for Spine itself), not per-customer app analytics.
Route and methods
None — this file exports no handler. It exports a single createHandler-wrapped const, metrics, which nothing else imports or dispatches. As shipped there is no HTTP entrypoint: the file is deployed to the functions directory by the assembly script like every other .framework/functions file, but Netlify has no handler export to invoke. Treat it as a dormant module pending a dispatch handler (or a wiring bug); do not cite it as a live endpoint.
Authentication
If metrics were wired: requireSystemContextWithAudit runs first — anonymous → 401, non-system_admin → 403. All queries run on adminDb across all accounts (see Agent notes).
Request contract
metrics(ctx, body) takes no parameters — the 30-day window is hardcoded.
Response contract
{ anonymous_visitors, identified_users, installed_instances, conversion_rates: { anonymous_to_identified, identified_to_installed }, stage_distribution: [{ stage, count, percentage }] }
anonymous_visitors—anonymous_sessionitems in the last 30 days whosedata->lifecycle->>stitched_to_account_idis null.identified_users— distinctaccount_ids onfunnel_signalitems in the last 30 days.installed_instances—spine_instanceitems with a non-nulldata->>claimed_by_person_id(all time).stage_distribution— counts offunnel_signal.data->>stageover the last 30 days, only counting rows that have anaccount_id.
Side effects
None — read-only aggregation.
Errors
No explicit error paths. Missing signal types are expected on a clean install (the types are seeded by installed apps): when none of the three type slugs resolves, metrics returns a zeroed payload instead of failing. Database errors would surface as thrown errors through createHandler's 500 path.
Agent notes
- Verify before use. The missing
handlerexport means there is no routed endpoint; check the current tree before assumingGET /api/admin-funneldoes anything. - Platform-wide reads, system-gated. Every query runs on
adminDbwith noaccount_idfilter — appropriate for a platform funnel. TherequireSystemContextWithAuditgate means onlysystem_adminprincipals reach it, so cross-account visibility is intended, not a leak. - Signal data is written elsewhere —
emitSignalin.framework/functions/_shared/funnel.tsinserts typed signal items (funnel_signalamong them) and firesitem_createdtriggers; these admin modules only read the results. - The
funnel_signal_usetype seed exists in the framework (.framework/seeds/types/funnel_signal_use.json); thefunnel_signal/anonymous_session/spine_instanceslugs the queries look for are seeded by installed apps, hence the degrade-to-zeros behavior.