Skip to content

Insights: Positive Sentiment KPI is diluted by answers that never mention the brand #508

Closed

Description

@gkhngyk

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 the insights_aggregates RPC. (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_stats returns visible_results (see getVisibilityRateKpi in web/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 (InsightsSummary is 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 typecheck and yarn format:check pass from web/.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions