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(content): show the Plan's Priority Score, and how it is worked out (#1342)
Cihan34bdbcc38a70
diff --git a/web/messages/en.json b/web/messages/en.jsonindex f8f3f377e..0a51261cd 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -3141,6 +3141,7 @@"ranked": "Ranked by impact","filtered": "Filtered · click it again to clear","columns": {+ "score": "Priority Score","page": "Page","action": "Action","why": "Why · last {days} days",@@ -3171,6 +3172,15 @@"loadError": "Couldn't load the content plan.","retry": "Try again","priority": "Priority",+ "score": {+ "label": "Priority Score {score}: how it is worked out",+ "title": "How this score is worked out",+ "opportunity": "The content opportunity's own score: {score}",+ "citationsDown": "{base} + {pctPoints} for {pct}% fewer citations + {lostPoints} for {lost, plural, one {# citation} other {# citations}} lost = {score}{capped, select, true { (at most {max})} other {}}",+ "protect": "{base} + {citations, plural, one {# citation} other {# citations}} = {score}{capped, select, true { (at most {max})} other {}}",+ "higher": "The higher of the two counts.",+ "marked": "Marked as a priority, so it's listed first."+ },"rowMenu": {"label": "Actions for {title}","assign": "Assign to…",diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsxindex 06c84b3c4..4f99fbadc 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx@@ -21,11 +21,14 @@ import {TableHeader,TableRow,} from '@/components/ui/table';+import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';+import { PriorityBadge } from '@/components/action-center/action-table';import { DRAFT_METHOD_BADGE, DRAFT_STATUS_BADGE } from '@/components/content/draft-badges';import { contentEditorPath, isPageType } from '@/lib/content/drafts';import { platformNames } from '@/lib/content/impact';import { pagePath } from '@/lib/content/overlap';-import type { PlanAction, PlanPeriod, PlanRow, PlanWhy } from '@/lib/content/plan';+import type { PlanAction, PlanPeriod, PlanRow, PlanScorePart, PlanWhy } from '@/lib/content/plan';+import { priorityLevelOf } from '@/lib/action-center/priority';import { formatNumber } from '@/lib/format';import { cn } from '@/lib/utils';@@ -37,8 +40,9 @@ export const PLAN_ACTION_BADGE: Record<PlanAction, string> = {};/**- * The Plan's priority list (CE-014): rank, the page (a new one, or the- * brand's own), the action, why for the period with where it comes from,+ * The Plan's priority list (CE-014): rank, the Priority Score (what the+ * list is ranked by, with how it was worked out), the page (a new one, or+ * the brand's own), the action, why for the period with where it comes from,* who is on it, the button that starts it — or opens its draft — and a row* menu: assign it to a teammate, and for admins and managers, mark it as a* priority or hide it.@@ -68,6 +72,10 @@ export function PlanTable({<TableHeader><TableRow><TableHead className="w-10 pl-6">#</TableHead>+ {/* Narrow windows: two lines, and the score without its level's name. */}+ <TableHead className="w-16 whitespace-normal leading-tight xl:w-auto xl:whitespace-nowrap">+ {t('columns.score')}+ </TableHead><TableHead>{t('columns.page')}</TableHead><TableHead>{t('columns.action')}</TableHead><TableHead>{t('columns.why', { days })}</TableHead>@@ -85,7 +93,11 @@ export function PlanTable({{rows.map((row, i) => (<TableRow key={row.key}><TableCell className="pl-6 tabular-nums text-muted-foreground">{i + 1}</TableCell>- <TableCell className="max-w-[250px]">+ <TableCell>+ <ScoreBadge row={row} />+ </TableCell>+ {/* Narrower below xl, to leave room for the Priority Score at 1024 px. */}+ <TableCell className="max-w-[200px] xl:max-w-[250px]"><p className="flex min-w-0 items-center gap-1.5 font-medium"><span className="truncate" title={row.title}>{row.title}@@ -221,6 +233,73 @@ function RowMenu({);}+/**+ * The row's Priority Score, coloured by its level as the Action Center's+ * are, and on hover or focus what it is made of.+ */+function ScoreBadge({ row }: { row: PlanRow }) {+ const t = useTranslations('contentEditor.plan.score');+ const score = Math.round(row.score);+ return (+ <Tooltip>+ <TooltipTrigger+ delay={300}+ closeDelay={0}+ render={+ <button+ type="button"+ className="rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"+ aria-label={t('label', { score })}+ />+ }+ >+ <PriorityBadge+ score={score}+ level={priorityLevelOf(score)}+ levelClassName="hidden xl:inline"+ />+ </TooltipTrigger>+ <TooltipContent className="max-w-72 space-y-1">+ <p className="font-medium">{t('title')}</p>+ {row.scoreParts.map((part) => (+ <p key={part.kind}>+ <ScorePartText part={part} />+ </p>+ ))}+ {row.scoreParts.length > 1 && <p className="opacity-80">{t('higher')}</p>}+ {row.priority && <p className="opacity-80">{t('marked')}</p>}+ </TooltipContent>+ </Tooltip>+ );+}++function ScorePartText({ part }: { part: PlanScorePart }) {+ const t = useTranslations('contentEditor.plan.score');+ switch (part.kind) {+ case 'opportunity':+ return t('opportunity', { score: part.score });+ case 'citationsDown':+ return t('citationsDown', {+ base: part.base,+ pct: part.pct,+ pctPoints: part.pctPoints,+ lost: part.lost,+ lostPoints: part.lostPoints,+ score: part.score,+ capped: String(part.base + part.pctPoints + part.lostPoints > part.max),+ max: part.max,+ });+ case 'protect':+ return t('protect', {+ base: part.base,+ citations: part.citations,+ score: part.score,+ capped: String(part.base + part.citations > part.max),+ max: part.max,+ });+ }+}+function WhyText({ why }: { why: PlanWhy }) {const t = useTranslations('contentEditor.plan.why');const format = useFormatter();diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsxindex 02097bbad..8da9d75c5 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx@@ -143,9 +143,12 @@ const button = (name: string) =>[...container.querySelectorAll<HTMLButtonElement>('button')].find((b) =>b.textContent?.startsWith(name),)!;+/** A row's Start button: past the Priority Score, which is a button too. */+const START = 'td:nth-child(n+3) button';+// The page, the action and why: after the rank and the Priority Score.const rowTexts = () =>[...container.querySelectorAll('tbody tr')].map((tr) =>- [...tr.querySelectorAll('td')].slice(1, 4).map((td) => td.textContent),+ [...tr.querySelectorAll('td')].slice(2, 5).map((td) => td.textContent),);beforeEach(() => {@@ -203,6 +206,23 @@ describe('the Content plan', () => {expect(container.querySelector('thead')!.textContent).toContain('Why · last 30 days');});+ it("shows each row's Priority Score, and on focus how it is worked out", async () => {+ await renderPage();+ const scores = [...container.querySelectorAll('tbody tr')].map((tr) => tr.children[1]);+ // The opportunity's 74; 40 + 14 for −70% + 7 citations lost; 20 + 12 citations.+ expect(scores.map((td) => td.textContent)).toEqual(['74Medium', '61Medium', '32Low']);+ expect(container.querySelector('thead')!.textContent).toContain('Priority Score');++ const trigger = scores[1].querySelector('button')!;+ expect(trigger.getAttribute('aria-label')).toBe('Priority Score 61: how it is worked out');+ act(() => trigger.focus());+ await act(() => new Promise((resolve) => setTimeout(resolve, 400)));+ expect(document.querySelector('[data-slot="tooltip-content"]')?.textContent).toBe(+ 'How this score is worked out' ++ '40 + 14 for 70% fewer citations + 7 for 7 citations lost = 61',+ );+ });+it('filters the list by a card, and clears it on a second click', async () => {await renderPage();await act(async () => button('Protect').click());@@ -248,7 +268,7 @@ describe('the Content plan', () => {],});await renderPage();- await act(async () => container.querySelector<HTMLButtonElement>('tbody tr button')!.click());+ await act(async () => container.querySelector<HTMLButtonElement>(`tbody tr ${START}`)!.click());expect(dialog.props).toMatchObject({preset: {kind: 'opportunity',@@ -275,7 +295,7 @@ describe('the Content plan', () => {await renderPage();const rows = container.querySelectorAll('tbody tr');- await act(async () => rows[1].querySelector('button')!.click());+ await act(async () => rows[1].querySelector<HTMLButtonElement>(START)!.click());expect(dialog.props).toMatchObject({open: true,preset: { kind: 'page', url: 'https://acme.example/guides/coffee-subscriptions' },@@ -283,7 +303,7 @@ describe('the Content plan', () => {await act(async () => (dialog.props!.onOpenChange as (open: boolean) => void)(false));expect(dialog.props).toMatchObject({ open: false, preset: null });- await act(async () => rows[0].querySelector('button')!.click());+ await act(async () => rows[0].querySelector<HTMLButtonElement>(START)!.click());expect(dialog.props).toMatchObject({ preset: { kind: 'opportunity', id: 'o1', page: null } });expect(rows[2].textContent).toContain('Agent');diff --git a/web/src/components/action-center/action-table.tsx b/web/src/components/action-center/action-table.tsxindex b9a70c9f7..cb60bb8ae 100644--- a/web/src/components/action-center/action-table.tsx+++ b/web/src/components/action-center/action-table.tsx@@ -135,9 +135,12 @@ export const PRIORITY_BADGE: Record<PriorityLevel, string> = {export function PriorityBadge({score,level,+ levelClassName,}: {score: number | null;level: PriorityLevel | null;+ /** For the level's name: the Content Plan hides it where its table is narrow. */+ levelClassName?: string;}) {const t = useTranslations('actionCenter.actionsPage.priority');if (score === null || level === null) {@@ -152,7 +155,7 @@ export function PriorityBadge({<Badge variant="outline" className={cn('font-semibold tabular-nums', PRIORITY_BADGE[level])}>{score}</Badge>- <span className="text-xs">{t(`levels.${level}`)}</span>+ <span className={cn('text-xs', levelClassName)}>{t(`levels.${level}`)}</span></span>);}diff --git a/web/src/lib/content/plan.test.ts b/web/src/lib/content/plan.test.tsindex f19839a9c..2fd724e27 100644--- a/web/src/lib/content/plan.test.ts+++ b/web/src/lib/content/plan.test.ts@@ -317,3 +317,66 @@ describe('buildPlan', () => {expect(counts).toEqual({ create: 1, optimize: 0, protect: 0, priority: 0 });});});++// The Priority Score column shows each row's score and what it is made of.+describe("a row's score breakdown", () => {+ it("is the opportunity's own score, rounded as the row's", () => {+ const { rows } = plan([], [opportunity('o1', { score: 81.4 })]);+ expect(rows[0].score).toBe(81);+ expect(rows[0].scoreParts).toEqual([{ kind: 'opportunity', score: 81 }]);+ });++ it("adds up a drop's points to the row's score", () => {+ const { rows } = plan([page('/features/forecasting', { citations: { cur: 6, prev: 10 } })]);+ // Down 40% (+8), 4 citations lost (+4), on a base of 40.+ expect(rows[0].scoreParts).toEqual([+ {+ kind: 'citationsDown',+ base: 40,+ pct: 40,+ pctPoints: 8,+ lost: 4,+ lostPoints: 4,+ max: 100,+ score: 52,+ },+ ]);+ expect(rows[0].score).toBe(52);+ });++ it('gives an opportunity on a page losing ground both parts, the higher counting', () => {+ const { rows } = plan(+ [page('/guides/espresso', { citations: { cur: 2, prev: 8 } })],+ [+ opportunity('o1', {+ decision: 'optimize',+ targetPage: 'https://acme.example/guides/espresso',+ score: 50,+ }),+ ],+ );+ expect(rows[0].scoreParts.map((p) => [p.kind, p.score])).toEqual([+ ['opportunity', 50],+ ['citationsDown', citationsDownScore(75, 6)],+ ]);+ expect(rows[0].score).toBe(Math.max(...rows[0].scoreParts.map((p) => p.score)));+ });++ it("counts a top page's citations on a base of 20, up to 60", () => {+ const { rows } = plan([+ page('/a', { citations: { cur: 18, prev: 18 } }),+ page('/b', { citations: { cur: 55, prev: 55 } }),+ ]);+ expect(rows.map((r) => r.scoreParts)).toEqual([+ [{ kind: 'protect', base: 20, citations: 55, max: 60, score: 60 }],+ [{ kind: 'protect', base: 20, citations: 18, max: 60, score: 38 }],+ ]);+ });++ it('caps a drop at 100 and its citations lost at 40 points', () => {+ const { rows } = plan([page('/x', { citations: { cur: 0, prev: 90 } })]);+ expect(rows[0].scoreParts).toEqual([+ expect.objectContaining({ pctPoints: 20, lost: 90, lostPoints: 40, score: 100 }),+ ]);+ });+});diff --git a/web/src/lib/content/plan.ts b/web/src/lib/content/plan.tsindex 7ee4d0aeb..600da3e1b 100644--- a/web/src/lib/content/plan.ts+++ b/web/src/lib/content/plan.ts@@ -106,6 +106,8 @@ export interface PlanRow {why: PlanWhy;source: 'opportunity' | 'citations' | 'protect';score: number;+ /** What the score is made of (the Priority Score's breakdown). */+ scoreParts: PlanScorePart[];opportunityId: string | null;draft: PlanDraft | null;/** Marked as a priority: at the top of the list, tagged. */@@ -123,6 +125,14 @@ export const MIN_TOP_CITATIONS = 5;export const MAX_PROTECT = 5;export const MAX_ROWS = 50;+const DROP_BASE = 40;+const PROTECT_BASE = 20;+const MAX_PROTECT_SCORE = 60;+/** A drop's points: a fifth of the drop in percent, and the citations lost (up to 40). */+function citationsDownPoints(pct: number, lost: number) {+ return { pct: Math.round(pct / 5), lost: Math.min(40, lost) };+}+/*** The rank of each kind of row, on the opportunities' 0–100 scale: an* opportunity keeps its own score; a page losing citations ranks by how much@@ -132,10 +142,55 @@ export const MAX_ROWS = 50;* protecting comes after the work to do.*/export function citationsDownScore(pct: number, lost: number): number {- return Math.min(100, 40 + Math.round(pct / 5) + Math.min(40, lost));+ const points = citationsDownPoints(pct, lost);+ return Math.min(100, DROP_BASE + points.pct + points.lost);}export function protectScore(citations: number): number {- return Math.min(60, 20 + citations);+ return Math.min(MAX_PROTECT_SCORE, PROTECT_BASE + citations);+}++/**+ * What a row's score is made of, for the Priority Score's breakdown: the+ * opportunity's own score; for a page losing citations, the base and the+ * points for the drop and the citations lost; for a top page, the base and+ * its citations. An opportunity whose page is losing ground has both, and+ * ranks by the higher. `max` is where a score stops.+ */+export type PlanScorePart =+ | { kind: 'opportunity'; score: number }+ | {+ kind: 'citationsDown';+ base: number;+ pct: number;+ pctPoints: number;+ lost: number;+ lostPoints: number;+ max: number;+ score: number;+ }+ | { kind: 'protect'; base: number; citations: number; max: number; score: number };++function citationsDownPart(drop: { pct: number; lost: number }): PlanScorePart {+ const points = citationsDownPoints(drop.pct, drop.lost);+ return {+ kind: 'citationsDown',+ base: DROP_BASE,+ pct: drop.pct,+ pctPoints: points.pct,+ lost: drop.lost,+ lostPoints: points.lost,+ max: 100,+ score: citationsDownScore(drop.pct, drop.lost),+ };+}+function protectPart(citations: number): PlanScorePart {+ return {+ kind: 'protect',+ base: PROTECT_BASE,+ citations,+ max: MAX_PROTECT_SCORE,+ score: protectScore(citations),+ };}const CREATE_DECISIONS = new Set(['create']);@@ -212,6 +267,10 @@ export function buildPlan({score: drop? Math.max(o.score, citationsDownScore(drop.pct, drop.lost)): Math.round(o.score),+ scoreParts: [+ { kind: 'opportunity', score: Math.round(o.score) },+ ...(drop ? [citationsDownPart(drop)] : []),+ ],opportunityId: o.id,draft: draftFor(o.id, create ? null : o.targetPage),priority: false,@@ -240,6 +299,7 @@ export function buildPlan({why: dropWhy(page, drop),source: 'citations',score: citationsDownScore(drop.pct, drop.lost),+ scoreParts: [citationsDownPart(drop)],});} else if (page.citations.cur >= MIN_TOP_CITATIONS) {protect.push({@@ -249,6 +309,7 @@ export function buildPlan({why: { kind: 'top', citations: page.citations.cur, aiVisits: page.aiVisits },source: 'protect',score: protectScore(page.citations.cur),+ scoreParts: [protectPart(page.citations.cur)],});}}