Repository navigation
feat(citations): Competitor Gaps — domains that cite competitors but not us, + per-competitor source map - #326
Merged
Conversation
… us + per-competitor source map Add a getCitationGaps server action that derives, from the same prompt_results data the citations overview reads, response-level weighted co-occurrence between cited domains, competitor mentions and our presence. No LLM/scraper calls, no new writes, minimal column select scoped to the date window. - Gap list: third-party domains that cite >=1 competitor in answers where we're absent and never appear in an answer where we're present, weighted by 1 / distinct sources per answer, thresholded to cut noise. - By competitor: domains feeding a chosen competitor, with an 'Also cites us?' flag distinguishing exclusive vs overlapping sources. - Low-visibility notice, methodology tooltip. UI: a new Competitor Gaps tab on /dashboard/citations next to Domains/URLs (segmented Gap list / By competitor), reusing the existing filter bar and lazy-loaded only when the tab is opened.
There was a problem hiding this comment.
Pull request overview
Adds a new “Competitor Gaps” feature to the Citations dashboard, computing and displaying third-party domains that co-occur with competitors while never co-occurring with the brand, plus a per-competitor “source map” view.
Changes:
- Added a new server action
getCitationGapsthat aggregates response-level, weighted co-occurrence data fromprompt_results. - Added a new “Competitor Gaps” tab on the Citations page with “Gap list” and “By competitor” views, including lazy-loading behavior.
- Refactored Citations page filter-to-API mapping into a shared
apiFiltersmemo.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| web/src/lib/actions/citations.ts | Adds getCitationGaps server action plus related result types/constants. |
| web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx | Adds UI for the new tab, tables, and lazy-loading fetch logic wired to existing filters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+459
to
+462
| let query = supabase | ||
| .from('prompt_results') | ||
| .select('id, model_used, region, created_at, citations, competitor_mentions, mention_count') | ||
| .eq('brand_id', brandId); |
Comment on lines
+1142
to
+1161
| // Lazy-load Competitor Gaps only when its tab is active; re-fetch when the | ||
| // shared filters change while it's open. | ||
| useEffect(() => { | ||
| if (sourceTab !== 'gaps' || !activeBrandId) return; | ||
| let cancelled = false; | ||
| setGapsLoading(true); | ||
| getCitationGaps(activeBrandId, apiFilters) | ||
| .then((res) => { | ||
| if (!cancelled) setGaps(res); | ||
| }) | ||
| .catch(() => { | ||
| if (!cancelled) setGaps(null); | ||
| }) | ||
| .finally(() => { | ||
| if (!cancelled) setGapsLoading(false); | ||
| }); | ||
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| }, [sourceTab, activeBrandId, apiFilters]); |
Merged
7 tasks done
gkhngyk
added a commit
that referenced
this pull request
Jul 2, 2026
…rom domain-list flags (#327) Follow-up to #326 (Copilot review): - getCitationGaps selected model_used / region / created_at but never read them from the rows (they're only used in the WHERE clause). Trim the select to id, citations, competitor_mentions, mention_count. - The Gaps tab fetch was keyed off apiFilters, which includes the exclude-own / competitor-only / own-only domain-list flags that getCitationGaps doesn't apply — so toggling them triggered a no-op refetch. Split out a gapFilters memo (date/platform/region/topic/prompt only) and key the gaps effect off it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Competitor Gaps view to the Citations page: the third-party domains AI engines use as sources around competitors but never around us (an outreach list), and per competitor, which domains feed their visibility.
Server action —
getCitationGaps(web/src/lib/actions/citations.ts)Computes response-level weighted co-occurrence from the same
prompt_resultsdata the overview reads — no LLM/scraper/external calls, no new writes. For each answer it looks at the set of cited domains, whether any competitor was mentioned, and whether we were present (brand mentioned OR one of our domains cited):1 / distinct sources in the answer, so a focused 2-source answer counts more than a 20-source one. A small threshold (≥2competitor answers) cuts noise.alsoCitesUsflag), the competitor list, and alowVisibilityflag.citations,competitor_mentions,mention_count) scoped to the date window — same shape/cost asgetCitationsOverview.UI (
web/.../citations/page.tsx)A new Competitor Gaps tab next to Domains / URLs, reusing the existing filter bar, with a segmented control:
Non-goals
Sentence/span-level attribution — the stored
startIndex/endIndexare placeholders for web-scraped platforms, and both needs here act on domains, not sentences.Related issue
Closes #300
Type of change
feat— New featureHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)