Skip to content

feat(insights): visibility rate trend chart with per-brand lines and end-of-line logos - #571

Merged
gkhngyk merged 11 commits into
mainfrom
feature/visibility-rate-trend-chart
Jul 31, 2026
Merged

gkhngyk merged 11 commits into
mainfrom
feature/visibility-rate-trend-chart

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the provider bar chart inside the Insights "AI Visibility — Brand vs Competitors" card with a Visibility Rate trend chart: one line per brand over the selected date range, each line ending in a circle-clipped logo.

Data

  • New RPC visibility_rate_trend (migration 00039, already applied to the hosted database): daily UTC buckets of visible-prompt counts for the brand and each live competitor. Rules match the rate family exactly — same run-visibility definition, deleted-competitor filtering (00035 semantics), chatgpt-shopping excluded, and a shared denominator (the brand's per-day distinct prompt count) so all lines are directly comparable.
  • getVisibilityRateTrend action: maps counts to one-decimal rates (same rounding as everywhere), resolves logos (brands.logo_url for the own brand, domain favicons via getFaviconUrl otherwise), and computes the headline: overall window rate + delta vs the previous equal-length window (same visible_prompt_stats / tracked_prompt_count pair as the KPI header, fetched in one parallel batch).

Chart (VisibilityRateTrendChart in _charts.tsx)

  • 5 lines total, matching the leaderboard: own brand (green, thicker) + top 4 competitors by period-average rate (navy / purple / orange / red).
  • Circle-clipped logo on each line's last point; when logos overlap, the higher rate renders on top (lines are drawn lowest-rate first).
  • Hovering a line or its legend entry brings it forward and dims the rest; legend is centered under the chart.
  • Y axis ticks run 5%, 15%, 25%, … and the top tick sits just above the highest visible rate (no wasted space up to 100%); horizontal gridlines removed.
  • Card header now leads with the own brand's overall rate for the window plus a green/red points delta and the previous window's date range ("vs Jul 24, 2026 – Jul 31, 2026").
  • Follows the page filters (date preset incl. 24h, model, region, topic) exactly, loaded in parallel with the insights bundle — no extra latency, and the headline never contradicts the KPI header.

Related issue

—

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Open Insights for a brand with competitors — the card shows the headline rate, the delta vs the previous window, and one line per brand with its logo at the end.
  2. Switch date presets (24h/7d/30d/custom) and filters — chart, headline and delta follow.
  3. Hover lines and legend entries — highlight/dim behavior.
  4. Verified against live data: the last day's rate matches the dashboard's KPI for the same window.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

@gkhngyk
gkhngyk merged commit 546f031 into main Jul 31, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the feature/visibility-rate-trend-chart branch July 31, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant