Repository navigation
feat(content): show conversions from AI journeys through a page on the Live page tab (CE-017, part 4a) - #1530
Conversation
… Traffic snippet, for brands with conversions on (CE-017, part 1: server) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rder id sent first by anyone can't shut the real one out; keep no label or order ref that looks personal; check an event before reading the brand (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ippet, with consent first: journey pages, forms, ansvisor('conversion'), Consent Mode (CE-017, part 2)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ent Mode default, read Consent Mode before keeping anything, take an id kept earlier as consent given, send only values the server takes, count a form once a page (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e after t.js, pause on a denying default even beside regional ones, and take a queued "denied" before keeping or sending anything (consent review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…onsent call, forms, calls and the Shopify pixel to install (CE-017, part 3) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ify's cookie banner's answer to the snippet, keep the pixel's amount and units in the server's range, and say what the snippet really does (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e Live page tab: goals by site type, by source, top journeys (CE-017, part 4a) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…time; count only orders' and bookings' value as revenue; give each goal its own card; mark this page from the database's key; keep what was counted on show while conversions are off (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups to fix before #1527's server is deployed.
What I checked:
- 00287's security.
content_page_conversionsissecurity definerwithsearch_path = public, and every table it reads is schema-qualified.- It runs the same organization check as
content_page_results(00210) before it reads anything, and returns null for a non-member. - Every read of
ai_traffic_eventsis by the brand id that was checked, the pageview subqueries included, so it can't reach another brand's or organization's events. - It's revoked from public and anon, and granted to authenticated and service_role. It opens nothing beyond what the table's select policy (00286) already lets a member read.
- Counting.
- The filter is on conversions, so a conversion counts once even when its journey landed on the page, went through it and ended on it.
- The window is whole UTC days to yesterday, as in 00210.
- Revenue is orders' and bookings' value per currency, and a value without a currency is left out. The Units card reads orders' units.
- Sources are first touch. Journeys are ranked by count, and the latest comes first among equal counts.
- A journey's steps start with
first_url. That's right, because the snippet sends no pageview for the first landing. Repeats in a row are dropped, and a pageview at the conversion's time comes before it.
- The journey key. Keying by
visitor_idrather thanfirst_atis right. The server clampsfirst_atper event (traffic-events.js:109), so it can differ within one journey. The snippet makes a new id only when there's none, or when the old one is past 30 days. - Index. The partial index matches the
kind = 'conversion'predicate. A plaincreate indexon the table 00286 just made is quick. Pageview lookups useai_traffic_events_journey. - The tab.
- A failed read hides only this section.
- Every key it builds (
cards.*,goals.*) exists inen.json, and the goal keys match the table's check. - The settings link opens Tracking:
TABShas it. - Tests cover the cards per site type, the sources, shortening, conversions off and a failed read.
- Before the API deploy. The section reads Supabase, not the API, so nothing breaks. With no events yet:
- a brand with conversions off (every brand today) sees the note and the link to Brand settings;
- a brand that turns them on sees cards at 0 and "No conversions from AI journeys through this page in this period."
- Merge. The stack merges on current main. Against the #1514–#1526 stack, only
schema.sqlconflicts.
Follow-ups (please fix before #1527's server is deployed):
-
supabase/migrations/00287_content_page_conversions.sql:85-92and:102-108: for each conversion, the function reads all the pageviews its visitor id has before it.- Those reads have no lower time bound and no cap, and nothing limits how many pageviews one visitor id can have.
throughmakes this read for every conversion of the brand in the period. 00288 caps it at 2,000; this function doesn't.pathsthen reads the same pageviews again for each matching conversion, withnormalize_page_pathper row.- So a visitor id with a long history, and several conversions on it, can push the read past the 8 s statement timeout. The whole tab waits for this read (
_impact-tab.tsx:77) before it shows without the section.
In a follow-up migration (00288 needs the same, so one migration can replace both):
- Read pageviews only from the start of the journey:
p.occurred_at >= c.first_at - interval '1 day'. The day covers the server's 24-hour clock allowance, sincefirst_atis clamped per event. It also keeps the read within about 31 days of the conversion. - Cap the steps per journey, in both the
throughcheck andpaths: the latest N pageviews before the conversion (say 100). - Check the page once per visitor, not once per conversion: take the earliest time each visitor id saw the page, then join. Then several conversions on one id don't re-read the same pages.
- On the dev database, time it on one visitor id with 50,000 pageviews and 1,000 conversions in the period. It should stay well under the timeout.
-
web/src/lib/content/conversions.ts:95-97: a journey of more than five pages shows the first page, "…" and the last three. If the page itself is in the hidden middle, the journey shows without This page, though the docs (#1532) say it's marked. When you shorten a journey, keep the page in view, e.g. the first page, "…", This page, "…" and the last page. Add a test.
…id and one tracking code can store, keep an order's id only as a hash, and drop an index nothing reads (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…itor takes back, run queued consent calls first, add no hooks for a visitor it doesn't follow, and never stop the site's own push or route change (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nversion-settings
… "Don't wait" too; send no order ref without Shopify's order id, never the checkout token; say a privacy policy isn't consent (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
… journey's reads compare keys instead of working each address out again (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nversion-settings
…-live-page-conversions
…-page-conversions # Conflicts: # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
…once for the page, from a day before its first AI visit, by the stored keys; a journey's latest 100 steps; the latest 2,000 journeys), and keep this page in view when a journey is shortened (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…se that ran 00286 before them, and keep a handle such as /@acme in a path: only an email goes (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s part fails, and test the push wrapper with a send that fails (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nversion-settings
…hows the consent call too (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-live-page-conversions
…a journey's first page (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, both are fixed here rather than in a follow-up migration (0303679). 00287 isn't merged yet, so it's edited in place, and re-applied on the dev database.
Also: when this page comes right after the first page, no "…" is shown between them. Merge: I merged |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good.
What I checked:
- Earlier items.
- Done (5f8b528).
- The page check runs once per visitor id.
seen(00287_content_page_conversions.sql:89-105) takes the earliest time each visitor id saw the page, bypage_key, from a day before its first AI visit to its last conversion in the period. A conversion then counts through the page when that time is at or before the conversion and no more than a day before its own first visit (:113).- The snippet keeps one first visit per id. The server moves
first_atonly to the event's own time, and only when a browser clock runs ahead, by a day at most (traffic-events.js:131,:144). So the day's allowance misses no pageview of the journey. seenisn't capped by a count, but #1527's per-visitor limits (300 pageviews in 30 days,traffic.js:249-259) keep each read to a few hundred rows.
- The snippet keeps one first visit per id. The server moves
- A journey's steps are the landing page, the latest 100 pageviews from a day before its first visit (
limit 100, read backwards throughai_traffic_events_journey), and the converting page (:125-140). - The journeys come from the latest 2,000 matching conversions (
:145). Goals, revenue and sources still count all of them. - Pages are compared by the keys stored with each event (
page_key,first_key), so no address is worked out again per row. - Timing. Your dev timing (0.87 s for one id with 50,000 pageviews and 1,000 conversions) covers a case the server's limits now rule out. The read is bounded at about 2,000 × 100 step rows, plus one short read per converting visitor id.
- The page check runs once per visitor id.
- Done (5f8b528, 0303679).
journeyPages(pages, page)(conversions.ts:97-104) shows the first page, "…", This page, "…" and the last page when the page would fall in the gap. When the page comes right after the first, no "…" sits between them. Tests cover the helper and the tab.
- Done (5f8b528).
- 00287 again.
- It's still
security definerwithsearch_path = public, and every table is schema-qualified. - The organization check runs before any read. Every read of
ai_traffic_events, the newseenand step reads included, is by the brand id that was checked. - It's revoked from public and anon, and granted to authenticated and service_role.
- Counting.
seenhas one row per visitor id, so the left join adds no rows, and each conversion counts once.conversionsandthroughare each read more than once, so they're computed once.
- It's still
- Migrations. 00287 reads
page_keyandfirst_key. 00286 has them only at #1527's current head (fb41530), so apply that version of 00286 first. The partial index goes on a table that's still empty, so it's quick.schema.sqlcarries 00287 as the file is. - Merges.
- f706346, db7d276 and ce2f3f4 change nothing beyond merging their parents.
- db7d276 (main) had one conflict,
page.test.tsx, and it keeps both sides' mocks. - On #1529 plus main, the PR's own change is 11 files: the migration,
schema.sql, types,en.json, the action, the tab, its section and helper, and their tests. - On current main (with #1514), only
schema.sqlconflicts. CI passes.
- Before the API deploy. The same as before: the section reads Supabase, so nothing breaks. Every brand has conversions off today, so each sees the note and the link to Brand settings.
…ersion-events # Conflicts: # supabase/schema.sql
…nversion-settings
…-live-page-conversions
|
Merged the PR below it forward (bcb4d85), which brings in Checks after the merge:
|
…irst, so a long address reads fast and an encoded dot is caught (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or says no (review follow-up) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nversion-settings
…-live-page-conversions
…ush review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nversion-settings
…-live-page-conversions
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good.
What I checked:
- Since round 31 (0303679), three merges bring in #1529's forward merges: bcb4d85, 3eb0144 and 2b6e1fd.
- 00287 hasn't changed since round 31: the file is the same at 0303679 and 2b6e1fd. It reads 00286's
page_keyandfirst_key, and 00286 hasn't changed either. So the order is still 00286, then 00287. - Merge state.
schema.sqlmatches the build.- The PR merges cleanly on 4efa150. On today's main, only
schema.sqlconflicts. - CI passes.
- Before the API deploy. As before: the section reads Supabase, so nothing breaks once 00287 is applied. Every brand has conversions off, so each sees the note and the link to Brand settings.
Summary
CE-017, part 4a: the Live page tab. Stacked on #1529 (Settings), which is on #1528 (snippet) and #1527 (server). The PR's own changes are its commits after #1529's branch.
The editor's Live page tab gets Conversions from AI journeys (spec §7 points 26–28), from the AI Traffic snippet with conversions on. It sits under the existing Results from AI visits, which comes from Google Analytics; the two read side by side.
Migration
00287_content_page_conversions.sql:content_page_conversions(brand, page, days)content_page_results(00210).kind = 'conversion'): most events are pageviews.The section:
The Plan page's AI results strip comes in part 4b; the docs in part 5.
Related issue
Content Editor spec v2, CE-017 (§7 points 26–28, §7b).
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
ai_traffic_eventsfor one of its live pages. The snippet from feat(traffic): follow an AI visitor to conversions in the tracking snippet, consent first (CE-017, part 2) #1528 makes them, or insert a few.I checked it in the browser at 1024 px, light and dark, on a demo e-commerce brand's published page with three test journeys:
The test events and settings were removed after. I also ran the function on the dev database in rolled-back transactions:
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 6 warnings are in files this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)bash supabase/build-schema.shrun andsupabase/schema.sqlincludedWeb:
yarn testandyarn build. Tests:A pre-push review ran; its fixes are the last commit:
The migration was applied on the dev database again after it, and lint, typecheck,
yarn testandyarn buildrerun.🤖 Generated with Claude Code