Skip to content

fix(traffic): say whether the tracking snippet is installed, not a bare 0 (00433) - #1927

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:fix/ai-traffic-tracking-status
Nov 1, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:fix/ai-traffic-tracking-status

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

AI Traffic said "Not detected" for the tracking snippet whenever there had been no AI visit in the last 7 days. So a site with the snippet and no AI visitors read the same as a site without it, and MCP and Chat answered "0 visits" either way.

Now the server checks the brand's home page for the snippet, and AI Traffic tells three states apart. Customer priorities plan, P0 item 4.

What changes

  • The check:
    • The server reads the brand's home page with the existing SSRF-guarded helper: the bare domain first, then www..
    • It looks for the t.js tag or the tracking code.
    • Nothing is added to customers' pages.
    • New route POST /api/brands/:id/tracking-snippet/check: every member of the brand may call it, with its own rate limit.
    • It also runs once while the brand is first set up, during site-type detection.
    • If the page can't be read, nothing is stored.
  • 00433:
    • adds brands.snippet_checked_at and brands.snippet_found_at, and reloads the API schema;
    • schema.sql and supabase.ts are updated.
    • Before the migration runs, the code reads empty values without failing.
  • Three states:
    • active: an AI visit in the last 7 days;
    • installed_quiet: the check found the snippet, or an AI visit was ever stored;
    • not_detected: neither.
  • AI Traffic:
    • The Data sources strip reads "Not detected on {domain}" or "Installed · no AI visits in the last 7 days".
    • The code box opens only when the state is not detected. It has setup steps, Check again, and a result line: not found, page unreadable, or no domain.
    • The empty card says "Add the tracking snippet…" only when the snippet hasn't been seen. The export writes the state.
  • MCP and Chat: the answer carries tracking: 'not_detected' | 'installed_quiet' | 'active', and the tools' descriptions say what each means.
  • Demo brands: the check is refused on a demo brand, like detect-site-type, because its site is a sample. The route is in the demo-brand coverage list.
  • Help: connect-ai-traffic-sources.md and ai-referral-traffic.md; approved-articles.json refreshed.

Next: "Check the snippet once on the first open" is stacked on this PR (owner decision 2026-11-01).

For @gkhngyk:

  • Apply 00433.
  • MCP get_ai_traffic gains tracking; a skills docs PR follows.
  • Known limit: a snippet added through a tag manager isn't in the home page's HTML, so it shows "not detected" until the first AI visit. The code box and Help say so.

Related issue

None. Customer priorities plan, P0 item 4.

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 00433.
  2. Open AI Traffic on three brands:
    • one with AI visits in the last 7 days: "Active · last visit …";
    • one with older visits only: "Installed · no AI visits in the last 7 days";
    • one with none: "Not detected on {domain}", with the code box open.
  3. On the last one, click Check again. You see "Not found on {domain}'s home page yet", or Installed once the tag is there.
  4. Unit tests:
    • the three states;
    • a failed check (page unreadable);
    • a brand with no domain;
    • the www. try;
    • the migration not applied yet;
    • the route, the client and MCP;
    • Check again;
    • the demo-brand guard.

Checked in the browser at 1024px: Active and Installed states on the strip. The user approved the screens.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 old warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)
  • Migration added (00433) and supabase/schema.sql rebuilt

Full checks on this branch (d7b2012): web 806 files / 8395 tests pass, and yarn build passes. Server format:check and lint are clean, and 354 files / 5006 tests pass (3 skipped).

🤖 Generated with Claude Code

cihan-gyk and others added 3 commits November 1, 2026 08:39
…re 0

AI Traffic called the snippet "detected" only after an AI visit in the
last 7 days, so a site with the snippet and no AI visitors read the same
as one without it; the empty card never said "Add the tracking snippet"
because tracking_code is always set; MCP get_ai_traffic and Chat
get_ai_traffic_summary answered total_visits: 0 either way.

- Check, with no request added to customers' pages: the server reads the
  brand's home page through safe-fetch (public addresses only), at the
  domain as added then www., and looks for the snippet (its t.js tag or
  the tracking code). POST /api/brands/:id/tracking-snippet/check (any
  brand member, own rate limit) for Check again; setup's site type
  detection runs it once too. A read that fails keeps nothing.
- 00433: brands.snippet_checked_at and snippet_found_at; schema.sql and
  the Supabase types regenerated. A deploy ahead of it reads nulls.
- Three states (traffic-sources.ts snippetState): active (AI visit in 7
  days), installed_quiet (the check found it, or any AI visit before),
  not_detected. The Data sources strip says "Not detected on {domain}" or
  "Installed - no AI visits in the last 7 days"; the code banner, shown
  only while not detected, gives the steps and Check again with what it
  saw (not found, unreachable, no domain); the empty card asks to add the
  snippet only then; the export names the state.
- MCP and Chat: tracking: 'not_detected' | 'installed_quiet' | 'active'
  in the answer, and the tool descriptions say what it means.
  skills/*/SKILL.md and docs (mcp-server, api-reference/metrics) need a
  line about it: separate docs PR.
- Help: connect-ai-traffic-sources, ai-referral-traffic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ons do

Without the reload, PostgREST keeps serving brands without
snippet_checked_at and snippet_found_at until its next restart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /brands/:id/tracking-snippet/check reads the brand's home page and
writes when it was checked; a demo brand's site is a sample, so the demo
guard refuses it like detect-site-type. Names the route in the demo-brand
coverage test's guarded list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 1, 2026
gkhngyk
gkhngyk previously approved these changes Nov 1, 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.

LGTM

@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.

LGTM

@gkhngyk
gkhngyk merged commit fadd381 into ansvisor:main Nov 1, 2026
5 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 2, 2026
…iewer (#1964)

The MCP tools changed in #1920, #1927 and #1916; the skills and the MCP
guide still described the old answers.

- get_ai_traffic / GET /ai-traffic: `tracking` (not_detected,
  installed_quiet, active); a 0 with not_detected means nothing is
  measured yet. Coach skills (MCP + REST), mcp-server.mdx and
  api-reference/metrics.mdx (GET /api/v1/ai-traffic returns it too).
- run_site_audit / POST /site-audits: a running page's audit comes back
  with alreadyRunning and no credit; a page audited in the last 10 minutes
  returns recently_audited and starts nothing unless force. Coach skills,
  audit-fix (Chat) and mcp-server.mdx; library.json refreshed.
- get_content_draft_package: the qualified reviewer (reviewer) and its
  WebPage reviewedBy JSON-LD once the page names them. mcp-server.mdx.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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