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.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(prompts): filter tracked prompts by performance instead of late or missing (#1110)
Cihan9c4325fbd0dd
diff --git a/docs/guides/prompts.mdx b/docs/guides/prompts.mdxindex 27af1650d..86a720d3d 100644--- a/docs/guides/prompts.mdx+++ b/docs/guides/prompts.mdx@@ -28,6 +28,17 @@ Each row in **Tracked Prompts** has a status:The table opens on Active + New. The **Status** filter, or the cards above the table, show one status or all of them. **Track** on a suggestion in the Visibility page's Opportunities opens Tracked Prompts in a new tab, with the new prompts on top.+## Performance++The **Performance** filter groups prompts by where your brand is named in their AI answers over the selected range, across every platform the prompt tracks:++- **Best** — named in the first third of the brands an answer lists+- **Good** — named in the middle third+- **Late** — named in the last third+- **Missing** — named in fewer than half the answers++Late and Missing list the furthest behind first. A prompt with no answers in the range, such as a new one, has no performance yet. The dots in the **Positions** column show each platform on its own.+## Prompt Suggestions logicThe suggestion engine considers four signals:diff --git a/web/messages/en.json b/web/messages/en.jsonindex e467e1e86..fa2e6dd62 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -2961,9 +2961,17 @@"stoppedDescription": "Deleting stopped at an error. {kept, plural, one {The other prompt is} other {The other # prompts are}} back in the list, so you can try again.","notDeleted": "{kept} of {total} {total, plural, one {prompt} other {prompts}} couldn't be deleted."},- "lateFilter": {- "label": "Late or missing · {count}",- "title": "Prompts named late, or not at all, on at least one AI platform. On, the furthest behind come first.",+ "performance": {+ "label": "Performance",+ "title": "Where your brand is named in this prompt's AI answers: Best in the first third of the brands listed, Good in the middle, Late in the last third, Missing in fewer than half the answers. Late and Missing list the furthest behind first.",+ "all": "All performance",+ "best": "Best",+ "good": "Good",+ "late": "Late",+ "missing": "Missing",+ "option": "{label} · {count}",+ "none": "No prompts are {label} in this range.",+ "showAll": "Show all performance","order": "Furthest behind first: late or missing on the most AI platforms, then the worse average position."}},diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsxindex 0e3670641..e687d5b3b 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx@@ -108,6 +108,7 @@ import {positionCellKind,type PlatformDot,type PlatformDotState,+ type PromptPerformance,type PromptPositionCell,} from '@/lib/prompt-position-summary';import { mentionRateLabel } from '@/lib/prompt-improve';@@ -2463,7 +2464,7 @@ export default function PromptsPage() {/*** Average position with its trend against the previous period; hovering it- * lists each platform, which is what the "Late or missing" filter reads. A+ * lists each platform, the detail behind the Performance filter. A* prompt that was tracked but never named reads "Not mentioned", not the "—"* of a prompt with no answers.*/@@ -2643,6 +2644,13 @@ const STATUS_BADGE: Record<PromptStatus, string> = {const STATUS_FILTERS: PromptStatusFilter[] = ['tracked', 'active', 'new', 'paused', 'all'];+type PerformanceFilter = 'all' | PromptPerformance;++const PERFORMANCE_FILTERS: PerformanceFilter[] = ['all', 'best', 'good', 'late', 'missing'];++/** Late and Missing order the table furthest behind first (see compareLateness). */+const isBehind = (filter: PerformanceFilter) => filter === 'late' || filter === 'missing';+const WORK_FILTER_LABELS: Record<string, string> = {all: 'All work',todo: 'To do',@@ -2698,7 +2706,7 @@ function AllPromptsTab({const tUsage = useTranslations('prompts.usage');const format = useFormatter();const tDelete = useTranslations('prompts.bulkDelete');- const tLate = useTranslations('prompts.lateFilter');+ const tPerformance = useTranslations('prompts.performance');const tStatus = useTranslations('prompts.status');const now = useNow({ updateInterval: 60_000 }).getTime();// Rows deleted from the row menu or the bulk bar, hidden at once and@@ -3061,8 +3069,8 @@ function AllPromptsTab({);const [search, setSearch] = useState('');const [workFilter, setWorkFilter] = useState<'all' | 'none' | PromptWorkStatus>('all');- // Quick filter: prompts late or missing on at least one engine.- const [lateOnly, setLateOnly] = useState(false);+ // Where the brand stands in each prompt's answers: Best, Good, Late, Missing.+ const [performanceFilter, setPerformanceFilter] = useState<PerformanceFilter>('all');// Optimistic per-row status overrides — the prompts prop belongs to the// parent's load cycle; a full reload for a one-column change would flash// the whole table.@@ -3143,10 +3151,9 @@ function AllPromptsTab({const rawSort = searchParams.get('sort');const activeSort: AllPromptsSortKey = isAllPromptsSortKey(rawSort) ? rawSort : 'visibility';const dir: SortDir = searchParams.get('dir') === 'asc' ? 'asc' : 'desc';- // With "Late or missing" on and no column picked, the furthest behind come- // first: nearly every tracked prompt is late or missing somewhere, so the- // filter alone left the first page as it was (see compareLateness).- const latenessOrder = lateOnly && !isAllPromptsSortKey(rawSort);+ // With Late or Missing picked and no column, the furthest behind come first+ // (see compareLateness).+ const latenessOrder = isBehind(performanceFilter) && !isAllPromptsSortKey(rawSort);// Click a header to sort: a new column starts at desc ("show me the extremes");// re-clicking the active column toggles desc⇄asc. Persisted to the URL so the@@ -3157,7 +3164,7 @@ function AllPromptsTab({(key: AllPromptsSortKey) => {const params = new URLSearchParams(Array.from(searchParams.entries()));// Position is best when lowest, so it starts at asc (#1 first). Under the- // "Late or missing" order no column is active, so any header starts afresh.+ // furthest-behind order no column is active, so any header starts afresh.const nextDir: SortDir =activeSort === key && !latenessOrder? dir === 'desc'@@ -3174,15 +3181,18 @@ function AllPromptsTab({[searchParams, activeSort, dir, latenessOrder],);- // Turning "Late or missing" on sets a picked column aside, so the furthest- // behind lead; turning it off brings that column back, unless a header was- // clicked in between, which then stays.+ // Picking Late or Missing sets a picked column aside, so the furthest behind+ // lead; leaving them brings that column back, unless a header was clicked+ // in between, which then stays.const setAsideSort = useRef<{ sort: string; dir: string | null } | null>(null);- // Read and flipped at click time, so a quick second click sees the first.- const lateOnlyNow = useRef(lateOnly);- const toggleLateOnly = useCallback(() => {- const turningOn = !lateOnlyNow.current;- lateOnlyNow.current = turningOn;+ // Read and set at pick time, so a quick second pick sees the first.+ const performanceNow = useRef(performanceFilter);+ const changePerformance = useCallback((next: PerformanceFilter) => {+ const wasBehind = isBehind(performanceNow.current);+ performanceNow.current = next;+ setPerformanceFilter(next);+ if (wasBehind === isBehind(next)) return;+ const turningOn = isBehind(next);const params = new URLSearchParams(window.location.search);const sort = params.get('sort');if (turningOn && sort) {@@ -3196,11 +3206,10 @@ function AllPromptsTab({window.history.replaceState(null, '', `?${params.toString()}`);}if (!turningOn) setAsideSort.current = null;- setLateOnly(turningOn);}, []);- // Search, prompt status and work status first: the "Late or missing" count- // is out of these.+ // Search, prompt status and work status first: the Performance counts are+ // out of these.const searched = useMemo(() => {const q = search.trim().toLowerCase();let list = [...prompts];@@ -3218,13 +3227,37 @@ function AllPromptsTab({return list;}, [prompts, search, statusFilter, workFilter, statusOf, now]);- const lateCount = useMemo(- () => searched.filter((p) => positions[p.id]?.lateOrMissing).length,- [searched, positions],- );+ const performanceCounts = useMemo(() => {+ const counts: Record<PerformanceFilter, number> = {+ all: searched.length,+ best: 0,+ good: 0,+ late: 0,+ missing: 0,+ };+ for (const p of searched) {+ const performance = positions[p.id]?.performance;+ if (performance) counts[performance] += 1;+ }+ return counts;+ }, [searched, positions]);+ // The menu's options, each with its count, as the old "Late or missing · N" read.+ const performanceItems = PERFORMANCE_FILTERS.map((value) => ({+ value,+ label:+ value === 'all'+ ? tPerformance('all')+ : tPerformance('option', {+ label: tPerformance(value),+ count: format.number(performanceCounts[value]),+ }),+ }));const filtered = useMemo(() => {- const list = lateOnly ? searched.filter((p) => positions[p.id]?.lateOrMissing) : [...searched];+ const list =+ performanceFilter === 'all'+ ? [...searched]+ : searched.filter((p) => positions[p.id]?.performance === performanceFilter);if (latenessOrder) {// Equally far behind: the more visible prompt first, as the table opens.const score = (p: Prompt) => visibility[p.id]?.score ?? 0;@@ -3262,7 +3295,7 @@ function AllPromptsTab({return isAllPromptsSortKey(rawSort) ? sorted : newFirst(sorted, now);}, [searched,- lateOnly,+ performanceFilter,latenessOrder,rawSort,activeSort,@@ -3277,7 +3310,7 @@ function AllPromptsTab({// changes the visible row set (search text, sort column, sort direction, work// status filter) so usePagination jumps back to page 0 automatically when// any filter or sort changes — satisfying the issue's acceptance criteria.- const promptsResetKey = `${search}::${statusFilter}::${workFilter}::${lateOnly}::${activeSort}::${dir}`;+ const promptsResetKey = `${search}::${statusFilter}::${workFilter}::${performanceFilter}::${activeSort}::${dir}`;// From every row, pending deletes included, so the title agrees with the// usage cards until a delete actually lands after its Undo window.const statusCounts = useMemo(() => countByStatus(allRows, now), [allRows, now]);@@ -3409,17 +3442,26 @@ function AllPromptsTab({<SelectItem value="none">No status</SelectItem></SelectContent></Select>- <Button- type="button"- size="sm"- variant={lateOnly ? 'default' : 'outline'}- className="h-8 text-xs"- aria-pressed={lateOnly}- title={tLate('title')}- onClick={toggleLateOnly}+ <Select+ value={performanceFilter}+ onValueChange={(v) => changePerformance((v as PerformanceFilter | null) ?? 'all')}+ items={performanceItems}>- {tLate('label', { count: lateCount })}- </Button>+ <SelectTrigger+ className="h-8 w-36 text-xs"+ aria-label={tPerformance('label')}+ title={tPerformance('title')}+ >+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {performanceItems.map((item) => (+ <SelectItem key={item.value} value={item.value}>+ {item.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select><div className="relative w-60"><Search className="absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground" /><Input@@ -3456,7 +3498,9 @@ function AllPromptsTab({/>)}<Table stickyHeader stickyFirstColumn>- {latenessOrder && <TableCaption className="sr-only">{tLate('order')}</TableCaption>}+ {latenessOrder && (+ <TableCaption className="sr-only">{tPerformance('order')}</TableCaption>+ )}<TableHeader><TableRow><TableHead className="pl-6">@@ -3767,7 +3811,19 @@ function AllPromptsTab({onPage={promptsPager.setPage}/>{filtered.length === 0 &&- (statusFilter === 'all' ? (+ (performanceFilter !== 'all' && searched.length > 0 ? (+ // Rows are there, just none in this group: lead back to them.+ <div className="py-10 text-center text-sm text-muted-foreground">+ {tPerformance('none', { label: tPerformance(performanceFilter) })}{' '}+ <button+ type="button"+ onClick={() => changePerformance('all')}+ className="underline underline-offset-2 hover:text-foreground"+ >+ {tPerformance('showAll')}+ </button>+ </div>+ ) : statusFilter === 'all' ? (<div className="py-10 text-center text-sm text-muted-foreground">No prompts match your search.</div>diff --git a/web/src/lib/actions/prompt.test.ts b/web/src/lib/actions/prompt.test.tsindex cf2497b8d..a93551edb 100644--- a/web/src/lib/actions/prompt.test.ts+++ b/web/src/lib/actions/prompt.test.ts@@ -247,7 +247,7 @@ describe('getPromptsPageData', () => {const page = await getPromptsPageData('b1');expect(page.promptSets[0].prompts.map((p) => p.id)).toEqual(['p1']);- expect(page.positions.p1).toEqual({ avg: null, delta: null, dots: [], lateOrMissing: false });+ expect(page.positions.p1).toEqual({ avg: null, delta: null, dots: [], performance: null });expect(console.error).toHaveBeenCalledWith(expect.stringContaining('position summaries'),expect.any(Error),diff --git a/web/src/lib/prompt-position-summary.test.ts b/web/src/lib/prompt-position-summary.test.tsindex e8264b4ea..05531c562 100644--- a/web/src/lib/prompt-position-summary.test.ts+++ b/web/src/lib/prompt-position-summary.test.ts@@ -2,7 +2,8 @@* prompt-position-summary.test.ts (PROMPT-007)** Tests the Tracked Prompts Positions cell: the average the panel shows, the- * trend against the previous period, and the per-platform dots.+ * trend against the previous period, the per-platform dots, and the prompt's+ * performance for the Performance filter.*/import { describe, expect, test } from 'vitest';@@ -95,7 +96,8 @@ describe('buildPositionCell', () => {['google-aio', 'missing'],['copilot-web', 'no_runs'],]);- expect(cell.lateOrMissing).toBe(true);+ // Across them: named at #3 of 5 on average, in the middle third.+ expect(cell.performance).toBe('good');});test('mentioned in under half the runs is missing, like the Improve tab, however high it ranked', () => {@@ -124,7 +126,7 @@ describe('buildPositionCell', () => {mentionedRuns: 8,},]);- expect(cell.lateOrMissing).toBe(true);+ expect(cell.performance).toBe('missing');// The average stays the Positions panel's.expect(cell.avg).toBe(1);});@@ -136,16 +138,50 @@ describe('buildPositionCell', () => {platforms.slice(0, 1),);expect(cell.dots[0].state).toBe('early');- expect(cell.lateOrMissing).toBe(false);+ expect(cell.performance).toBe('best');});+});- test('not late or missing when every tracked platform is early or has no runs', () => {- const cell = buildPositionCell(- [row('chatgpt-web', { positionSum: 1, positionCount: 1 })],+describe('the prompt performance', () => {+ // Five brands listed per answer, so #1 is the first third and #5 the last.+ const at = (rank: number) =>+ buildPositionCell(+ [row('chatgpt-web', { positionSum: rank * 4, positionCount: 4 })],[],platforms.slice(0, 2),+ ).performance;++ test('reads where the brand is named among the brands listed', () => {+ expect(at(1)).toBe('best');+ expect(at(2)).toBe('best');+ expect(at(3)).toBe('good');+ expect(at(4)).toBe('late');+ expect(at(5)).toBe('late');+ });++ test('pools every platform: early on one and missing on another can still be good', () => {+ const cell = buildPositionCell(+ [+ row('chatgpt-web', { positionSum: 4, positionCount: 4 }),+ row('perplexity-web', { positionSum: 20, positionCount: 4 }),+ row('gemini-web', { mentionAnswers: 0, positionSum: 0, positionCount: 0 }),+ ],+ [],+ platforms,);- expect(cell.lateOrMissing).toBe(false);+ expect(cell.dots.map((d) => d.state)).toEqual(['early', 'late', 'missing', 'no_runs']);+ expect(cell.performance).toBe('good');+ });++ test('named with no stored position is good', () => {+ expect(+ buildPositionCell([row('chatgpt-web', { positionSum: 0, positionCount: 0 })], [], platforms)+ .performance,+ ).toBe('good');+ });++ test('none without runs in the window, as for a prompt just added', () => {+ expect(buildPositionCell([], [], platforms).performance).toBeNull();});});@@ -161,7 +197,7 @@ describe('compareLateness', () => {runs: 4,mentionedRuns: 0,})),- lateOrMissing: states.some((s) => s === 'late' || s === 'missing'),+ performance: null,});const order = (cells: Record<string, PromptPositionCell | undefined>) =>Object.keys(cells).sort((a, b) => compareLateness(cells[a], cells[b]));diff --git a/web/src/lib/prompt-position-summary.ts b/web/src/lib/prompt-position-summary.tsindex 3794025cc..8d7fc452f 100644--- a/web/src/lib/prompt-position-summary.ts+++ b/web/src/lib/prompt-position-summary.ts@@ -44,14 +44,24 @@ export interface PlatformDot {mentionedRuns: number;}+/**+ * Where the brand stands in a prompt's answers across its platforms, for the+ * table's Performance filter. The dots' rule, over all the prompt's answers:+ * - best named in the first third of the brands an answer lists+ * - good named in the middle third, or named with no stored position+ * - late named in the last third+ * - missing named in fewer than half the runs, or never+ */+export type PromptPerformance = 'best' | 'good' | 'late' | 'missing';+export interface PromptPositionCell {/** Average mention position over the window; null when never ranked. */avg: number | null;/** Previous period's average minus this one: positive means it moved up. */delta: number | null;dots: PlatformDot[];- /** Late or missing on at least one platform — the "work queue" filter. */- lateOrMissing: boolean;+ /** Null when nothing was tracked in the window. */+ performance: PromptPerformance | null;}const round1 = (n: number) => Math.round(n * 10) / 10;@@ -62,6 +72,21 @@ function average(rows: PlatformPositionRow[]): number | null {return count > 0 ? round1(sum / count) : null;}+function performanceOf(rows: PlatformPositionRow[]): PromptPerformance | null {+ const sum = (key: Exclude<keyof PlatformPositionRow, 'platform'>) =>+ rows.reduce((a, r) => a + r[key], 0);+ const runs = sum('runs');+ if (runs === 0) return null;+ if (sum('mentionAnswers') < runs * MIN_MENTION_RATE) return 'missing';+ const count = sum('positionCount');+ if (count === 0) return 'good';+ const rank = sum('positionSum') / count;+ const entities = sum('entityCount');+ const total = entities > 0 ? sum('entitySum') / entities : rank;+ const tone = positionTone(rank, Math.max(total, rank));+ return tone === 'Early' ? 'best' : tone === 'Mid' ? 'good' : 'late';+}+function dotState(row: PlatformPositionRow | undefined): PlatformDotState {if (!row || row.runs === 0) return 'no_runs';// Same rule as the Improve tab: #1 in 8 of 120 answers is mostly missing.@@ -106,7 +131,7 @@ export function buildPositionCell(avg,delta: avg !== null && prev !== null ? round1(prev - avg) : null,dots,- lateOrMissing: dots.some((d) => d.state === 'late' || d.state === 'missing'),+ performance: performanceOf(now),};}@@ -144,12 +169,11 @@ export function opensPositionsPanel(answers: AnswerCounts | undefined): boolean}/**- * Orders prompts furthest behind first, for the "Late or missing" filter.- * Nearly every tracked prompt is late or missing somewhere, so the filter- * alone barely changes the table; this puts first the prompts late or missing- * on the most platforms, then those missing on more of them, then the worse- * average position, a prompt never ranked counting as the furthest back.- * Negative when `a` is further behind.+ * Orders prompts furthest behind first, for the Performance filter's Late and+ * Missing: first the prompts late or missing on the most platforms, then+ * those missing on more of them, then the worse average position, a prompt+ * never ranked counting as the furthest back. Negative when `a` is further+ * behind.*/export function compareLateness(a: PromptPositionCell | undefined,