Skip to content

feat(signals): show where a page's AI visits come from and its prompts - #1066

Merged
gkhngyk merged 67 commits into
ansvisor:mainfrom
cihan-gyk:feature/traffic-signal-evidence
Oct 17, 2026
Merged

gkhngyk merged 67 commits into
ansvisor:mainfrom
cihan-gyk:feature/traffic-signal-evidence

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The last part of AC-001 part two: traffic signals. Stacked on #1065, which sits on #1064, #1063, #1061, #1060, #1059 and #1058. Please review the eighth commit, feat(signals): show where a page's AI visits come from and its prompts, or merge those first.

The spec asks a traffic signal for "URL, engagement rank, sessions, AI referrals by platform, prompts where this page could be cited". The signals recorded their pages and a session count, so the drawer from #1060 said "Not available" for the referrals and the prompts.

Database: migration 00143_traffic_signal_evidence.sql

ae_page_traffic_evidence(brand, pages, windows, exact), service-role only like the other ae_* reads. For the pages given it returns:

Part Read from
AI-referred sessions per platform, this window and the one before Analytics (ga_ai_traffic_stats) and the tracking snippet (ai_traffic_logs), both as they are. The snippet counts Analytics' visits again, so the caller picks one per page and never adds them, as the detector does.
The active prompts that name the page as their target URL prompt_target_urls. Explicit targeting only, as in 00075.

With no pages it returns the whole site's sessions per platform.

  • Two ways to match a page's visits:
    • exact: as written. The AI-traffic detector's pages are these tables' own values, so a signal's referrals add up to its own numbers.
    • Otherwise as a path, as the page-opportunity read matches them (lower(normalize_page_path(…))).
  • Target URLs always match as paths.
  • Each row's key is computed once, so the join is a hashable equality.
  • schema.sql is regenerated.

Server

  • signals/traffic-evidence.js: trafficEvidence calls the read and summarizeReferrals lists the platforms, most visits first. Per page, Analytics is used when it has the page, else the snippet.

  • record.js attachTrafficEvidence:

    Signals Records
    AI-traffic page signals (ai_traffic_slipping, _drop, ai_landing_page_winner, ai_landing_underperforming, converting_page_slipping) and page_opportunity referrals for the first five pages, referralDays, and citablePrompts (up to 10, from all its pages, each once) with citablePromptsTotal
    Site-wide (cross_channel_risk, visibility_traffic_loss) the site's referrals
    • At most three reads per brand (pages as written, pages as paths, the site), run side by side.
    • A failed read costs its own signals only, and keepRecordedEvidence keeps an earlier night's.
  • One window: the 14-day window is one constant, TRAFFIC_WINDOW_DAYS, which the detector now uses too.

Web

  • AI referrals by platform: per page, e.g. "ChatGPT 31 → 18 · Perplexity 6 → 7". "No AI referrals" when there are none, and the period is stated. A signal about one page doesn't name the page again.
  • Prompts it could be cited on: linked prompts, or "None" once looked for. Without recorded evidence both still read "Not available", as the spec asks.
  • Site-wide findings: they show scope and referrals only, since there is no page to cite.
  • Periods: the AI-traffic findings' "What changed" now says "Last 14 days" / "Last 14 days against the 14 days before". It used to say 7, which their detector never compared.
  • Platform names: getPlatformName moves from the Traffic page's chart file to lib/traffic-platforms.ts, so the drawer and the page share it. It gains Grok and DeepSeek, which the Analytics sync already stores.
  • MCP: list_signals returns where.ai_referrals (platform names included) and where.citable_prompts.

Review

I ran a code review before opening this. Nine of ten findings are fixed:

  • Matching: detector pages are matched as written; paused prompts are left out.
  • Prompts: the count now covers all of a signal's pages.
  • Labels and layout: the 7-day period label; names for Grok and DeepSeek; no prompts row on site-wide findings; no repeated page.
  • Reads: run side by side; one shared window constant.

Left as is: in path mode (page opportunities) each snippet row in the window is normalized once. This is the same order of work as the detector's own read of that table.

A separate follow-up: the Search Console and cross-channel findings label 28-day and mixed windows as 7 days. That predates this PR.

Related issue

None. Product spec AC-001 (Action Center), part 2 for traffic signals. With #1061, #1063, #1064 and #1065 this covers every category's details.

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

  1. Apply 00143_traffic_signal_evidence.sql, then run a signal pass for a brand with AI traffic (Analytics or the snippet), or wait for the nightly one.
  2. Open an AI-traffic finding (e.g. "AI traffic slipping on …"):
    • AI referrals by platform for its first pages, with the period;
    • the prompts that target its pages;
    • "What changed · Last 14 days".
  3. Add a page as a prompt's target URL, run again: the prompt appears. Pause it: it goes.
  4. Open "Search and AI traffic falling together": scope and the site's referrals.
  5. The Traffic page still names platforms as before.
  6. Call MCP list_signals: where.ai_referrals, where.citable_prompts.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 7 warnings are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server: npm run format, npm run lint (clean), and npm test 1217/1217. New tests:
    • traffic-evidence.test.js: summary order and totals, one source per page, the windows, exact, site mode, a failed read.
    • record-evidence.test.js: the step's three reads, first pages, prompts each once, the site, other kinds untouched, keeping an earlier night's.
    • nightly-reads.test.js lists the new module.
  • web: yarn test 617/617 (fields, "None" vs "Not available", site layout, periods, API shape, the drawer lines) and yarn build.
  • Root: npm run version:check, and bash supabase/build-schema.sh.
  • Against the dev database:
    • Migration: applied 00143 after a rolled-back trial. Exact mode matched only the URL as written, path mode both forms; a target URL "…/About/?utm=x" matched "/about"; site mode gave six platforms.
    • Server read: trafficEvidence returned the snippet's visits by platform for demo pages.
  • In the browser: the drawer, in light and dark mode, at 1440px and 1024px, and the Traffic page.

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 15, 2026 14:20
…ls by platform

The Signals list never said which AI platform or location a signal was
about, and named platforms by their raw ids ("Visibility dropped on
gemini-web", "Weak in JP"). Part one of AC-002:

- Each row's Affected cell gets a line with the engines and locations the
  signal is about: from the payload for platform and country signals, and
  from the prompts' tracked platforms and locations for prompt and topic
  signals. A line rather than a column keeps the table within the page
  beside a pinned sidebar.
- Platforms and locations read as people know them ("Gemini", "Japan").
- Descriptions carry the measured fact instead of a generic sentence, e.g.
  "Your mention rate fell from 34% to 18% against the week before."
- A Platform filter, search over platform and location names, and
  platforms and locations columns in the CSV export.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A brand can track the same prompt text as several prompts, and the
detectors write one signal per prompt: on production one pass wrote ten
identical "Citations lost for '…'" rows, which read as duplicates and
inflated every count. Part two of AC-002:

- Signals of one kind, about one prompt text (case, spacing and the
  closing "?" ignored), found in one pass are one row with a "×N grouped"
  toggle. Opened, it lists each copy with its topic, place and status; each
  copy keeps its own drawer and menu, and the group's menu acts on the
  copies it applies to.
- The category tabs, the tab badge and the summary cards count groups.
  Migration 00141 adds signal_group_key (the same rule as
  lib/signals/group.ts), counts signals_summary over groups, where a group
  is resolved only once every copy is, and adds signals_new_count for the
  badge.
- A drawer opened from a link to a copy opens its group.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hat it rests on

The signal drawer showed bare numbers ("0 → 251 +167") and no platform,
location, page or action. Part one of AC-001: the drawer has three blocks.

- Where: the fields the spec asks per category (prompt, topic, platforms,
  locations, domain, competitor, pages, queries, and for a lost citation
  the page cited before and who is cited now). A field no detector records
  yet says "Not available"; platforms read from a signal's prompts say
  "Tracked on".
- What changed: every figure with its metric, whose or which window, and
  unit, over its period: "Mention rate · previous 7 days 34% → last 7 days
  18%, −16 pts". A source domain's three counts are named instead of read
  as a before and after. A fall in the brand's own numbers is red, a
  competitor's rise too (the old colouring showed drops as good news).
- Evidence and links: the page behind the signal (the prompt's answers, the
  topic, Citations…), first and last detection, and the actions using it.

MCP list_signals returns the same detail per signal (where, change,
evidence, used_by_actions) beside the raw row, from lib/signals/detail.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A lost citation was recorded with its prompt only, so the drawer could not
say which page lost its citation, where, or who replaced it. Part two of
AC-001, for lost citations:

- The recorder reads the lost prompts' answers back (server
  signals/lost-citation-evidence.js) and writes, with the signal: the
  platforms and locations it was lost on, the brand's page cited before
  with its position and last cited date, the pages cited in the quiet
  answers with their position and how many of the answers read cite them,
  and its cited days before and since. Best effort, and a night whose read
  fails keeps the evidence an earlier night recorded.
- The drawer shows them: Platforms and Locations (where it was lost),
  "Your page cited before", "Cited now", and "Cited days · earlier 9 / 11
  → latest 0 / 3". A loss on one platform names it in the title ("Citations
  lost on ChatGPT for …"), and the row says which page is no longer cited.
- MCP list_signals returns the same evidence.
- ownDomainMatcher is the own-domain rule countOwnDomainCitations already
  used, now shared.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A competitor signal named the competitor and one number, so the drawer had
"Not available" for positions by prompt and the sources behind its wins.
Part two of AC-001, for competitor signals (leads, gaining, surge,
crossed, overtaken, citation gap):

- Migration 00142 adds ae_competitor_positions: per competitor, the prompts
  and platforms where it is level with or ahead of the brand, with both
  positions this week and last, from the daily rollups (harmonic mean of
  mention positions). Service role only, like the other detector reads.
- The recorder writes, with each competitor signal, those positions and the
  domains most cited in the latest answers the competitor wins (named, the
  brand not). Best effort, and an earlier night's evidence is kept when a
  read fails.
- The drawer shows "Positions by prompt" ("ChatGPT · Profound #1 ↑2 · You
  #3 ↓1", "You — lost"), coloured as news for the brand, the platforms it
  leads on, and "Sources behind their wins". MCP list_signals returns them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The "Brand mentioned without citation" signal listed prompt ids only, so
the drawer had "Not available" for the mention's platform, position,
sentiment and excerpt. Part two of AC-001, for mention signals:

- The detector lists its prompts most mentioned first (prompt id breaks
  ties), and the recorder describes the first five: the platforms whose
  answers name the brand without citing it, the brand's median position,
  the answers' most common sentiment, how many answers, and a quote of the
  newest answer that names the brand (trying the next two if it doesn't).
  Best effort; a failed text read keeps the rest, and an earlier night's
  evidence is kept when a read fails.
- mentionExcerpt quotes an answer around the brand's first mention with the
  mention count's own matching, without links or markdown marks, cut on
  whole words.
- The drawer lists "Mentions by prompt" (prompt, platforms, #position,
  sentiment, answers, the quote and where it is from). Platforms and
  locations are each labelled by what they say: the platforms that mention
  the brand, the locations where the prompts are tracked. MCP list_signals
  returns the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts on

The audits family now records, per page, each failed check's label and
evidence. The AI bot access check names the bots robots.txt blocks, read
group by group: the old text-window scan took the next group's rules for
an allowed bot's. The drawer shows the issue, the affected crawlers for a
blocked-crawler finding, and what each check found, page by page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Traffic signals now record, for their first pages, AI-referred visits
by platform over the last 14 days against the 14 before, and the active
prompts that name any of their pages as the target URL; site-wide ones
record the site's visits by platform. One read (ae_page_traffic_evidence)
matches the detector's pages as written and a page opportunity's as a
path. The drawer shows both, and the AI-traffic findings now say they
compare 14 days.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk AC-001 part 2 for traffic signals, ready for review; with #1061, #1063, #1064 and #1065 every category's details are covered. Stacked on #1065: please review the last commit, or merge the stack first. It adds migration 00143 (a service-role read, ae_page_traffic_evidence) with schema.sql regenerated.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 15, 2026
cihan-gyk and others added 27 commits October 16, 2026 11:37
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
…nal-evidence

# Conflicts:
#	supabase/schema.sql
…nal-evidence

# Conflicts:
#	supabase/schema.sql
…l-evidence

main carries the stack below as squashes; this branch keeps only its own commit on top, with schema.sql regenerated.
…l-evidence

main now carries ansvisor#1065 as a squash; the tree is the one CI passed.

@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, approving. 00143 is applied on production, execute only for the service role. ae_page_traffic_evidence reads small tables today (821 Analytics rows, 14.8k snippet rows): on the busiest brand it took 14 ms site-wide and 27 ms for 50 pages. I merged main into the branch, so it keeps only its own commit on top of #1065, and CI is green on this tree.

@gkhngyk
gkhngyk merged commit 880d460 into ansvisor:main Oct 17, 2026
4 of 5 checks passed
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 17, 2026
…l-analytics

main now carries ansvisor#1066 as a squash; the tree is the one CI 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