Repository navigation
fix(insights): use the same denominator for brand and competitor averages - #478
Merged
Merged
Conversation
…ages The competitor leaderboard and the per-provider comparison chart divided each competitor's visibility sum by its own appearance row count — the number of runs since that competitor was added to the brand's list — while the brand's average is divided by every filtered run. On wide ranges (All time) a recently added competitor was therefore graded only on the recent window while the brand carried its full history, letting competitors outrank a brand with far more mentions and citations. Competitor sums are now divided by the same total run count as the brand's (absence counts as 0, like the brand), in the displayed average, the delta-window averages, the per-provider rows, and the MCP competitor-comparison surface.
7 of 12 tasks
gkhngyk
added a commit
that referenced
this pull request
Jul 20, 2026
#490) * feat(insights): lead the KPI row with Visibility Rate and Share of Voice Averaging visibility over ALL results reads near zero for most brands — every answer the brand is absent from contributes a 0, and tracking many platforms dilutes each appearance further. That number buried the two facts users act on: how often the brand shows up, and how good it looks when it does. Competing tools headline exactly those two. The KPI row now leads with Visibility Rate (distinct prompts the brand appeared in / prompts that produced results, same filters as the row — the Tracked Prompts KPI is the denominator on purpose) with the quality split in its sub-line (avg score over only the answers the brand is in), and Share of Voice (already computed for the charts, now surfaced with its period delta). The raw average leaves the headline; it lives on in the rate's sub-line and the per-model breakdown sheet. New visible_prompt_stats RPC (00027) mirrors tracked_prompt_count's filters and shopping exclusion; applied to the hosted DB. sovData is no longer nulled when per-platform rows are empty — the chart section gates on byPlatform itself so the KPI card keeps overallSov. * feat(insights): leaderboard ranks by prompt-level visibility rate Follow-up to the Visibility Rate headline: the Brand vs Competitors leaderboard still displayed the all-rows score average, which reads ~1% for a brand that appears in a third of its prompts and contradicted the new headline number sitting right above it. competitor_aggregates (00028, applied to the hosted DB) now also returns distinct-prompt counts: total prompts in the window plus per-entity prompts-appeared, for the brand and each competitor. The leaderboard ranks and displays visible_prompts / prompt_count with the same denominator for everyone (#478 rule kept — absence still costs), and its delta badge is the rate's point change vs the previous window. The score average stays in the payload for the per-provider chart. Also drops the Visibility Rate KPI card's sub-line per feedback — the percentage stands alone. * feat(insights): leaderboard rows show appeared-in/tracked prompt counts Replace each row's mentions · citations sub-line with the fraction behind the displayed rate (appeared in X/Y prompts) so the number and its explanation sit together. Entries carry the raw numerator and the shared denominator alongside the percentage. * feat(insights): drop the Share of Voice KPI card, back to a 5-card row Six cards made the KPI row cramped; SoV keeps its own chart section below with the same number and delta, so the headline card was redundant. sovData handling reverts to chart-gated. * feat(insights): provider chart plots prompt-level visibility rate Completes the rate switch: the Brand vs Competitors provider bars still plotted the all-rows score average, contradicting the leaderboard next to them. competitor_aggregates (00029, applied to the hosted DB) now carries distinct-prompt counts per (model_used, platform) group, and the provider fold divides everyone by the brand bucket's prompt count — the same-denominator rule at provider granularity. Summing DISTINCT counts across two engines of one provider counts a shared prompt once per engine in numerator and denominator alike, so the folded rate stays unbiased. * feat(insights): restore mentions/citations line in leaderboard rows Bring the mentions · citations line back above the appeared-in fraction — dropping it lost the intensity signal that explains rate ties (many citations vs broad-but-shallow presence).
5 tasks done
gkhngyk
pushed a commit
that referenced
this pull request
Jul 22, 2026
…denominator (#491) (#502) Three changes, all additive: 1. getVisibilitySummaryFor — adds visiblePrompts, promptCount and visibilityRatePct to totals. Counts distinct prompt_ids from the same filtered prompt_results rows (chatgpt-shopping excluded). A prompt is 'visible' when mention_count > 0 OR citation_count > 0, matching the visible_prompt_stats RPC and the Insights KPI card. 2. getVisibilitySummaryFor — fixes topCompetitors[].avgVisibility to divide by the total result-row count (same denominator as the brand) instead of the competitor's own mention count. Prevents inflated scores for competitors that only appear in their best runs (#478). 3. getCompetitorComparisonFor — maps brand_prompt_count, brand_visible_prompts and by_competitor[].visible_prompts from the competitor_aggregates RPC (already present since #490) to new output fields: visibility_rate_pct, visible_prompts, prompt_count on both brand and every competitor. All rates share brand_prompt_count as the denominator so entries are directly comparable, matching the dashboard leaderboard. avg_visibility_score kept for backward compat. Updates MCP tool descriptions so an assistant knows visibilityRatePct / visibility_rate_pct is the headline and avgVisibility is the intensity score. yarn lint, yarn typecheck, yarn format:check all pass from web/.
6 tasks done
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
On the Insights page, a brand could rank last on the competitor leaderboard despite having far more mentions and citations than every competitor. The leaderboard sorts by average visibility score, and that average was computed asymmetrically:
competitor_mentionsrecords every configured competitor per run, so this equals the number of runs since that competitor was added to the brand's list.On wide date ranges (All time) a recently added competitor was graded only on its recent window while the brand carried its entire history (including thousands of early zero-score runs), so a competitor seen in ~4% of the brand's runs could post a far higher average and outrank it.
Competitor sums are now divided by the same total run count as the brand's — absence from a response counts as 0, exactly like it does for the brand — in all four places that did this division:
get_competitor_comparisonsurface (web/src/lib/mcp/data.ts), which mirrors the same math so API answers rank brands the same way the page does. Itsappearance_countfield is unchanged (still the honest appearance count).No SQL/migration changes — the
competitor_aggregatesRPC already returns the total row count per window; only the JS division changed. Verified against production data for the reporting brand: with the shared denominator the brand moves from last place to ahead of every competitor except the one that genuinely out-cites it.Trade-off, deliberate: a competitor added recently is counted as 0 for runs before it existed. That is consistent (the brand is subject to the same rule for its whole history) and beats comparing different time windows across rows of the same table.
Related issue
None — raised from internal dogfooding feedback.
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
/dashboard/insightsfor a brand with competitors and pick All as the date range.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)