Skip to content

Reports: lead the KPI section with the visibility rate, with a fallback for old snapshots #492

Closed

Description

@gkhngyk

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):

Viewer:

  • KPI row: lead with the rate (X%, with the visiblePrompts/promptCount fraction as its sub-line); keep the score average as a secondary stat.
  • Competitors table: show each entry's visibilityRate with appeared 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 visibilityRate nor 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:check pass from web/.

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

  1. added
    enhancement
    on Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions