Repository navigation
feat(insights): replace the share of voice charts with the by AI platform table - #1039
Conversation
Adding prompts inflated every change on the Insights page: 509 new prompts read as +203% mentions, and the breakdown counted each new prompt as a gain from 0 (VIS-002). A "Compare: Same prompts" switch in the filter bar, on by default and kept in the URL (?compare=all when off), measures every change only on the prompts answered in both periods: the Visibility change, every leaderboard row, Mentions, Citations, Sentiment and the breakdown panel. The numbers themselves still cover every prompt. The trend card says how many new prompts were left out (or included, with the switch off). The per-prompt components come from the daily rollups: migration 00130 adds them to insights_prompt_daily and insights_competitor_prompt_daily, writes them in refresh_insights_daily, and adds insights_same_prompt_compare[_daily]. The new columns read NULL until a day is refreshed; such a comparison is reported incomplete and the page compares all prompts, so the history needs one backfill run after deploy (server/src/scripts/backfill-insights-daily.js). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The KPI row becomes the mockup's two rows (VIS-003): today's cards on the first (Visibility with the brand's rank, Tracked prompts with the plan's slots left, Mentions, Citations, and Net sentiment in place of Positive sentiment), and the new rates on the second (Coverage, Share of voice, Avg. position, Citation rate). Each card has its value, a change coloured by whether it's good news, a line of context and a daily sparkline. Every change follows "Compare: Same prompts", and All time shows none. The Formulas dialog defines each metric and gains the Visibility confidence factor. Migration 00131 adds the negative count and the position sum to the brand and prompt rollups, returns the new components from insights_aggregates and the same-prompt functions, and adds insights_kpi_series for the sparklines. Until the history is backfilled (server/src/scripts/backfill-insights-daily.js), Net sentiment and Avg. position show no value rather than a partial one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The v2 mockup opens Insights with one line of facts (VIS-006): the
Visibility score and change, the brand's rank and the gap to its
neighbour (or the lead over the runner-up, or a tie), the platforms whose
Visibility rose and fell most, and what the change compares ("vs <days> ·
N new prompts excluded", moved here from the trend card). A copy button
puts the same line on the clipboard as text. It's a fixed template over
numbers the page already shows; no AI call.
Platform movers follow "Compare: Same prompts". Migration 00132 adds
insights_platform_compare[_daily]: the Visibility components per (model,
platform) in both windows, over the shared prompts when asked, from the
prompt-grain rollups (raw rows for the 24h and topic views).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…form table The v2 mockup shows one "By AI platform" table where the Share of Voice donut and trend were (VIS-008): per platform, Visibility, its change, Coverage, Share of voice and Avg. position. A platform with fewer than 20 answers shows "Low sample · N runs" and one answered only last period shows "No runs this period", never 0%. The biggest drop is tinted. Changes follow "Compare: Same prompts", and a change over fewer than 20 answers in either window is left out, so the summary line's movers and the table always agree. All time shows the table without changes. Migration 00133 extends insights_platform_compare[_daily] with the position sum and, for the current window, the prompt ids answered and visible per engine, so Coverage counts a prompt once per platform even when several models answer it. Window bounds now default to open, and no previous window reads the current one alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk this is ready for review. It's VIS-008 from the Visibility spec v2, stacked on #1038 → #1037 → #1036 → #1035. Until those merge, the VIS-008 change is the last commit. It replaces the Share of Voice donut and trend with the mockup's "By AI platform" table: Visibility, Change, Coverage, Share of voice and Avg. position per platform, "Low sample · N runs" / "No runs this period" instead of numbers a platform can't support, and the biggest drop tinted. Things to look at:
Code review (9 of 12 findings fixed, the rest noted in the description), |
…i-cards # Conflicts: # web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx
…bers insights_same_prompt_compare_daily timed out on the largest brand: 4.5 s as the owner, over 30 s for an org member against the 8 s timeout. A SQL function is planned without its argument values on PostgreSQL 17, and RLS ran inside the scan. 00147 makes both same-prompt RPCs plpgsql with force_custom_plan and security definer with an explicit org-membership check (as 00119). The service role still reads, for the cached 24h view. Rollup rows are folded per prompt and window first. Output is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
getSamePromptComparison returned null on an RPC error, so strict mode cached the all-prompt changes until the next tracking run. It now throws: loadWindowedInsights wraps it in lenient(), and the breakdown panel catches it and compares all prompts, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
00147 (ansvisor#1036) makes insights_same_prompt_compare[_daily] fast but carries 00130's output. Migrations run in number order, so it would replace 00131's version here and drop the fields the KPI cards read (negative count, position sum and count, visible prompts, competitor mentions). 00149 is 00131's output in 00147's shape: plpgsql with force_custom_plan, security definer with the org-membership check, rows folded per prompt and window first. Output is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nto feature/insights-kpi-cards # Conflicts: # supabase/schema.sql # web/src/lib/actions/tracking.ts
…i-cards # Conflicts: # supabase/schema.sql # web/messages/en.json # web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx # web/src/lib/actions/tracking-visibility-parity.test.ts # web/src/lib/actions/tracking.ts # web/src/lib/insights-same-prompts.test.ts # web/src/lib/insights-same-prompts.ts # web/src/types/supabase.ts
# Conflicts: # supabase/schema.sql # web/src/lib/actions/tracking.ts
… feature/insights-summary-line
# Conflicts: # supabase/schema.sql # web/src/lib/actions/tracking.ts
…nto feature/insights-platform-table
…mmary-line # Conflicts: # supabase/schema.sql # web/messages/en.json # web/src/app/[locale]/(dashboard)/dashboard/insights/_kpi-cards.tsx # web/src/app/[locale]/(dashboard)/dashboard/insights/kpi-format.test.ts # web/src/app/[locale]/(dashboard)/dashboard/insights/kpi-format.ts # web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx # web/src/lib/actions/tracking.ts # web/src/types/supabase.ts
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, thanks. I merged main in (f1fcbd5): main was #1038 as this branch already had it, so the tree is this PR's own. Checked:
- 00133 hasn't changed since it was applied to production.
- On the tree,
schema.sqlmatchesbuild-schema.shand web tests pass (689). CI is green. - Timed on production as a signed-in member of the largest brand:
insights_platform_compare_daily: 1.4 s for 30 days with Same prompts, 1.2 s without, 0.7 s for 90 days, 1.7 s for All time.insights_platform_compare: 0.24 s for 24h; on the largest topic, 0.37 s over 30 days and 0.42 s for All time.
- Coverage counts a prompt once per platform, and a change needs 20 answers in both periods, so the table and the summary line agree.
Summary
The v2 mockup replaces the Share of Voice donut and the Share of Voice trend with one By AI platform table. This is VIS-008 in the Visibility spec v2. Some rows from the mockup:
What each column is:
gpt-4oandgpt-5-miniare both ChatGPT).Rows:
A change needs at least 20 answers in both periods. Below that it shows "—" and isn't named by the summary line. The two can no longer disagree: before, the summary could say "Down most: Grok" while the table showed Grok as low sample. This settles the low-sample note left on #1038 for platforms.
All time shows the table without changes, since it has no previous period.
The trend chart component is deleted. The donut component stays, because the topic page still uses it.
Data
Migration
00133replacesinsights_platform_compare_dailyandinsights_platform_compare(00132). The argument order is unchanged, so the summary line reads them as before. Changes:resolveProvider), and a prompt must count once per platform.completealso waits for the 00131 backfill, which the position sum depends on.On the dev database, the rollup and raw versions return the same totals for 30d and for All time.
Review
I ran a code review before opening this. It found 12 things and 9 are fixed:
insights.sovByPlatform), stale comments, a redundant flag, and a missing parse test.Left as notes:
Not in this PR: the mockup links each platform name. The Prompts page has no platform filter to link to yet, so names are plain text.
Related issue
None. Product spec: Visibility spec v2, task VIS-008. Depends on #1038, #1037, #1036 and #1035.
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
00129to00133, then refill the rollups (backfill script, orrefresh_insights_dailyper brand).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: 586/586. New tests ininsights-summary.test.tscover:yarn build: passed. Locally this neededSTRIPE_SECRET_KEYset to a placeholder, as CI does.bash supabase/build-schema.sh:schema.sqlis up to date.npm run version:check: passed.🤖 Generated with Claude Code