> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vorel.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Analytics

> Per-tenant dashboard at /(dashboard)/analytics: conversation volume, lead funnel, QA score distribution, tool-call success rate, voice-minute trend. Plus a weekly-rollup API for digest workflows.

Vorel ships a per-tenant analytics dashboard at `/(dashboard)/analytics` and a programmatic `weekly-rollup` API for around-the-brain digest workflows. Same `computeAnalytics()` helper backs both; the route runs under `withTenantContext` so RLS scopes every read.

## What the dashboard surfaces

`app.vorel.ai/(dashboard)/analytics`: five cards over the last 30 days:

<CardGroup cols={2}>
  <Card title="Conversation volume" icon="messages">
    Total conversations + breakdown by channel (whatsapp / voice) + breakdown by status (open /
    closed / handoff\_pending / etc.). Server-rendered; loads in a Suspense boundary against the
    same RLS-scoped tx.
  </Card>

  <Card title="Lead funnel" icon="filter">
    Conversations started → leads created → leads moved off `new` → appointments booked. Four
    counters; raw conversion math is up to you.
  </Card>

  <Card title="QA score distribution" icon="award">
    Average score over the window + a 4-bucket histogram (`0-3` / `4-6` / `7-9` / `10-11` on the
    11-criterion rubric). Empty buckets render as zeros so the histogram axis is stable.
  </Card>

  <Card title="Tool-call success rate" icon="circle-check">
    Top 20 tools by call count, with success rate computed from
    `messages.tool_payload->>'ok'`. Fast surface for "is `crm_create_record` flapping for this
    tenant this week?"
  </Card>

  <Card title="Voice-minute trend" icon="phone">
    Per-day voice-minute consumption, oldest-first, with empty-day zeros so the chart doesn't gap.
    Total minutes summary on top.
  </Card>
</CardGroup>

The dashboard requires the user's authenticated dashboard session to resolve a tenant. Cross-tenant operator views (`/admin/tenants/[id]/analytics`) reuse the same `computeAnalytics()` function with the operator's tenant pick.

## The weekly rollup (digest workflows)

`GET /api/v1/analytics/weekly-rollup`: JSON body shaped for the `weekly-qa-rollup` automation template (Monday-09:00 cron, then format, then deliver by email or Slack). Response shape:

```json theme={null}
{
  "since": "2026-04-29T00:00:00.000Z",
  "computed_at": "2026-05-06T09:00:00.123Z",
  "qa_avg": 7.4,
  "qa_p50": 8.0,
  "qa_p95": 11.0,
  "conversation_count": 142,
  "agent_turn_count": 1031,
  "hallucination_flag_count": 7,
  "top_flag_kinds": [
    { "kind": "unsupported_price", "count": 3 },
    { "kind": "unsupported_availability", "count": 2 }
  ],
  "top_handoff_reasons": [
    { "kind": "explicit_request", "count": 12 },
    { "kind": "complaint", "count": 4 }
  ]
}
```

Window contract: every metric in the response is `created_at >= since`. Default `since` is
7 days before `computed_at`. Maximum window is 90 days; wider windows return `400 bad_request`
to avoid sequential scans across the full `messages` table.

## Authentication + scopes

Public-API analytics endpoints are bearer-token authed:

* **`GET /v1/analytics/weekly-rollup`**: `read` scope. Per-key rate limit 200 req/min.

Authed via `vapk_live_<48 hex>` API keys issued from `/(dashboard)/settings/integrations/api-keys`.

The dashboard surface (`/(dashboard)/analytics`) uses your authenticated dashboard session; no API key required for the in-app view.

## Data sources

* **`conversations`**: channel + status counts.
* **`leads`**: funnel counters (`status` + `created_at` for the window).
* **`appointments`**: appointments booked in the window.
* **`qa_evaluations`**: score + per-criterion breakdown for QA.
* **`messages`**: tool-call success rate via `tool_payload->>'ok'`; agent-turn count for the
  rollup; hallucination flags for the digest.
* **`billing_events`**: voice-minute trend (sum of `voice_minute` event types per day).

All reads use the RLS-scoped tx, so a tenant only ever sees their own data.

## The analytics workbench

Beyond the at-a-glance dashboard cards, Vorel ships an analytics **workbench**: saveable reports
built from a report definition (source, metric, dimensions, filters, visualization, time window),
composable dashboards, scheduled CSV / email-summary exports, threshold alerts, read-only share
links, and built-in preset rollups. A natural-language composer (the in-product AI rail) turns a
plain-English ask into a validated report definition. Power users can also drop into a guarded
read-only SQL escape hatch. Every report compiles against a per-source field allow-list and runs
under row-level security, so a report can never read past your tenant scope.

Custom date ranges, compare-to-previous-period, and CSV export are supported through the workbench
and the scheduled-export path.

## What's NOT supported today

* **Per-conversation drill-down from a chart.** Click-through from a histogram bucket to the
  underlying conversations isn't wired yet.
* **PDF export.** CSV and email-summary exports ship; PDF is not a current export format.
* **Real-time streaming updates.** Surfaces are server-rendered on each request, not live-streaming.

## Around-the-brain integration patterns

The `weekly-qa-rollup` template ([n8n templates](/integrations/n8n)) wires
`GET /v1/analytics/weekly-rollup` → format → email/Slack on a Monday-09:00 cron. Operator imports
the template into n8n, sets the API key + delivery target, and the digest fires automatically.

For custom analytics workflows (per-segment cohorts, per-month trends, per-vertical comparisons),
build against the public API + your own warehouse. Vorel exposes the canonical numbers; your
analytics stack does the rest.

## Related docs

* [API Reference](/api-reference/introduction): endpoint catalog
* [Automation](/product/automation): n8n templates, including `weekly-qa-rollup`
* [Guardrails](/product/guardrails): what hallucination flags mean and how they're graded
* [How it works](/getting-started/how-it-works): QA scoring pipeline

{/* verified-against: apps/web/src/lib/analytics-weekly.ts WeeklyRollup shape + 90-day max window */}

{/* verified-against: apps/web/src/app/api/v1/analytics/weekly-rollup/route.ts (read-scope public API) */}

{/* verified-against: handoff/codebase/web-analytics-billing.md — analytics workbench (compile-report.ts report definitions, presets, scheduled CSV/email exports, alerts, shares, SQL escape hatch); AI rail NL→chart composer; date-range.ts custom ranges + compare-period */}
