Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(citations): replace source filters with client-side scope (#742)

Bharadwajjjjj76643757298e
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
index 033d4ae25..e3cf7bedb 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
@@ -811,10 +811,44 @@ export default function CitationsPage() {
const [hasAnyCitations, setHasAnyCitations] = useState<boolean | null>(null);
const [loadFailed, setLoadFailed] = useState(false);
+ const filteredDomainRows = (data?.rows ?? []).filter((row) => {
+ switch (filters.sourceScope) {
+ case 'own':
+ return row.category === 'you';
+
+ case 'competitors':
+ return row.category === 'competitor';
+
+ case 'third_party':
+ return row.category !== 'you' && row.category !== 'competitor';
+
+ case 'all':
+ default:
+ return true;
+ }
+ });
+
+ const filteredUrlRows = (data?.urlRows ?? []).filter((urlRow) => {
+ switch (filters.sourceScope) {
+ case 'own':
+ return urlRow.category === 'you';
+
+ case 'competitors':
+ return urlRow.category === 'competitor';
+
+ case 'third_party':
+ return urlRow.category !== 'you' && urlRow.category !== 'competitor';
+
+ case 'all':
+ default:
+ return true;
+ }
+ });
+
// Pagination — resets to page 0 whenever any filter changes
const filterKey = JSON.stringify(filters);
- const domainPager = usePagination(data?.rows?.length ?? 0, filterKey);
- const urlPager = usePagination(data?.urlRows?.length ?? 0, filterKey);
+ const domainPager = usePagination(filteredDomainRows.length, filterKey);
+ const urlPager = usePagination(filteredUrlRows.length, filterKey);
const [isLoading, setIsLoading] = useState(true);
const [isExporting, setIsExporting] = useState(false);
const [topics, setTopics] = useState<Topic[]>([]);
@@ -855,16 +889,6 @@ export default function CitationsPage() {
filters.prompt,
]);
- const apiFilters = useMemo<CitationsFilters>(
- () => ({
- ...gapFilters,
- excludeOwnDomain: filters.excludeOwnDomain,
- competitorOnly: filters.competitorOnly,
- ownOnly: filters.ownOnly,
- }),
- [gapFilters, filters.excludeOwnDomain, filters.competitorOnly, filters.ownOnly],
- );
-
useEffect(() => {
if (!activeBrandId) return;
getTopics(activeBrandId)
@@ -892,7 +916,7 @@ export default function CitationsPage() {
setLoadFailed(false);
try {
const [overview, hasAny] = await Promise.all([
- getCitationsOverview(activeBrandId, apiFilters),
+ getCitationsOverview(activeBrandId, gapFilters),
brandHasCitations(activeBrandId),
]);
if (stale()) return;
@@ -926,7 +950,7 @@ export default function CitationsPage() {
} finally {
if (!stale()) setIsLoading(false);
}
- }, [activeBrandId, apiFilters]);
+ }, [activeBrandId, gapFilters]);
useEffect(() => {
loadData();
@@ -1013,7 +1037,7 @@ export default function CitationsPage() {
'models',
];
- const rows = (data.rows ?? []).map((r) => ({
+ const rows = filteredDomainRows.map((r) => ({
domain: r.domain,
category: r.category,
total_citations: r.totalCitations,
@@ -1036,7 +1060,7 @@ export default function CitationsPage() {
'usage_pct',
];
- const rows = (data.urlRows ?? []).map((r) => ({
+ const rows = filteredUrlRows.map((r) => ({
url: r.url,
domain: r.domain,
category: r.category,
@@ -1161,7 +1185,7 @@ export default function CitationsPage() {
Competitor Gaps stays lazy — it fetches on activation. */}
<TabsContent value="domains" keepMounted className="mt-4">
<DomainsTable
- rows={data?.rows ?? []}
+ rows={filteredDomainRows}
brandId={activeBrandId ?? ''}
onAdded={loadData}
page={domainPager.page}
@@ -1175,7 +1199,7 @@ export default function CitationsPage() {
</TabsContent>
<TabsContent value="urls" keepMounted className="mt-4">
<UrlsTable
- rows={data?.urlRows ?? []}
+ rows={filteredUrlRows}
page={urlPager.page}
onPage={urlPager.setPage}
filters={filters}
diff --git a/web/src/components/citations/filter-bar.tsx b/web/src/components/citations/filter-bar.tsx
index 0a775dc34..6f818e81d 100644
--- a/web/src/components/citations/filter-bar.tsx
+++ b/web/src/components/citations/filter-bar.tsx
@@ -43,9 +43,7 @@ export interface CitationsUIFilters {
region: string;
topic: string;
prompt: string;
- excludeOwnDomain: boolean;
- competitorOnly: boolean;
- ownOnly: boolean;
+ sourceScope: 'all' | 'third_party' | 'competitors' | 'own';
}
export const DEFAULT_CITATIONS_FILTERS: CitationsUIFilters = {
@@ -56,9 +54,7 @@ export const DEFAULT_CITATIONS_FILTERS: CitationsUIFilters = {
region: '',
topic: '',
prompt: '',
- excludeOwnDomain: false,
- competitorOnly: false,
- ownOnly: false,
+ sourceScope: 'all',
};
export interface PromptOption {
@@ -326,50 +322,21 @@ export function CitationsFilterBar({
{showCategoryToggles && (
<div className="flex items-center gap-2 pb-0.5">
- <Button
- type="button"
- variant={filters.excludeOwnDomain ? 'default' : 'outline'}
- size="sm"
- className="h-8 text-xs"
- onClick={() =>
- onChange({
- excludeOwnDomain: !filters.excludeOwnDomain,
- ownOnly: false,
- })
- }
- >
- Exclude own domain
- </Button>
- <Button
- type="button"
- variant={filters.competitorOnly ? 'default' : 'outline'}
- size="sm"
- className="h-8 text-xs"
- onClick={() =>
- onChange({
- competitorOnly: !filters.competitorOnly,
- excludeOwnDomain: !filters.competitorOnly ? true : filters.excludeOwnDomain,
- ownOnly: false,
- })
- }
- >
- Competitors only
- </Button>
- <Button
- type="button"
- variant={filters.ownOnly ? 'default' : 'outline'}
- size="sm"
- className="h-8 text-xs"
- onClick={() =>
- onChange({
- ownOnly: !filters.ownOnly,
- excludeOwnDomain: false,
- competitorOnly: false,
- })
- }
+ <Select
+ value={filters.sourceScope}
+ onValueChange={(value) => onChange({ sourceScope: value ?? 'all' })}
>
- Own domain only
- </Button>
+ <SelectTrigger>
+ <SelectValue placeholder="Sources" />
+ </SelectTrigger>
+
+ <SelectContent>
+ <SelectItem value="all">All</SelectItem>
+ <SelectItem value="own">Brand</SelectItem>
+ <SelectItem value="competitors">Competitors</SelectItem>
+ <SelectItem value="third_party">Third-party</SelectItem>
+ </SelectContent>
+ </Select>
</div>
)}
</div>
diff --git a/web/src/lib/actions/citations.ts b/web/src/lib/actions/citations.ts
index 954c30a2d..732ea264c 100644
--- a/web/src/lib/actions/citations.ts
+++ b/web/src/lib/actions/citations.ts
@@ -25,9 +25,6 @@ export interface CitationsFilters {
topicIds?: string[];
promptIds?: string[];
regions?: string[];
- excludeOwnDomain?: boolean;
- competitorOnly?: boolean;
- ownOnly?: boolean;
}
export interface CitationArticleTypeCount {
@@ -337,22 +334,11 @@ export async function getCitationsOverview(
return category;
};
- // Scope filters apply to aggregated rows rather than to citations, which is
- // exact: a domain's category is a property of the domain, so filtering after
- // the rollup keeps every count identical to filtering before it.
- const keep = (category: SourceCategory) => {
- if (filters.excludeOwnDomain && category === 'you') return false;
- if (filters.competitorOnly && category !== 'competitor') return false;
- if (filters.ownOnly && category !== 'you') return false;
- return true;
- };
-
const usagePct = (resultsCiting: number) =>
totalResults > 0 ? Math.round((resultsCiting / totalResults) * 1000) / 10 : 0;
const rows: CitationDomainRow[] = ((domainRes.data as DomainAggRow[] | null) ?? [])
.map((row) => ({ row, category: categoryOf(row.domain) }))
- .filter(({ category }) => keep(category))
.map(({ row, category }) => {
const resultsCiting = Number(row.results_citing);
const totalCitations = Number(row.total_citations);
@@ -373,7 +359,6 @@ export async function getCitationsOverview(
const urlRowsRaw = (urlRes.data as UrlAggRow[] | null) ?? [];
const urlRows: CitationUrlRow[] = urlRowsRaw
.map((row) => ({ row, category: categoryOf(row.domain) }))
- .filter(({ category }) => keep(category))
.map(({ row, category }) => {
const resultsCiting = Number(row.results_citing);
return {