Repository navigation
fix(insights): show the same visibility on the card, breakdown and leaderboard - #1035
Merged
gkhngyk merged 2 commits intoOct 15, 2026
Merged
Conversation
…aderboard The Visibility card, the "View breakdown" panel and the leaderboard's own row could show different numbers for the same filters (VIS-001): - the panel fetched raw answers, capped at 1,000 per window in no fixed order, so it scored an arbitrary sample (24.1 in the panel against 17.4 on the card for the same 30 days); - the panel built its previous window from timestamps, the card from whole UTC days; - on All time the leaderboard compared all time with the last 7 days, and the panel quietly showed the last 7 days. All three now take their windows from one place (insights-windows.ts), and the totals come from the card's own aggregates. The panel's prompt, platform and topic slices are grouped in Postgres by a new RPC, insights_breakdown_groups (00129), so no row cap applies. All time shows no change anywhere. The "vs" label names the days actually compared, and whole-day presets count their days instead of rounding elapsed time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
@gkhngyk this is ready for review. It's VIS-001 from the Visibility spec v2. The Visibility card, the "View breakdown" panel and the leaderboard now show the same number and change for the same filters. The panel used to score a 1,000-row raw sample over its own windows (17.4 on the card vs 24.1 in the panel for the same 30 days). Things to look at:
Code review, |
This was referenced Oct 14, 2026
Merged
7 of 10 tasks
…d-visibility # Conflicts: # supabase/schema.sql
Contributor
|
Minor, non-blocking.
|
gkhngyk
approved these changes
Oct 15, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Approved. 00129 is applied to the hosted database. The breakdown RPC runs in 1.8s on the largest brand as an authenticated member.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For the same filters, the Visibility card, the "View breakdown" panel and the leaderboard's own row could show three different numbers. On the live page, the card showed 17.4 (+1.5) for 30 days while the breakdown showed 24.1 (+5). This is VIS-001 in the Visibility spec v2.
Why they disagreed:
ai_visibility_aggregates_daily)prompt_resultsrows, capped at 1,000 per window, unorderedThe panel also recomputed
nowon every render, and on All time it quietly showed the last 7 days.What changes:
web/src/lib/insights-windows.tsholds the day-window helpers moved out oftracking.ts, pluscomparisonWindows(). The card (getVisibilityRateTrend), the leaderboard (getCompetitorComparison) and the panel (getInsightsBreakdown) all take their current and previous windows from it, and read Visibility through one helper (aiVisibilityWindow).insights_breakdown_groups(migration00129) returns the score components and mention totals per (prompt, platform), already grouped, inside one jsonb value. It also returns the prompts' text and topic. Whole-day windows use the rollups' own UTC day boundaries. The rows are built inweb/src/lib/insights-breakdown.ts.new Date()recomputed on every render.Out of scope, per spec v2:
getInsightsSummary, which the topic detail page also uses, so it is left for VIS-003.Side effect worth knowing: the Action Center AI Visibility KPI calls
getVisibilityRateTrendwith onlydays. Its sparkline used to be a cumulative window starting at the warm-up day, so its last point didn't equal the KPI value. It is now the same rolling window as the Insights chart, and its last point equals the value.Review
I ran a code review before opening this. It found 10 things and 6 are fixed:
Left as notes:
Related issue
None. Product spec: Visibility spec v2, task VIS-001.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
supabase/migrations/00129_insights_breakdown_groups.sql.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 7 warnings are in code this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test: 539/539. New tests areinsights-windows.test.ts,insights-breakdown.test.tsandtracking-visibility-parity.test.ts. The parity test feeds the card, panel and leaderboard the same aggregates and checks they agree. On the old code it fails on All time.yarn build: passed.bash supabase/build-schema.sh:schema.sqlis up to date.🤖 Generated with Claude Code