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
fix(prompts): show prompt-level visibility rate instead of zero-diluted average score (#562)
Gökhan Geyik5f2bbbd88cbb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ede898fb5..f5a53edf0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Changed++- Prompts: the All Prompts **Visibility column now shows the prompt-level Visibility Rate** (share of runs in the last 30 days with a brand mention or citation) instead of the all-runs average score, which runs without any brand presence diluted into misleading single digits — same rate language as the Insights headline and topic pages; the tooltip keeps run counts and the average score across visible runs, and the CSV export gains `visibility_rate_30d` / `visible_runs_30d`+### Added- **Daily Pulse** — a per-brand digest generated after the daily tracking run: KPI strip (visibility rate, 7-day trend, mentions, citations, sentiment), highlights (first-time citations, top prompt gains, leaderboard overtakes, first appearance on a new engine) and anomaly warnings (sharp visibility drop, competitor surge, high-volume prompt losing citations) with a platform-outage guard and a 7-day warning cooldown. Email via Resend on cloud (active/trialing orgs only), a `daily_pulse.created` webhook event everywhere, and Settings → Notifications for per-brand frequency and recipients (#540)diff --git a/supabase/migrations/00037_prompt_visibility_summary_rate.sql b/supabase/migrations/00037_prompt_visibility_summary_rate.sqlnew file mode 100644index 000000000..e00c4b36d--- /dev/null+++ b/supabase/migrations/00037_prompt_visibility_summary_rate.sql@@ -0,0 +1,61 @@+-- Add prompt-level visibility-rate inputs to the All Prompts summary.+--+-- The Visibility column averaged visibility_score across ALL runs, so runs+-- where the brand didn't appear dragged heavily-mentioned prompts down to+-- misleading single digits (same dilution the Insights headline had before+-- the Visibility Rate switch in #490/#493). The table now needs:+--+-- visible_runs runs with >= 1 brand mention/citation — the+-- numerator of the prompt-level rate (runs is the+-- denominator), matching the run-visibility rule+-- used by insights_aggregates / topic detail+-- avg_visibility_visible average score across visible runs only, for the+-- "how strong when it shows up" tooltip+--+-- avg_visibility (all-runs average) is kept for compatibility.+--+-- The return type changes, so PostgreSQL requires the existing function to+-- be dropped before it can be recreated with the additional columns.++DROP FUNCTION public.prompt_visibility_summaries(uuid, timestamptz);++CREATE FUNCTION public.prompt_visibility_summaries(+ p_brand_id uuid,+ p_date_from timestamptz DEFAULT NULL+)+RETURNS TABLE (+ prompt_id uuid,+ avg_visibility double precision,+ avg_visibility_visible double precision,+ total_mentions bigint,+ total_citations bigint,+ runs bigint,+ visible_runs bigint,+ last_run_at timestamptz+)+LANGUAGE sql+STABLE+SECURITY INVOKER+SET search_path = public+AS $$+ SELECT pr.prompt_id,+ AVG(COALESCE(pr.visibility_score, 0))::double precision AS avg_visibility,+ AVG(COALESCE(pr.visibility_score, 0))+ FILTER (WHERE pr.mention_count > 0 OR pr.citation_count > 0)+ ::double precision AS avg_visibility_visible,+ COALESCE(SUM(pr.mention_count), 0)::bigint AS total_mentions,+ COALESCE(SUM(pr.citation_count), 0)::bigint AS total_citations,+ COUNT(*)::bigint AS runs,+ COUNT(*) FILTER (WHERE pr.mention_count > 0 OR pr.citation_count > 0)::bigint+ AS visible_runs,+ MAX(pr.created_at) AS last_run_at+ FROM public.prompt_results pr+ WHERE pr.brand_id = p_brand_id+ AND pr.prompt_id IS NOT NULL+ AND pr.platform <> 'chatgpt-shopping' -- #155 - isolate from analytics+ AND (p_date_from IS NULL OR pr.created_at >= p_date_from)+ GROUP BY pr.prompt_id+$$;++GRANT EXECUTE ON FUNCTION public.prompt_visibility_summaries(uuid, timestamptz)+ TO authenticated;diff --git a/supabase/schema.sql b/supabase/schema.sqlindex ecc9249a2..ea518de7d 100644--- a/supabase/schema.sql+++ b/supabase/schema.sql@@ -4187,3 +4187,68 @@ GRANT ALL ON TABLE "public"."sent_pulses" TO "anon";GRANT ALL ON TABLE "public"."sent_pulses" TO "authenticated";GRANT ALL ON TABLE "public"."sent_pulses" TO "service_role";+-- ─────────────────────────────────────────────────────────────────────────+-- migrations/00037_prompt_visibility_summary_rate.sql+-- ─────────────────────────────────────────────────────────────────────────+-- Add prompt-level visibility-rate inputs to the All Prompts summary.+--+-- The Visibility column averaged visibility_score across ALL runs, so runs+-- where the brand didn't appear dragged heavily-mentioned prompts down to+-- misleading single digits (same dilution the Insights headline had before+-- the Visibility Rate switch in #490/#493). The table now needs:+--+-- visible_runs runs with >= 1 brand mention/citation — the+-- numerator of the prompt-level rate (runs is the+-- denominator), matching the run-visibility rule+-- used by insights_aggregates / topic detail+-- avg_visibility_visible average score across visible runs only, for the+-- "how strong when it shows up" tooltip+--+-- avg_visibility (all-runs average) is kept for compatibility.+--+-- The return type changes, so PostgreSQL requires the existing function to+-- be dropped before it can be recreated with the additional columns.++DROP FUNCTION public.prompt_visibility_summaries(uuid, timestamptz);++CREATE FUNCTION public.prompt_visibility_summaries(+ p_brand_id uuid,+ p_date_from timestamptz DEFAULT NULL+)+RETURNS TABLE (+ prompt_id uuid,+ avg_visibility double precision,+ avg_visibility_visible double precision,+ total_mentions bigint,+ total_citations bigint,+ runs bigint,+ visible_runs bigint,+ last_run_at timestamptz+)+LANGUAGE sql+STABLE+SECURITY INVOKER+SET search_path = public+AS $$+ SELECT pr.prompt_id,+ AVG(COALESCE(pr.visibility_score, 0))::double precision AS avg_visibility,+ AVG(COALESCE(pr.visibility_score, 0))+ FILTER (WHERE pr.mention_count > 0 OR pr.citation_count > 0)+ ::double precision AS avg_visibility_visible,+ COALESCE(SUM(pr.mention_count), 0)::bigint AS total_mentions,+ COALESCE(SUM(pr.citation_count), 0)::bigint AS total_citations,+ COUNT(*)::bigint AS runs,+ COUNT(*) FILTER (WHERE pr.mention_count > 0 OR pr.citation_count > 0)::bigint+ AS visible_runs,+ MAX(pr.created_at) AS last_run_at+ FROM public.prompt_results pr+ WHERE pr.brand_id = p_brand_id+ AND pr.prompt_id IS NOT NULL+ AND pr.platform <> 'chatgpt-shopping' -- #155 - isolate from analytics+ AND (p_date_from IS NULL OR pr.created_at >= p_date_from)+ GROUP BY pr.prompt_id+$$;++GRANT EXECUTE ON FUNCTION public.prompt_visibility_summaries(uuid, timestamptz)+ TO authenticated;+diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsxindex 6232d2b8c..77a14f558 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx@@ -762,8 +762,8 @@ export default function PromptDetailPage() {<div className={cn('space-y-6', isRefetching && 'opacity-60')}><div className="grid gap-4 sm:grid-cols-3"><KpiCard- title="Visibility Score"- value={`${data.summary.avgVisibilityScore}/100`}+ title={`Visibility Rate — appeared in ${data.summary.visibleResults} of ${data.summary.totalResults} answers`}+ value={data.summary.visibilityRate}icon={Eye}/><KpiCarddiff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsxindex ef7e87b25..1f0fab6f9 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx@@ -143,13 +143,14 @@ function ColHead({// ─── Sortable column header (All Prompts) ─────────────────────────────────────-type AllPromptsSortKey = 'visibility' | 'mentions' | 'citations' | 'volume' | 'lastRun';+type AllPromptsSortKey = 'visibility' | 'mentions' | 'citations' | 'volume' | 'runs' | 'lastRun';const ALL_PROMPTS_SORT_KEYS: AllPromptsSortKey[] = ['visibility','mentions','citations','volume',+ 'runs','lastRun',];@@ -221,6 +222,8 @@ const PROMPT_EXPORT_HEADERS = ['est_ai_volume','total_google_volume','intent',+ 'visibility_rate_30d',+ 'visible_runs_30d','avg_visibility_30d','total_mentions_30d','total_citations_30d',@@ -1125,6 +1128,8 @@ export default function PromptsPage() {est_ai_volume: volumeByPromptId.get(p.id)?.estAiVolume ?? '',total_google_volume: volumeByPromptId.get(p.id)?.totalGoogleVolume ?? '',intent: volumeByPromptId.get(p.id)?.intent ?? '',+ visibility_rate_30d: visibility[p.id]?.visibilityRate ?? '',+ visible_runs_30d: visibility[p.id]?.visibleRuns ?? '',avg_visibility_30d: visibility[p.id]?.avgVisibility ?? '',total_mentions_30d: visibility[p.id]?.totalMentions ?? '',total_citations_30d: visibility[p.id]?.totalCitations ?? '',@@ -1741,13 +1746,15 @@ function AllPromptsTab({const vol = volumeByPromptId.get(p.id);switch (activeSort) {case 'visibility':- return vis ? vis.avgVisibility : null;+ return vis ? vis.visibilityRate : null;case 'mentions':return vis ? vis.totalMentions : null;case 'citations':return vis ? vis.totalCitations : null;case 'volume':return vol ? vol.estAiVolume : null;+ case 'runs':+ return vis ? vis.runs : null;case 'lastRun':return vis?.lastRunAt ? new Date(vis.lastRunAt).getTime() : null;}@@ -1851,7 +1858,7 @@ function AllPromptsTab({</ColHead><SortableHeadclassName="text-right"- tooltip="Average brand visibility score in AI answers for this prompt over the last 30 days."+ tooltip="Visibility Rate: the percentage of AI answers for this prompt (last 30 days) that mentioned or cited the brand. Hover a value for run counts and the average score across visible answers."sortKey="visibility"activeSort={activeSort}dir={dir}@@ -1895,6 +1902,16 @@ function AllPromptsTab({>Competition</ColHead>+ <SortableHead+ className="text-right"+ tooltip="Number of tracking runs for this prompt over the last 30 days (one per platform per day)."+ sortKey="runs"+ activeSort={activeSort}+ dir={dir}+ onSort={handleSort}+ >+ Runs+ </SortableHead><SortableHeadclassName="text-right"tooltip="Most recent tracking run for this prompt."@@ -1963,23 +1980,30 @@ function AllPromptsTab({</TableCell><TableCell className="text-right">{vis ? (- <div className="inline-flex items-center gap-2 justify-end min-w-[110px]">+ <div+ className="inline-flex items-center gap-2 justify-end min-w-[110px]"+ title={`Appeared in ${vis.visibleRuns} of ${vis.runs} runs (30d)${+ vis.avgVisibilityVisible !== null+ ? ` · avg score when visible: ${vis.avgVisibilityVisible.toFixed(0)}`+ : ''+ }`}+ ><spanclassName={cn('text-sm font-semibold tabular-nums',- visibilityColorClass(vis.avgVisibility),+ visibilityColorClass(vis.visibilityRate),)}>- {vis.avgVisibility.toFixed(0)}+ {vis.visibilityRate}</span><div className="h-1.5 w-16 rounded-full bg-muted overflow-hidden"><divclassName={cn('h-full rounded-full',- visibilityBarClass(vis.avgVisibility),+ visibilityBarClass(vis.visibilityRate),)}style={{- width: `${Math.min(100, Math.max(0, vis.avgVisibility))}%`,+ width: `${Math.min(100, Math.max(0, vis.visibilityRate))}%`,}}/></div>@@ -2017,6 +2041,13 @@ function AllPromptsTab({/></div></TableCell>+ <TableCell className="text-right tabular-nums text-sm">+ {vis ? (+ vis.runs.toLocaleString()+ ) : (+ <span className="text-xs text-muted-foreground">—</span>+ )}+ </TableCell><TableCell className="text-right text-xs text-muted-foreground">{formatRelative(vis?.lastRunAt)}</TableCell>diff --git a/web/src/lib/actions/tracking.ts b/web/src/lib/actions/tracking.tsindex afa002f6b..c8e263d47 100644--- a/web/src/lib/actions/tracking.ts+++ b/web/src/lib/actions/tracking.ts@@ -115,6 +115,10 @@ export interface PromptDetailData {};summary: {avgVisibilityScore: number;+ /** visibleResults / totalResults as a percentage, one decimal. */+ visibilityRate: number;+ /** Results with >= 1 brand mention/citation. */+ visibleResults: number;totalMentions: number;totalCitations: number;totalResults: number;@@ -906,6 +910,13 @@ export async function getPromptDetail(totalResults > 0? Math.round(results.reduce((sum, row) => sum + row.visibilityScore, 0) / totalResults): 0;+ // Prompt-level Visibility Rate — same run-visibility rule as the All+ // Prompts column and the Insights headline (mention or citation > 0).+ const visibleResults = results.filter(+ (row) => row.mentionCount > 0 || row.citationCount > 0,+ ).length;+ const visibilityRate =+ totalResults > 0 ? Math.round((visibleResults / totalResults) * 1000) / 10 : 0;// Aggregate citations by domain — same shape and rounding as getCitationsOverview,// but scoped to this prompt's already-loaded results.@@ -997,6 +1008,8 @@ export async function getPromptDetail(},summary: {avgVisibilityScore,+ visibilityRate,+ visibleResults,totalMentions: results.reduce((sum, row) => sum + row.mentionCount, 0),totalCitations: results.reduce((sum, row) => sum + row.citationCount, 0),totalResults,@@ -1301,9 +1314,15 @@ export async function cancelTrackingJob(jobId: string): Promise<void> {export interface PromptVisibilitySummary {avgVisibility: number;+ /** Average score across visible runs only (null when never visible). */+ avgVisibilityVisible: number | null;totalMentions: number;totalCitations: number;runs: number;+ /** Runs with >= 1 brand mention/citation — numerator of the prompt-level rate. */+ visibleRuns: number;+ /** visibleRuns / runs as a percentage, one decimal — same rounding as the Insights headline. */+ visibilityRate: number;lastRunAt: string;}@@ -1337,11 +1356,16 @@ export async function getPromptVisibilitySummaries(const result: Record<string, PromptVisibilitySummary> = {};for (const row of data ?? []) {+ const runs = Number(row.runs ?? 0);+ const visibleRuns = Number(row.visible_runs ?? 0);result[row.prompt_id] = {avgVisibility: row.avg_visibility ?? 0,+ avgVisibilityVisible: row.avg_visibility_visible ?? null,totalMentions: Number(row.total_mentions ?? 0),totalCitations: Number(row.total_citations ?? 0),- runs: Number(row.runs ?? 0),+ runs,+ visibleRuns,+ visibilityRate: runs > 0 ? Math.round((visibleRuns / runs) * 1000) / 10 : 0,lastRunAt: row.last_run_at,};}diff --git a/web/src/types/supabase.ts b/web/src/types/supabase.tsindex c5f584293..aaf6075b1 100644--- a/web/src/types/supabase.ts+++ b/web/src/types/supabase.ts@@ -1450,9 +1450,11 @@ export type Database = {Returns: {prompt_id: string;avg_visibility: number;+ avg_visibility_visible: number | null;total_mentions: number;total_citations: number;runs: number;+ visible_runs: number;last_run_at: string;}[];};