Skip to content

fix(citations): count the Unique Domains KPI within the selected source scope - #1249

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/citations-unique-domains-scope
Oct 20, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/citations-unique-domains-scope

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up from #1218's approval: "A follow-up to scope the Unique Domains KPI the same way would be welcome."

The Unique Domains card counted every cited domain (totals.domains) whatever the source scope. Two numbers beside it were already scoped:

So on Brand, which the page opens on, the card could read "3 unique domains · 0 unique URLs".

The card now counts the domains in the selected scope: filteredDomainRows.length, the same rows the Domains tab lists (inSourceScope). On All the number is unchanged, since totals.domains is rows.length.

The page gets its first test (citations/page.test.tsx). It renders the page with a mocked overview of five domains, two of them the brand's, and checks the card on Brand (2), Third party (2) and All (5), each beside the server's URL count.

Total Citations and Avg citations per result still count all sources; see my comment below.

Related issue

Follow-up to #1218.

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 Citations with a range that has citations (e.g. All).
  2. Switch the Top Sources scope between Brand, Competitors, Third-Party and All.
  3. The Unique Domains card's number matches the Domains (N) tab each time, and sits beside that scope's URL count.

On the dev data (three cited domains, all third-party): Brand 0 · 0 URLs, Third-Party 3 · 3, All 3 · 3. Before, Brand read 3 · 0. The new tests fail on the old line for Brand and Third party, and pass now. I checked it in light and dark mode, at 1440 and 1024 px.

Checklist

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

yarn test (1794) and yarn build pass too.

🤖 Generated with Claude Code

…ce scope

The Unique Domains card counted every cited domain whatever the scope,
while the unique URLs under it are counted within the scope (ansvisor#745) and
the Domains tab counts its rows (ansvisor#1218). On Brand it could read 3
domains over 0 URLs. It now counts the domains in the selected scope,
the same rows the Domains tab lists; All keeps its number.

The page's first test pins it for Brand, Third party and All.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk the follow-up you asked for on #1218: Unique Domains now counts the domains in the selected scope, the Domains tab's rows, beside the already-scoped URL count.

A question before I go further: Total Citations and Avg citations per result still count every source, while the card between them is now scoped. Should they follow the scope too? Total Citations could sum the scoped rows' totalCitations, and Avg per result could divide that by totals.results. Or should they stay page-wide, since they describe the answers rather than the sources? I left them as they are.

Side note: on the dev DB, prompt_result_citations was empty for every brand, so the page read nothing. I ran backfill-citations.js (426 rows for the demo brand) and refresh_citations_daily there. That was dev only.

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

Looks good. The domain rows come back whole and pages are cut in the browser, so filteredDomainRows.length is the full count in the scope. On All it equals totals.domains, as the description says. Thanks for the page's first test.

@gkhngyk
gkhngyk merged commit d032353 into ansvisor:main Oct 20, 2026
6 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