Repository navigation
feat(analytics): detect valuable pages AI engines send no traffic to - #724
Merged
Merged
Conversation
Phase 3 collected the traffic; nothing read it. This is the detection half of Phase 5: for each brand, which pages carry commercial weight and get nothing from AI engines. Detection only — no model runs in this path, and clustering, enrichment and the full lifecycle are deliberately absent until there is enough volume to verify them. The ranking signal is chosen from what the property actually reports, not assumed: revenue where there is revenue, then transactions, then key events, then engagement. That last fallback matters more than it looks — a property with no ecommerce and no configured key events would otherwise produce no findings at all, and "nobody set up conversion tracking" is not a reason to tell a customer there is nothing to look at. The signal is stored on every finding, because a surface that calls an engagement rank "your most valuable page" is making a true statement about the wrong thing. Qualifying needs both a percentile and absolute floors. A percentile alone qualifies a constant share of any site, so a brand with genuinely little to fix would still be handed a full list; a floor alone buries a small site's best page under a large one's long tail. The path exclusions move to a shared module, because the suggestion generator and this engine ask the same question and had no business answering it differently. Careers and legal pages join the transactional ones: they take real traffic and rank on engagement, but nobody acts on "your job posting is invisible to AI" — two of them showed up in the first live run. Findings that stop qualifying are stamped resolved rather than deleted, so the list can show that something improved. The sweep selects by the timestamp the upsert just wrote rather than excluding a list of paths, since that filter has to be built as a string and a landing page containing a comma would silently change which rows it matched. Verified against the live connected property: 15 findings, all correctly labelled engagement, percentiles 71–98, in under a second. Re-running changes nothing and leaves first_detected_at intact, so an open finding keeps its age. The two career pages moved to resolved when the exclusions landed.
8 of 12 tasks
gkhngyk
added a commit
that referenced
this pull request
Aug 14, 2026
) * chore(web): regenerate Supabase types and fix the RPC calls they now 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`. * feat(traffic): show the pages AI engines aren't sending traffic to 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.
This was referenced Aug 24, 2026
Merged
gkhngyk
added a commit
that referenced
this pull request
Aug 25, 2026
Detection (#724) finds pages that carry commercial weight and receive no AI referral. It could not say why, and the three reasons need different actions: answers already cite the page, a prompt we track points at it and no answer cites it, or nothing points at it at all. On the only connected property, 5 of 16 open findings are cited — one of them 104 times in 28 days — and the card told all 16 the same story. The classification is deterministic and joins nothing new: own-domain citations come from citation_urls, targeting from prompt_target_urls. No model runs in this path. Two repairs travel with it, both in the same RPC: - The reads were un-paginated selects over 28 days of ga_page_stats and ga_ai_traffic_stats, which PostgREST truncates at 1000 rows. ga-sync keeps up to 5000 pages a day, so a property with more than ~36 pages taking traffic on an average day overflows it; today's only property produces 743 rows and fits. The AI half truncating is worse than missing findings — a page that did receive AI traffic falls out of the lookup and is raised as a finding that is false. Aggregation moves into SQL and the caller pages through the rest. - Paths are matched case-insensitively but reported as Analytics spelled them. Folding the case turned a real slug, /blog/YmVzdC10b2, into a URL that 404s, which the finding would then have shown to the customer told to fix that page. Percent-decoding is total by design: 12.7% of own-domain cited URLs are encoded, and some decode to invalid UTF-8, which would abort the run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 3 (#704) collected the traffic; nothing read it. This is the detection half of Phase 5: for each brand, which pages carry commercial weight and get nothing from AI engines.
Detection only. No model runs in this path, and clustering, LLM enrichment and the full opportunity lifecycle are deliberately absent — they need more volume than this produces today, and a finding nobody can verify is worse than one that is merely narrow.
The signal is chosen, not assumed
That last fallback matters more than it looks: a property with no ecommerce and no configured key events would otherwise produce no findings at all, and "nobody set up conversion tracking" is not a reason to tell a customer there is nothing to look at.
The signal used is stored on every finding. A surface that calls an engagement rank "your most valuable page" is making a true statement about the wrong thing, and that is the kind of error a customer notices once and never trusts again.
Qualifying needs a percentile and absolute floors
This was the flaw in the scoring approach as originally sketched. A percentile alone qualifies a constant share of any site — "one customer has 7, another has 340" does not follow from it. A floor alone buries a small site's best page under a large one's long tail. Both conditions, so the count follows what a site actually has to fix.
Shared path exclusions
isTransactionalPathmoves out of the suggestion generator intopage-paths.js, because both surfaces ask the same question and had no business answering it differently. Careers and legal pages join the transactional ones — they take real traffic and rank on engagement, but nobody acts on "your job posting is invisible to AI". Two of them appeared in the first live run, which is how they were found.Matching stays on whole path segments:
/cartis excluded,/cartography-guidesis kept.Lifecycle seed
A finding that stops qualifying is stamped
resolved_atrather than deleted, so the list can show that something improved instead of silently shrinking. The sweep selects by the timestamp the upsert just wrote rather than excluding a list of paths — that filter has to be built as a string, and a landing page containing a comma or a quote would silently change which rows it matched.Related issue
Part of #719 — the detection layer. The intelligence and action layers stay open.
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
Automated —
cd server && yarn test(276 pass; 31 new acrosspage-opportunities.test.jsandpage-paths.test.js).The revenue, transaction and key-event branches cannot be exercised against real data today — the only connected property reports none of them — so they are pinned by tests instead. A customer connecting a property with real conversions must get the right answer on the first night with no code change, and that is what those tests hold.
Verified live against the connected property:
engagement, percentiles 71–98, in under a second.first_detected_atintact, so an open finding keeps its age rather than resetting nightly.resolvedwhen the exclusions landed, which is the resolve path working end to end.Detection is chained onto the GA sync rather than fired alongside it: it reads the tables the sync writes, so running both concurrently would score yesterday's window, and a sync failure now skips detection instead of letting it publish findings from stale data.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromserver/)yarn formatpasses (run fromserver/)supabase/schema.sqlregenerated viabash supabase/build-schema.sh