Skip to content

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

Merged
gkhngyk merged 50 commits into
ansvisor:mainfrom
cihan-gyk:feature/ce-017-plan-strip
Oct 26, 2026
Merged

gkhngyk merged 50 commits into
ansvisor:mainfrom
cihan-gyk:feature/ce-017-plan-strip

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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:

From AI visits · 30 full days to yesterday (UTC): 4 visits · 2 orders from journeys · 1 newsletter signup
Top journey: ChatGPT › /blog/cold-brew-at-home › /shop/cold-brew-kit › /checkout › Purchase · 2 conversions

  • Migration 00288_brand_ai_conversions.sql: brand_ai_conversions(brand, days) reads the same 7 / 30 / 90 whole UTC days to yesterday as content_plan_insights. It's a security definer with an organization check, as that function is. It returns:
  • getContentPlanInsights reads it beside the insights. If it fails (for example, on a database before 00288), the strip still shows without it.
  • The strip:
    • adds up to four goals, the most first, after Google Analytics' parts ("48 signups · 20 demo forms");
    • orders read orders from journeys, so they aren't taken for Analytics' orders;
    • the top journey is a line of its own: the source and goal as chips, as on the Live page tab. A journey of more than five pages shows the first, "…" and the last three, as there;
    • without Google Analytics, when goals show, the link reads "Connect Google Analytics for key events and revenue." instead of "… to see what they did next."

Related issue

Content Editor spec v2, CE-017 (§4 point 8, §7b).

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. Apply 00286–00288, and turn conversions on for a brand with ai_traffic_events in the last 30 days.
  2. Open Content › Plan. The strip lists the goals after the visits, with a Top journey line under them.
  3. Switch to 7 or 90 days. The goals and journey follow.
  4. Without conversions, the strip is as before.

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

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 6 warnings are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Migration added as a new file; bash supabase/build-schema.sh run and supabase/schema.sql included
  • Changes are focused — one concern per PR

Web: yarn test and yarn build. Tests:

  • the action reads both functions, and goes on without the conversions when they fail;
  • the strip shows four goals at most, the most first, and the top journey, shortened when it's long;
  • without Google Analytics, the strip shows the goals and the shorter link text, and no journey line when there's none.

A pre-push review ran.

🤖 Generated with Claude Code

cihan-gyk and others added 11 commits October 26, 2026 02:16
… 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]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 26, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with a follow-up to fix before #1527's server is deployed.

What I checked:

  • 00288's security.
    • brand_ai_conversions is security definer with search_path = public, and its tables are schema-qualified.
    • It runs the same organization check as content_plan_insights and 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.
  • 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.sql conflicts.

Follow-up (please fix before #1527's server is deployed):

  1. 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_path runs 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.

cihan-gyk and others added 16 commits October 26, 2026 09:36
…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]>
… "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]>
…-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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Thanks, the same fix as #1530 is in 00288, edited in place and re-applied on dev (4cef3c0):

  • the top journey is picked among the latest 2,000 conversions;
  • each journey's steps are the landing page, the latest 100 pageviews before the conversion (from a day before its first AI visit) and the converting page, by the stored keys;
  • the goals count every conversion.

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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

What I checked:

  • Earlier item.
    1. 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 through ai_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.
  • 00288 again.
    • Only the journey read changed. It's still security definer with search_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.
  • Migrations. 00288 also reads 00286's page_key and first_key (#1527 at fb41530). Apply in order: 00286, 00287, 00288. schema.sql carries 00288 as the file is.
  • Merges.
    • 3188a1e and 4cef3c0 change nothing beyond merging their parents.
    • The web side is as at round 30. The strip calls journeyPages(pages) without a page, so it shortens journeys as before.
    • On current main, only schema.sql conflicts. CI passes.
  • Before the API deploy. The same as before: the strip reads Supabase. With no events, it looks as it does today.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged the PR below it forward (680f2f0), which brings in main (00285 and the brief and editor work). No conflicts; schema.sql matches build-schema.sh.

Checks after the merge:

cihan-gyk and others added 12 commits October 26, 2026 14:48
…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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged #1527's holdsEmail fix forward (618ba46). No change of its own.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
  • 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.sql matches the build.
    • The PR merges cleanly on 4efa150. On today's main, only schema.sql conflicts.
    • CI passes.
  • Before the API deploy. As before: the strip reads Supabase. With no events, it looks as it does today.

@gkhngyk
gkhngyk merged commit 4b05f7d into ansvisor:main Oct 26, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants