Repository navigation
feat(content): add the goals AI visitors reached and the top journey to the Content plan's AI results strip (CE-017, part 4b) - #1531
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]>
…to the Content plan's AI results strip (CE-017, part 4b) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…does, name the journey count, ask for Google Analytics for key events and revenue beside goals, and pick the top journey among the latest 2,000 conversions (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 a follow-up to fix before #1527's server is deployed.
What I checked:
- 00288's security.
brand_ai_conversionsissecurity definerwithsearch_path = public, and its tables are schema-qualified.- It runs the same organization check as
content_plan_insightsand returns null for a non-member. - Every read is by the brand id that was checked, the journey's pageviews included.
- It's revoked from public and anon, and granted to authenticated and service_role.
- It takes only 7, 30 or 90 days, as the Plan does.
- Counting.
- The goals count every conversion in the period, through 00287's partial index.
- The top journey is built the way 00287 builds its journeys (landing page, pageviews, the converting page, repeats in a row dropped). It's picked among the latest 2,000 conversions, the latest first among equal counts.
- The strip.
- It shows up to four goals, the most first, after Google Analytics' parts. Every goal has its plural key in
en.json. - Orders read "orders from journeys".
- The shorter "for key events and revenue" link shows only when goals do.
- The journey is shortened as on the Live page tab.
- A failed read leaves the strip as it was. The action test covers a database without 00288.
- It shows up to four goals, the most first, after Google Analytics' parts. Every goal has its plural key in
- Before the API deploy. Nothing breaks: the read is Supabase, not the API. With no events, the goals are empty and there's no journey, so the strip is as it is today.
- Merge. It merges on #1530 as is. Against the #1514–#1526 stack, only
schema.sqlconflicts.
Follow-up (please fix before #1527's server is deployed):
-
supabase/migrations/00288_brand_ai_conversions.sql:69-74: the 2,000 cap limits how many conversions are read, but not how many pageviews each one reads.- Each conversion still reads every pageview its visitor id has before it, with no lower time bound, and
normalize_page_pathruns per row. - Several conversions on one id re-read the same pages.
- A visitor id with a long history can therefore push the read past the 8 s timeout. The whole Plan page waits for it: one spinner for both reads (
page.tsx:183,content-plan.ts:387).
Use the same fix as 00287 (#1530, item 1), in the same follow-up migration:
- read pageviews only from
c.first_at - interval '1 day'; - cap the steps per journey at the latest N pageviews before the conversion;
- time it on the dev database with one visitor id that has 50,000 pageviews and 1,000 conversions.
- Each conversion still reads every pageview its visitor id has before it, with no lower time bound, and
…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]>
… a journey's latest 100 steps from a day before its first AI visit, by the stored keys (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]>
…a journey's first page (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, the same fix as #1530 is in 00288, edited in place and re-applied on dev (4cef3c0):
Timing on dev (the same 50,000 pageviews and 1,000 conversions): 0.65 s for 30 days, all 1,000 counted. Merged #1530, and with it current main. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good.
What I checked:
- Earlier item.
- Done (e6fc611).
paths(00288_brand_ai_conversions.sql:67-95) now builds each journey as 00287 does: the landing page, the latest 100 pageviews from a day before its first AI visit (limit 100, read backwards throughai_traffic_events_journey), and the converting page. Pages are compared by their stored keys.- The read is at most 2,000 conversions × 100 steps, and no address is worked out again per row.
- Several conversions on one id still read their own steps. Each read is capped, though, and #1527 keeps an id to 10 conversions a day.
- The goals still count every conversion in the period.
- Done (e6fc611).
- 00288 again.
- Only the journey read changed. It's still
security definerwithsearch_path = public, and its tables are schema-qualified. - The organization check runs before any read, and every read is by the brand id that was checked.
- It's revoked from public and anon, and takes only 7, 30 or 90 days.
- Only the journey read changed. It's still
- Migrations. 00288 also reads 00286's
page_keyandfirst_key(#1527 at fb41530). Apply in order: 00286, 00287, 00288.schema.sqlcarries 00288 as the file is. - Merges.
- Before the API deploy. The same as before: the strip reads Supabase. With no events, it looks as it does today.
…ersion-events # Conflicts: # supabase/schema.sql
…nversion-settings
…-live-page-conversions
|
Merged the PR below it forward (680f2f0), 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 (4cef3c0), three merges bring in #1530's forward merges: 680f2f0, fcb8539 and 618ba46.
- Re-merged with
merge-tree: the trees match, with no conflicts. - The PR's own change on top of #1530 is the same as at round 31, line for line.
- Re-merged with
- 00288 hasn't changed since round 31: the file is the same at 4cef3c0 and 618ba46. Apply the migrations in order: 00286, 00287, 00288.
- 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 strip reads Supabase. With no events, it looks as it does today.
Summary
CE-017, part 4b: the Content plan's AI results strip. Stacked on #1530 (Live page tab), which is on #1529, #1528 and #1527. The PR's own changes are its commits after #1530's branch.
The Content plan's AI results strip (spec v2 §4 point 8, CE-014) shows the visits from AI assistants and Google Analytics' key events and orders. With conversions on, it now also says which goals the AI Traffic snippet followed those visitors to, plus the top journey, for example:
00288_brand_ai_conversions.sql:brand_ai_conversions(brand, days)reads the same 7 / 30 / 90 whole UTC days to yesterday ascontent_plan_insights. It's a security definer with an organization check, as that function is. It returns:content_page_conversions(feat(content): show conversions from AI journeys through a page on the Live page tab (CE-017, part 4a) #1530) builds them. It's picked among the period's latest 2,000 conversions, so a big brand's 90 days don't hold the Plan page up. The goals still count every conversion.getContentPlanInsightsreads it beside the insights. If it fails (for example, on a database before 00288), the strip still shows without it.Related issue
Content Editor spec v2, CE-017 (§4 point 8, §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_eventsin the last 30 days.I checked it in the browser at 1024 px, light and dark, on the demo brand with test journeys: 4 visits · 2 orders from journeys · 1 newsletter signup and the top journey. They were removed after. I also ran the function on the dev database in a rolled-back transaction.
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.
🤖 Generated with Claude Code