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(traffic): count a single-page app's not-found route as a broken AI link (#1247)
Cihan248aee873ae3
diff --git a/server/src/lib/tracking-script.js b/server/src/lib/tracking-script.jsindex 9c9e21e20..9e23c7701 100644--- a/server/src/lib/tracking-script.js+++ b/server/src/lib/tracking-script.js@@ -13,7 +13,18 @@* It also sends the landing page's HTTP status as the browser saw it, for* Broken AI links (AT-012): st, from the navigation entry, or 0 where the* browser doesn't report one (Safari); then nf is 1 when the page's title- * reads "404" or "not found".+ * reads "404" or "not found". With a 2xx, nf is 1 only when the title is+ * the not-found page's own ("404", "Page not found | Acme"): a single-page+ * app answers every path with 200 and shows its own not-found route (a soft+ * 404), while "How we fixed our 404s" is an ordinary page. Both patterns are+ * English only: "Seite nicht gefunden" reads as a working page.+ *+ * The visit's beacon goes at once, as it always has, so the visits counted+ * don't depend on the page loading. Such an app sets its title later, so+ * when the title didn't read not found, the snippet reads it again a moment+ * after load and, if it now does, sends k: "nf" for the address it landed+ * on: the server marks that visit's pageview, it doesn't count another+ * (gkhngyk on #1247).** Plain ES5 apart from URL / URLSearchParams, as before: it runs on the* customer's pages, in whatever browser their visitors have.@@ -54,13 +65,23 @@ if(!pf){try{pf=m(new URLSearchParams(location.search).get("utm_source"),true)}caif(!pf)return;window.__at=1;var c=document.currentScript,k=c.getAttribute("data-t"),o=c.src.replace(/\\/t\\.js(\\?.*)?$/,"");-var st=0,nf=0;+var u=location.href,st=0,x=o+"/track/"+k;try{var n=performance.getEntriesByType("navigation")[0];st=n&&n.responseStatus||0}catch(e){}-if(!st&&/(^|[^0-9])404([^0-9]|$)|not found/i.test(document.title||""))nf=1;-var b=JSON.stringify({u:location.href,r:r,s:pf,v:V,a:navigator.userAgent,t:Date.now(),l:navigator.language,d:screen.width+"x"+screen.height,st:st,nf:nf});-var x=o+"/track/"+k;+function post(d){+var b=JSON.stringify(d);if(navigator.sendBeacon)navigator.sendBeacon(x,new Blob([b],{type:"text/plain;charset=UTF-8"}));else fetch(x,{method:"POST",body:b,headers:{"Content-Type":"text/plain;charset=UTF-8"},keepalive:!0}).catch(function(){});+}+function nfOf(ti){+if(!st)return /(^|[^0-9])404([^0-9]|$)|not found/i.test(ti)?1:0;+return st>199&&st<300&&/(^|[|:\\u00b7\\u2022\\u2013\\u2014-]\\s*)(404 page not found|404 not found|404 error|error 404|page not found|not found|404)\\s*([|:\\u00b7\\u2022\\u2013\\u2014-]|$)/i.test(ti)?1:0;+}+var nf=nfOf(document.title||"");+post({u:u,r:r,s:pf,v:V,a:navigator.userAgent,t:Date.now(),l:navigator.language,d:screen.width+"x"+screen.height,st:st,nf:nf});+if(!nf&&(!st||st>199&&st<300)){+var again=function(){setTimeout(function(){if(nfOf(document.title||""))post({k:"nf",u:u,s:pf,a:navigator.userAgent,st:st})},1500)};+if(document.readyState==="complete")again();else window.addEventListener("load",again);+}})();`;}diff --git a/server/src/lib/tracking-script.test.js b/server/src/lib/tracking-script.test.jsindex 9407254d4..41ab0005f 100644--- a/server/src/lib/tracking-script.test.js+++ b/server/src/lib/tracking-script.test.js@@ -11,31 +11,50 @@ import { buildTrackingScript } from './tracking-script.js';const SCRIPT = buildTrackingScript();-/** Runs t.js on a page; returns the beacon it sent, or null. */-function visit({+/**+ * Runs t.js on a page, then lets the page go on: `then` changes it after the+ * script ran (a single-page app setting its title), and pending timers run.+ * Returns the visit's beacon (or null), every beacon it sent, its timers and+ * a way to fire the page's events.+ */+function run({referrer = '',search = '',alreadyTracked = false,title = 'Menu · Acme Coffee',navigation,+ readyState = 'complete',+ then,+ runTimers = true,} = {}) {const sent = [];+ const timers = [];+ const listeners = {};+ const on = (scope) => (type, fn) => (listeners[`${scope}:${type}`] ||= []).push(fn);+ const fire = (key) => (listeners[key] || []).forEach((fn) => fn());const window = alreadyTracked ? { __at: 1 } : {};+ window.addEventListener = on('window');+ const document = {+ title,+ referrer,+ readyState,+ visibilityState: 'visible',+ addEventListener: on('document'),+ currentScript: {+ src: 'https://api.ansvisor.test/t.js',+ getAttribute: (name) => (name === 'data-t' ? 'abcdef123' : null),+ },+ };+ const location = { href: `https://acme.example/menu${search}`, search };runInNewContext(SCRIPT, {window,// A browser without the navigation entry (older Safari) has none....(navigation === undefined? {}: { performance: { getEntriesByType: () => (navigation ? [navigation] : []) } }),- document: {- title,- referrer,- currentScript: {- src: 'https://api.ansvisor.test/t.js',- getAttribute: (name) => (name === 'data-t' ? 'abcdef123' : null),- },- },- location: { href: `https://acme.example/menu${search}`, search },+ document,+ location,+ setTimeout: (fn, ms) => timers.push({ fn, ms }),navigator: {userAgent: 'Mozilla/5.0',language: 'en-US',@@ -53,10 +72,25 @@ function visit({Date,String,});- if (sent.length === 0) return null;- return { url: sent[0].url, ...JSON.parse(sent[0].blob.text) };+ then?.({ document, location });+ if (runTimers) for (const timer of timers) timer.fn();+ // Read when asked, so a beacon sent after a later event or timer counts.+ const parse = () => sent.map((b) => ({ url: b.url, ...JSON.parse(b.blob.text) }));+ return {+ get beacon() {+ return parse()[0] ?? null;+ },+ get beacons() {+ return parse();+ },+ timers,+ fire,+ };}+/** The beacon a visit sent, or null. */+const visit = (options) => run(options).beacon;+describe('the tracking snippet', () => {it("sends the source's key and the list version to the brand's beacon", () => {const beacon = visit({ referrer: 'https://chat.openai.com/c/123' });@@ -102,10 +136,84 @@ describe('the tracking snippet', () => {st: 404,nf: 0,});- // A status says it all, whatever the title.+ // A 2xx page that only mentions 404s is an ordinary page.expect(visit({ ...from, navigation: { responseStatus: 200 }, title: 'How we fixed our 404s' }),).toMatchObject({ st: 200, nf: 0 });+ // Any other status says it all, whatever the title.+ expect(+ visit({ ...from, navigation: { responseStatus: 404 }, title: 'Page not found' }),+ ).toMatchObject({ st: 404, nf: 0 });+ });++ // gkhngyk on #1192: a single-page app answers 200 and shows its own+ // not-found route, so soft 404s were never seen.+ it("reads a 2xx page's title as a soft 404 only when it's the not-found page's own", () => {+ const ok = { referrer: 'https://chatgpt.com/', navigation: { responseStatus: 200 } };+ for (const title of [+ '404',+ '404 | Acme Coffee',+ '404 Not Found',+ 'Page Not Found – Acme',+ 'Acme Coffee - Page not found',+ 'Error 404 · Acme',+ ]) {+ expect(visit({ ...ok, title }), title).toMatchObject({ st: 200, nf: 1 });+ }+ for (const title of ['Error 404 explained', 'Lost and not found | Books', 'Menu · Acme']) {+ expect(visit({ ...ok, title }), title).toMatchObject({ st: 200, nf: 0 });+ }+ });++ // gkhngyk on #1247: the visit's beacon waited for load on every page.+ it('sends the visit at once, and says so later when the app shows its not-found page', () => {+ const { beacons, timers } = run({+ referrer: 'https://chatgpt.com/',+ navigation: { responseStatus: 200 },+ title: 'Acme Coffee',+ // The app's router resolves the route and shows its not-found page.+ then: ({ document, location }) => {+ document.title = 'Page not found | Acme Coffee';+ location.href = 'https://acme.example/elsewhere';+ },+ });+ expect(timers.map((t) => t.ms)).toEqual([1500]);+ expect(beacons).toHaveLength(2);+ expect(beacons[0]).toMatchObject({ st: 200, nf: 0, u: 'https://acme.example/menu' });+ // The address the visit landed on, not where the app went since; a mark, not a visit.+ expect(beacons[1]).toEqual({+ url: 'https://api.ansvisor.test/track/abcdef123',+ k: 'nf',+ u: 'https://acme.example/menu',+ s: 'chatgpt.com',+ a: 'Mozilla/5.0',+ st: 200,+ });+ });++ it("doesn't wait for the page to load, and checks the title again only after it", () => {+ const loading = run({+ referrer: 'https://chatgpt.com/',+ navigation: { responseStatus: 200 },+ readyState: 'loading',+ runTimers: false,+ });+ expect(loading.beacons).toHaveLength(1);+ expect(loading.timers).toHaveLength(0);+ loading.fire('window:load');+ expect(loading.timers).toHaveLength(1);+ // The title still reads as a page: nothing more.+ loading.timers[0].fn();+ expect(loading.beacons).toHaveLength(1);++ // Nothing to check again: a 404, or a title that already said not found.+ expect(+ run({ referrer: 'https://chatgpt.com/', navigation: { responseStatus: 404 } }).timers,+ ).toHaveLength(0);+ expect(+ run({ referrer: 'https://chatgpt.com/', navigation: { responseStatus: 200 }, title: '404' })+ .timers,+ ).toHaveLength(0);});it('says whether the title reads "not found" when the browser gives no status', () => {diff --git a/server/src/routes/traffic-track.test.js b/server/src/routes/traffic-track.test.jsindex beba274de..d5e4989c6 100644--- a/server/src/routes/traffic-track.test.js+++ b/server/src/routes/traffic-track.test.js@@ -11,18 +11,40 @@ import { AI_SOURCES_VERSION } from '../lib/ai-sources.js';const inserted = [];const findVisitOf = vi.fn();let insertError = null;+// The not-found mark (k: "nf"): the filters of its lookup, what it finds, what it updates.+const filters = [];+let latestPageview = null;+const updated = [];vi.mock('../config/supabase.js', () => ({default: {- from: (table) => ({- select: () => ({- eq: () => ({ single: async () => ({ data: { id: 'b1' }, error: null }) }),- }),- insert: async (row) => {- inserted.push({ table, row });- return { error: insertError };- },- }),+ from: (table) => {+ const filter = (op) => (col, val) => {+ if (table === 'ai_traffic_logs') filters.push([op, col, val]);+ return chain;+ };+ const chain = {+ select: () => chain,+ eq: filter('eq'),+ is: filter('is'),+ gte: filter('gte'),+ order: () => chain,+ limit: () => chain,+ single: async () => ({ data: { id: 'b1' }, error: null }),+ maybeSingle: async () => ({ data: latestPageview, error: null }),+ insert: async (row) => {+ inserted.push({ table, row });+ return { error: insertError };+ },+ update: (fields) => ({+ eq: async (col, val) => {+ updated.push({ table, fields, [col]: val });+ return { error: null };+ },+ }),+ };+ return chain;+ },},}));vi.mock('../middleware/rate-limiter.js', () => ({ trafficLimiter: (req, res, next) => next() }));@@ -51,6 +73,9 @@ beforeEach(() => {inserted.length = 0;insertError = null;findVisitOf.mockReset();+ filters.length = 0;+ latestPageview = null;+ updated.length = 0;});const beacon = (body = {}) =>@@ -142,14 +167,19 @@ describe('POST /track/:trackingCode', () => {await beacon({ st: 404, nf: 0 });// Safari: no status, and the title said "not found".await beacon({ st: 0, nf: 1 });- // A status wins over the title.+ // A 2xx whose title said not found: a soft 404 (00200).await beacon({ st: 200, nf: 1 });+ // Any other status wins over the title.+ await beacon({ st: 301, nf: 1 });+ await beacon({ st: 404, nf: 1 });// An older snippet sends neither.await beacon();expect(inserted.map((i) => [i.row.http_status, i.row.not_found_title])).toEqual([[404, false],[null, true],- [200, false],+ [200, true],+ [301, false],+ [404, false],[null, false],]);});@@ -176,4 +206,46 @@ describe('POST /track/:trackingCode', () => {expect(res.status).toBe(204);expect(logger.error).toHaveBeenCalledWith({ err: insertError }, 'traffic track insert failed');});++ // gkhngyk on #1247: the visit's beacon goes at once again; a single-page+ // app's not-found title, read after load, marks that pageview.+ it("marks the visit's pageview when the app shows its not-found page later, without counting a visit", async () => {+ latestPageview = { id: 'pv9' };+ const res = await beacon({ k: 'nf', st: 200 });+ expect(res.status).toBe(204);+ expect(inserted).toEqual([]);+ expect(findVisitOf).not.toHaveBeenCalled();+ expect(filters).toEqual(+ expect.arrayContaining([+ ['eq', 'url', 'https://acme.example/menu'],+ ['eq', 'ip_address', '203.0.113.7'],+ ['eq', 'user_agent', 'Mozilla/5.0'],+ ['eq', 'http_status', 200],+ ['eq', 'not_found_title', false],+ ]),+ );+ expect(filters.find(([op]) => op === 'gte')?.[1]).toBe('created_at');+ expect(updated).toEqual([+ { table: 'ai_traffic_logs', fields: { not_found_title: true }, id: 'pv9' },+ ]);+ });++ it('marks nothing without a recent pageview to mark, or for a status that says it all', async () => {+ await beacon({ k: 'nf', st: 200 });+ expect(updated).toEqual([]);++ // A 404 says it all: no lookup at all.+ latestPageview = { id: 'pv9' };+ const lookedUp = filters.length;+ await beacon({ k: 'nf', st: 404 });+ expect(updated).toEqual([]);+ expect(filters).toHaveLength(lookedUp);++ // Safari reports no status: the pageview has none either.+ filters.length = 0;+ await beacon({ k: 'nf', st: 0 });+ expect(filters).toContainEqual(['is', 'http_status', null]);+ expect(updated).toHaveLength(1);+ expect(inserted).toEqual([]);+ });});diff --git a/server/src/routes/traffic.js b/server/src/routes/traffic.jsindex 7401987f0..edbbc0d92 100644--- a/server/src/routes/traffic.js+++ b/server/src/routes/traffic.js@@ -130,11 +130,31 @@ router.post('/track/:trackingCode', trafficLimiter, beaconBody, async (req, res)// page's title said "not found".const httpStatus =Number.isInteger(body.st) && body.st >= 100 && body.st <= 599 ? body.st : null;- const notFoundTitle = httpStatus === null && body.nf === 1;+ // The title counts without a status, or with a 2xx: a soft 404 (00200).+ const notFoundTitle =+ body.nf === 1 && (httpStatus === null || (httpStatus >= 200 && httpStatus < 300));const userAgent = (body.a || '').slice(0, 512) || null;const ipAddress = ip || null;+ // The snippet's second word on a visit it just sent: a single-page app's+ // title read not found only after load (00200). It marks that pageview+ // (the same address, IP and browser in the last minutes, with no status+ // or a 2xx) rather than counting another visit.+ if (body.k === 'nf') {+ if (httpStatus !== null && (httpStatus < 200 || httpStatus > 299)) {+ return res.status(204).end();+ }+ await markNotFoundTitle({+ brandId: brand.id,+ url: (body.u || '').slice(0, 2048),+ ipAddress,+ userAgent,+ httpStatus,+ });+ return res.status(204).end();+ }+// A reload or a second link from the same answer continues the visit// rather than counting as another (AT-003). If the lookup fails the// pageview is still stored, as a visit of its own.@@ -173,4 +193,42 @@ router.post('/track/:trackingCode', trafficLimiter, beaconBody, async (req, res)}});+/** How long after a visit its pageview may still be marked as a soft 404. */+const NOT_FOUND_MARK_WINDOW_MS = 10 * 60 * 1000;++/**+ * Marks the latest pageview of this address, IP and browser in the last+ * minutes as a not-found title. Best effort: a failure is logged, the+ * beacon can't be retried.+ */+async function markNotFoundTitle({ brandId, url, ipAddress, userAgent, httpStatus }) {+ try {+ const since = new Date(Date.now() - NOT_FOUND_MARK_WINDOW_MS).toISOString();+ let query = supabaseAdmin+ .from('ai_traffic_logs')+ .select('id')+ .eq('brand_id', brandId)+ .eq('url', url)+ .eq('not_found_title', false)+ .gte('created_at', since);+ query = ipAddress ? query.eq('ip_address', ipAddress) : query.is('ip_address', null);+ query = userAgent ? query.eq('user_agent', userAgent) : query.is('user_agent', null);+ query =+ httpStatus === null ? query.is('http_status', null) : query.eq('http_status', httpStatus);+ const { data, error } = await query+ .order('created_at', { ascending: false })+ .limit(1)+ .maybeSingle();+ if (error) throw new Error(error.message);+ if (!data) return;+ const { error: updateError } = await supabaseAdmin+ .from('ai_traffic_logs')+ .update({ not_found_title: true })+ .eq('id', data.id);+ if (updateError) throw new Error(updateError.message);+ } catch (err) {+ logger.error({ err }, 'traffic not-found mark failed');+ }+}+export default router;diff --git a/supabase/migrations/00200_ai_traffic_soft_404.sql b/supabase/migrations/00200_ai_traffic_soft_404.sqlnew file mode 100644index 000000000..128caa375--- /dev/null+++ b/supabase/migrations/00200_ai_traffic_soft_404.sql@@ -0,0 +1,357 @@+-- ============================================================================+-- 00200: soft 404s count as broken AI links+-- ============================================================================+-- Follow-up from #1192's review (AT-012). A single-page app answers every+-- path with 200 and shows its own "Page not found" route, so the browser's+-- status says the page works. The snippet now reads the title for a 2xx+-- landing page too (with a stricter pattern), a moment after load so the+-- app has set it, and the beacon keeps not_found_title with a 2xx status.+--+-- ai_traffic_broken_pages counts such a page as missing (status soft404)+-- once at least two visits saw it, doesn't let its 2xx count as working,+-- and doesn't let the nightly page read clear it: that read gets the app's+-- shell with a 200 too. The beacon is public, so one visit, stray or made+-- up, lists nothing (gkhngyk on #1247): nothing would clear it, and a cited+-- page would raise broken_citation_target from that visit. ai_traffic_broken_links reads those pageviews for the visits. The+-- rest of both functions is 00186's.++comment on column public.ai_traffic_logs.not_found_title is+ 'True when the page''s title read "404" or "not found" and the browser reported no status, or a 2xx (a soft 404) (AT-012).';++create or replace function public.ai_traffic_broken_pages(+ p_brand_id uuid,+ p_from timestamptz,+ p_to timestamptz+)+returns table (page_key text, status text, routed boolean)+language sql+stable+set search_path to 'public'+as $$+ with+ -- Only the pageviews that say something about the page: a status, or a+ -- not-found title. Read up to now, so a page that works again since the+ -- window ended isn't listed.+ logs as (+ select+ n.page_key,+ -- The address: the path plus its query, tracking parameters left out,+ -- in one order. Worked out only when the URL has a query.+ case when q.query is null then n.page_key else n.page_key || '?' || q.query end as address,+ l.created_at,+ l.http_status,+ l.not_found_title,+ -- The visit a pageview belongs to: a reload continues one (AT-003).+ coalesce(l.visit_of, l.id) as visit_id,+ -- A soft 404: the server answered 2xx and the page says not found (a+ -- single-page app's route that doesn't exist).+ coalesce(l.not_found_title and l.http_status between 200 and 299, false) as soft_404,+ (p_to is null or l.created_at <= p_to)+ and (+ l.http_status in (404, 410)+ or (l.not_found_title and (l.http_status is null or l.http_status between 200 and 299))+ )+ as failed_in_window+ from public.ai_traffic_logs l+ cross join lateral (select lower(public.normalize_page_path(l.url)) as page_key) n+ cross join lateral (+ select case when strpos(l.url, '?') > 0 then (+ select string_agg(qp.part, '&' order by qp.part)+ from unnest(string_to_array(split_part(split_part(l.url, '#', 1), '?', 2), '&')) as qp(part)+ where qp.part <> ''+ and qp.part !~* '^(utm_[^=]*|gclid|fbclid|msclkid|srsltid|_gl|ref)(=|$)'+ ) end as query+ ) q+ where l.brand_id = p_brand_id+ and l.created_at >= coalesce(p_from, '-infinity'::timestamptz)+ and (l.http_status is not null or l.not_found_title)+ ),+ address_state as (+ select+ page_key,+ address,+ (array_agg(http_status order by created_at desc) filter (where http_status is not null))[1]+ as last_status,+ -- Whether that latest status was a soft 404.+ (array_agg(soft_404 order by created_at desc) filter (where http_status is not null))[1]+ as last_soft_404,+ bool_or(not_found_title) as title_not_found,+ max(created_at) filter (where failed_in_window) as last_failed_at+ from logs+ group by page_key, address+ ),+ -- The visits that saw each page as a soft 404.+ soft_visits as (+ select page_key, count(distinct visit_id) as visits+ from logs+ where soft_404+ group by page_key+ ),+ page_state as (+ select+ a.page_key,+ max(last_status) filter (where last_status in (404, 410)) as last_status,+ bool_or(last_status is null and title_not_found) as title_not_found,+ coalesce(bool_or(last_soft_404), false) and coalesce(max(v.visits), 0) >= 2 as soft_404,+ -- No address with a status reads as not working, not as unknown; a soft+ -- 404's 2xx doesn't either.+ coalesce(bool_or(last_status between 200 and 399 and not last_soft_404), false) as works,+ max(last_failed_at) as last_failed_at,+ -- Every missing address carries a query: a route on the page, not the page.+ bool_and(a.address <> a.page_key)+ filter (+ where last_status in (404, 410)+ or last_soft_404+ or (last_status is null and title_not_found)+ )+ as routed+ from address_state a+ left join soft_visits v on v.page_key = a.page_key+ group by a.page_key+ ),+ -- What the nightly page read found (00104).+ fetched as (+ select lower(public.normalize_page_path(sp.url)) as page_key,+ bool_or(sp.fetch_status between 200 and 399) as works,+ max(sp.fetched_at) filter (where sp.fetch_status between 200 and 299) as last_ok_at+ from public.site_pages sp+ where sp.brand_id = p_brand_id+ and sp.fetch_status is not null+ group by 1+ )+ select+ s.page_key,+ case+ when s.last_status in (404, 410) then s.last_status::text+ when s.soft_404 then 'soft404'+ else 'title'+ end,+ coalesce(s.routed, false)+ from page_state s+ left join fetched f on f.page_key = s.page_key+ where not s.works+ and s.last_failed_at is not null+ and (+ -- The nightly read gets the app's shell with a 200 as well: only the+ -- visitors' browsers can tell a soft 404.+ s.soft_404+ or (+ -- The nightly read found it working after its last miss: fixed since.+ not coalesce(f.last_ok_at > s.last_failed_at, false)+ and (+ s.last_status in (404, 410)+ or (s.last_status is null and s.title_not_found and not coalesce(f.works, false))+ )+ )+ );+$$;++revoke all on function public.ai_traffic_broken_pages(uuid, timestamptz, timestamptz)+ from public, anon, authenticated;+grant execute on function public.ai_traffic_broken_pages(uuid, timestamptz, timestamptz)+ to service_role;++comment on function public.ai_traffic_broken_pages(uuid, timestamptz, timestamptz) is+ 'AI Traffic (AT-012): the brand''s pages AI visitors found missing in a window whose latest reported status up to now is 404 or 410, or a 2xx with a not-found title (a soft 404, status soft404), or, with no status, whose title said not found and that the nightly page read never found working; not those the nightly read found working after their last miss. Decided per address (path plus query, utm_* and click ids left out), and a path none of whose addresses last answered 2xx or 3xx; routed when every missing address carries a query. No organization check: called only by ai_traffic_broken_links and ai_traffic_pages, after theirs.';++-- ─── Broken AI links ────────────────────────────────────────────────────────++create or replace function public.ai_traffic_broken_links(+ p_brand_id uuid,+ p_from timestamptz,+ p_to timestamptz,+ p_limit integer default 50,+ p_offset integer default 0+)+returns jsonb+language plpgsql+stable+security definer+set search_path to 'public'+as $$+declare+ v_since date := (p_from at time zone 'utc')::date;+ v_until date := coalesce((p_to at time zone 'utc')::date, (now() at time zone 'utc')::date);+ v_result jsonb;+begin+ if not exists (+ select 1 from public.brands b+ join public.profiles pf on pf.organization_id = b.organization_id+ where b.id = p_brand_id and pf.id = auth.uid()+ ) and auth.role() is distinct from 'service_role' then+ return null;+ end if;++ with+ logs as (+ select+ lower(n.page) as page_key,+ n.page,+ coalesce(l.visit_of, l.id) as visit,+ l.created_at,+ coalesce(nullif(l.source_platform, ''), 'unknown') as platform+ from public.ai_traffic_logs l+ cross join lateral (select public.normalize_page_path(l.url) as page) n+ where l.brand_id = p_brand_id+ and l.created_at >= coalesce(p_from, '-infinity'::timestamptz)+ and (p_to is null or l.created_at <= p_to)+ -- Only the pageviews that found the page missing, not those from before it broke.+ and (+ l.http_status in (404, 410)+ or (l.not_found_title and (l.http_status is null or l.http_status between 200 and 299))+ )+ ),+ broken as (+ select bp.page_key, bp.status, bp.routed+ from public.ai_traffic_broken_pages(p_brand_id, p_from, p_to) bp+ ),+ visits as (+ select l.page_key, min(l.page) as page, count(distinct l.visit)::bigint as visits,+ max(l.created_at) as last_visit+ from logs l+ join broken b on b.page_key = l.page_key+ group by l.page_key+ ),+ platforms as (+ select page_key, (array_agg(platform order by visits desc, platform))[1:3] as platforms+ from (+ select l.page_key, l.platform, count(distinct l.visit) as visits+ from logs l+ join broken b on b.page_key = l.page_key+ group by 1, 2+ ) t+ group by 1+ ),+ cited as (+ select c.page_key, c.citations+ from public.ai_traffic_page_citations(p_brand_id, v_since, v_until) c+ ),+ -- Pages known to work, to redirect to. Only a page's own address counts:+ -- /product.php?id=5 answering 200 says nothing about /product.php.+ landed as (+ select lower(n.page) as page_key,+ min(n.page) as page,+ (array_agg(l.http_status order by l.created_at desc))[1] as last_status+ from public.ai_traffic_logs l+ cross join lateral (select public.normalize_page_path(l.url) as page) n+ where l.brand_id = p_brand_id+ and l.http_status is not null+ and l.created_at >= now() - interval '90 days'+ and (+ strpos(l.url, '?') = 0+ or not exists (+ select 1+ from unnest(string_to_array(split_part(split_part(l.url, '#', 1), '?', 2), '&')) as qp(part)+ where qp.part <> ''+ and qp.part !~* '^(utm_[^=]*|gclid|fbclid|msclkid|srsltid|_gl|ref)(=|$)'+ )+ )+ group by 1+ ),+ candidates as (+ select page_key, min(page) as page, max(weight) as weight+ from (+ select lower(public.normalize_page_path(sp.url)) as page_key,+ public.normalize_page_path(sp.url) as page,+ sp.ga_sessions as weight+ from public.site_pages sp+ where sp.brand_id = p_brand_id+ and sp.fetch_status between 200 and 299+ union all+ select page_key, page, 0 from landed where last_status between 200 and 299+ ) c+ where page_key not in (select page_key from broken)+ group by page_key+ ),+ candidate_words as (+ select distinct c.page_key, regexp_replace(w.word, '^(.{3,})s$', '\1') as word+ from candidates c+ cross join lateral regexp_split_to_table(c.page_key, '[^[:alnum:]]+') as w(word)+ where length(w.word) >= 2+ ),+ broken_words as (+ select distinct b.page_key, regexp_replace(w.word, '^(.{3,})s$', '\1') as word+ from broken b+ cross join lateral regexp_split_to_table(b.page_key, '[^[:alnum:]]+') as w(word)+ where length(w.word) >= 2+ ),+ candidate_sizes as (select page_key, count(*) as words from candidate_words group by 1),+ broken_sizes as (select page_key, count(*) as words from broken_words group by 1),+ similar_pages as (+ select distinct on (page_key) page_key, target+ from (+ select+ bw.page_key,+ c.page as target,+ c.weight,+ count(*)::numeric / (bs.words + cs.words - count(*)) as overlap+ from broken_words bw+ join candidate_words cw on cw.word = bw.word+ join candidates c on c.page_key = cw.page_key+ join broken_sizes bs on bs.page_key = bw.page_key+ join candidate_sizes cs on cs.page_key = cw.page_key+ group by bw.page_key, c.page_key, c.page, c.weight, bs.words, cs.words+ ) m+ where overlap >= 0.5+ order by page_key, overlap desc, weight desc, length(target), target+ ),+ parent_pages as (+ select distinct on (b.page_key) b.page_key, c.page as target+ from broken b+ join candidates c+ on c.page_key <> '/'+ and left(b.page_key, length(c.page_key) + 1) = c.page_key || '/'+ order by b.page_key, length(c.page_key) desc+ ),+ result_rows as (+ select+ v.page,+ v.visits,+ v.last_visit,+ b.status,+ coalesce(p.platforms, '{}'::text[]) as platforms,+ coalesce(ci.citations, 0)::bigint as citations,+ -- A route on the page (every missing address has a query) gets no+ -- redirect: one from its path would move the whole route.+ case when v.page_key <> '/' and not b.routed then coalesce(s.target, pa.target, '/') end+ as target,+ case+ when v.page_key = '/' then null+ when b.routed then 'query'+ when s.target is not null then 'similar'+ when pa.target is not null then 'parent'+ else 'home'+ end as target_reason+ from visits v+ join broken b on b.page_key = v.page_key+ left join platforms p on p.page_key = v.page_key+ left join cited ci on ci.page_key = v.page_key+ left join similar_pages s on s.page_key = v.page_key+ left join parent_pages pa on pa.page_key = v.page_key+ )+ select jsonb_build_object(+ 'count', (select count(*) from result_rows),+ 'rows', coalesce((+ select jsonb_agg(to_jsonb(r))+ from (+ select * from result_rows+ order by visits desc, citations desc, last_visit desc, page+ limit greatest(p_limit, 0) offset greatest(p_offset, 0)+ ) r+ ), '[]'::jsonb)+ )+ into v_result;++ return v_result;+end;+$$;++revoke all on function public.ai_traffic_broken_links(uuid, timestamptz, timestamptz, integer, integer)+ from public, anon;+grant execute on function public.ai_traffic_broken_links(uuid, timestamptz, timestamptz, integer, integer)+ to authenticated, service_role;++comment on function public.ai_traffic_broken_links(uuid, timestamptz, timestamptz, integer, integer) is+ 'AI Traffic "Broken AI links" (AT-012, spec §3.5): the pages AI-referred visitors landed on that answered 404 or 410 (or, without a status, whose title said not found) in a window, with their visits, platforms, citations and a suggested redirect to a working page (similar path, parent page or home; none for a route on the page, target_reason query). Security definer with an organization check.';++notify pgrst, 'reload schema';diff --git a/supabase/schema.sql b/supabase/schema.sqlindex 89802616b..36ace93f5 100644--- a/supabase/schema.sql+++ b/supabase/schema.sql@@ -27586,6 +27586,367 @@ create unique index if not exists citation_url_daily_keyon public.citation_url_daily (brand_id, day, model_used, platform, region, topic_id, url_id)nulls not distinct;+-- ─────────────────────────────────────────────────────────────────────────+-- migrations/00200_ai_traffic_soft_404.sql+-- ─────────────────────────────────────────────────────────────────────────+-- ============================================================================+-- 00200: soft 404s count as broken AI links+-- ============================================================================+-- Follow-up from #1192's review (AT-012). A single-page app answers every+-- path with 200 and shows its own "Page not found" route, so the browser's+-- status says the page works. The snippet now reads the title for a 2xx+-- landing page too (with a stricter pattern), a moment after load so the+-- app has set it, and the beacon keeps not_found_title with a 2xx status.+--+-- ai_traffic_broken_pages counts such a page as missing (status soft404)+-- once at least two visits saw it, doesn't let its 2xx count as working,+-- and doesn't let the nightly page read clear it: that read gets the app's+-- shell with a 200 too. The beacon is public, so one visit, stray or made+-- up, lists nothing (gkhngyk on #1247): nothing would clear it, and a cited+-- page would raise broken_citation_target from that visit. ai_traffic_broken_links reads those pageviews for the visits. The+-- rest of both functions is 00186's.++comment on column public.ai_traffic_logs.not_found_title is+ 'True when the page''s title read "404" or "not found" and the browser reported no status, or a 2xx (a soft 404) (AT-012).';++create or replace function public.ai_traffic_broken_pages(+ p_brand_id uuid,+ p_from timestamptz,+ p_to timestamptz+)+returns table (page_key text, status text, routed boolean)+language sql+stable+set search_path to 'public'+as $$+ with+ -- Only the pageviews that say something about the page: a status, or a+ -- not-found title. Read up to now, so a page that works again since the+ -- window ended isn't listed.+ logs as (+ select+ n.page_key,+ -- The address: the path plus its query, tracking parameters left out,+ -- in one order. Worked out only when the URL has a query.+ case when q.query is null then n.page_key else n.page_key || '?' || q.query end as address,+ l.created_at,+ l.http_status,+ l.not_found_title,+ -- The visit a pageview belongs to: a reload continues one (AT-003).+ coalesce(l.visit_of, l.id) as visit_id,+ -- A soft 404: the server answered 2xx and the page says not found (a+ -- single-page app's route that doesn't exist).+ coalesce(l.not_found_title and l.http_status between 200 and 299, false) as soft_404,+ (p_to is null or l.created_at <= p_to)+ and (+ l.http_status in (404, 410)+ or (l.not_found_title and (l.http_status is null or l.http_status between 200 and 299))+ )+ as failed_in_window+ from public.ai_traffic_logs l+ cross join lateral (select lower(public.normalize_page_path(l.url)) as page_key) n+ cross join lateral (+ select case when strpos(l.url, '?') > 0 then (+ select string_agg(qp.part, '&' order by qp.part)+ from unnest(string_to_array(split_part(split_part(l.url, '#', 1), '?', 2), '&')) as qp(part)+ where qp.part <> ''+ and qp.part !~* '^(utm_[^=]*|gclid|fbclid|msclkid|srsltid|_gl|ref)(=|$)'+ ) end as query+ ) q+ where l.brand_id = p_brand_id+ and l.created_at >= coalesce(p_from, '-infinity'::timestamptz)+ and (l.http_status is not null or l.not_found_title)+ ),+ address_state as (+ select+ page_key,+ address,+ (array_agg(http_status order by created_at desc) filter (where http_status is not null))[1]+ as last_status,+ -- Whether that latest status was a soft 404.+ (array_agg(soft_404 order by created_at desc) filter (where http_status is not null))[1]+ as last_soft_404,+ bool_or(not_found_title) as title_not_found,+ max(created_at) filter (where failed_in_window) as last_failed_at+ from logs+ group by page_key, address+ ),+ -- The visits that saw each page as a soft 404.+ soft_visits as (+ select page_key, count(distinct visit_id) as visits+ from logs+ where soft_404+ group by page_key+ ),+ page_state as (+ select+ a.page_key,+ max(last_status) filter (where last_status in (404, 410)) as last_status,+ bool_or(last_status is null and title_not_found) as title_not_found,+ coalesce(bool_or(last_soft_404), false) and coalesce(max(v.visits), 0) >= 2 as soft_404,+ -- No address with a status reads as not working, not as unknown; a soft+ -- 404's 2xx doesn't either.+ coalesce(bool_or(last_status between 200 and 399 and not last_soft_404), false) as works,+ max(last_failed_at) as last_failed_at,+ -- Every missing address carries a query: a route on the page, not the page.+ bool_and(a.address <> a.page_key)+ filter (+ where last_status in (404, 410)+ or last_soft_404+ or (last_status is null and title_not_found)+ )+ as routed+ from address_state a+ left join soft_visits v on v.page_key = a.page_key+ group by a.page_key+ ),+ -- What the nightly page read found (00104).+ fetched as (+ select lower(public.normalize_page_path(sp.url)) as page_key,+ bool_or(sp.fetch_status between 200 and 399) as works,+ max(sp.fetched_at) filter (where sp.fetch_status between 200 and 299) as last_ok_at+ from public.site_pages sp+ where sp.brand_id = p_brand_id+ and sp.fetch_status is not null+ group by 1+ )+ select+ s.page_key,+ case+ when s.last_status in (404, 410) then s.last_status::text+ when s.soft_404 then 'soft404'+ else 'title'+ end,+ coalesce(s.routed, false)+ from page_state s+ left join fetched f on f.page_key = s.page_key+ where not s.works+ and s.last_failed_at is not null+ and (+ -- The nightly read gets the app's shell with a 200 as well: only the+ -- visitors' browsers can tell a soft 404.+ s.soft_404+ or (+ -- The nightly read found it working after its last miss: fixed since.+ not coalesce(f.last_ok_at > s.last_failed_at, false)+ and (+ s.last_status in (404, 410)+ or (s.last_status is null and s.title_not_found and not coalesce(f.works, false))+ )+ )+ );+$$;++revoke all on function public.ai_traffic_broken_pages(uuid, timestamptz, timestamptz)+ from public, anon, authenticated;+grant execute on function public.ai_traffic_broken_pages(uuid, timestamptz, timestamptz)+ to service_role;++comment on function public.ai_traffic_broken_pages(uuid, timestamptz, timestamptz) is+ 'AI Traffic (AT-012): the brand''s pages AI visitors found missing in a window whose latest reported status up to now is 404 or 410, or a 2xx with a not-found title (a soft 404, status soft404), or, with no status, whose title said not found and that the nightly page read never found working; not those the nightly read found working after their last miss. Decided per address (path plus query, utm_* and click ids left out), and a path none of whose addresses last answered 2xx or 3xx; routed when every missing address carries a query. No organization check: called only by ai_traffic_broken_links and ai_traffic_pages, after theirs.';++-- ─── Broken AI links ────────────────────────────────────────────────────────++create or replace function public.ai_traffic_broken_links(+ p_brand_id uuid,+ p_from timestamptz,+ p_to timestamptz,+ p_limit integer default 50,+ p_offset integer default 0+)+returns jsonb+language plpgsql+stable+security definer+set search_path to 'public'+as $$+declare+ v_since date := (p_from at time zone 'utc')::date;+ v_until date := coalesce((p_to at time zone 'utc')::date, (now() at time zone 'utc')::date);+ v_result jsonb;+begin+ if not exists (+ select 1 from public.brands b+ join public.profiles pf on pf.organization_id = b.organization_id+ where b.id = p_brand_id and pf.id = auth.uid()+ ) and auth.role() is distinct from 'service_role' then+ return null;+ end if;++ with+ logs as (+ select+ lower(n.page) as page_key,+ n.page,+ coalesce(l.visit_of, l.id) as visit,+ l.created_at,+ coalesce(nullif(l.source_platform, ''), 'unknown') as platform+ from public.ai_traffic_logs l+ cross join lateral (select public.normalize_page_path(l.url) as page) n+ where l.brand_id = p_brand_id+ and l.created_at >= coalesce(p_from, '-infinity'::timestamptz)+ and (p_to is null or l.created_at <= p_to)+ -- Only the pageviews that found the page missing, not those from before it broke.+ and (+ l.http_status in (404, 410)+ or (l.not_found_title and (l.http_status is null or l.http_status between 200 and 299))+ )+ ),+ broken as (+ select bp.page_key, bp.status, bp.routed+ from public.ai_traffic_broken_pages(p_brand_id, p_from, p_to) bp+ ),+ visits as (+ select l.page_key, min(l.page) as page, count(distinct l.visit)::bigint as visits,+ max(l.created_at) as last_visit+ from logs l+ join broken b on b.page_key = l.page_key+ group by l.page_key+ ),+ platforms as (+ select page_key, (array_agg(platform order by visits desc, platform))[1:3] as platforms+ from (+ select l.page_key, l.platform, count(distinct l.visit) as visits+ from logs l+ join broken b on b.page_key = l.page_key+ group by 1, 2+ ) t+ group by 1+ ),+ cited as (+ select c.page_key, c.citations+ from public.ai_traffic_page_citations(p_brand_id, v_since, v_until) c+ ),+ -- Pages known to work, to redirect to. Only a page's own address counts:+ -- /product.php?id=5 answering 200 says nothing about /product.php.+ landed as (+ select lower(n.page) as page_key,+ min(n.page) as page,+ (array_agg(l.http_status order by l.created_at desc))[1] as last_status+ from public.ai_traffic_logs l+ cross join lateral (select public.normalize_page_path(l.url) as page) n+ where l.brand_id = p_brand_id+ and l.http_status is not null+ and l.created_at >= now() - interval '90 days'+ and (+ strpos(l.url, '?') = 0+ or not exists (+ select 1+ from unnest(string_to_array(split_part(split_part(l.url, '#', 1), '?', 2), '&')) as qp(part)+ where qp.part <> ''+ and qp.part !~* '^(utm_[^=]*|gclid|fbclid|msclkid|srsltid|_gl|ref)(=|$)'+ )+ )+ group by 1+ ),+ candidates as (+ select page_key, min(page) as page, max(weight) as weight+ from (+ select lower(public.normalize_page_path(sp.url)) as page_key,+ public.normalize_page_path(sp.url) as page,+ sp.ga_sessions as weight+ from public.site_pages sp+ where sp.brand_id = p_brand_id+ and sp.fetch_status between 200 and 299+ union all+ select page_key, page, 0 from landed where last_status between 200 and 299+ ) c+ where page_key not in (select page_key from broken)+ group by page_key+ ),+ candidate_words as (+ select distinct c.page_key, regexp_replace(w.word, '^(.{3,})s$', '\1') as word+ from candidates c+ cross join lateral regexp_split_to_table(c.page_key, '[^[:alnum:]]+') as w(word)+ where length(w.word) >= 2+ ),+ broken_words as (+ select distinct b.page_key, regexp_replace(w.word, '^(.{3,})s$', '\1') as word+ from broken b+ cross join lateral regexp_split_to_table(b.page_key, '[^[:alnum:]]+') as w(word)+ where length(w.word) >= 2+ ),+ candidate_sizes as (select page_key, count(*) as words from candidate_words group by 1),+ broken_sizes as (select page_key, count(*) as words from broken_words group by 1),+ similar_pages as (+ select distinct on (page_key) page_key, target+ from (+ select+ bw.page_key,+ c.page as target,+ c.weight,+ count(*)::numeric / (bs.words + cs.words - count(*)) as overlap+ from broken_words bw+ join candidate_words cw on cw.word = bw.word+ join candidates c on c.page_key = cw.page_key+ join broken_sizes bs on bs.page_key = bw.page_key+ join candidate_sizes cs on cs.page_key = cw.page_key+ group by bw.page_key, c.page_key, c.page, c.weight, bs.words, cs.words+ ) m+ where overlap >= 0.5+ order by page_key, overlap desc, weight desc, length(target), target+ ),+ parent_pages as (+ select distinct on (b.page_key) b.page_key, c.page as target+ from broken b+ join candidates c+ on c.page_key <> '/'+ and left(b.page_key, length(c.page_key) + 1) = c.page_key || '/'+ order by b.page_key, length(c.page_key) desc+ ),+ result_rows as (+ select+ v.page,+ v.visits,+ v.last_visit,+ b.status,+ coalesce(p.platforms, '{}'::text[]) as platforms,+ coalesce(ci.citations, 0)::bigint as citations,+ -- A route on the page (every missing address has a query) gets no+ -- redirect: one from its path would move the whole route.+ case when v.page_key <> '/' and not b.routed then coalesce(s.target, pa.target, '/') end+ as target,+ case+ when v.page_key = '/' then null+ when b.routed then 'query'+ when s.target is not null then 'similar'+ when pa.target is not null then 'parent'+ else 'home'+ end as target_reason+ from visits v+ join broken b on b.page_key = v.page_key+ left join platforms p on p.page_key = v.page_key+ left join cited ci on ci.page_key = v.page_key+ left join similar_pages s on s.page_key = v.page_key+ left join parent_pages pa on pa.page_key = v.page_key+ )+ select jsonb_build_object(+ 'count', (select count(*) from result_rows),+ 'rows', coalesce((+ select jsonb_agg(to_jsonb(r))+ from (+ select * from result_rows+ order by visits desc, citations desc, last_visit desc, page+ limit greatest(p_limit, 0) offset greatest(p_offset, 0)+ ) r+ ), '[]'::jsonb)+ )+ into v_result;++ return v_result;+end;+$$;++revoke all on function public.ai_traffic_broken_links(uuid, timestamptz, timestamptz, integer, integer)+ from public, anon;+grant execute on function public.ai_traffic_broken_links(uuid, timestamptz, timestamptz, integer, integer)+ to authenticated, service_role;++comment on function public.ai_traffic_broken_links(uuid, timestamptz, timestamptz, integer, integer) is+ 'AI Traffic "Broken AI links" (AT-012, spec §3.5): the pages AI-referred visitors landed on that answered 404 or 410 (or, without a status, whose title said not found) in a window, with their visits, platforms, citations and a suggested redirect to a working page (similar path, parent page or home; none for a route on the page, target_reason query). Security definer with an organization check.';++notify pgrst, 'reload schema';+-- ─────────────────────────────────────────────────────────────────────────-- migrations/00201_gsc_pages_backfill_from.sql-- ─────────────────────────────────────────────────────────────────────────diff --git a/web/messages/en.json b/web/messages/en.jsonindex 82a822dbf..f00de5b64 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -3595,6 +3595,7 @@"brokenStatuses": {"404": "Not found (404)","410": "Gone (410)",+ "soft404": "Shows a not-found page (200)","title": "Page title says not found"},"redirectReasons": {@@ -4096,6 +4097,7 @@"status": {"404": "Not found (404)","410": "Gone (410)",+ "soft404": "Shows a not-found page (200)","title": "Page title says not found"},"reason": {diff --git a/web/src/lib/actions/traffic-broken-links.test.ts b/web/src/lib/actions/traffic-broken-links.test.tsindex 8270d9c77..2702dfad6 100644--- a/web/src/lib/actions/traffic-broken-links.test.ts+++ b/web/src/lib/actions/traffic-broken-links.test.ts@@ -108,6 +108,25 @@ describe('getTrafficBrokenLinks', () => {});});+ // 00200: a single-page app's route that shows its not-found page with a 200.+ it('reads a soft 404, and an unknown status as a 404', async () => {+ rpc.mockResolvedValue({+ data: {+ count: 2,+ rows: [+ { ...link, page: '/app/old-route', status: 'soft404' },+ { ...link, page: '/x', status: 'teapot' },+ ],+ },+ error: null,+ });+ const result = await getTrafficBrokenLinks(BRAND, WEEK);+ expect(result.rows.map((r) => [r.page, r.status])).toEqual([+ ['/app/old-route', 'soft404'],+ ['/x', '404'],+ ]);+ });+it('throws on a failed read', async () => {rpc.mockResolvedValue({ data: null, error: { message: 'permission denied' } });await expect(getTrafficBrokenLinks(BRAND, WEEK)).rejects.toThrow('permission denied');diff --git a/web/src/lib/actions/traffic.ts b/web/src/lib/actions/traffic.tsindex 4d84dbb3e..1756f958c 100644--- a/web/src/lib/actions/traffic.ts+++ b/web/src/lib/actions/traffic.ts@@ -574,8 +574,12 @@ export interface TrafficBrokenLink {/** Times tracked AI answers cited it in the range. */citations: number;lastVisit: string;- /** The status the browser reported, or 'title' when only the title said so. */- status: '404' | '410' | 'title';+ /**+ * The status the browser reported; 'soft404' when it answered 2xx with a+ * not-found title (a single-page app's route, 00200), 'title' when it+ * reported none and only the title said so.+ */+ status: '404' | '410' | 'soft404' | 'title';/** Where to redirect it: a working page; none for the home page itself or a route on a page. */target: string | null;/**@@ -590,7 +594,7 @@ export interface TrafficBrokenLinks {rows: TrafficBrokenLink[];}-const BROKEN_STATUSES = new Set(['404', '410', 'title']);+const BROKEN_STATUSES = new Set(['404', '410', 'soft404', 'title']);const TARGET_REASONS = new Set(['similar', 'parent', 'home', 'query']);/** Broken AI links (AT-012, spec §3.5; 00186), from the snippet alone. */diff --git a/web/src/lib/traffic-export.test.ts b/web/src/lib/traffic-export.test.tsindex bff97abc8..209b08e08 100644--- a/web/src/lib/traffic-export.test.ts+++ b/web/src/lib/traffic-export.test.ts@@ -703,6 +703,16 @@ describe('trafficTable: Broken AI links (AT-012)', () => {['No AI visitor landed on a missing page in this range'],]);});++ it('names a soft 404 for what the visitor saw', () => {+ const [row] = brokenLinks().rows;+ const table = trafficTable(+ 'brokenLinks',+ data({ brokenLinks: { count: 1, rows: [{ ...row, status: 'soft404' }] } }),+ label,+ );+ expect(table.rows[0].at(-1)).toBe('Shows a not-found page (200)');+ });});describe('filtersTable', () => {