Repository navigation
feat(audit): rank Site Audit opportunities by a priority score - #1138
Merged
Merged
Conversation
SA-004 of the Site Audit v2 spec, first sources: audits were only of the URLs someone typed, with nothing suggesting which pages to audit (F5, F7). - GET /api/audits/opportunities builds the inbox (lib/audit/opportunities.js): Google Analytics' open "no AI traffic" pages (page_opportunities: valuable pages AI engines send no visitors to) and the site's pages (site_pages) never audited or audited more than auditMaxAgeDays (90) ago. One row per page across spellings, with why (chips), its last audit and its AI visits over 30 days (Analytics where it has the page, else the snippet). Pinned pages come first; excluded ones are listed apart; checkout-like paths stay out. Until the priority score (SA-005) rows follow GA value, then never audited, then citations and sessions. - Migration 00164 adds site_audit_page_prefs (pinned / excluded per page), written through PUT /api/audits/opportunities/prefs. - The hub gets Opportunities and Pages tabs; Opportunities opens when it lists pages. Select pages to Audit selected (the bulk audit, within the quota), Pin / Unpin or Exclude (with Undo); excluded pages can be restored from the list under the table. The bulk bar takes each table's own audit label and actions. Competitor-cited pages and Search Console sources come in later PRs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t Opportunities
SA-004's citation source: prompts where a competitor's page is cited and
the brand's never is point to the brand page closest to them, as a page
worth auditing.
- Migration 00165 adds audit_competitor_cited_prompts (service role only):
per active prompt over a window, answers citing a competitor's domain,
answers citing the brand's own, and the competitor domains cited, read
from prompt_result_citations (domains match with their subdomains).
- competitorGapPages (lib/audit/opportunities.js) keeps the prompts the
brand was never cited on and maps each to its target URL, else the best
site_pages match (candidatePages, as Content opportunities use), one row
per page with its prompts and competitor names.
- GET /api/audits/opportunities adds them as a competitor_cited reason over
the last 30 days; without competitor domains it asks nothing, and on a
database without 00165 (PGRST202) the other sources still list. Until
the priority score (SA-005) these pages rank after GA's valuable pages and
before pages never audited.
- The Opportunities table shows them as "Crema Club cited on 3 prompts"
("+N" for more competitors).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
main took 00164 (insights topic rollups), so this branch's migration moves to 00165_site_audit_page_prefs.sql; schema.sql rebuilt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nities-competitors
main took 00164 (insights topic rollups) and the Opportunities prefs migration moved to 00165, so this one follows as 00166; schema.sql rebuilt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each page in the Opportunities inbox gets a 0-100 priority: its value to the business x the opportunity an audit can win x how easy it is to fix, each 0-1, shown as the cube root of the product (SA-005). Pinned pages stay on top; the rest are ordered by priority. The table shows the score in a pill (dark from 80) with its parts on hover. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
…ed_prompts The read matched every citation of the window against every brand and competitor domain with LIKE: 2.7 s warm, 13.5 s cold, for 30 days of the largest brand (796k citations, 118k distinct URLs), on each Opportunities open. It now matches each distinct URL once, through its domain's suffixes, and joins only the matched URLs' citations to their answers: 1.4 s warm, the same 176 rows (checked against the SQL version on production). plpgsql with force_custom_plan, planned with the brand and window in hand. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
approved these changes
Oct 17, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Rebuilt on main after #1137. The priority, opportunities and route tests, the Opportunities table tests, typecheck, lint and format pass, and CI is green. The score is pure and computed per request over at most a few hundred rows, so it adds no database reads; sessionsRanker's linear scan per row stays well under a millisecond at the 500-page cap site_pages has on production.
8 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Site Audit Opportunities is now ordered by a priority score. Each page gets a 0–100 score: its value to the business × the opportunity an audit can win × how easy it is to fix. This is task SA-005 of the Site Audit v2 spec.
Server:
lib/audit/priority.js(new, pure)Each part is 0–1. The score is
round(100 × cbrt(value × opportunity × ease)): it keeps the product's order, on a scale people read. The spec's example, 0.96 × 0.9 × 0.8, scores 88. All weights live inPRIORITY_WEIGHTS, so they can be tuned in one place.scorePages.rankOpportunities: scores every row and orders the inbox: pinned pages first, then by priority, then by path. Each row gainspriorityandpriorityParts.Server: route
GET /api/audits/opportunitiesranks the rows once each has its AI visits.buildOpportunitiesno longer orders by source; it returns rows pinned first, then by path.site_pages, whatever source listed it.Web
en.jsonunderaudit.opportunities.Related issue
None. Site Audit v2 spec, task SA-005.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no errors; the 7 warnings are in files this PR does not touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
server:npm run format,npm run lintandnpm test(1532) pass.lib/audit/priority.test.js(new):lib/audit/opportunities.test.js: rows in path order, with their title and sessions fromsite_pages.routes/audits-opportunities.test.js: the route returnspriorityandpriorityParts.web:yarn test(1331) andyarn buildpass._opportunities-table.test.tsxcovers the column, the dark pill from 80 and the parts on hover.🤖 Generated with Claude Code