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): show the table's answer counts on the positions panel's cards (#1088)
Cihane52fae554bf8
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 27337e556..3f7e8f222 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -2332,6 +2332,15 @@"exportError": "Failed to export CSV"},"prompts": {+ "positions": {+ "answers": "{count, plural, one {# answer} other {# answers}}",+ "answersInPeriod": "{count, plural, one {# answer} other {# answers}} in this period",+ "mentionedIn": "In {mentioned} of {answers, plural, one {# answer} other {# answers}} · {mentions, plural, one {# mention} other {# mentions}}",+ "citedIn": "In {cited} of {answers, plural, one {# answer} other {# answers}} · {citations, plural, one {# citation} other {# citations}}",+ "mentionedInPeriod": "In {mentioned} of {answers, plural, one {# answer} other {# answers}} in this period · {mentions, plural, one {# mention} other {# mentions}}",+ "citedInPeriod": "In {cited} of {answers, plural, one {# answer} other {# answers}} in this period · {citations, plural, one {# citation} other {# citations}}",+ "includedOnly": "Answer counts cover the platforms your plan includes."+ },"title": "Prompt Volumes","description": "Discover query volumes and trends across AI platforms.","totalVolume": "Total Volume",diff --git a/web/src/components/prompts/prompt-positions-sheet.test.tsx b/web/src/components/prompts/prompt-positions-sheet.test.tsxnew file mode 100644index 000000000..b38b4d245--- /dev/null+++ b/web/src/components/prompts/prompt-positions-sheet.test.tsx@@ -0,0 +1,146 @@+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { NextIntlClientProvider } from 'next-intl';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import messages from '../../../messages/en.json';+import { summarizePositions, type PositionAnswer } from '@/lib/prompt-positions';+import type { PromptPositionsData } from '@/lib/actions/prompt-positions';++/**+ * The positions panel over a week: its cards carry the table's answer,+ * mention and citation counts beside the days.+ */++const { getPromptPositions } = vi.hoisted(() => ({ getPromptPositions: vi.fn() }));+vi.mock('@/lib/actions/prompt-positions', () => ({ getPromptPositions }));+vi.mock('./prompt-improve-tab', () => ({+ ImproveTab: () => null,+ useImprove: () => ({ count: null, dirty: false }),+}));+vi.mock('@/components/filters/date-range-filter', () => ({ DateRangeFilter: () => null }));+vi.mock('@/i18n/navigation', () => ({+ Link: ({ href, children }: { href: string; children: React.ReactNode }) => (+ <a href={href}>{children}</a>+ ),+}));++const { PromptPositionsSheet } = await import('./prompt-positions-sheet');++(+ globalThis as typeof globalThis & {+ IS_REACT_ACT_ENVIRONMENT: boolean;+ }+).IS_REACT_ACT_ENVIRONMENT = true;++const WEEK = { from: '2026-10-04T00:00:00.000Z', to: '2026-10-10T23:59:59.999Z' };++const answer = (over: Partial<PositionAnswer> & { createdAt: string }): PositionAnswer => ({+ platform: 'chatgpt-web',+ region: 'US',+ mentioned: false,+ mentions: 0,+ mentionPosition: null,+ mentionTotal: null,+ sentiment: null,+ cited: false,+ citations: 0,+ citation: null,+ ...over,+});++function data(locked = false): PromptPositionsData {+ const { summary, platforms } = summarizePositions(+ [+ answer({+ createdAt: '2026-10-08T02:00:00Z',+ mentioned: true,+ mentions: 3,+ mentionPosition: 2,+ mentionTotal: 3,+ cited: true,+ citations: 2,+ citation: { rank: 1, total: 4 },+ }),+ answer({ createdAt: '2026-10-09T02:00:00Z' }),+ ],+ [+ { id: 'chatgpt-web', label: 'ChatGPT', access: { state: 'included' } },+ ...(locked+ ? [+ {+ id: 'google-aio' as const,+ label: 'Google AI Overviews',+ access: { state: 'locked' as const, requiredPlan: 'growth' as const },+ },+ ]+ : []),+ ],+ WEEK,+ );+ return {+ prompt: { id: 'p1', text: 'Best coffee subscription?', topicName: null, isActive: true },+ planId: 'enterprise',+ window: WEEK,+ summary,+ platforms,+ improving: null,+ };+}++let container: HTMLDivElement;+let root: Root;++async function open(preset: '7d' | '24h' = '7d') {+ await act(async () =>+ root.render(+ <NextIntlClientProvider locale="en" messages={messages} timeZone="UTC">+ <PromptPositionsSheet+ prompt={{ id: 'p1', text: 'Best coffee subscription?' }}+ range={{ preset, from: '', to: '' }}+ window={WEEK}+ onRangeChange={() => {}}+ region=""+ onClose={() => {}}+ />+ </NextIntlClientProvider>,+ ),+ );+}++beforeEach(() => {+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ getPromptPositions.mockResolvedValue(data());+});++afterEach(() => {+ act(() => root.unmount());+ container.remove();+});++describe('PromptPositionsSheet', () => {+ it("puts the table's answer, mention and citation counts beside the days", async () => {+ await open();+ const text = document.body.textContent ?? '';+ expect(text).toContain('2 answers');+ expect(text).toContain('In 1 of 2 answers · 3 mentions');+ expect(text).toContain('In 1 of 2 answers · 2 citations');+ expect(text).not.toContain('your plan includes');+ });++ it("says the 24h cards' answer counts cover the period, not the latest run", async () => {+ await open('24h');+ const text = document.body.textContent ?? '';+ expect(text).toContain('2 answers in this period');+ expect(text).toContain('In 1 of 2 answers in this period · 3 mentions');+ });++ it('says the counts leave out a platform the plan locks', async () => {+ getPromptPositions.mockResolvedValue(data(true));+ await open();+ expect(document.body.textContent).toContain(+ 'Answer counts cover the platforms your plan includes.',+ );+ });+});diff --git a/web/src/components/prompts/prompt-positions-sheet.tsx b/web/src/components/prompts/prompt-positions-sheet.tsxindex 19070adba..71f1145de 100644--- a/web/src/components/prompts/prompt-positions-sheet.tsx+++ b/web/src/components/prompts/prompt-positions-sheet.tsx@@ -12,6 +12,7 @@*/import { useEffect, useMemo, useState } from 'react';+import { useTranslations } from 'next-intl';import {AlertTriangle,CalendarDays,@@ -52,6 +53,7 @@ import type {PlatformDay,PlatformPositions,PositionStats,+ PositionsSummary,} from '@/lib/prompt-positions';import type { Sentiment } from '@/types';import { actionCenterLink } from '@/lib/prompt-improve';@@ -357,16 +359,61 @@ function LoadError({ message, onRetry }: { message: string; onRetry: () => void// ─── Shared pieces ────────────────────────────────────────────────────────────-function Stat({ label, value, sub }: { label: string; value: string; sub?: string }) {+function Stat({+ label,+ value,+ sub,+ detail,+}: {+ label: string;+ value: string;+ sub?: string;+ /** The answer-level count beside the card's days or platforms (the table's numbers). */+ detail?: string;+}) {return (<div className="rounded-lg border p-3"><p className="text-[11px] font-medium text-muted-foreground">{label}</p><p className="mt-1 text-lg font-semibold leading-tight tabular-nums">{value}</p>{sub && <p className="mt-0.5 text-[11px] text-muted-foreground">{sub}</p>}+ {detail && <p className="mt-0.5 text-[11px] text-muted-foreground">{detail}</p>}</div>);}+/**+ * The answers behind a card, as the Prompts table counts them: its Runs,+ * Mentions and Citations columns sum answers, not days or platforms. The 24h+ * cards count platforms, so their lines say they cover the whole period.+ * Locked platforms' answers are never read here, so where the plan locks one+ * the counts say they cover the included platforms only.+ */+function useAnswerDetails(data: PromptPositionsData, { latest }: { latest: boolean }) {+ const t = useTranslations('prompts.positions');+ const s: PositionsSummary = data.summary;+ return {+ mentioned: t(latest ? 'mentionedInPeriod' : 'mentionedIn', {+ mentioned: s.mentionedAnswers,+ answers: s.answers,+ mentions: s.mentions,+ }),+ cited: t(latest ? 'citedInPeriod' : 'citedIn', {+ cited: s.citedAnswers,+ answers: s.answers,+ citations: s.citations,+ }),+ answers: t(latest ? 'answersInPeriod' : 'answers', { count: s.answers }),+ includedOnly: data.platforms.some((p) => p.access.state === 'locked')+ ? t('includedOnly')+ : null,+ };+}++/** Says the answer counts leave out the platforms the plan locks. */+function IncludedOnlyNote({ note }: { note: string | null }) {+ return note ? <p className="text-xs text-muted-foreground">{note}</p> : null;+}+function PlatformName({ platform }: { platform: { id: string; label: string } }) {return (<span className="flex min-w-0 items-center gap-2 sm:w-44">@@ -523,6 +570,7 @@ function LatestView({latestPositions.length > 0? `#${Math.round((latestPositions.reduce((a, b) => a + b, 0) / latestPositions.length) * 10) / 10}`: '—';+ const details = useAnswerDetails(data, { latest: true });return (<div className="space-y-4">@@ -531,11 +579,23 @@ function LatestView({label="Platforms answered"value={`${answered.length} / ${included.length}`}sub="in their latest run"+ detail={details.answers}+ />+ <Stat+ label="Mentioned on"+ value={`${mentioned} / ${answered.length}`}+ sub="platforms"+ detail={details.mentioned}+ />+ <Stat+ label="Cited on"+ value={`${cited} / ${answered.length}`}+ sub="platforms"+ detail={details.cited}/>- <Stat label="Mentioned on" value={`${mentioned} / ${answered.length}`} sub="platforms" />- <Stat label="Cited on" value={`${cited} / ${answered.length}`} sub="platforms" /><Stat label="Avg. position" value={avg} sub="when mentioned" /></div>+ <IncludedOnlyNote note={details.includedOnly} /><Tabs defaultValue={initialTab}><TabsList>@@ -618,6 +678,7 @@ function PeriodView({initialTab: 'platforms' | 'improve';}) {const s = data.summary;+ const details = useAnswerDetails(data, { latest: false });return (<div className="space-y-4"><div className="grid grid-cols-2 gap-2 sm:grid-cols-4">@@ -625,16 +686,19 @@ function PeriodView({label="Runs"value={String(s.runs)}sub={`${s.trackedDays} of ${plural(s.days.length, 'day')} tracked`}+ detail={details.answers}/><Statlabel="Mentioned"value={`${s.mentionedDays} / ${plural(s.trackedDays, 'day')}`}sub={`${s.trackedDays - s.mentionedDays} not mentioned`}+ detail={details.mentioned}/><Statlabel="Cited"value={`${s.citedDays} / ${plural(s.trackedDays, 'day')}`}sub={`${s.trackedDays - s.citedDays} not cited`}+ detail={details.cited}/><Statlabel="Avg. position"@@ -646,6 +710,7 @@ function PeriodView({}/></div>+ <IncludedOnlyNote note={details.includedOnly} />{s.untrackedDays > 0 && (<p className="text-xs text-muted-foreground">{plural(s.untrackedDays, 'day')} without a completed run. Untracked days don't countdiff --git a/web/src/lib/actions/prompt-positions.ts b/web/src/lib/actions/prompt-positions.tsindex 1947fe9bf..f1c8135d8 100644--- a/web/src/lib/actions/prompt-positions.ts+++ b/web/src/lib/actions/prompt-positions.ts@@ -141,10 +141,12 @@ export async function getPromptPositions(createdAt: row.created_at as string,region: (row.region as string | null) ?? null,mentioned,+ mentions: Number(row.mention_count ?? 0),mentionPosition: (row.mention_position as number | null) ?? null,mentionTotal: (row.mentioned_entity_count as number | null) ?? null,sentiment: sentiment && SENTIMENTS.includes(sentiment) ? (sentiment as Sentiment) : null,cited,+ citations: Number(row.citation_count ?? 0),citation: cited? brandCitationPosition(sourcesById.get(row.id as string), brandDomains): null,diff --git a/web/src/lib/prompt-positions.test.ts b/web/src/lib/prompt-positions.test.tsindex dcf653cce..d905424a5 100644--- a/web/src/lib/prompt-positions.test.ts+++ b/web/src/lib/prompt-positions.test.ts@@ -172,10 +172,12 @@ function answer(over: Partial<PositionAnswer> & { createdAt: string }): Positionplatform: 'chatgpt-web',region: 'us',mentioned: false,+ mentions: 0,mentionPosition: null,mentionTotal: null,sentiment: null,cited: false,+ citations: 0,citation: null,...over,};@@ -191,6 +193,40 @@ const PLATFORMS = [const WEEK = { from: '2026-10-04T00:00:00.000Z', to: '2026-10-10T23:59:59.999Z' };describe('summarizePositions', () => {+ it("counts the answers, mentions and citations the Prompts table's columns count", () => {+ const { summary } = summarizePositions(+ [+ answer({+ createdAt: '2026-10-08T02:00:00Z',+ mentioned: true,+ mentions: 3,+ cited: true,+ citations: 2,+ }),+ answer({ createdAt: '2026-10-08T02:20:00Z', mentioned: true, mentions: 1 }),+ answer({ createdAt: '2026-10-09T02:00:00Z', platform: 'perplexity-web' }),+ // A locked engine's answer is not the panel's, nor counted.+ answer({+ createdAt: '2026-10-09T02:00:00Z',+ platform: 'google-aio',+ mentioned: true,+ mentions: 5,+ }),+ ],+ PLATFORMS,+ WEEK,+ );+ expect(summary).toMatchObject({+ answers: 3,+ mentionedAnswers: 2,+ citedAnswers: 1,+ mentions: 4,+ citations: 2,+ runs: 2,+ mentionedDays: 1,+ });+ });+it("files an answer under the viewer's day, not the UTC one", () => {const late = answer({ createdAt: '2026-10-08T22:30:00Z', mentioned: true, mentionPosition: 1 });const utc = summarizePositions([late], PLATFORMS, WEEK);diff --git a/web/src/lib/prompt-positions.ts b/web/src/lib/prompt-positions.tsindex ebd806dcf..0007497d7 100644--- a/web/src/lib/prompt-positions.ts+++ b/web/src/lib/prompt-positions.ts@@ -106,12 +106,16 @@ export interface PositionAnswer {createdAt: string;region: string | null;mentioned: boolean;+ /** How often the answer names the brand, as the table's Mentions column sums it. */+ mentions: number;/** 1-based rank among the tracked brands the answer names; null when not stored. */mentionPosition: number | null;/** How many tracked brands the answer names. */mentionTotal: number | null;sentiment: Sentiment | null;cited: boolean;+ /** The brand's own sources in the answer, as the table's Citations column sums them. */+ citations: number;/** The brand's first source; null when not cited or the source can't be found. */citation: { rank: number; total: number } | null;}@@ -127,10 +131,12 @@ export interface AnswerView {at: string;region: string | null;mentioned: boolean;+ mentions: number;/** Null when not mentioned, or mentioned with no stored position. */mention: { position: number; total: number | null } | null;sentiment: Sentiment | null;cited: boolean;+ citations: number;/** Null when not cited, or cited with no locatable source. */citation: { rank: number; total: number } | null;}@@ -169,6 +175,16 @@ export interface PositionsSummary {days: string[];/** Tracking runs that produced an answer for this prompt, across engines. */runs: number;+ /**+ * The answers themselves, and the brand's mentions and own sources in them:+ * what the Prompts table's Runs, Mentions and Citations columns count, for+ * the engines the panel shows.+ */+ answers: number;+ mentionedAnswers: number;+ citedAnswers: number;+ mentions: number;+ citations: number;trackedDays: number;mentionedDays: number;citedDays: number;@@ -235,12 +251,14 @@ function toView(a: PositionAnswer): AnswerView {at: a.createdAt,region: a.region,mentioned: a.mentioned,+ mentions: a.mentions,mention:a.mentioned && a.mentionPosition !== null && a.mentionPosition > 0? { position: a.mentionPosition, total: a.mentionTotal }: null,sentiment: a.mentioned ? a.sentiment : null,cited: a.cited,+ citations: a.citations,citation: a.cited ? a.citation : null,};}@@ -325,6 +343,11 @@ export function summarizePositions(summary: {days,runs: countRuns(counted.map((a) => a.at)),+ answers: counted.length,+ mentionedAnswers: counted.filter((a) => a.mentioned).length,+ citedAnswers: counted.filter((a) => a.cited).length,+ mentions: counted.reduce((sum, a) => sum + a.mentions, 0),+ citations: counted.reduce((sum, a) => sum + a.citations, 0),trackedDays: tracked.size,mentionedDays: mentioned.size,citedDays: cited.size,