Shipflash logoDocs

Analytics

Analytics turns stored app, waitlist, content, billing, usage, and credit records into dashboard charts.

On this page

Where to look

AreaPaths
Routessrc/app/(dashboard)/analytics/platform, /analytics/revenue
Range APIssrc/app/api/analytics/platform/range/route.ts, src/app/api/analytics/revenue/range/route.ts
Serversrc/features/analytics/server/queries, services, schemas, persistence
Sharedsrc/features/analytics/shared/chart-config.ts, date-range.ts
UIsrc/features/analytics/ui/platform-dashboard.tsx, revenue-dashboard.tsx, chart cards, time-range-selector.tsx
Data sourcesanalytics_events, waitlist_signups, billing_usage_events, billing_credit_transactions, billing_orders, billing_invoices

Code-backed analytics map

Dashboard surfaces

Dashboard pages and range APIs delegate metric assembly to analytics feature modules.

  • src/app/(dashboard)/analytics/platform/page.tsx
  • src/app/(dashboard)/analytics/revenue/page.tsx
  • src/app/api/analytics/platform/range/route.ts
  • src/app/api/analytics/revenue/range/route.ts

Metric queries

Platform, revenue, MRR, and signal summaries are assembled server-side before chart UI renders them.

  • src/features/analytics/server/queries/platform-metrics.ts
  • src/features/analytics/server/queries/revenue-dashboard-data.ts
  • src/features/analytics/server/queries/mrr.ts
  • src/features/analytics/server/queries/revenue-signal-summary.ts

Series and model visibility

Revenue charts use shared range, time-series, and billing-model helpers so disabled billing models do not leak into UI.

  • src/features/analytics/server/services/query-range.ts
  • src/features/analytics/server/services/revenue/model-visibility.ts
  • src/features/analytics/server/queries/timeseries/revenue.ts

Analytics range flow

  1. 1

    Normalize the requested range

    Range services and schemas keep dashboard and API requests on the same date-window contract.

    • src/features/analytics/server/services/dashboard-range.ts
    • src/features/analytics/shared/date-range.ts
  2. 2

    Query source tables server-side

    Metric queries read analytics, waitlist, content, billing, usage, and credit records without provider calls in render loops.

    • src/features/analytics/server/queries/platform-metrics.ts
    • src/features/analytics/server/queries/revenue-dashboard-data.ts
  3. 3

    Build chart series

    Series helpers normalize activity, checkout, revenue, usage, and credit data before UI cards render.

    • src/features/analytics/server/services/series.ts
    • src/features/analytics/server/queries/timeseries/revenue.ts
  4. 4

    Render with shared chart config

    UI components consume prepared data and shared chart config rather than duplicating metric rules.

    • src/features/analytics/shared/chart-config.ts
    • src/features/analytics/ui/platform-dashboard.tsx
    • src/features/analytics/ui/revenue-dashboard.tsx

Analytics API authorization

Source: src/features/analytics/server/services/dashboard-range.ts

Range APIs authorize the user and feature before loading server-side analytics.

ts
async function authorizeRangeRequest(requestId: string): Promise<ServiceResult<never> | null> {
  const auth = await requireApiAuth(requestId);
  if (!auth.ok) {
    return serviceFailure(auth.error.code, auth.error.message, requestId, apiStatusForErrorCode(auth.error.code));
  }

  const feature = await requireApiFeature(auth.data.profile, "insights", requestId);
  if (!feature.ok) {
    return serviceFailure(feature.error.code, feature.error.message, requestId, apiStatusForErrorCode(feature.error.code));
  }

  return null;
}

Chart rules

  • Aggregate on the server before rendering chart components.
  • Avoid provider API calls in chart loops.
  • Keep revenue charts tied to local billing projection tables.
  • Show empty data as a normal state.
  • Use enabled billing models to decide which revenue or usage series should appear.