Skip to content

feat(mentions): add Copy summary and Export CSV to the Mentions page - #1125

Merged
gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-export
Oct 17, 2026
Merged

gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-export

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Copy summary, Export CSV and Reports on the Mentions & Sentiment page (MS-13), as in the mockup's header. Spec §16 asks that both "include the active filters and the n values", so the file and the copied text say what they were taken over. API/MCP endpoints and a Mentions section in scheduled reports come in their own PRs.

Stacked on #1124 → #1123 → #1121 → #1118 → #1117 → #1116 → #1115. The diff includes their commits until they merge.

Export CSV

  • Rows: every mention under the page's filters, one row per answer naming the brand. On the Mentions tab, the table's Sentiment and Co-mentioned filters and its sort apply too (read from the URL, where the tab keeps them), so the file holds what the table lists.
  • Columns: date_utc, prompt, topic, platform, model, country, sentiment, times_named, position, brands_named, co_mentioned, excerpt.
  • Header lines above the rows:
    • the brand and the period (UTC days, or UTC moments under two days);
    • Platform, Country and Topic (with "All …" when left open), Search, and the table's filters when set;
    • Tracked responses (n), Mentions (n), Prompts with mentions (n), Mentions in this file (n);
    • when the export was taken.
  • Reading: exportMentions (server action) reads mentions_list's pages of 100, five at a time, up to 5,000 rows. Each answer is cut to its excerpt on the server, as the table's reads do. Past the cap the file says so in a Note line and a toast warns. An answer stored mid-export shifts the pages; its repeat is dropped.
  • Selection: ticked table rows get an Export button in the selection bar, with the same header lines.
  • Format: a UTF-8 byte order mark so Excel keeps Turkish characters, and the formula guard from lib/csv.ts. That file gains a small csvLine helper for the header lines; toCsv uses it.

Copy summary

The Overview's figures as text, read when clicked:

Mentions & Sentiment · Acme Coffee
All platforms · All countries · All topics
Net sentiment is +21 (↑ 1 vs the previous 30 days). AI usually names Acme Coffee next to Crema Club and Northline Roasters.
Total mentions: 107 (+206%)
Mention rate: 100.0% of 107 tracked responses
Prompts with mentions: 5 of 5 tracked prompts
Net sentiment: +21 · 40% positive, 40% neutral, 20% negative (n=107)
Built from aggregates with a fixed template, no LLM call · Sep 18 – Oct 17 · 107 tracked responses · 107 mentions
  • Same sentences as the page: _headline.tsx now picks the summary line's sentences once (headlineSentences). The page renders them with bold and coloured parts; Copy summary uses them as plain text, so the two can't drift apart.
  • Low sample: under 20 the summary says "Low sample · n responses" instead of a split, as the KPI cards do.
  • Clipboard: Safari only lets a page write the clipboard during the click itself, so the text goes over as a promise inside a ClipboardItem where the browser takes one, with writeText as the fallback.
  • Errors: a failed read says "try again". A clipboard the browser refused asks to allow clipboard access instead.

Reports

The Reports button links to /dashboard/reports, as on Insights.

Layout

The three buttons sit right of the title and wrap below it on narrow screens. They are disabled, with a hint, on a custom range without dates.

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 and click Copy summary, then paste.
    • The figures match the Overview.
    • The filters line follows the Platform, Country, Topic and Search filters.
  3. Click Export CSV.
    • "Mentions (n)" equals the Overview's Total mentions, with one row per mention.
  4. On the Mentions tab:
    • set Sentiment to Negative and export: the row count matches the table's "N mentions" and a Sentiment,Negative line appears;
    • tick two rows and use Export in the selection bar: the file holds those two rows.
  5. Pick Custom without dates: Copy summary and Export CSV are disabled.

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 (1297) and yarn build pass.
    • _header-actions.test.tsx:
      • the copied text, with the filters and with a low sample;
      • a failed read and a refused clipboard;
      • the file's header lines, rows and byte order mark;
      • the Mentions tab's filters from the URL;
      • the cap's Note and warning;
      • nothing to export, a failed export, no dates, and the Reports link.
    • lib/actions/mentions.test.ts: every page read ungrouped, the 5,000 cap, the repeat dropped when pages shift, PGRST202, and a failing later page.
    • lib/mentions-export.test.ts: quoting, the formula guard, empty cells, the file name, UTC minutes.
    • _mentions-tab.test.tsx: ticked rows go to the export with the table's filters.
    • lib/csv.test.ts: csvLine.
  • Browser: checked on the demo brand with the dev database.
    • The file had 107 rows, as the Overview's 107 mentions, and 21 under Negative, as the table.
    • The copied text matched the page.
    • 1440px and 1024px, light and dark.
    • The app's built-in browser refuses clipboard writes (the existing Copy on Insights fails there too), so the copy was checked by intercepting the write.

🤖 Generated with Claude Code

cihan-gyk and others added 30 commits October 17, 2026 09:13
…iment page shell

Mentions & Sentiment (MS-05) gets its sidebar item, "Mentions" with a New
pill and a speech-bubble icon, directly above Citations, its sibling
concept. Once Topics moves into Prompts, it sits between Prompts and
Citations.

/dashboard/mentions has the page's title and description, its V1 tabs
(Overview, Mentions, Perception; Sentiment and Fact-check stay hidden until
built) and the filter bar every tab shares: date range (30 days by default,
as in the mockup), AI platform, country, topic and a search over prompts,
brands and phrases. Tab and filters live in the URL, so a refresh or a
shared link restores the view. The tabs' figures and charts arrive with the
next PRs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The data layer for Mentions & Sentiment (MS-03/04), built from what
tracking already stores on each answer: mention_count, mention_position,
competitor_mentions and the answer's sentiment toward the brand. Opening
the page or changing a filter never calls an LLM.

Migration 00157 adds two daily rollups:
- mentions_prompt_daily (day x prompt x platform x region): answers, the
  answers naming the brand, occurrences, positive and negative mentions,
  and the brand's positions;
- mentions_competitor_daily: answers naming each competitor, and those
  naming the brand too.
refresh_mentions_daily rebuilds them (service role only), and
mentions_overview reads a window and the one before it, filtered by
platform, region, topic and a prompt search: under two days from the
answers, longer windows from whole UTC days. It is security definer with
the organization check made explicit.

The server refreshes the rollups with the Insights and Citations ones,
when a run stamps and in the nightly sweep, and
scripts/backfill-mentions-daily.js fills a brand's history. The web gets
getMentionsOverview, the Overview's metrics (mention rate, the sentiment
split with neutral kept, net sentiment, low sample under 20 mentions,
average position) and the filters-to-query helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Overview tab of Mentions & Sentiment (MS-06), as in the mockup:

- a summary line written from the aggregates by a fixed template (net
  sentiment and its change, the platform behind most of it, the
  competitors named beside you), never an LLM;
- KPI cards: Total mentions, Mention rate, Prompts with mentions and Net
  sentiment with its split and n; under 20 responses a rate is a low
  sample and shows no change;
- a daily trend with a Mentions / Mention rate / Net sentiment toggle;
- a by-platform table with the sentiment split, net and its change, and
  a note when platforms disagree;
- competitor framing: mentions, rate and same-answer counts, with
  sentiment for your brand only.

MetricCard is exported from the Insights cards and takes a footer in
place of its sparkline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Mentions tab of Mentions & Sentiment (MS-07/MS-08, read-only V1):

- migration 00158 adds mentions_list: the answers naming the brand in
  mentions_overview's window, a page of 100 at a time, filtered by
  sentiment and by a competitor named in the same answer (or none),
  sorted newest, oldest, by co-mentions or most negative, and grouped by
  prompt or platform; security definer with the organization check;
- listMentions cuts each answer to the passage around the brand's first
  mention on the server (lib/mention-match.ts matches names as tracking
  does), and getMentionResponse reads one answer for the drawer;
- the table pins its header and Prompt column, marks your brand in
  violet and competitors in grey, and keeps its controls in the URL;
- the drawer shows the prompt, platform and model, country, date,
  sentiment, position and topic, the excerpt, the competitors named,
  the full stored answer with the names marked, and its citations typed
  as on the Citations page, with Copy and View prompt.

The search box now says it searches prompts, as both tabs do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The response drawer's actions and the Mentions table's multi-select
(MS-08):

- Send to Action Center: one or more answers naming the brand become one
  mention_review action. The server reads the answers again (only the
  brand's own mentions count), files them as Protect when any is negative
  (Growth otherwise) with impact from the negative share, plans F08's
  review tasks, quotes the answers as evidence, keeps the selection's
  sentiment as the baseline, and measures the action on the answers'
  prompts once done. The same answers sent again return the open action.
  POST /api/mentions/action, lib/action-center/from-mentions.js.
- The Action Center knows the kind: its title names the prompt (or the
  number of prompts), and the drawer shows the answers quoted when sent.
- Suggest content runs the Prompts page's flow for the answer's prompt,
  with its quota and existing-suggestion checks.
- The table ticks answers on the page and sends them together.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
"Sentiment is wrong" (MS-08): admins and managers correct the tone of an
answer toward the brand, with an optional note.

- Migration 00160 adds sentiment_overrides, the corrections' append-only
  history (previous and new tone, who, when, note; members read it), and
  override_mention_sentiment, which checks the caller is an admin or
  manager of the answer's organization, changes the answer's sentiment
  and its visibility_score by tracking's sentiment bonus, records the
  correction, and refreshes that UTC day's Insights and Mentions rollups,
  so every figure counts the new tone at once.
- The drawer shows the last correction ("Corrected by … · was …") and,
  for admins and managers, a form to correct it; the row updates at once
  and a sentiment-filtered table reads its page again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
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]>
The Mentions & Sentiment header gets Copy summary, Export CSV and Reports
(MS-13). Export CSV writes every mention under the page's filters (and, from
the Mentions tab, the table's), up to 5,000 rows read a page at a time, under
lines that state the filters and the n values; ticked table rows export the
same way. Copy summary puts the Overview's summary line, KPIs and their n on
the clipboard, from the same sentences the page shows.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Copy summary, Export CSV (up to 5,000 mentions with the filters and n values on top, plus Export for ticked table rows) and the Reports link on the Mentions page. Web only, no migration. Stacked on #1124 → … → #1115. API/MCP endpoints come next in their own PR.

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

Rebuilt on main without the Perception commits (#1123/#1124 are on hold). This branch only shared context lines with them: the Perception strings in en.json and the _perception import in page.tsx. On main the Perception tab still shows "coming soon", and the header actions work on every tab. The diff is this PR's own commit, 14 files, +1184/−81. The mentions page tests, the actions, csv and mentions-export tests, typecheck, lint and format pass, and CI is green.

Measured on production for the largest brand over 30 days, which has 7,358 mentions, so the 5,000 cap applies:

  • One mentions_list page at offset 4,900 takes 1.3 s as authenticated, under the 8 s limit, and returns 0.6 MB, mostly the responses' text.
  • A full export is 50 such calls, five at a time: about 65 s of database time and 30 MB moved to the server action, which cuts it down to excerpts.

That's fine for an on-demand button. If exports become frequent, a follow-up could add an export read that returns only the excerpt window and pages by (created_at, id) instead of offset.

@gkhngyk
gkhngyk merged commit 0ca1ceb 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