Repository navigation
Description
Problem
Reports snapshot their data as a frozen JSONB payload (web/src/lib/actions/reports.ts) and the viewer (web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/page.tsx) still leads its KPI section with payload.insights.avgVisibilityScore — the all-rows score average the dashboard just moved away from (#490). A customer reads "Visibility ~1%" in a report and a meaningful rate on the Insights page for the same period.
Fix
Snapshot (report generation):
- When the
kpissection is enabled, also fetch the Visibility Rate the dashboard shows —getVisibilityRateKpi+getTrackedPromptsKpifromweb/src/lib/actions/tracking.ts(same date range) — and storevisibilityRate: { visiblePrompts, promptCount, ratePct }in the payload. - The competitors section needs no generation change: it already stores
CompetitorComparisonEntry[], which carriesvisibilityRate/visiblePrompts/promptCountsince feat(insights): visibility rate as the headline metric across Insights #490.
Viewer:
- KPI row: lead with the rate (
X%, with thevisiblePrompts/promptCountfraction as its sub-line); keep the score average as a secondary stat. - Competitors table: show each entry's
visibilityRatewithappeared in X/Y prompts, mirroring the dashboard leaderboard. - The PDF export (
web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/_report-pdf.tsx) renders the same KPI and competitor numbers — apply the identical rate-first display and fallback there. - Old snapshots must keep rendering: payloads generated before this change have neither
visibilityRatenor the new entry fields. Fall back to the current display (avgVisibilityScore) whenever the new fields are absent — no migration or backfill of stored reports.
Out of scope: the trend chart and the per-prompt / per-topic performance tables stay score-based — per-prompt and per-topic averages are meaningful at that granularity. The server-side executive-summary prompt may mention "visibility score"; adjusting its wording can ride along if trivial, otherwise skip.
Acceptance criteria
- A newly generated report's KPI section leads with the same visibility rate the Insights page shows for the identical date range, and its competitors table matches the dashboard leaderboard's numbers.
- A report generated before this change still renders exactly as today (no crashes, no empty KPI).
yarn lint,yarn typecheck,yarn format:checkpass fromweb/.
Getting started
Depends on #490 (the entry fields and getVisibilityRateKpi) — start after it merges. See CONTRIBUTING.md for setup. Comment here to claim the issue before opening a PR.
Activity