Skip to content

feat(mentions): show the Perception tab - #1124

Merged
gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-perception-ui
Oct 21, 2026
Merged

gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-perception-ui

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The Mentions & Sentiment Perception tab (MS-09): what AI says next to the brand, and how that compares with its competitors. It replaces the "on its way" placeholder and reads mentions_perception from the previous PR, with the page's filters (date range, platform, country, topic, search).

Rebased on main (2026-10-21), stacked on #1123. The earlier stack is on main. The diff includes #1123's commits until it merges; this PR's own are "show the Perception tab" and the colour/label fix.

Cards (web/src/app/[locale]/(dashboard)/dashboard/mentions/)

  • What AI associates with {brand} (_perception-cards.tsx): the brand's top terms with a bar, the responses each comes in (on hover, its share of the responses naming the brand) and the change against the previous window. The change is neutral in colour, since more of a term isn't better or worse.
  • Brand shape: you vs top competitors (_brand-shape.tsx, _brand-shape-chart.tsx):
  • Biggest gap (spec §9), under the radar: an amber note such as "“enterprise”: Profound in 60% of the responses naming it; Ansvisor in 10% (fix(ui): give brand avatars a light backdrop for transparent logos #2)", or "AI doesn't use it for Ansvisor" when the brand is unplaced.
    • biggestGap now leaves out shares taken over fewer than 20 mentions (LOW_SAMPLE_MENTIONS, as the Overview's net sentiment does). On a 24h window one answer would otherwise read as 100%.
    • It is taken among the brands the radar draws, so it never names one the chart doesn't show.
  • Brand × attribute heat map: each attribute's share of the responses naming each brand, the cell in a neutral tint by share (readable on both themes), "—" for a brand with no mentions.
  • The shares are over the responses that name a brand, so the labels say "of responses naming …": "mention" on this page counts every time a brand is named.
  • Frequently mentioned with: the competitors named in the same responses as the brand, with the change against the previous window ("is the AI's consideration set around you changing?").
  • A line under the cards says how the terms are found: by rule, no LLM; a sentence naming two brands lends its words to both.

Tab (_perception.tsx)

The same pattern as the Overview:

  • one read per filter change, after a 250 ms pause;
  • a newer change wins over a read still on its way;
  • a skeleton while loading;
  • messages for a custom range without dates, a failed read, an unavailable function (PGRST202) and a brand AI never named in the period.

At xl the cards sit two by two; below that they stack.

Text

The strings are in en.json under mentions.perception. The unused mentions.comingSoon is removed.

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. Apply 00157–00161 and run node src/scripts/backfill-mentions-daily.js (server), as in the previous PRs.
  2. Open Mentions → Perception for a brand with tracked answers and competitors.
    • The terms, the radar, the heat map and "Frequently mentioned with" appear.
    • The co-mention counts equal the Overview's "Same answer as you".
  3. Switch between 24h / 7d / 30d / 90d, a platform or a topic: every card follows.
  4. Pick Custom without dates: the tab asks for them.
  5. Check the dark theme and a 1024px wide window.

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 (1,963) and yarn build pass (checked on feat(mentions): read Mentions & Sentiment and correct a sentiment from the API and MCP #1126, which sits on this PR).
    • mentions/_perception.test.tsx (13):
      • the terms with responses, share and change;
      • the heat map's cells and tint;
      • co-mentions without the ones never named;
      • both gap sentences;
      • the radar's series and colours;
      • the gap kept to the radar's brands;
      • too few attributes;
      • the tab's read and its loading, error, no-dates, never-named and unavailable states.
    • lib/mentions-perception.test.ts: the gap leaves out shares over fewer than 20 mentions.
  • Browser: checked on the demo brand with the dev database at 1440px and 1024px, in the light and dark themes.
    • A fix on the way: the angle axis' outline polygon took the label colour's fill and covered the radar. The grid draws that outline, so the axis line is off.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 17, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk the Perception tab itself: terms, the brand-shape radar with the biggest gap, the brand × attribute heat map and "Frequently mentioned with", on the data from #1123. Web only, no migration. Stacked on #1123 → … → #1115. Next come the export, copy summary and API/MCP pieces.

@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.

@cihan-gyk please rebase this on main after #1123 lands. Its own change is the Perception UI (d05c1bc5); everything below it comes from the stack. There are no migrations in this PR, and main still shows the "on its way" placeholder, so nothing here is superseded.

Conflicts:

  • page.tsx: keep main's header (MentionsHeaderActions, useMentionsExport, the exporter prop on the Mentions tab) and only swap the placeholder for MentionsPerceptionTab.
  • en.json: drop comingSoon and add the perception block.
  • _mentions-tab.test.tsx and actions/mentions.ts: take main's version. These conflicts come from the stack, not from this PR.

Small fixes:

  1. Colours. Since #1217 / #1220 the Mentions page draws your brand in ink (var(--primary)) and no longer uses indigo or violet.
    • The radar uses OWN_BRAND_COLOR (green) and COMPETITOR_PALETTE, whose second colour is violet.
    • The heat map tints cells with indigo (rgba(99, 102, 241, …)).
    • Draw the brand in ink on both, as the trend chart does, and use a neutral tint for the cells.
  2. If #1226 merges first, "mention" on this page means every time the brand is named. The Perception shares are over the responses that name a brand, so label them "of responses naming …" rather than "of mentions" to keep the two pages consistent.

cihan-gyk and others added 5 commits October 21, 2026 18:28
The Perception tab's data (MS-09), deterministic as spec §9 asks for V1:

- migration 00161: mention_terms() takes the sentences of an answer that
  name an entity and returns their words and two-word phrases, minus stop
  words in 13 languages (Snowball dictionaries), words answers use about
  every brand alike, every brand's names and the question's own words;
  mentions_answer_terms keeps the distinct terms per answer and entity
  named (the brand or a competitor), filled by refresh_mentions_daily with
  the mention rollups; mentions_perception() reads a window and the one
  before: the brand's top terms with their trend, the 8 attributes that
  tell it and its four most mentioned competitors apart with each one's
  share of mentions, and the competitors named in the same answers
- the mention history refreshes three days a call: the terms make each
  call heavier than the citation rollups' fortnight
- web: getMentionsPerception, the parsed shape, shares, and the biggest
  gap (a competitor leading an attribute by 20+ points)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reading the answers' text for their terms takes about 2.4 ms per answer
and entity named: about 7 s for a recent day of the largest brand, and
more on its busier days. Inside refresh_mentions_daily that also ran in a
sentiment correction (00160), within the person's 8 s request, where the
terms never change.

refresh_mention_terms now holds that part, and refresh_mentions_daily
stays as 00157 wrote it. The server calls both for a completed run, the
nightly sweep and the backfill; the backfill goes a day at a time.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
…day at a time

- refresh_mention_terms takes a per-brand advisory lock of its own, as
  refresh_mentions_daily does since 00192: a run's refresh and the nightly
  sweep can cover the same days, and the second insert would fail on the
  (result_id, entity) key.
- refreshMentionsDaily refreshes the rollups for the range in one call and
  the terms one day per call, so the sweep's three days stay well inside
  the service role's statement timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Mentions & Sentiment Perception tab (MS-09) reads mentions_perception
and shows what AI associates with the brand, a radar of the brand against
its three most mentioned competitors, the brand x attribute heat map, the
competitors named beside it and the biggest gap. The gap leaves out shares
taken over fewer than 20 mentions, as the Overview does, and only names a
brand the radar draws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he shares are of responses naming a brand

- The radar draws the brand in ink (var(--primary)), as the rest of the
  Mentions page does since ansvisor#1217/ansvisor#1220, and the competitors in orange,
  teal and red (no violet); insights-trend keeps its palette to itself.
- The brand × attribute cells take a neutral tint instead of indigo.
- The shares are over the responses that name a brand, so the labels say
  "of responses naming …" rather than "of mentions", which on this page
  counts every time a brand is named.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk
cihan-gyk force-pushed the feature/mentions-perception-ui branch from 7f2c7f3 to aa24cb2 Compare October 21, 2026 15:43
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Rebased on main (stacked on the rebased #1123) and force-pushed.

  • Conflicts:
    • page.tsx keeps main's header (MentionsHeaderActions, useMentionsExport, the exporter) and only swaps the placeholder for MentionsPerceptionTab;
    • en.json keeps main's export block, adds perception and drops comingSoon;
    • _mentions-tab.test.tsx and actions/mentions.ts are main's (through feat(mentions): add the per-answer terms and the Perception read #1123).

Fixes (aa24cb2):

  1. Colours:
    • the radar draws the brand in ink (var(--primary)) and the competitors in orange, teal and red (no violet);
    • insights-trend.ts is back to main's (the palette export isn't needed);
    • the heat map cells use a neutral tint (rgba(120, 113, 108, …), up to 0.45) instead of indigo.
  2. Labels: the shares are over the responses that name a brand, so they read "… of responses naming {brand}" on the terms' hover, "of the responses naming it" in the gap, and "Share of the responses naming each brand" on the heat map and radar. feat(mentions): count mentions and net sentiment the same way on Insights and Mentions #1226 hasn't merged yet, but this wording is right either way.

Checked through #1126, which sits on this PR: the Perception tests (50) and tsc here; the full web suite and yarn build on #1126. Old head kept locally as backup/1124-before-rebase (7f2c7f3).

gkhngyk
gkhngyk previously approved these changes Oct 21, 2026

@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.

Ready to merge after #1123. There are no migrations and nothing to apply on the database.

Rebase

  • The branch is #1123 plus 842845c8 (the Perception tab) and aa24cb2e (the fixes).
  • git merge-tree onto the current main (4ac82ce5) is clean. Against main, the result touches only #1123's files and this PR's 9.
  • page.tsx keeps main's header actions and exporter, and only swaps the placeholder for MentionsPerceptionTab.
  • en.json only drops comingSoon and adds the perception block.
  • insights-trend.ts is back to main's.
  • CI is green.

Colours

  • The radar draws the brand in var(--primary), as main's trend chart does, and the competitors in #f97316, #0d9488 and #ef4444. There's no violet left.
  • The heat map tint is neutral: rgba(120, 113, 108, …), capped at 0.45. The indigo is gone.

Labels

  • The terms tooltip says "… of responses naming {brand}".
  • The gap note says "… of the responses naming it".
  • The heat map and radar say "Share of the responses naming each brand".
  • These are right whether or not #1226 changes what "mention" means.

Nit (optional): a doc comment in _perception-cards.tsx (line 100) and one test title in _perception.test.tsx still say "share of each brand's mentions". They aren't shown to users.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 21, 2026

@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.

Merging. #1123 is in, refresh_mention_terms with the lock is applied on production, and the terms are backfilled for all history: 603k rows across 72 brands, from 2026-04-16.

One follow-up for you: mentions_perception on the biggest brand is close to the 8 s authenticated timeout. Timed on production as a member:

Brand · window Time
Biggest · 30 days, first call 9.97 s
Biggest · 30 days, warm 5.8 s
Biggest · 7 days 0.83 s
Second biggest · 30 days 0.26 s

So a cold first open of the Perception tab for that brand can time out. The read aggregates the terms per answer at request time. A daily per-entity terms rollup, or force_custom_plan plus a narrower read, would keep it well under. A member of another organization gets null, as expected.

@gkhngyk
gkhngyk merged commit 38c6808 into ansvisor:main Oct 21, 2026
5 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 21, 2026
The tool description said null only when no competitor leads by 20+
points; it is also null when the brand or that competitor has fewer than
20 mentions (ansvisor#1124's low-sample rule), as the skills now say (ansvisor#1127).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 21, 2026
…p is

- Only changes.netSentimentPoints is null on a low sample (and the
  mention rate's change under 20 tracked responses); mentionsPct isn't
  gated.
- biggestGap is also null when the brand or the leading competitor has
  fewer than 20 mentions (ansvisor#1124's low-sample rule).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk pushed a commit that referenced this pull request Oct 22, 2026
…m the API and MCP (#1126)

* feat(mentions): read Mentions & Sentiment and correct a sentiment from the API and MCP

The Mentions page's figures over the API and MCP (MS-13): summary, the
mentions list, one answer, competitors and perception, under the page's
filters, from the page's own database functions after a brand check; and
"Sentiment is wrong" as the API key's owner. Migration 00162 lets
override_mention_sentiment correct for that person when the service role
calls, still only for an admin or manager of the answer's organization. The
in-app agent gets the five reads.

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

* docs(mentions): say when get_mentions_perception's biggestGap is null

The tool description said null only when no competitor leads by 20+
points; it is also null when the brand or that competitor has fewer than
20 mentions (#1124's low-sample rule), as the skills now say (#1127).

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

* fix(mentions): read get_mentions_summary's changes as the page's cards do

Total mentions' change is now on times named (occurrences), and every
change is taken on the prompts both windows answered (changeBasis,
00195), with the counts behind it in changes.basis. The mention rate's
change is null when either window has under 20 responses, as on the
card. Adds promptsWithMentionsPct, and timesNamed per platform and day.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
gkhngyk pushed a commit that referenced this pull request Oct 22, 2026
* docs(skills): teach the AEO coach the Mentions & Sentiment tools

Both skills learn the six Mentions tools and REST endpoints from #1126: the
numbers to quote (net sentiment, low sample, brand only), a workflow for
"why did sentiment drop on Gemini?", and the correction as a write. The
sentiment reference explains net sentiment and the README lists the new
questions.

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

* docs(skills): say which Mentions changes are null, and when biggestGap is

- Only changes.netSentimentPoints is null on a low sample (and the
  mention rate's change under 20 tracked responses); mentionsPct isn't
  gated.
- biggestGap is also null when the brand or the leading competitor has
  fewer than 20 mentions (#1124's low-sample rule).

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

* docs(skills): say Mentions changes are on the prompts both windows answered, and mentionsPct is times named

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

* docs(skills): lead the Mentions glossary with times named, the page's Total mentions

As the Overview card counts them, "mentions" are every time AI names the
brand (timesNamed): the coach quotes that for "how many mentions", and
mentions (responses naming the brand) as the base of the rate, net
sentiment and lowSample, whose 20 is responses naming the brand.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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