Skip to content

fix(traffic): name only known platforms and pages in the weekly AI Traffic digest - #1229

Merged
gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:fix/digest-beacon-keys
Oct 20, 2026
Merged

gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:fix/digest-beacon-keys

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up from #1196's approval: "the top changes still name any platform key or page path the public beacon sends; only unknown is filtered out."

The snippet's beacon is public, so a source key or page path in the AI traffic data can be any text a caller sent. The digest printed it into a customer's e-mail.

Platforms

  • isNamedPlatform(key) accepts only keys platform-names.json can name. That is the page's own list, old keys such as chat.openai.com included, and never unknown.
  • It applies to:
    • the top changes;
    • the platform list (topPlatforms);
    • the "X sent the most" sentence.

Pages

  • pageCandidates(data) lists the pages whose AI visits moved by 3 or more, keyed as the Pages section keys them.
  • readDigestData asks ai_traffic_known_pages (migration 00194) which of them a source the beacon can't write knows:
    • the site's pages (site_pages: up to 500 from the sitemap, Analytics and citations, written nightly);
    • Google Analytics (ga_page_stats, ga_ai_traffic_stats) in the last 90 days;
    • pages AI answers cited in the last 90 days;
    • active prompts' target URLs;
    • the home page.
  • topChanges names only those pages. Without the answer, it names no page.
  • The function is service role only.

Broken AI links (review of 2026-10-20)

The page agrees: the AI Traffic page's summary line ("X sent the most") and its Top platform card pick the top platform among those isNamedPlatform accepts (web traffic-platforms.ts, the same names), so they and the e-mail name the same platform.

A real page no trusted source has seen is no longer named. I think that is the right trade for an e-mail that goes to customers.

Deploy: apply 00194, then deploy the server.

Numbering: 00188–00193 are #1210, #1223, #1225, #1226, #1227 and #1228. schema.sql is built without them; whichever merges later needs build-schema.sh again.

Related issue

Follow-up to #1196 (approval of 2026-10-19 21:31 UTC).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

On the dev DB with 00194 applied, for the demo brand (8 site pages):

  • ai_traffic_known_pages(…, {/menu, /gifts, /cheap-pills, /, /shipping}) returns {/, /gifts, /shipping};
  • members can't call it (has_function_privilege('authenticated', …) is false).

The demo brand had no AI visits last week, so scripts/test-traffic-digest.js renders an e-mail without changes. Unit tests cover the logic:

  • summary.test.js: a beacon-made platform key and unknown are left out of the platform list and the changes; an unknown page is not named; pageCandidates asks about the moved pages.
  • engine.test.js: the digest asks ai_traffic_known_pages about ['/cheap-pills', '/menu'], and the e-mail says "/menu got 30 AI visits, none the week before." and never mentions cheap-pills.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): web not touched
  • yarn typecheck passes (run from web/): web not touched
  • yarn format:check passes (run from web/): web not touched
  • Changes are focused — one concern per PR

Also run:

  • server: npm run format, npm run lint, npm test (1820 passed);
  • bash supabase/build-schema.sh.

🤖 Generated with Claude Code

…affic digest

The digest's top changes, platform list and "sent the most" sentence named
any platform key or page path in the AI traffic data, and the snippet's
beacon is public: a caller could put any text in a customer's e-mail.

Platforms are now named only when the page can name them (platform-names
.json, old keys included). Pages are named only when a source the beacon
can't write knows them: ai_traffic_known_pages (00194) checks the week's
moved pages against the site's pages (site_pages), Google Analytics and AI
answer citations in the last 90 days, active prompts' target URLs, and the
home page.

Follow-up to ansvisor#1196's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This is the last AI Traffic follow-up, #1196's beacon-keys note. The digest now names:

  • only platforms platform-names.json knows;
  • only pages that a source the beacon can't write knows. ai_traffic_known_pages (00194) checks them against site_pages, GA (90 days), citations (90 days), active target URLs and /.

00194 is on the dev DB. One choice to check: a real page that only the snippet has seen isn't named any more.

With this, every follow-up from the AI Traffic approvals has a PR: #1222–#1225, #1228 and #1229.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 19, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform and page filters are right: site_pages is never filled from the beacon, and every real platform is in platform-names.json. One change:

The broken-link row still names a beacon-only page (summary.js, topChanges). It prints brokenRows[0].page and brokenRows[0].target unconditionally, and it comes first in Top changes. engine.js reads ai_traffic_broken_links with p_limit: 1 and no visit minimum. A single beacon request for /<any text> with http_status: 404 therefore puts "1 page AI visitors landed on doesn't exist: /, redirect to …" in Monday's e-mail. The target can be beacon text too, since 00186's landed candidates come from ai_traffic_logs. That goes against 00194's own comment that it "never prints a path only the public beacon sent". After #1228 it also names a one-visit 404 that Action Center no longer signals.

Name the page only when it is cited or in knownPages (add the broken page and its target to the ai_traffic_known_pages ask). Otherwise print only the count, and drop the target unless it is known. Apply #1228's "cited or at least 3 visits" rule too, so the e-mail and the signal agree.

Nit: "X sent the most" now skips unnamed keys, but the page's line (traffic-summary-line.ts) still takes platforms[0], so the two can name different platforms.

cihan-gyk and others added 4 commits October 20, 2026 10:19
…or known

The weekly e-mail's broken-link line printed the first row's page and
redirect unconditionally, and both can be any text the public beacon
sent (00186 also picks redirects among the pages it logged). It now
reads the broken links as the broken_citation_target signal does (50
rows, cited or brokenLinkMinVisits, ansvisor#1228), asks ai_traffic_known_pages
about the top one's page and redirect along with the moved pages, and
names the page only when AI answers cite it or it's known, the redirect
only when it's known; otherwise the line gives the count.

The AI Traffic page's summary line and its Top platform card now pick
the platform that sent the most among those they can name, as the
e-mail does, so a key only the beacon sent isn't named there either.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk thanks, fixed in 59125cd:

Broken-link row

  • engine.js reads ai_traffic_broken_links as the broken_citation_target signal does: 50 rows, then keeps those AI answers cite or with brokenLinkMinVisits (3) visits, the fix(action-center): keep one stray 404 visit from raising a broken-link signal, and read only the candidates for a new AI platform #1228 rule (ENGINE_THRESHOLDS.library.brokenLinkMinVisits, so they can't drift apart).
  • The top kept row's page and target go into the same ai_traffic_known_pages ask as the moved pages. It now runs after the broken read, in parallel with ga_platform_value.
  • topChanges names the page only when it is cited or known, and the target only when it is known; otherwise changeText gives the count: "2 pages AI visitors landed on don't exist."

Nit: the page's summary line now picks the top platform among those isNamedPlatform accepts (web traffic-platforms.ts, same names as platform-names.json). Checking it, I found the Top platform card beside it still showed the beacon-made key, so the page contradicted itself; the card uses the same rule now.

Checked locally with tagged temp rows on the dev DB (deleted since), rendering the e-mail with test-traffic-digest.js (not sent):

  • /win-a-prize with 4 404 visits, beacon only, plus a 1-visit /typo → "1 page AI visitors landed on doesn't exist." (no path, /typo not counted);
  • /business (in site_pages) with 5 404 visits → "2 pages … don't exist: /business, redirect to /.";
  • 5 visits from made-up.example today → the summary line and the Top platform card both say ChatGPT.

Server 1843 tests, web 1793 tests + build pass; schema.sql rebuilt (00194's header now mentions the broken link; the function is unchanged).

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the broken-link line is right now:

  • it counts only what #1228's signal would raise (cited, or brokenLinkMinVisits);
  • it names the page only when AI answers cite it or another source knows it, and the redirect only when it is known;
  • ai_traffic_known_pages is asked about both;
  • the summary line and the Top platform card now name the same platform as the e-mail.

I timed 00194 on production in a rolled-back transaction:

  • Largest traffic brand: 20 ms for its 14 most visited keys plus a made-up one. 5 are known; the made-up key isn't.
  • Largest citation brand: 144 ms.

00194 is now applied to production. I pushed a merge commit with schema.sql rebuilt.

Small, not blocking: count is now the number of qualifying rows among the 50 read. A week with more than 50 broken links worth a line therefore says "50 pages". When 50 rows come back and broken.count is higher, print "50+".

@gkhngyk
gkhngyk merged commit 7a21583 into ansvisor:main Oct 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants