Skip to content

feat(traffic): show the pages AI engines aren't sending traffic to - #725

Merged
gkhngyk merged 2 commits into
mainfrom
feature/719-opportunity-surface
Aug 14, 2026
Merged

gkhngyk merged 2 commits into
mainfrom
feature/719-opportunity-surface

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

The detection engine (#724) has been writing findings since it merged and nobody could see them. This puts them on AI Traffic Analytics, below the tables that count the tracking snippet's own visits and clearly attributed to Analytics — the two origins describe different things and are never summed, per the constraint #704 set.

The card reads the nightly run rather than computing anything. The ranking, the signal and the evidence were decided server-side; recomputing them here would let the card disagree with what the engine stored.

The wording follows the signal the engine actually used. On a property with revenue the column reads Revenue and the rank is "by revenue". On one with none it reads Engagement, says so, and points at Analytics key events as the way to rank by what pages earn instead. Calling an engagement rank "your most valuable page" would be a true sentence about the wrong thing, and the copy is where that promise is kept or broken.

Nothing renders without findings, so the twenty-nine brands with no mapped property meet no empty card explaining a feature they have not connected.

The types commit, and why it is here

The first commit regenerates web/src/types/supabase.ts, which was last refreshed around migration 00049 — the three Analytics tables and page_opportunities were missing, so nothing could read them from the web app. This PR cannot work without it.

It brought more than the tables. The previous file declared Functions: { [_ in never]: never }: every supabase.rpc() call in the app was untyped, and had been since the file was first generated. With real signatures in place, 35 call sites stop compiling — they pass null for optional parameters the generator declares as ?: string.

All 35 become undefined, which is behaviour-preserving: an omitted key lets each function apply its own DEFAULT NULL. Verified against the live database rather than assumed —

ai_visibility_aggregates(brand, NULL, NULL, NULL, from, to, NULL, NULL)
  = ai_visibility_aggregates(p_brand_id => brand, p_date_from => from, p_date_to => to)
→ true   (same for insights_aggregates)

Kept as a separate commit so the surface diff stays readable.

Related issue

Part of #719 — the surface for the detection layer. Clustering, LLM enrichment and the action/validation layers stay open.

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. Open AI Traffic Analytics on a brand with a mapped GA4 property. A card appears below the tables listing the pages that rank high on their own site and received no AI-referred visit in the window.
  2. The badge reads Google Analytics · last 28 days; the rank column names the signal the engine used.
  3. Open it on a brand without a mapped property — the page is exactly as it was, no empty card.
  4. Switch brands with the card open: findings from the previous brand must not render under the new brand's name (the loaded rows carry their brand and are compared before rendering).

yarn typecheck, yarn lint (6 pre-existing warnings, 0 errors), yarn format:check, yarn test (84 pass) and yarn build all pass locally. The production build was run before committing — tsc alone does not catch what CI's web job does.

Checklist

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

…check

The generated types were last refreshed around migration 00049, so the three
Analytics tables and page_opportunities were missing and nothing could read
them from the web app.

Regenerating brought more than the tables. The previous file declared
`Functions: { [_ in never]: never }` — every `supabase.rpc()` call in the app
was untyped, and had been since the file was first generated. With real
signatures in place, 35 call sites stop compiling: they pass `null` for
optional RPC parameters the generator declares as `?: string`.

All 35 become `undefined`, which is behaviour-preserving. An omitted key lets
each function apply its own `DEFAULT NULL`, and the two forms were checked
against the live database: `ai_visibility_aggregates` and
`insights_aggregates` return byte-identical results whether the optional
arguments are passed as explicit NULLs or left out entirely.

`modelFilterArray` and the shared `baseArgs` / `rateArgs` objects return
`undefined` instead of `null` for the same reason — they exist only to be
spread into RPC arguments, where "no bound" is spelled `undefined`.
The detection engine has been writing findings since #724 and nobody could
see them. This puts them on AI Traffic Analytics, below the tables that count
the tracking snippet's own visits and clearly attributed to Analytics — the
two origins describe different things and are never summed.

The card reads the nightly run rather than computing anything. The ranking,
the signal and the evidence were decided server-side, and recomputing them
here would let the card disagree with what the engine stored.

Its wording follows the signal the engine actually used. On a property with
revenue the column reads Revenue and the rank is "by revenue"; on one with
none it reads Engagement, says so, and points at Analytics key events as the
way to rank by what pages earn instead. Calling an engagement rank "your most
valuable page" would be a true sentence about the wrong thing, and the copy
is where that promise is kept or broken.

Nothing renders without findings, so the twenty-nine brands with no mapped
property meet no empty card explaining a feature they have not connected.
@gkhngyk
gkhngyk merged commit 2385482 into main Aug 14, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the feature/719-opportunity-surface branch August 18, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant