Repository navigation
Description
Problem
The Insights Positive Sentiment KPI computes positive_count ÷ ALL result rows (web/src/lib/actions/tracking.ts, positiveSentimentPct). But the tracking pipeline short-circuits sentiment to neutral whenever the brand is absent from the answer (server/src/lib/response-parser.js) — sentiment analysis never even runs on those rows.
So for a typical brand the denominator is dominated by answers where sentiment was never measured, and the card reads a permanent ~1–2%. Users read the remaining ~98% as "negative", when the actual negative count can be zero. Real production example over 30 days: 119 positive / 158 neutral-while-visible / 0 negative among the 277 answers that actually mentioned the brand — i.e. 43% positive — yet the card shows ~1% because 13,002 brand-absent rows sit in the denominator.
This is the same dilution family the headline Visibility Score had before #490 replaced it with the prompt-level rate.
Fix
Make the KPI answer "when AI mentions the brand, how does it talk about it?":
- Numerator:
positive_count— already returned by theinsights_aggregatesRPC. (Positive rows are by definition rows where the brand appeared, so the numerator needs no change.) - Denominator: visible results — the count of rows with
mention_count > 0 OR citation_count > 0. The Insights page already fetches this since feat(insights): visibility rate as the headline metric across Insights #490:visible_prompt_statsreturnsvisible_results(seegetVisibilityRateKpiinweb/src/lib/actions/tracking.ts). No new RPC or migration needed. - Guard the division (0 visible results → 0), same rounding style as the other KPI cards.
- Update the card's tooltip to say the percentage is of answers that mention the brand, e.g. "Percentage of AI answers mentioning your brand that described it positively."
- Check other consumers of
positiveSentimentPct(InsightsSummaryis reused by the topic detail page and reports) — they should either get the same corrected value automatically or be listed in the PR as intentionally unchanged.
Acceptance criteria
- A brand with 119 positive answers out of 277 brand-mentioning answers shows ~43%, regardless of how many brand-absent answers exist in the window.
- Zero visible answers renders 0% without dividing by zero.
- The tooltip states the denominator (answers mentioning the brand).
- The KPI responds to the page's date/model/region/topic filters exactly like the neighboring cards.
yarn lint,yarn typecheckandyarn format:checkpass fromweb/.
Getting started
See CONTRIBUTING.md for setup. npm run dev with the seed data (supabase/seed.sql) is enough to verify. Comment here to claim the issue before opening a PR.
Activity
feat(mentions): count mentions and net sentiment the same way on Insi…
feat(mentions): take the Mentions page's changes on the same prompts …