Repository navigation
feat(traffic): list the Google queries no prompt tracks, with Track and Track all - #1178
Conversation
…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]>
…ng clicks AT-008 part B (spec §3.6): a Google Search Console section with "Is AI taking Google clicks?" — pages whose impressions rose 15% or more while their CTR fell 20% or more against the period before, most clicks lost first. Each row's next step is the Positions panel of a tracked prompt about the page, or Add prompts when there is none. - 00181: gsc_page_stats (Search Console by page and day, member select policy) and ai_traffic_google_pages. The window keeps the range's length and ends on Google's latest reported day (§3.01). Pages need 100 impressions in the period before. When the page history doesn't reach back to that period, it says so rather than reading every page as rising. Security definer with an organization check (citations). - Server: the daily GSC sync also pulls pages. A brand's first page sync reads 190 days in 28-day steps, later ones the last 28, and the prune keeps 190 days. A failed page step leaves the query rows synced. - Web: the section with its connection states (§3.8b), the "Needed for" list, and the export sheet "Is AI taking Google clicks". Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd Track all AT-009 (spec §3.6): beside "Is AI taking Google clicks?", a card with the top Search Console queries by clicks that no tracked prompt covers. Track adds a query as a prompt; Track all adds the listed ones within the plan's prompt slots (PROMPT-012). The summary line states their number while Search Console is connected (§3.1, §3.8b rule 5). - 00182 ai_traffic_google_queries: queries with clicks between two days, most clicks first, ending on Google's latest reported day (§3.01). - Server: GET /api/prompts/untracked-queries/:brandId drops the queries an active prompt covers, by the rule Prompt Suggestions uses for Google queries, so the two pages agree. Prompts are tokenized once and read past the 1,000-row page. - Web: UntrackedQueriesCard, the summary line's count (counted again after tracking), the export sheet "Untracked Google queries" and the "Needed for" list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk AT-009 is stacked on #1177 → #1176, so please merge those first. This PR's own change is the last commit, Deploy: apply One product note: Track adds the Google query as a prompt word for word, with no topic and no target URL. If you'd rather turn queries into question-style prompts first (as Prompt Suggestions does with a model), that could be a follow-up. |
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]>
…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]>
gkhngyk
left a comment
There was a problem hiding this comment.
No blockers here; it waits on #1177. 00182 on production (rolled back), as a member of the largest Search Console brand: 125 ms for 90 days and 110 ms for all time. A user from another organization gets no rows.
Two notes:
web/src/app/api/traffic/export/route.tsnow calls the API throughgetUntrackedGoogleQuerieswithout a.catch, so an API 5xx fails the whole export..catch(() => null), asgetTrafficSourceshas, keeps the rest of the export.- The page calls
/untracked-queriestwice per load, once for the card and once for the summary line. Each call matches up to 5,000 queries against every active prompt on the event loop. One fetch at page level would halve that.
…backfill Review of ansvisor#1177: - ai_traffic_google_pages spent its time on normalize_page_path, twice a row (4 s warm, 18 s cold on 110k rows). gsc_page_stats now stores page_key as a generated column and the function groups by it; only the ranked rows work out their display path. Plus an index on date for the table-wide prune. - A first page sync cut short left 28 days of history for months. The sync now reads the 190 days until one gets through them all for the property (brands.gsc_pages_backfilled_property), and drops the old property's pages when it changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk Thanks. This one only has #1177's fix merged forward (3e8e82b). Both of your notes go into one small follow-up after the stack, so it doesn't grow further:
Say if you'd rather have them here. |
The fallback prompt for a page in "Is AI taking Google clicks?" counted every citation of the page over 90 days, which read every answer that cited it (35,798 on the largest brand, 15 s cold, past the 8 s timeout). It now reads the page's latest citation and that one answer, at most one each per ranked page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ordering a page's citations by created_at still read every one of them from the heap, since the (url_id, brand_id) index has no created_at: 35,700 rows and 7.5 s cold on the largest brand's 50 pages. The lateral now stops at the first citation in 90 days whose prompt is active (2 s there, gkhngyk's measure), which also skips a paused prompt instead of leaving the page without one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
00182 is applied on prod. On the largest brand a member reads the Google queries in 0.6 s, and a stranger gets no rows. Tests pass on main with the whole stack. I pushed a merge commit (main after #1177's squash), so the tree is unchanged apart from main.
…d match the AI bots sheets to the report (#1244) * fix(traffic): keep the export going without the untracked queries, and match the AI bots sheets to the report Follow-ups from gkhngyk's AI Traffic reviews: - #1178: the export read the untracked Google queries without a .catch, so an API 5xx failed the whole file. It now leaves that sheet with its note and exports the rest, as the AI bot report already does. - #1182: the AI bots sheet had one row per bot while the By bot type card has one row per type; it now has one per type, with its bots. The cited pages no search bot read in 30 days get their own sheet, as the report lists them (the most cited, then how many more), with a note while the bot data is under 30 days or not whole. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(traffic): say an export section couldn't be read instead of that it's empty When the untracked-queries read or the AI bot report failed, the export left it out so the rest still exported, but its sheets then said "No query data from Google Search Console yet" or "No AI-bot requests in this range", which wasn't true. The route now notes those sections as unread, and their sheets say "Couldn't read this section; export again to include it". The uncrawled-pages sheet also tells a paused alert (stale) from one still waiting for 30 days of data, as the report does. Review on #1244. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
AI Traffic Analytics, spec AT-009 (§3.6): the "Untracked Google queries" card beside "Is AI taking Google clicks?". It lists the top Search Console queries by clicks that no tracked prompt covers. Track adds a query as a prompt; Track all adds the listed ones within the plan's prompt slots (PROMPT-012). The summary line now states their number while Search Console is connected.
Why
What changes
00182_ai_traffic_google_queries.sql:ai_traffic_google_queries(brand, since, until, latest, limit = 5000)returns the queries with clicks between two days, most clicks first, pluscappedwhen there were more.latest, the window ends on Google's latest reported day and keeps its length (§3.01), like the Google clicks card (00174).GET /api/prompts/untracked-queries/:brandId?since&until&limitchecks brand access, thenlib/untracked-queries.jsdrops the queries an active prompt covers.isCoveredByPrompts), so the two pages agree.gsc-suggestions.jsnow exposes the same rule over pre-tokenized prompts (promptTokenSets/isCoveredByTokenSets), so checking 5,000 queries doesn't re-split every prompt per query.isCoveredByPromptskeeps its behaviour.readAllRpcRows).UntrackedQueriesCard(_untracked-queries.tsx):trackPagePrompts(oneaddPromptToSeteach, plan-checked; the query text as the prompt, no topic, no target URL). It then reads the list again, so the tracked queries leave it.queriesRevision), so the line and the card agree.Deploy
Apply
00182, then deploy the server (new route) and the web together.Related issue
None. Spec AT-009 (AI Traffic Analytics plan, approved by product).
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
00182. Open AI Traffic Analytics on 30d for a brand with Search Console data.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no errors; 6 warnings, all in files this PR does not touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)npm run lintpasses (run fromserver/)npm testpasses (run fromserver/): 1703Also run:
web:yarn test(1670) andyarn buildpass.supabase:bash supabase/build-schema.sh;schema.sqlupdated.untracked-queries.test.js: covered queries dropped; stopword-only queries dropped; the prompt read past 1,000 rows; capped; errors.prompts-untracked-queries.test.js: the days and limit; invalid input; another organization's brand._untracked-queries.test.tsx: the rows, days and slots; Track and the reload; Track all within the slots; the plan limit toast; disabled states; empty reasons; the "+" floor.traffic-untracked-queries.test.ts: the API call and mapping._summary-line.test.tsx: the count only with Search Console; the floor; counting again after tracking; waiting while the state loads.🤖 Generated with Claude Code