Skip to content

feat(action-center): add a Positive Sentiment KPI - #1128

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/kpi-positive-sentiment
Oct 17, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/kpi-positive-sentiment

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

A Positive Sentiment KPI in the Action Center. It measures the positive share of the AI responses that name the brand: the same figure as Insights' Positive sentiment card, now trackable against a target like the other KPIs. It is the first of two PRs. The next one gives a brand with no KPIs a ready-made set with +20% targets, this KPI included.

KPI (web/src/lib/kpis/registry.ts)

  • positive_sentiment: percent, higher_is_better, source: 'tracking', default target 50. It files under the Mentions category, since sentiment is read over mentions.
  • Order: last in the Add KPI list and in the table (KPI_KEYS, DEFAULT_KPI_SET).
  • Templates: Brand Monitoring ("KPIs for mentions, sentiment and reputation"), which showed "Coming soon", is now Mentions + Positive Sentiment.

Value (web/src/lib/actions/kpis.ts)

  • Value: getInsightsSummary's positiveSentimentPct. That summary is already read for Mentions and Citations, so the KPI adds no query when they share a window.
  • Change: sentimentChange, in points, as Insights shows it.
  • Trend (7D): the daily share from the same seven insights_aggregates_daily reads that feed Mentions and Citations (positive_count / mentioning_results). A day without an answer naming the brand is left out rather than drawn as 0%.

Elsewhere

  • kpi-table.tsx: a Smile icon.
  • en.json: the name and a short description. A longer first draft pushed the Status column out of view at 1024px.
  • server/src/lib/action-center/from-mentions.js: Mentions actions (mention_review) list positive_sentiment among their kpi_keys, so the action drawer's related KPIs include it.

No migration: kpi_definitions.kpi_key is free text, and values are computed on read.

Related issue

None.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Open Action Center → KPIs for a brand with tracked answers and click Configure KPIs (or Edit KPIs).
    • Brand Monitoring is selectable and ticks Mentions and Positive Sentiment.
    • Positive Sentiment is last in the list, with a 50% target.
  2. Save. The Positive Sentiment row:
    • its value equals Insights' Positive sentiment card for the same 30 days;
    • its change is in points;
    • it is filed under the Mentions chip.
  3. Switch 7d / 30d / 90d: the value follows the window, and the percent target is not rescaled.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no errors; the 7 warnings are in files this PR does not touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • web: yarn test (1252) and yarn build pass.
    • A new lib/actions/kpis.test.ts covers:
      • the registry entry, its order and the Brand Monitoring template;
      • the value and the change in points;
      • the trend leaving out a day without mentions;
      • the seven shared rollup reads;
      • the table order.
  • server: npm run lint and npm test (1435) pass. from-mentions.test.js expects the new KPI key.
  • Browser: checked on the demo brand.
    • Brand Monitoring saved Mentions + Positive Sentiment.
    • Positive Sentiment read 40%, as the Mentions page's 40% positive.
    • 1440px and 1024px, light and dark.
    • The test KPIs were removed afterwards.

Known, unchanged here:

  • A change of exactly 0 renders as a red down arrow ("↘ 0 pts") for every KPI. A separate fix is in progress.
  • A window with no mentions reads 0%, as Insights' card does.
  • Action validation (BASKET_KPIS) doesn't measure positive sentiment before/after yet.

🤖 Generated with Claude Code

The Action Center can track Positive Sentiment: the positive share of the AI
responses naming the brand, the same figure as Insights' Positive sentiment
card, with its change in points and a daily trend that leaves out days
without a mention. It comes last in the KPI list, the Brand Monitoring
template becomes Mentions + Positive Sentiment, and Mentions actions link to
it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk an Action Center KPI for Positive Sentiment (the Insights card's positive share), last in the KPI list; Brand Monitoring becomes Mentions + Positive Sentiment, and Mentions actions link to it. No migration. A follow-up PR will give brands without KPIs a ready-made set with +20% targets.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebuilt on main: the KPI tests, typecheck, lint and format pass, and CI is green. The daily trend reads positive_count / mentioning_results from insights_aggregates_daily, the same ratio as the Insights card (checked on production: both fields are returned per day).

@gkhngyk
gkhngyk merged commit 8d600f3 into ansvisor:main Oct 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants