Skip to content

feat(traffic): compare AI visits with Google clicks on the AI Referral Trend card - #1176

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/traffic-google-trend
Oct 19, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/traffic-google-trend

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

AI Traffic Analytics, spec AT-008 part A (§3.3): the AI Referral Trend card gets a "vs Google clicks" tab. It compares AI visits with Google organic clicks, each indexed to 100, with markers on the days actions entered the Action Center or prompts were added.

Part B (page-level Search Console sync and the "Is AI taking Google clicks?" section) follows as its own PR, stacked on this one.

Why

Spec §3.3: "Two lines indexed to 100 at the start of the range: AI visits, and Google organic clicks. Event markers: Action Center actions sent, and prompts added. The legend states that AI Overviews / AI Mode clicks sit inside Google organic and can't be separated."

What changes

  • Migration 00180_ai_traffic_google_trend.sql: ai_traffic_google_trend(brand, since, until) returns jsonb with:

    • Search Console clicks per UTC day, summed over the brand's queries the way the Google clicks card sums them (00174);
    • the first and latest day Search Console has rows for the brand;
    • per day, the actions created in the Action Center and the prompts added to the brand's sets.

    It runs as security invoker: gsc_query_stats, actions and prompts each have a member select policy, so RLS decides the brand.

  • Tabs: the card header has By platform | vs Google clicks (the mockup's tabs). The view shows the "Needs Google Search Console" tag beside the title.

  • lib/traffic-google-trend.ts (pure) builds the view's points:

    • Each line is indexed to 100 on its first day with data.
    • The Google line is blank, not 0, before Search Console's history and after the latest day Google has reported (about two days late, §3.01). The note under the chart names that day: "Google clicks until Oct 17".
    • A range that starts mid-day (the rolling 7 and 30 days) leaves out its partial first day. Its few visits would otherwise set a misleading 100.
  • Chart (GoogleTrendChart in _charts.tsx):

    • two lines and a dotted 100 baseline;
    • a dashed amber line on each marker day;
    • the tooltip gives the raw counts with their index, e.g. "5 · index 250", plus "2 actions entered the Action Center · 3 prompts added";
    • the legend note says AI Overviews and AI Mode clicks are part of Google organic clicks and can't be separated.
  • 24-hour range: Google reports by day, so the tab says "Pick 7 days or longer…" with a Show last 7 days button. There is no hidden window of its own (F2).

  • Without Search Console: the view keeps the AI line, hides the Google line from the legend and tooltip, and says "The Google clicks line needs Google Search Console." (§3.8b's partial note). While the source states load, it shows a skeleton.

Not in this PR

  • AI Overviews impressions (spec §3.2, §3.6, §5.3): the Search Analytics API doesn't expose the Generative AI report. Its type values and dimensions have no AI Overviews or AI Mode option, and a third-party check on 2026-08-11 found the report is UI-only. Per §5.3 the card and column stay hidden, with no placeholder numbers.
  • Markers count every action created in the Action Center, not only person-sent kinds. Narrowing them is a small follow-up if you prefer.

Related issue

None. Spec AT-008 (AI Traffic Analytics plan, approved by product).

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 00180 (one new function; no table change).
  2. Open AI Traffic Analytics for a brand with Search Console data on 30d, then pick vs Google clicks on the trend card. Two indexed lines appear. The Google line stops at Google's latest reported day, and the note names it. Hover a day for the counts, the index and any markers.
  3. On a day with an action or new prompts, a dashed amber line is drawn and the tooltip lists them.
  4. Switch to 24h: the tab offers Show last 7 days, which switches the page's range.
  5. For a brand without a Search Console property, the tab keeps the AI line and says what the Google line needs.

Checklist

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

Also run:

  • web: yarn test (1646) and yarn build pass.
  • supabase: bash supabase/build-schema.sh; schema.sql updated.
  • Tests:
    • traffic-google-trend.test.ts: the days, the partial first day, indexing, Google's blank days, markers.
    • traffic-google-trend.test.ts (actions): the RPC read.
    • _google-trend.test.tsx: both lines, no Search Console, no clicks or a failed read, the first whole day and the loading states, 24h.
  • Browser:
    • Setup: temporary Search Console data and AI visits on the demo brand. Checked on 30d, 7d and 24h, with and without the property, in light and dark, at 1440 and 1024 px.
    • At 1024 the tabs wrap under the title with no overflow.
    • The temporary data was removed afterwards.

🤖 Generated with Claude Code

…l Trend card

AT-008 part A (spec §3.3): the trend card gets a "vs Google clicks" tab.
It draws AI visits and Google organic clicks, each indexed to 100 on its
first day with data, with markers on the days actions entered the Action
Center or prompts were added.

- 00180 ai_traffic_google_trend: Search Console clicks per UTC day, the
  first and latest day it has rows for the brand, and the markers.
  Security invoker; RLS decides the brand.
- The Google line is blank (not 0) before Search Console's history and
  after Google's latest reported day, which the view names.
- A range that starts mid-day leaves out its partial first day so it
  doesn't set a misleading 100.
- The 24-hour range offers "Show last 7 days" (Google reports by day).
- Without Search Console the view keeps the AI line and says what the
  Google line needs (§3.8b). The view shows the "Needs Google Search
  Console" tag.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk AT-008 part A, from main. Deploy: apply 00180 (one new security-invoker function, no table change), then the web. No server change.

Two notes:

  • AI Overviews impressions stay hidden (spec §5.3): the Search Analytics API has no AI Overviews / AI Mode type or dimension, so there's nothing to read yet.
  • The markers count every action created in the Action Center. If you'd rather mark only person-sent ones, I can narrow it in a follow-up.

Part B (page-level Search Console sync + "Is AI taking Google clicks?") comes next, stacked on this PR.

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

Tested on main with #1193: web vitest (1,646) and server tests (1,703) pass, and schema.sql is up to date. 00180 is applied on production. As a member of the largest Search Console brand it takes 0.9 s cold for 90 days and 41 ms for 30 days; a user from another organization gets an empty result. anon has no execute.

@gkhngyk
gkhngyk merged commit a98c35c into ansvisor:main Oct 19, 2026
6 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
main now has ansvisor#1176 (squash a98c35c, identical to this branch's 27f2ad2)
and ansvisor#1193. The conflicts are the files ansvisor#1177 extends after ansvisor#1176: this
branch's side kept; schema.sql rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…raffic-untracked-queries

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-google-pages, which carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…ure/traffic-bot-ingest

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-untracked-queries, which carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…ffic-bot-logs

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-bot-ingest, which carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…ic-bot-connect

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-bot-logs, which carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…affic-bot-report

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-bot-connect, which carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…ffic-broken-links

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-bot-report, which carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…raffic-alerts

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-broken-links, which carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 19, 2026
…-digest

main now has ansvisor#1176 (squash, identical to the stack's first commit) and ansvisor#1193;
merged through feature/traffic-alerts, which carries it.

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