Skip to content

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.

feat(audit): rank Site Audit opportunities by a priority score (#1138)

Cihand696ed9dd81c
diff --git a/server/src/lib/audit/opportunities.js b/server/src/lib/audit/opportunities.js
index 670fdbda3..52db00a8b 100644
--- a/server/src/lib/audit/opportunities.js
+++ b/server/src/lib/audit/opportunities.js
@@ -12,8 +12,9 @@
* (audit_competitor_cited_prompts), each through the brand page closest
* to it (the prompt's target URL, else the best site_pages match).
*
- * Pinned pages always show, first. Excluded pages are left out of the rows
- * and listed apart, so they can be put back.
+ * Pinned pages always show. Excluded pages are left out of the rows and
+ * listed apart, so they can be put back. The order is the priority score's
+ * (priority.js rankOpportunities); here rows come pinned first, then by path.
*/
import { isExcludedPath } from '../page-paths.js';
@@ -108,6 +109,8 @@ export function buildOpportunities({
now = Date.now(),
}) {
const audits = new Map(auditPages.map((p) => [p.key.toLowerCase(), p]));
+ // A page listed for another reason still takes its title and traffic from site_pages.
+ const sitePagesByKey = new Map(sitePages.map((p) => [opportunityKey(p.url), p]));
const prefsByKey = new Map(prefs.map((p) => [p.page_key, p]));
const pages = new Map();
@@ -193,8 +196,12 @@ export function buildOpportunities({
if (!page.pinned && page.reasons.length === 0) continue;
const audit = audits.get(page.key);
+ const site = sitePagesByKey.get(page.key);
rows.push({
...page,
+ title: page.title ?? site?.title ?? null,
+ sessions: page.sessions ?? site?.ga_sessions ?? null,
+ citations: page.citations ?? site?.ai_citations ?? null,
running: audit?.status === 'running',
lastAudit:
audit && audit.score !== null
@@ -209,34 +216,11 @@ export function buildOpportunities({
}
}
- rows.sort(compareOpportunities);
+ rows.sort((a, b) => Number(b.pinned) - Number(a.pinned) || a.path.localeCompare(b.path));
excluded.sort((a, b) => a.path.localeCompare(b.path));
return { rows, excluded };
}
-const gaPercentile = (row) => row.reasons.find((r) => r.type === 'no_ai_traffic')?.percentile ?? -1;
-const neverAudited = (row) => row.reasons.some((r) => r.type === 'never_audited');
-const competitorPrompts = (row) =>
- row.reasons.find((r) => r.type === 'competitor_cited')?.prompts ?? 0;
-
-/**
- * Until the priority score (SA-005): pinned first, then GA's most valuable
- * pages without AI traffic, then the pages closest to the most prompts a
- * competitor wins, then pages never audited before stale ones, then the most
- * cited and visited.
- */
-export function compareOpportunities(a, b) {
- return (
- Number(b.pinned) - Number(a.pinned) ||
- gaPercentile(b) - gaPercentile(a) ||
- competitorPrompts(b) - competitorPrompts(a) ||
- Number(neverAudited(b)) - Number(neverAudited(a)) ||
- (b.citations ?? 0) - (a.citations ?? 0) ||
- (b.sessions ?? 0) - (a.sessions ?? 0) ||
- a.path.localeCompare(b.path)
- );
-}
-
/**
* AI visits per page over the window, from ae_page_traffic_evidence: Google
* Analytics where it has the page, else the tracking snippet, never both
diff --git a/server/src/lib/audit/opportunities.test.js b/server/src/lib/audit/opportunities.test.js
index bed2afdb2..0e769caee 100644
--- a/server/src/lib/audit/opportunities.test.js
+++ b/server/src/lib/audit/opportunities.test.js
@@ -2,7 +2,6 @@ import { describe, expect, it } from 'vitest';
import {
aiVisitsByPage,
buildOpportunities,
- compareOpportunities,
competitorGapPages,
opportunityKey,
} from './opportunities.js';
@@ -93,10 +92,11 @@ describe('buildOpportunities', () => {
audit('https://acme.com/team', null, 2, 'failed'),
],
});
+ // Path order here; the priority score orders the inbox (priority.js).
expect(rows.map((r) => [r.path, r.reasons])).toEqual([
['/blog/guide', [{ type: 'never_audited' }]],
- ['/team', [{ type: 'never_audited' }]],
['/compare', [{ type: 'stale_audit', days: 120 }]],
+ ['/team', [{ type: 'never_audited' }]],
]);
expect(rows[0]).toMatchObject({ title: 'Guide', citations: 3, sessions: 40, lastAudit: null });
});
@@ -166,29 +166,6 @@ describe('buildOpportunities', () => {
});
});
-describe('compareOpportunities', () => {
- const row = (path, over = {}) => ({ path, pinned: false, reasons: [], ...over });
-
- it('orders pinned, then GA value, then never audited, then citations and visits', () => {
- const rows = [
- row('/stale', { reasons: [{ type: 'stale_audit', days: 100 }], citations: 9 }),
- row('/never-quiet', { reasons: [{ type: 'never_audited' }], citations: 0, sessions: 1 }),
- row('/never-cited', { reasons: [{ type: 'never_audited' }], citations: 4 }),
- row('/ga-80', { reasons: [{ type: 'no_ai_traffic', percentile: 80 }] }),
- row('/ga-95', { reasons: [{ type: 'no_ai_traffic', percentile: 95 }] }),
- row('/pinned', { pinned: true }),
- ];
- expect(rows.sort(compareOpportunities).map((r) => r.path)).toEqual([
- '/pinned',
- '/ga-95',
- '/ga-80',
- '/never-cited',
- '/never-quiet',
- '/stale',
- ]);
- });
-});
-
describe('aiVisitsByPage', () => {
it('takes Google Analytics where it has the page, else the snippet, never both', () => {
const visits = aiVisitsByPage({
@@ -288,14 +265,11 @@ describe('competitorGapPages', () => {
});
describe('buildOpportunities with competitor-cited pages', () => {
- it('adds the reason to the page and ranks it after GA value, before never audited', () => {
+ it('adds the reason to the page, with its traffic from site_pages', () => {
const { rows } = build({
- gaPages: [
- { landing_page: '/ga', value_signal: 'revenue', value_percentile: 90, sessions: 10 },
- ],
sitePages: [
- { url: 'https://acme.com/never', title: null, ga_sessions: 999, ai_citations: 9 },
- { url: 'https://acme.com/pricing', title: 'Pricing', ga_sessions: 1, ai_citations: 0 },
+ { url: 'https://acme.com/pricing', title: 'Pricing', ga_sessions: 40, ai_citations: 1 },
+ { url: 'https://acme.com/fresh', title: 'Fresh', ga_sessions: 12, ai_citations: 0 },
],
competitorPages: [
{ url: 'https://acme.com/pricing', prompts: 3, competitors: ['Crema Club'] },
@@ -303,17 +277,17 @@ describe('buildOpportunities with competitor-cited pages', () => {
],
auditPages: [audit('https://acme.com/fresh', 0.8, 2)],
});
- expect(rows.map((r) => [r.path, r.reasons.map((x) => x.type)])).toEqual([
- ['/ga', ['no_ai_traffic']],
- ['/pricing', ['never_audited', 'competitor_cited']],
- // Audited two days ago, still listed: the competitor gap is the reason.
- ['/fresh', ['competitor_cited']],
- ['/never', ['never_audited']],
+ const byPath = Object.fromEntries(rows.map((r) => [r.path, r]));
+ expect(byPath['/pricing'].reasons).toEqual([
+ { type: 'never_audited' },
+ { type: 'competitor_cited', prompts: 3, competitors: ['Crema Club'] },
]);
- expect(rows[1].reasons[1]).toEqual({
- type: 'competitor_cited',
- prompts: 3,
- competitors: ['Crema Club'],
+ // Audited two days ago, still listed: the competitor gap is the reason,
+ // and its title and sessions come from site_pages.
+ expect(byPath['/fresh']).toMatchObject({
+ reasons: [{ type: 'competitor_cited', prompts: 1, competitors: ['Northline'] }],
+ title: 'Fresh',
+ sessions: 12,
});
});
});
diff --git a/server/src/lib/audit/priority.js b/server/src/lib/audit/priority.js
new file mode 100644
index 000000000..4973b0272
--- /dev/null
+++ b/server/src/lib/audit/priority.js
@@ -0,0 +1,146 @@
+/**
+ * The Opportunities inbox's priority score (SA-005): value × opportunity ×
+ * ease, each 0–1, shown 0–100 as the cube root of the product (the same
+ * order as the product, on a scale people read: 0.96 × 0.9 × 0.8 is 88).
+ * Pure; the weights live here so they're tuned in one place.
+ *
+ * - Value: what the page is worth to the business. Google Analytics' value
+ * percentile, weighted by its signal (revenue and transactions above key
+ * events above engagement); else the page's sessions ranked within the
+ * site.
+ * - Opportunity: how much an audit can win. No AI traffic, a competitor
+ * cited on the page's prompts, a target page not cited, never or long ago
+ * audited, no AI visits.
+ * - Ease: how close the page is to passing. Its last score; unknown when
+ * never audited. (A template-level fix, SA-007, will add to it.)
+ */
+
+export const PRIORITY_WEIGHTS = Object.freeze({
+ value: Object.freeze({
+ signals: Object.freeze({ revenue: 1, transactions: 1, key_events: 0.9, engagement: 0.75 }),
+ /** A page without a GA value, at the top of the site's sessions. */
+ sessions: 0.6,
+ min: 0.15,
+ }),
+ opportunity: Object.freeze({
+ noAiTraffic: 0.45,
+ competitorCited: 0.3,
+ perExtraPrompt: 0.05,
+ competitorMax: 0.45,
+ targetedNotCited: 0.15,
+ neverAudited: 0.3,
+ staleAudit: 0.2,
+ zeroAiVisits: 0.1,
+ min: 0.1,
+ }),
+ ease: Object.freeze({
+ /** Last score from here up: close to passing (70). */
+ nearPassingScore: 0.6,
+ middleScore: 0.4,
+ nearPassing: 1,
+ middle: 0.75,
+ low: 0.55,
+ unaudited: 0.8,
+ }),
+});
+
+const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
+const round2 = (n) => Math.round(n * 100) / 100;
+
+/**
+ * Each page's sessions as a share of the site's pages it beats (0–1), from
+ * the site's 30-day sessions. As GA's value percentile (scorePages), ties
+ * share a rank; a page above every site page is 1.
+ *
+ * @param {Array<number|null>} siteSessions
+ * @returns {(sessions: number|null) => number|null}
+ */
+export function sessionsRanker(siteSessions) {
+ const sorted = siteSessions.filter((n) => typeof n === 'number' && n > 0).sort((a, b) => a - b);
+ return (sessions) => {
+ if (!(sessions > 0) || sorted.length === 0) return null;
+ let below = 0;
+ while (below < sorted.length && sorted[below] < sessions) below += 1;
+ return sorted.length === 1 ? 1 : Math.min(1, below / (sorted.length - 1));
+ };
+}
+
+/**
+ * @param {{ reasons: Array<object>, sessions: number|null, aiVisits?: number|null, lastAudit: { score: number }|null }} row
+ * @param {(sessions: number|null) => number|null} rankSessions
+ * @returns {{ priority: number, value: number, opportunity: number, ease: number }}
+ */
+export function scorePriority(row, rankSessions) {
+ const w = PRIORITY_WEIGHTS;
+ const reason = (type) => row.reasons.find((r) => r.type === type);
+
+ const ga = reason('no_ai_traffic');
+ const sessionsRank = rankSessions(row.sessions);
+ const value = clamp(
+ ga
+ ? (ga.percentile / 100) * (w.value.signals[ga.signal] ?? w.value.signals.engagement)
+ : (sessionsRank ?? 0) * w.value.sessions,
+ w.value.min,
+ 1,
+ );
+
+ const o = w.opportunity;
+ const competitor = reason('competitor_cited');
+ let opportunity = 0;
+ if (ga) opportunity += o.noAiTraffic;
+ if (ga?.citationState === 'targeted_not_cited') opportunity += o.targetedNotCited;
+ if (competitor) {
+ opportunity += Math.min(
+ o.competitorMax,
+ o.competitorCited + o.perExtraPrompt * Math.max(0, competitor.prompts - 1),
+ );
+ }
+ // Never audited is a fact about the page, whichever source listed it.
+ if (row.lastAudit === null) opportunity += o.neverAudited;
+ if (reason('stale_audit')) opportunity += o.staleAudit;
+ // GA's reason already says the page has no AI traffic.
+ if (!ga && row.aiVisits === 0) opportunity += o.zeroAiVisits;
+ opportunity = clamp(opportunity, o.min, 1);
+
+ const e = w.ease;
+ const score = row.lastAudit?.score ?? null;
+ const ease =
+ score === null
+ ? e.unaudited
+ : score >= e.nearPassingScore
+ ? e.nearPassing
+ : score >= e.middleScore
+ ? e.middle
+ : e.low;
+
+ return {
+ priority: Math.round(100 * Math.cbrt(value * opportunity * ease)),
+ value: round2(value),
+ opportunity: round2(opportunity),
+ ease: round2(ease),
+ };
+}
+
+/**
+ * Scores every row and orders the inbox: pinned pages first, then by
+ * priority, then by path.
+ *
+ * @template {{ path: string, pinned: boolean, reasons: Array<object>, sessions: number|null, aiVisits?: number|null, lastAudit: object|null }} R
+ * @param {R[]} rows
+ * @param {Array<number|null>} siteSessions the site pages' 30-day sessions
+ * @returns {Array<R & { priority: number, priorityParts: { value: number, opportunity: number, ease: number } }>}
+ */
+export function rankOpportunities(rows, siteSessions) {
+ const rankSessions = sessionsRanker(siteSessions);
+ return rows
+ .map((row) => {
+ const { priority, ...priorityParts } = scorePriority(row, rankSessions);
+ return { ...row, priority, priorityParts };
+ })
+ .sort(
+ (a, b) =>
+ Number(b.pinned) - Number(a.pinned) ||
+ b.priority - a.priority ||
+ a.path.localeCompare(b.path),
+ );
+}
diff --git a/server/src/lib/audit/priority.test.js b/server/src/lib/audit/priority.test.js
new file mode 100644
index 000000000..1e3d89f36
--- /dev/null
+++ b/server/src/lib/audit/priority.test.js
@@ -0,0 +1,131 @@
+import { describe, expect, it } from 'vitest';
+import { PRIORITY_WEIGHTS, rankOpportunities, scorePriority, sessionsRanker } from './priority.js';
+
+const row = (over = {}) => ({
+ path: '/page',
+ pinned: false,
+ reasons: [],
+ sessions: null,
+ aiVisits: null,
+ lastAudit: null,
+ ...over,
+});
+const noRank = () => null;
+
+describe('sessionsRanker', () => {
+ it("ranks a page's sessions among the site's, from 0 to 1", () => {
+ const rank = sessionsRanker([10, 40, null, 0, 90, 250]);
+ expect(rank(250)).toBe(1);
+ expect(rank(10)).toBe(0);
+ expect(rank(90)).toBeCloseTo(2 / 3);
+ // A page between two site pages beats the ones below it.
+ expect(rank(50)).toBeCloseTo(2 / 3);
+ // Above every site page it is still 1, and equal pages share a rank.
+ expect(rank(400)).toBe(1);
+ expect(sessionsRanker([10, 50, 50])(50)).toBe(0.5);
+ expect(rank(0)).toBeNull();
+ expect(rank(null)).toBeNull();
+ expect(sessionsRanker([])(30)).toBeNull();
+ expect(sessionsRanker([30])(30)).toBe(1);
+ });
+});
+
+describe('scorePriority', () => {
+ it("scores the spec's top example at 88: value 0.96 × opportunity 0.9 × ease 0.8", () => {
+ const score = scorePriority(
+ row({
+ reasons: [
+ {
+ type: 'no_ai_traffic',
+ signal: 'revenue',
+ percentile: 96,
+ citationState: 'targeted_not_cited',
+ },
+ { type: 'never_audited' },
+ ],
+ }),
+ noRank,
+ );
+ expect(score).toEqual({ priority: 88, value: 0.96, opportunity: 0.9, ease: 0.8 });
+ });
+
+ it('weighs revenue above key events above engagement', () => {
+ const value = (signal) =>
+ scorePriority(
+ row({ reasons: [{ type: 'no_ai_traffic', signal, percentile: 90, citationState: null }] }),
+ noRank,
+ ).value;
+ expect(value('revenue')).toBe(0.9);
+ expect(value('transactions')).toBe(0.9);
+ expect(value('key_events')).toBe(0.81);
+ expect(value('engagement')).toBe(0.68);
+ });
+
+ it("values a page without GA by its sessions' rank, and never below the floor", () => {
+ const rank = sessionsRanker([5, 20, 80]);
+ expect(scorePriority(row({ sessions: 80 }), rank).value).toBe(PRIORITY_WEIGHTS.value.sessions);
+ expect(scorePriority(row({ sessions: 20 }), rank).value).toBe(0.3);
+ expect(scorePriority(row({ sessions: null }), rank).value).toBe(PRIORITY_WEIGHTS.value.min);
+ });
+
+ it('adds up the opportunity, caps the competitor share and the total', () => {
+ // An audited page, so "never audited" doesn't add to these.
+ const audited = { lastAudit: { score: 0.5 } };
+ const opportunity = (reasons, extra = {}) =>
+ scorePriority(row({ reasons, ...audited, ...extra }), noRank).opportunity;
+ expect(opportunity([{ type: 'competitor_cited', prompts: 1, competitors: ['A'] }])).toBe(0.3);
+ expect(opportunity([{ type: 'competitor_cited', prompts: 3, competitors: ['A'] }])).toBe(0.4);
+ expect(opportunity([{ type: 'competitor_cited', prompts: 20, competitors: ['A'] }])).toBe(0.45);
+ expect(opportunity([{ type: 'stale_audit', days: 120 }])).toBe(0.2);
+ // Never audited counts from the page's audits, whichever source listed it.
+ expect(opportunity([], { lastAudit: null })).toBe(0.3);
+ // No AI visits counts once: GA's reason already says so.
+ expect(opportunity([{ type: 'never_audited' }], { aiVisits: 0, lastAudit: null })).toBe(0.4);
+ expect(
+ opportunity(
+ [
+ { type: 'no_ai_traffic', signal: 'revenue', percentile: 99, citationState: null },
+ { type: 'competitor_cited', prompts: 10, competitors: ['A'] },
+ ],
+ { aiVisits: 0, lastAudit: null },
+ ),
+ ).toBe(1);
+ // A pinned, audited page with nothing to fix still has the floor.
+ expect(opportunity([])).toBe(PRIORITY_WEIGHTS.opportunity.min);
+ });
+
+ it('makes a page close to passing easier than one far from it', () => {
+ const ease = (score) =>
+ scorePriority(row({ lastAudit: score === null ? null : { score } }), noRank).ease;
+ expect(ease(0.65)).toBe(1);
+ expect(ease(0.5)).toBe(0.75);
+ expect(ease(0.2)).toBe(0.55);
+ expect(ease(null)).toBe(0.8);
+ });
+});
+
+describe('rankOpportunities', () => {
+ it('orders pinned pages first, then by priority, then by path, and adds the parts', () => {
+ const ranked = rankOpportunities(
+ [
+ row({ path: '/never-b', reasons: [{ type: 'never_audited' }] }),
+ row({ path: '/never-a', reasons: [{ type: 'never_audited' }] }),
+ row({ path: '/pinned', pinned: true }),
+ row({
+ path: '/ga',
+ reasons: [
+ { type: 'no_ai_traffic', signal: 'revenue', percentile: 95, citationState: null },
+ ],
+ }),
+ ],
+ [],
+ );
+ expect(ranked.map((r) => [r.path, r.priority])).toEqual([
+ ['/pinned', 33],
+ ['/ga', 83],
+ ['/never-a', 33],
+ ['/never-b', 33],
+ ]);
+ expect(ranked[1].priorityParts).toEqual({ value: 0.95, opportunity: 0.75, ease: 0.8 });
+ });
+});
diff --git a/server/src/routes/audits-opportunities.test.js b/server/src/routes/audits-opportunities.test.js
index 172cab4f8..d505c6e12 100644
--- a/server/src/routes/audits-opportunities.test.js
+++ b/server/src/routes/audits-opportunities.test.js
@@ -187,6 +187,11 @@ describe('GET /api/audits/opportunities', () => {
}),
]);
expect(body.excluded.map((e) => e.path)).toEqual(['/blog']);
+ // Scored once its AI visits are in (SA-005).
+ expect(body.opportunities[0]).toMatchObject({
+ priority: expect.any(Number),
+ priorityParts: { value: 0.96, opportunity: 0.75, ease: 0.8 },
+ });
expect(body.staleDays).toBe(90);
// AI visits over the last 30 days, for the listed pages.
diff --git a/server/src/routes/audits.js b/server/src/routes/audits.js
index 088e7dc07..1b5500721 100644
--- a/server/src/routes/audits.js
+++ b/server/src/routes/audits.js
@@ -40,6 +40,7 @@ import {
competitorGapPages,
opportunityKey,
} from '../lib/audit/opportunities.js';
+import { rankOpportunities } from '../lib/audit/priority.js';
import { ENGINE_THRESHOLDS } from '../config/action-engine.js';
import { runSignals } from '../lib/audit/engine.js';
import { evaluateLlmSignals } from '../lib/audit/llm-signals.js';
@@ -699,10 +700,11 @@ router.get('/opportunities', async (req, res) => {
return res.json({
success: true,
- opportunities: rows.map((r) => ({
- ...r,
- aiVisits: visits === null ? null : (visits.get(r.url) ?? 0),
- })),
+ // Scored and ordered once each page has its AI visits (SA-005).
+ opportunities: rankOpportunities(
+ rows.map((r) => ({ ...r, aiVisits: visits === null ? null : (visits.get(r.url) ?? 0) })),
+ (sitePages.data ?? []).map((p) => p.ga_sessions),
+ ),
excluded,
staleDays: ENGINE_THRESHOLDS.detection.auditMaxAgeDays,
});
diff --git a/web/messages/en.json b/web/messages/en.json
index eca67663b..39efc8918 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -2114,6 +2114,9 @@
"noPages": "No pages audited yet. Audit an opportunity or enter a URL above."
},
"opportunities": {
+ "priority": "Priority",
+ "priorityTip": "How much auditing this page could win: its value to the business × the opportunity (no AI traffic, a competitor cited, never or long ago audited) × how easy it is to fix (how close it is to passing), each 0–1, on a 0–100 scale.",
+ "priorityParts": "Value {value} × opportunity {opportunity} × ease {ease}",
"page": "Page",
"why": "Why",
"aiVisits": "AI visits",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.test.tsx
index 9315a3cc9..2a2b68f1e 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.test.tsx
@@ -33,6 +33,8 @@ const opportunity = (over: Partial<AuditOpportunity> = {}): AuditOpportunity =>
running: false,
aiVisits: 0,
lastAudit: { at: '2026-10-14T12:00:00.000Z', score: 0.63, auditId: 'a1' },
+ priority: 88,
+ priorityParts: { value: 0.96, opportunity: 0.9, ease: 0.8 },
...over,
});
@@ -44,6 +46,8 @@ const blog = opportunity({
pinned: true,
aiVisits: 12,
lastAudit: null,
+ priority: 41,
+ priorityParts: { value: 0.3, opportunity: 0.4, ease: 0.8 },
});
let container: HTMLDivElement;
@@ -109,9 +113,16 @@ describe('OpportunitiesTable', () => {
]);
expect(rows().map(cells)).toEqual([
- ['', '/blog', 'PinnedNever audited', '12', 'never'],
- ['', '/pricing', 'No AI trafficTop 5% by revenueTargeted, not cited', '0', 'Oct 14 · 63'],
- ['', '/compare', 'Audited 120 days ago', '—', 'Oct 14 · 63'],
+ ['', '41', '/blog', 'PinnedNever audited', '12', 'never'],
+ [
+ '',
+ '88',
+ '/pricing',
+ 'No AI trafficTop 5% by revenueTargeted, not cited',
+ '0',
+ 'Oct 14 · 63',
+ ],
+ ['', '88', '/compare', 'Audited 120 days ago', '—', 'Oct 14 · 63'],
]);
// The page opens the live page; the last audit its report.
const [pageLink] = rows()[1].querySelectorAll('a');
@@ -133,12 +144,24 @@ describe('OpportunitiesTable', () => {
reasons: [{ type: 'competitor_cited', prompts: 1, competitors: ['Crema Club'] }],
}),
]);
- expect(rows().map((r) => cells(r)[2])).toEqual([
+ expect(rows().map((r) => cells(r)[3])).toEqual([
'Crema Club +1 cited on 3 prompts',
'Crema Club cited on 1 prompt',
]);
});
+ it('shows the priority, dark from 80, with its parts on hover', () => {
+ render([opportunity(), blog]);
+ const pill = (row: Element) => row.querySelectorAll('td')[1].querySelector('span')!;
+ const [high, low] = rows().map(pill);
+ expect(high.textContent).toBe('88');
+ expect(high.className).toContain('bg-foreground');
+ expect(high.getAttribute('title')).toBe('Value 0.96 × opportunity 0.90 × ease 0.80');
+ expect(low.textContent).toBe('41');
+ expect(low.className).toContain('bg-muted');
+ expect(container.querySelector('thead')?.textContent).toContain('Priority');
+ });
+
it('selects pages not being audited, one by one or all shown', () => {
const running = opportunity({ key: 'run', path: '/run', running: true, lastAudit: null });
render([opportunity(), blog, running], {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.tsx b/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.tsx
index 732afb67e..cfd7b55ac 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/audit/_opportunities-table.tsx
@@ -18,6 +18,33 @@ import {
import { pct } from '@/components/audit/audit-report';
import type { AuditOpportunity, ExcludedPage, OpportunityReason } from '@/lib/actions/audits';
import { formatMonthDay, formatNumber } from '@/lib/format';
+import { cn } from '@/lib/utils';
+import { InfoTip } from '../insights/_kpi-cards';
+
+/** A priority at or above this shows dark, as the mockup's high ones. */
+const HIGH_PRIORITY = 80;
+
+function PriorityPill({ row }: { row: AuditOpportunity }) {
+ const t = useTranslations('audit.opportunities');
+ const parts = t('priorityParts', {
+ value: row.priorityParts.value.toFixed(2),
+ opportunity: row.priorityParts.opportunity.toFixed(2),
+ ease: row.priorityParts.ease.toFixed(2),
+ });
+ return (
+ <span
+ title={parts}
+ className={cn(
+ 'inline-flex h-6 min-w-[2.125rem] items-center justify-center rounded-md px-1.5 text-xs font-semibold tabular-nums',
+ row.priority >= HIGH_PRIORITY
+ ? 'bg-foreground text-background'
+ : 'bg-muted text-foreground',
+ )}
+ >
+ {row.priority}
+ </span>
+ );
+}
/** Rows shown at first, and added by Show more. */
export const OPPORTUNITIES_STEP = 50;
@@ -173,6 +200,12 @@ export function OpportunitiesTable({
onCheckedChange={(on) => onSelect(selectable, on === true)}
/>
</TableHead>
+ <TableHead>
+ <span className="inline-flex items-center gap-1">
+ {t('priority')}
+ <InfoTip content={t('priorityTip')} />
+ </span>
+ </TableHead>
{/* The page column takes the room left, and long paths truncate in it. */}
<TableHead className="w-full">{t('page')}</TableHead>
<TableHead>{t('why')}</TableHead>
@@ -194,6 +227,9 @@ export function OpportunitiesTable({
onCheckedChange={(on) => onSelect([row.key], on === true)}
/>
</TableCell>
+ <TableCell>
+ <PriorityPill row={row} />
+ </TableCell>
<TableCell className="max-w-0">
<a
href={row.url}
diff --git a/web/src/lib/actions/audits.ts b/web/src/lib/actions/audits.ts
index d258f8891..a192cca88 100644
--- a/web/src/lib/actions/audits.ts
+++ b/web/src/lib/actions/audits.ts
@@ -306,6 +306,9 @@ export interface AuditOpportunity {
/** AI visits over the last 30 days; null without Analytics or the snippet. */
aiVisits: number | null;
lastAudit: { at: string; score: number; auditId: string } | null;
+ /** 0–100: the cube root of value × opportunity × ease (SA-005). */
+ priority: number;
+ priorityParts: { value: number; opportunity: number; ease: number };
}
export interface ExcludedPage {