Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Problem
The dashboard's visibility narrative moved to a prompt-level Visibility Rate — distinct prompts a brand appeared in ÷ distinct prompts that produced results (#490). The MCP data layer (web/src/lib/mcp/data.ts) still reports the old all-rows score average, so an assistant connected over MCP describes a brand's visibility as a near-zero score while the dashboard shows a meaningful percentage for the same window.
Specifically:
getVisibilitySummaryForreturnstotals.avgVisibility(all-rows average) and has no rate. It also has a real bug:topCompetitors[].avgVisibilitydivides the competitor's score sum by their mention count — the same skewed-denominator family of bugs fixed for the dashboard leaderboard in fix(insights): use the same denominator for brand and competitor averages #478 (competitors get graded only on their best runs).getCompetitorComparisonForcalls thecompetitor_aggregatesRPC but only maps the old average fields. Since feat(insights): visibility rate as the headline metric across Insights #490 the RPC already returnsbrand_prompt_count,brand_visible_promptsandby_competitor[].visible_prompts— the rate is a pure mapping exercise, no backend change needed.
Fix
getVisibilitySummaryFor: addvisiblePrompts,promptCountandvisibilityRatePcttototals, matching the semantics of thevisible_prompt_statsRPC (appeared =mention_count > 0 OR citation_count > 0, distinctprompt_id,chatgpt-shoppingexcluded — seeweb/src/lib/actions/tracking.tsgetVisibilityRateKpifor the reference consumer). Calling the RPC viasupabaseAdmin.rpc(...)with the brand filter is fine; keep the existing filters (dateFrom/dateTo/region/model) applied.getVisibilitySummaryFor: fixtopCompetitors[].avgVisibilityto divide by the same result-row count as the brand (every filtered row), not the competitor's mention count.getCompetitorComparisonFor: addvisibility_rate_pct,visible_promptsandprompt_countper entry using the fields the RPC already returns, with the shared denominator (brand_prompt_count) for the brand and every competitor. Keepavg_visibility_scorefor backward compatibility.- Update the MCP tool descriptions so an assistant knows which number is the headline (rate) and which is the intensity score.
- Out of scope (follow-up): a rate-based
get_visibility_trend— thevisibility_trend_aggregatesRPC would need the same distinct-prompt counters first.
Acceptance criteria
get_visibility_summaryreturns the rate fields and its numbers match the Insights KPI card for the same brand/window/filters.get_competitor_comparisonentries exposevisibility_rate_pctconsistent with the dashboard leaderboard, same denominator for all entries.topCompetitors[].avgVisibilityno longer divides by mention count.- Existing response fields keep their names and meanings (additive change only).
yarn lint,yarn typecheck,yarn format:checkpass fromweb/.
Getting started
Depends on #490 (the RPC fields this maps) — start after it merges. See CONTRIBUTING.md for setup. Comment here to claim the issue before opening a PR.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
fix(mcp): expose prompt-level visibility rate and fix competitor avg …