Skip to content

Analytics Module

Public Summary

Tracks visitor and user behavior — page views, feature usage, session activity — and provides dashboard summaries with CSV export.

Internal Details

Files

FileRole
analytics.controller.jsHTTP handlers
analytics.service.jsAggregation and export logic
analytics.routes.jsRoute definitions
analytics.schema.jsZod validation
analytics.model.jsEvent and aggregate schemas
analytics.repository.jsData access
analytics.cron.jsDaily cleanup cron

Endpoints

MethodPathAuthDescription
POST/analytics/heartbeatPublicTrack page view / activity
GET/analytics/summaryJWTDashboard summary data
GET/analytics/feature-trendsJWTFeature usage trends
GET/analytics/exportJWT (admin)CSV export

Data Models

AnalyticsEvent

type     : PAGE_VIEW | HEARTBEAT | FEATURE_USAGE
visitorId: String
userId   : ObjectId → User (optional)
metadata : Object
createdAt: Date

AnalyticsMonthlyAggregate — pre-computed monthly rollups.

Cron Job

  • Daily at 02:30: purges raw events older than 90 days.
  • Monthly aggregates are retained indefinitely.

Dual Identity Tracking

Events track both anonymous visitorId (cookie-based) and authenticated userId when available, allowing correlation of pre-login and post-login behavior.

Source Anchors

PathRelevance
apps/server/src/modules/analytics/Controller, service, routes, schema, model, repository, cron

Student Obrok engineering documentation.