Skip to content

feat(mentions): take the Mentions page's changes on the same prompts as Insights - #1230

Merged
gkhngyk merged 12 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-same-prompt-changes
Oct 22, 2026
Merged

gkhngyk merged 12 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-same-prompt-changes

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #1226. Merge that one first. Until then this PR also shows #1226's commit; this PR's own change is ffafdd00.

After #1226, Insights and Mentions show the same values, but their "vs the previous period" changes still differed:

  • Insights compares only the prompts answered in both windows (insights_same_prompt_compare_daily, 00164). Adding or removing prompts doesn't read as a rise or a fall.
  • The Mentions page compared all prompts.

On the dev data for 7 days, Total mentions read +25% on Insights and −69% on Mentions. The product owner asked for the Mentions page to follow Insights.

Migration 00195 redefines mentions_overview from 00191's definition (#1226) with additions only:

Web

  • changeBasis(overview) returns the shared-prompt totals, or all prompts before 00195. Every change on the page uses it:
    • the four KPI cards (Total mentions, Mention rate, Prompts with mentions, Net sentiment);
    • the summary line's net change, and the platform that moved it most;
    • the By AI platform change (platformNetChange).
  • The values themselves stay the whole window's, as on Insights.
  • Low sample (review of 2026-10-20): a change needs the whole window and both shared windows to clear the floor, on the cards as in the summary line. Each card counts its own sample: Mention rate the responses, Net sentiment the responses naming the brand (isLowSample).

Related issue

Requested by the product owner after #1226 (Insights vs Mentions numbers).

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 00195 (after 00191). Open Insights ?range=7d and note the Mentions card's change.
  2. Click it: Mentions opens on 7d with the same change on Total mentions.

On the dev DB (demo brand, 7 days):

  • mentions_overview reads all prompts 25 vs 80 occurrences, and the shared prompt 25 vs 20;
  • the cards show 25 +25% on both pages (Mentions said −69% before);
  • Prompts with mentions now shows ±0 (it said −50%).

I checked it in the browser on :3002, in light and dark mode, at 1440 and 1024 px.

Tests:

  • mentions-overview.test.ts: parsing same and the platform same counts; changeBasis with and without them.
  • _overview.test.tsx: the cards' changes come from the shared prompts while the values stay the window's.
  • mentions-headline.test.ts: the net change and the platform change on the shared prompts.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors, only the existing warnings
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • yarn test (1786 passed);
  • yarn build with the CI placeholder env;
  • bash supabase/build-schema.sh.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 20, 2026 01:43
…ghts and Mentions

The two pages showed different "Mentions" and "Net sentiment" for the same
days. Product decision: a mention is every time an answer names the brand
(three times in one answer counts three), and net sentiment is positive
minus negative over the answers that name the brand.

- Insights: Net sentiment, its split, the same-prompt change and the Action
  Center Positive sentiment KPI now divide by the answers naming the brand
  (mention_results / mention_answers, 00191) rather than those naming or
  citing it (ansvisor#508); cited-only answers are always neutral and pulled the
  net toward zero. The net is rounded once, as the Mentions page does; a
  test checks the two formulas agree.
- Mentions: Total mentions, its trend, the platform table and the summary
  line count occurrences (the RPC gains them per day and per platform).
  The competitor table keeps responses, as its rollup has no occurrences,
  and says so in its header.
- Insights' Mentions and Net sentiment cards open Mentions on the same
  range, country and topic (All time opens Mentions' default 30 days).

00191 redefines insights_aggregates_daily, insights_kpi_series and
mentions_overview with those fields added; existing fields are unchanged,
and the web falls back to the old base until the migration is applied.

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

After ansvisor#1226 both pages show the same mentions and net sentiment, but their
"vs the previous period" changes still differed: Insights compares only
the prompts answered in both windows, so adding or removing prompts doesn't
read as a rise or a fall, and the Mentions page compared all of them (on
the dev data, 7 days read +25% on Insights and -69% on Mentions).

mentions_overview (00195, from 00191's definition) also returns `same`:
how many prompts both windows answered, how many are new or dropped, and
both windows' totals on the shared ones; each platform row gains the same
counts. The page takes every change from them (changeBasis): the four KPI
cards, the summary line's net change and mover, and the platform table.
The values stay the whole window's, and before the migration the changes
fall back to all prompts.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Following #1226, this PR closes the last gap between Insights and Mentions: the change vs the previous period. The Mentions page now takes all its changes on the prompts answered in both windows, as Insights does; until now it compared all prompts. On the dev data, 7 days moves from −69% to +25%, matching Insights.

Migration 00195 adds same and the platforms' same_* fields to mentions_overview, and is on the dev DB. This PR is stacked on #1226, so please merge that one first.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 19, 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.

This looks right on top of #1226. 00195 has the same signature as 00191 and only adds fields, and the shared-prompt set matches Insights. After #1226's squash, please rebase onto main from cf821c4d (rebase --onto origin/main cf821c4d); merged as is, it conflicts in _overview-kpis.tsx, mentions-overview.test.ts and schema.sql. I'll apply 00195 after 00191 and 00192.

Smaller: the Net sentiment and Mention rate cards check the low-sample rule only on the whole window, while the summary line also needs both shared-prompt windows to pass (mentions-headline.ts). So a card can show a change taken over fewer than 20 shared responses while the summary line shows none. Add !isLowSample(base) && !isLowSample(prev) to the cards.

cihan-gyk and others added 5 commits October 20, 2026 10:19
… feature/mentions-same-prompt-changes

# Conflicts:
#	supabase/schema.sql
00191 moved Insights' daily path and Action Center to the answers that
name the brand, but the raw insights_aggregates RPC (reports, the 24h
window) and the Daily Pulse still divided by answers that name or cite
it, so they showed a lower positive share. 00191 now also redefines
insights_aggregates (8 args, security invoker) with mention_results,
and Pulse reads it, falling back before the migration.

Also from the review:
- the Mentions copy summary's Total mentions and its basis count
  occurrences, as the card does; the tab line and the CSV say
  "responses" where they count responses, and the CSV adds the card's
  Total mentions;
- a custom range's days are UTC days, the days mentions_overview and
  Insights read, so a viewer west of UTC opens the same window;
- mentions_overview orders platforms by occurrences, the column shown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 2 commits October 20, 2026 12:37
…a low sample

The Mention rate and Net sentiment cards checked the low-sample rule
only on the whole window, while the summary line also needs both
shared-prompt windows to pass, so a card could show a change taken over
a handful of shared responses next to a summary line with none. Each
card now also checks both shared windows over its own sample: the
responses for the rate, the responses naming the brand for the net.

00195 redefines mentions_overview from 00191, so it carries ansvisor#1226's
order of the platforms by occurrences, the column the table shows.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk thanks, fixed in b97c28b (after merging #1226's latest, 8c03ead, in as a normal merge, 3b638f4):

  • Low sample on the cards: a change now needs the whole window and both shared windows to clear the floor, as the summary line does. One deliberate difference from your wording: each card checks its own sample.
    • Net sentiment: isLowSample(cur) || isLowSample(base) || isLowSample(prev), as you wrote.
    • Mention rate: the card's own rule was already answers < 20 (its denominator), so the shared windows are checked on answers too. With isLowSample (responses naming the brand), the rate's change would disappear for a brand that's rarely named, which is when the rate matters most. Happy to switch if you prefer it the other way.
    • The new test in _overview.test.tsx (large whole windows, 18 and 30 shared responses) fails on the old code and passes now.
  • 00195 redefines mentions_overview from 00191, so it now carries feat(mentions): count mentions and net sentiment the same way on Insights and Mentions #1226's platform order (occurrences desc, mentions desc, platform). Without it, applying 00195 after 00191 would have put the old order back. Re-applied on the dev DB.

Server 1840 and web 1802 tests + build pass; schema.sql rebuilt. On the demo brand, the shared windows are small, so the summary line, Mention rate and Net sentiment all show no change now, and Total mentions and Prompts with mentions still do.

Still CONFLICTING against main on schema.sql since #1228. I haven't merged main in, as you asked. I'll do the rebase --onto origin/main cf821c4d you suggested once #1226 is squashed, with Cihan's OK, since it rewrites the branch.

… feature/mentions-same-prompt-changes

# Conflicts:
#	supabase/schema.sql

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

The fixes check out:

  • The cards now hold a change on a low-sample shared window.
  • 00195 carries #1226's platform order.

On production:

  • 00195 is applied after 00191.
  • Every value mentions_overview returned before is still there; the only change is the added same and same_* fields.
  • On the largest brand it reads in 2.1 s for 24 hours and 1.4 s for 30 days.

Merge: I merged main in after #1226's squash. The result is the tree I tested with #1226, which passes web (2,507 tests), server (2,011 tests), tsc, lint and Prettier.

@gkhngyk
gkhngyk merged commit 20e8ba8 into ansvisor:main Oct 22, 2026
4 of 5 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 28, 2026
…prompts as its card (#1628)

Since #1230 the Mentions page takes every change on the prompts both
windows answered, as Insights does, so adding or removing prompts doesn't
read as a rise or a fall. Copy summary still took the Total mentions change
on all of each window's responses: the copied text could say +30% under a
card that said +10%.

It now takes it on the same basis (changeBasis), as the card does. The
other lines of the summary carry no change.

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

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants