Repository navigation
feat(mentions): count mentions and net sentiment the same way on Insights and Mentions - #1226
Conversation
…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]>
|
@gkhngyk For the same dates, Insights and Mentions showed different Mentions and Net sentiment. The product decision is:
Both pages now use these. Migration 00191 only adds fields to
A separate PR will follow for |
gkhngyk
left a comment
There was a problem hiding this comment.
The migration is safe: the same signatures and return types as 00164, 00131 and 00157, and only additions in the bodies. One change before merge:
Two sentiment bases. Insights' daily path and Action Center now use "answers that name the brand", but these still use "answers that name or cite it":
- Daily Pulse:
server/src/lib/pulse/metrics.js:179readsmentioning_results. - The raw RPC
insights_aggregates: its latest definition is 00131, and it isn't updated, somention_resultsis undefined there andtracking.ts:2048falls back to the old base. Reports always take that path, sincereports.tspasses nodays. So does the 24h fallback.
For the same brand and 30 days, Insights and Action Center would show one positive %, and the report and the Pulse e-mail a lower one. Today they all agree.
The fix:
- in 00191, also redefine
insights_aggregateswith its 8 arguments, addingcount(*) filter (where mention_count > 0) as mention_results, and keep it security invoker; - in
pulse/metrics.js, useagg?.mention_results ?? agg?.mentioning_results.
Smaller:
- Copy summary on Mentions (
_use-mentions-export.ts:185, 202, 236) still builds "Total mentions" from responses, while the card now shows occurrences (299 vs 99 on dev). The Mentions tab's "N mentions · M prompts" line and the CSV "Mentions (n)" count responses under the same word. - Custom ranges, west of UTC: the card's link to Mentions opens a different window. Insights reads custom days as UTC days, while Mentions resolves them in the viewer's zone. The presets match.
- Platform order:
mentions_overviewstill orders platforms by responses, while the column now shows occurrences.
I'll apply 00191 before the merge; until then the web reads occurrences as 0.
…ns-kpis # Conflicts: # supabase/schema.sql
…ns-kpis # 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]>
|
@gkhngyk thanks, all fixed in 8c03ead: One sentiment base
Smaller
Server: 1840 tests; web: format, lint, typecheck, 1797 tests and build pass; |
…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]>
…ns-kpis # Conflicts: # supabase/schema.sql
gkhngyk
left a comment
There was a problem hiding this comment.
The fixes check out, and the product call is confirmed: Mentions counts every occurrence, and Net sentiment is taken over the answers that name the brand.
On production:
- 00191 and 00195 are applied.
- Before applying, I checked that prod's live
insights_aggregates,insights_aggregates_daily,insights_kpi_seriesandmentions_overviewmatch 00131, 00164 and 00157, the versions 00191 builds on. - After applying, I compared against a snapshot taken before, for two brands at 30 and 7 days. Every value each function returned before is still there; the only change is the added fields.
- Timed on the largest brand as a member:
mentions_overview: 24h 2.1 s, 7d 0.1 s, 30d 1.4 s, 90d 1.9 s;insights_kpi_series: up to 1.0 s.
Tests: main with #1226 and #1230 passes web (2,507 tests) and server (2,011 tests), along with tsc, lint and Prettier. schema.sql matches a rebuild.
…as Insights (#1230) * feat(mentions): count mentions and net sentiment the same way on Insights 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 (#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]> * feat(mentions): take the Mentions page's changes on the same prompts as Insights After #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]> * fix(mentions): give reports and the Pulse e-mail the same sentiment base 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]> * fix(mentions): hold the rate and net changes when a shared window is 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 #1226's order of the platforms by occurrences, the column the table shows. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Gökhan Geyik <[email protected]>
Summary
For the same dates, Insights and Mentions showed different Mentions and Net sentiment, and the gap widened on 7 days. They counted two different things:
sum(mention_count))Product decision (2026-10-20): a mention is every occurrence (three times in one answer counts three), and net sentiment is (positive − negative) over the answers that name the brand. Both pages now use those definitions.
Insights
kpiRatestakesnamed(answers naming the brand) instead ofmentioning. The net is computed like the Mentions page'ssentimentSplit+wholeNet: shares multiplied first, rounded once. A test checks the two formulas give the same net for every split up to 40 answers.getInsightsSummary(net, split,positiveSentimentPct, sample size), the sparkline series, the same-prompt changes and the Action Center Positive sentiment trend all use that base.mention_resultsoninsights_aggregates_dailyand on the rawinsights_aggregates(reports, the 24h window), anddays[].mention_answersoninsights_kpi_series.positiveSentimentPctinserver/src/lib/pulse/metrics.js).neutral, so they had pulled the net toward 0. The "Based on N answers that name you" tooltip is now accurate.mentionsHref). Mentions has no All time, so it opens on its default 30 days.Mentions page
mentions_overviewgainsdaily[].occurrencesandplatforms[].occurrences;current/previousalready had them.mentions_overviewand Insights read. In the viewer's zone, a viewer west of UTC who picked Oct 1–7 read Oct 2–8, and the Insights card link opened another window.mentions_competitor_dailykeeps no occurrences, so its column header now says Responses.Migration 00191 redefines
insights_aggregates_daily(00164),insights_aggregates(00131, still security invoker),insights_kpi_series(00131) andmentions_overview(00157) with only those fields added, and Mentions' platforms ordered by occurrences. Existing fields are unchanged, so either deploy order works; the web uses the new base once the migration is in.Not in this PR
refresh_mentions_dailyhas no advisory lock or unique key (the overlap fix(rollups): serialize concurrent refreshes of a brand's daily rollups #1020 fixed for Insights in 00164);Numbering: 00188 is #1210's, 00189 #1223's and 00190 #1225's.
schema.sqlis built without them; whichever merges later needsbuild-schema.shagain.Related issue
None. Reported by the product owner (Insights vs Mentions numbers on app.ansvisor.com).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
?range=7dand note Mentions and Net sentiment.?range=7dwith the same Total mentions and Net sentiment. Repeat with 30d.On the dev DB, both pages' RPCs read the same values for the demo brand. I checked this in the browser on :3002, in light and dark mode, at 1440 and 1024 px:
Tests cover:
mentionsHref;Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors, only the existing warningsyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test(1782 passed);yarn buildwith the CI placeholder env;bash supabase/build-schema.sh.🤖 Generated with Claude Code