Repository navigation
fix(traffic): count a single-page app's not-found route as a broken AI link - #1247
Conversation
…I link
A single-page app answers every path with 200 and shows its own "Page
not found" route, so Broken AI links never listed it: the snippet read
the title only when the browser reported no status, and a 2xx counted
as working.
The snippet now sends its beacon a moment after load (or as the visitor
leaves), so the app has set its title, keeping the landing address and
time, and with a 2xx reads the title with a stricter pattern: the
not-found page's own title ("404", "Page not found | Acme"), not a page
about 404s. /track keeps not_found_title with a 2xx. 00198 lists such a
page as broken with status soft404, doesn't let its 2xx count as
working, and keeps the nightly page read from clearing it, since that
read gets the app's shell with a 200 too. The page and the export say
"Shows a not-found page (200)".
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk this is the soft-404 follow-up from #1192: a single-page app's 200 "Page not found" route now shows in Broken AI links as "Shows a not-found page (200)". Two things worth a look:
00198 only redefines |
… to 00200 main now has 00198 (ansvisor#1239) and 00199 (ansvisor#1131), so the soft-404 migration moves from 00198 to 00200, with the comments that name it, and schema.sql is rebuilt from the migrations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Good catch on single-page apps, and the stricter title pattern for a 2xx reads right. Main has 00198 and 00199 now, so this takes 00200 (see my note above). After the rename it only conflicts in schema.sql.
-
One beacon is enough to list a working page, and nothing clears it. The beacon is public: anyone with the tracking code can send
st: 200, nf: 1for any URL.- A 404 row is cleared once the nightly page read finds the page working. A soft 404 skips that check by design, so the row stays until another AI visitor lands on the same address with a normal title.
- On a cited page it's worse. The detector counts a cited page from its first visit, so one beacon, stray or made up, raises a high-impact
broken_citation_targetwith an Action Center action. The page also shows in the weekly digest.
Please let
ai_traffic_broken_pagescount a soft 404 only after at least two visits saw it (brokenLinkMinVisitsis 3). Add a test with one soft-404 beacon on a cited page. -
The visit beacon now waits on every page. It goes at load plus 1.5 s, or when the visitor leaves, instead of at once. AI visits are the number this snippet exists for. A visitor who closes the tab before load now depends on
pagehideorvisibilitychangedelivering the beacon. Most browsers do, but this changes every customer's counts. Please say how you checked it, or compare one brand's daily visits for a few days on each side of the deploy.
Smaller:
- The title pattern is English only, so "Seite nicht gefunden" or "Página no encontrada" reads as a working page. Fine for now; worth a line in the comment.
Measured on prod as authenticated, on the largest traffic brand, then rolled back. Every one of its 10,949 pageviews was given a status, with 1 in 20 paths soft-404ing.
| Read | 00186 | This PR |
|---|---|---|
ai_traffic_broken_links, all time |
1.5 s | 3.0 s |
ai_traffic_broken_links, 30 days |
3.9 s | 4.4 s |
ai_traffic_pages, all time |
0.8 s | 0.8 s |
ai_traffic_broken_pages, all time |
0.5 s | 0.5 s |
- The rise comes from 159 broken pages instead of 48, mostly in the similar-page match.
- A member of another org gets null.
- The migration replaces only 00186's two functions, and prod's bodies match 00186, so nothing later is undone.
…isits The beacon is public, so one visit with a 200 and a not-found title, stray or made up, listed a working page as broken, nothing cleared it, and on a cited page it raised broken_citation_target. 00200 now counts a soft 404 only once at least two visits saw it (a reload continues one). The snippet sends the visit's beacon at once again, so the visits counted don't depend on the page loading. When the title didn't read not found, it reads it again a moment after load and, if a single-page app now shows its not-found page, sends k: "nf" for the address it landed on; /track marks that visit's pageview (same address, IP and browser in the last ten minutes) instead of counting another. The title patterns are English only, as the comment now says. Review on ansvisor#1247. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk thanks, both points are fixed in f9e02f3: 1. Two visits. 00200 counts a soft 404 only once at least two visits saw the page:
So one beacon, stray or made up, lists nothing, and nothing reaches 2. The visit beacon doesn't wait any more. Rather than argue the delay was safe, I took it out. The visit's beacon goes at once, as before this PR, so the counts can't change. When the title didn't read not found (with a 2xx or no status), the snippet reads it again 1.5 s after Checked end to end with the branch's API: a visit beacon stored the row with
Smaller: the comment now says both patterns are English only. Server 1902 tests pass; |
schema.sql is rebuilt with build-schema.sh after the migrations that landed today. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks, both points are fixed:
- One beacon no longer lists a page. A soft 404 now needs two distinct visits, counted by
visit_of. - The visit beacon goes at once again. The
nffollow-up only marks that visit's own pageview: same address, IP and browser within ten minutes, a 2xx or no status, not already marked. It never adds a visit.
Tested with #1244 on main: server 1,919 and web 1,893 tests pass, and tsc, lint and Prettier are clean.
00200 is applied to production. On the largest traffic brand's real data, ai_traffic_broken_links takes 20 ms over all time and 8 ms over 30 days. Prod has almost no status rows yet, so the synthetic numbers from my last review are the ones to watch as the new snippet spreads. I pushed a merge commit with schema.sql rebuilt.
Summary
Follow-up promised in #1192's review: soft 404s in Broken AI links.
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. Broken AI links never listed such a page:
Snippet (
server/src/lib/tracking-script.js)load. If a single-page app now shows its not-found page, it sends{k: "nf", u, s, a, st}for the address it landed on.nfis 1 only for the not-found page's own title, a stricter pattern: "404", "Page not found | Acme", "Acme – 404 Not Found", and not "How we fixed our 404s". Without a status, the old pattern stays./track(server/src/routes/traffic.js) keepsnot_found_titlewith no status or a 2xx; a 3xx–5xx status alone decides. Ak: "nf"body marks the latest pageview of that address, IP and browser in the last 10 minutes, with the same status, as a not-found title. It counts no visit.Migration 00200 (
ai_traffic_broken_pages,ai_traffic_broken_links; the rest is 00186's)soft404, once at least two visits saw it. A reload continues a visit, so it doesn't count again. The beacon is public, so one visit, stray or made up, lists nothing.ai_traffic_broken_linksreads those pageviews for the visits.Web:
TrafficBrokenLink.statusgains'soft404', shown on the page and in the export as "Shows a not-found page (200)". An unknown status still reads as a 404.Deploy: any order works. Before 00200, such rows count as working, as today; before the web,
soft404reads as a 404. Applying 00200 first lists the first soft 404s as soon as the new snippet sends them.Numbering: main has 00198 (#1239) and 00199 (#1131), so this migration is 00200 (renumbered at gkhngyk's request). Open PRs: 00188 #1210, 00190 #1225, 00191 #1226, 00194 #1229, 00195 #1230, 00196 #1234, 00197 #1243.
schema.sqlis rebuilt from main plus 00200.Related issue
Follow-up to #1192 (review of 2026-10-19).
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
Unit tests
tracking-script.test.jsruns the snippet in a VM with fake timers and listeners:load, and thek: "nf"mark only when the title turns not found after load, with the address the visit landed on;nf: 1and "How we fixed our 404s" givesnf: 0.traffic-track.test.js:nfis kept with a 2xx or no status, and dropped with a 3xx–5xx;k: "nf"marks the latest matching pageview (same address, IP, browser and status, last 10 minutes) without inserting a row, and does nothing for a 404 or with no match.traffic-broken-links.test.tsandtraffic-export.test.ts:soft404rows and their label.Dev DB (00200 applied; each case in a rolled-back transaction, as the service role)
statussoft404404In the browser: two temporary visits to
/app/old-routewith a 200 and a not-found title show in AI Referral Traffic › Pages › Broken AI links as "Shows a not-found page (200)". I checked it in light and dark mode, at 1440 and 1024 px, then deleted the rows.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also: web
yarn test(1793) andyarn build; servernpm run lint,npm test(1842);bash supabase/build-schema.sh.🤖 Generated with Claude Code