POST /api/analytics/collect
Client ingestion for AnalyticsTracker — sessions, page views, clicks, etc. runtime: nodejs.
Handler
POST via withUniversalEnhancements(postHandler).
Auth
Optional session: auth() supplies userId when logged in; anonymous events still accepted.
Body modes
- Batched:
{ events: [...] }validated byBatchedAnalyticsRequestSchema— each event passed toprocessEventwith client IP (getClientIpAddress), user-agent, optional user id. - Single event: non-batch shape handled in the same handler (see
processEventswitch in source).
Zod schemas at top of file (SessionDataSchema, PageViewSchema, …) define allowed payload fields.
Storage
Writes via sql and helper functions in the same route module (large file ~1000 lines) — dashboard reads aggregated tables.
Sources: src/app/api/analytics/collect/route.ts, src/lib/analytics/AnalyticsTracker.ts (caller)