Skip to content

feat(traffic): turn conversions on in brand settings, with what to install and the Shopify pixel (CE-017, part 3) - #1529

Merged
gkhngyk merged 32 commits into
ansvisor:mainfrom
cihan-gyk:feature/ce-017-conversion-settings
Oct 26, 2026
Merged

gkhngyk merged 32 commits into
ansvisor:mainfrom
cihan-gyk:feature/ce-017-conversion-settings

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

CE-017, part 3: brand settings and the Shopify pixel. Stacked on #1528 (the snippet), which is on #1527 (server). The PR's own changes are its commits after #1528's branch.

The plan had the Shopify pixel and the Settings section as two PRs. The pixel's code is built in the web app, as the snippet's tag always was, from the public API URL and the brand's tracking code, so it ships with the Settings section that shows it. Five CE-017 PRs instead of six.

Brand settings › Tracking › Conversions from AI visits (new card, under the existing tracking card):

  • Track conversions from AI visits (checkbox, saved at once). Admins and managers change it, as the brands writes allow; others read it.
    • Off: the snippet keeps nothing in the browser.
    • On: it keeps a random id for AI visitors only.
  • Consent (when on):
    • Wait for the visitor's consent (recommended, the default);
    • Don't wait: our own banner covers it.
  • What to install, each with a copy button that says what it copies:
    • the tag with conversions (data-c="1" data-consent="…"), with the queue stub on the line above it. The tag is deferred, so a cookie banner's or a thank-you page's ansvisor(…) call always runs first; without the stub it would throw and be lost;
    • with wait, the consent call (ansvisor('consent', 'granted')) and a note on Google Consent Mode, including that a banner set up inside GTM needs a tag that runs the call;
    • forms, as the snippet counts them:
      • contact and newsletter forms with an email field count as signups too;
      • data-ansvisor-goal="demo" names a goal, and data-ansvisor="off" leaves a form out;
      • a password login doesn't count;
      • a signup shouldn't also be called from code for the same form;
    • the site's own calls: a conversion, and an order with value and units;
    • Shopify store:
      • the Customer events custom pixel, with where it goes and its privacy settings (Permission: Analytics);
      • with wait, a theme script that tells the snippet the answer from Shopify's own cookie banner (Customer Privacy API: visitorConsentCollected, and analyticsProcessingAllowed() on each page). Without it, the default mode would never keep an id on a Shopify store;
      • a note that a headless store whose checkout is on another domain can't link its orders this way;
      • it shows at once for an e-commerce site and behind a button for others.
  • What it can't see (spec §7b point 35):
    • visitors who refuse cookies;
    • AI visits without a referrer (Direct);
    • AI Overviews and AI Mode, which stay an estimate;
    • journeys across subdomains (www to app);
    • forms in an iframe;
    • and no name, email or IP address is stored.

The Shopify pixel (shopifyPixelCode): on checkout_completed it sends the order, its value, currency, units and the order id (the checkout's token only where Shopify gives none). An amount or units the server wouldn't take are left out, so the order still counts. It reads the visitor id the snippet kept on the storefront (the checkout is on the shop's domain) and sends to /track/:code as the snippet's events do (#1527). A visitor the snippet didn't follow sends nothing. The checkout's address goes as /checkout, because the thank-you page's path carries the order's token.

One tag everywhere: the existing tracking card and the Traffic page's snippet banner and dialog build the tag with trackingSnippetTag. A brand with conversions on is never shown the old tag to copy.

Brand gets conversionsEnabled / conversionsConsent, updateBrand takes them (an unknown consent mode is refused), and types/supabase.ts has the columns from 00286.

Related issue

Content Editor spec v2, CE-017 (§7b points 31, 32, 35).

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. With 00286 applied, open Brand settings › Tracking as an admin or manager.
  2. Tick Track conversions from AI visits. A toast says it's on.
  3. The tag in both cards has data-c="1" data-consent="wait". The steps show the consent call, forms, calls and the queue stub.
  4. Switch Consent to Don't wait. The tag says data-consent="always" and the consent step goes.
  5. For an e-commerce brand the Shopify pixel shows at once; for a B2B brand, behind Show the Shopify pixel.
  6. As a member who isn't an admin or manager, the checkbox is disabled, with a note.

I checked it in the browser at 1024 px, light and dark, on the demo brand: the tag, steps, Shopify pixel and limits. The setting was turned off again afterwards.

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/)
  • Changes are focused — one concern per PR

Web: yarn test and yarn build. Tests:

  • the tag with and without conversions;
  • the pixel run as Shopify runs it (fake analytics, browser.localStorage, fetch), checking its payload, a visitor not followed, a missing amount and the token fallback;
  • the card: on/off, a failed save turned back, consent mode, Shopify pixel by site type, members;
  • updateBrand's new fields, and the Traffic dialog's tag.

A pre-push review ran; its fixes are the last commit:

  • the queue stub with the tag;
  • the Shopify consent script;
  • the pixel's ranges;
  • texts that say what the snippet really does, including that turning conversions off needs the old tag back on the site;
  • the card following the brand as the store reads it;
  • copy buttons that say what they copy.

After them: lint, typecheck, yarn test and yarn build again.

🤖 Generated with Claude Code

cihan-gyk and others added 7 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]>

@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.

Needs changes.

What I checked:

  • Without conversions.
    • The Tracking card and the Traffic page's banner and dialog show the same tag as before, byte for byte (trackingSnippetTag(…, null), tested).
    • The new card shows only its checkbox.
    • The brand's new columns come in through select('*') in mapBrandRow.
  • Who changes it.
    • The checkbox and the consent select are disabled for anyone who can't manage.
    • updateBrand writes through RLS, whose update policy is admins and managers only.
    • An unknown consent mode is refused here and by 00286's check. A failed save turns the control back.
  • The tag.
    • The queue stub goes above the deferred tag, so a banner's or a thank-you page's earlier call is queued and replayed by t.js.
    • The Select has items, and the strings are in en.json.
  • Turning it off. The toast and the help say the tag without conversions must go back on the site, and the Tracking card then shows that tag.
  • The Shopify pixel.
    • It sends only for a visitor the snippet kept on the storefront, so only after consent there, and it runs under Permission: Analytics.
    • The address goes as /checkout. Value and units go only within the server's ranges, and the server checks the currency again.
    • The consent script passes Shopify's answer both ways (visitorConsentCollected) and reads it again on each page.
  • Before the API deploy.
    • The old t.js ignores data-c: it keeps nothing and sends what it did before.
    • The old /track answers the pixel's body with 204 and stores nothing, since the body has no s.
    • A brand can turn conversions on and install the tag, but nothing is kept or stored until the API is deployed. No live feature changes.
  • Merge. Linear on #1528, no merge commits.

Before merge:

  1. web/src/lib/conversion-tracking.ts:41-42, _conversions-card.tsx:216-224, en.json:7966-7967: the consent step gives only ansvisor('consent', 'granted'), "once the visitor agrees, and on every page after".
    • The snippet takes an id kept earlier as consent on later pages (#1528).
    • So on a site set up as the card says, a visitor who takes consent back in the banner is still followed until the 30 days run out. Nothing tells the snippet.
    • Show ansvisor('consent', 'denied'); beside it, "when the visitor says no or takes consent back", and say the GTM tag needs both.
    • Show the step with always too, without the granted line: a site whose own banner covers it still has visitors who refuse.
  2. conversion-tracking.ts:111: without an order id, the pixel sends checkout.token as the order ref.
    • That token is why the address goes as /checkout (:79-80, :105): the thank-you page's path carries it.
    • 00286 keeps order_ref for the order's own id at the shop.
    • Send no ref without an order id. Such an order then just isn't deduplicated.
    • Change the test "names the order by its token without an id".

Follow-ups:
3. en.json:7960: "or privacy policy". Where consent is needed, a privacy policy isn't consent to analytics storage. Say "Use this only if your cookie banner already asks for analytics storage, or where no consent is needed."
4. The pixel and the consent script are tested with stand-ins only. Before brands are pointed at them, try them once on a Shopify development store:

  • the pixel reading the storefront's ansvisor_v at checkout through browser.localStorage;
  • the fetch from the pixel's sandbox;
  • loadFeatures and visitorConsentCollected in a theme.

cihan-gyk and others added 13 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]>
…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]>
…hows the consent call too (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Thanks, both are in, plus follow-up 3 (08c24cf).

  1. The refusal call. DENY_CALL = ansvisor('consent', 'denied');.
    • With Wait, the step shows the grant and the refusal, "when the visitor says no, or takes consent back".
    • With Don't wait, the step is titled "When the visitor refuses" and shows the refusal only.
    • The GTM line now says a banner set up in Tag Manager needs a tag for each line.
    • Tests: both modes' codes.
  2. No token as the order ref. The pixel sends ref only with Shopify's order id; an order without one just isn't deduplicated. The test now checks there is no ref and no token in the body.
  3. alwaysHint: "Use this only if your cookie banner already asks for analytics storage, or where no consent is needed."

Also: in Wait mode, the refusal sits under its own "When the visitor refuses" line, below the grant.

Item 4 (a Shopify development store) isn't something I can do from here. I've noted it as owed before brands are pointed at the pixel.

Web: yarn lint (0 errors), typecheck, test (3,953 passed) and build. Merged #1527 and #1528's fixes in.

@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 follow-ups.

What I checked:

  • Earlier items.
    1. Done (54bbb5b, 08c24cf).
      • DENY_CALL (web/src/lib/conversion-tracking.ts:49) shows in both modes (_conversions-card.tsx:218-231).
        • With Wait, it sits under its own "When the visitor refuses" line, below the grant.
        • With Don't wait, the step is the refusal only, under that title.
      • denyHelp says when to call it and what it does, and that matches #1528's deny().
      • The GTM line now asks for a tag for each line.
      • Tests cover both modes' codes and titles.
    2. Done.
      • The pixel sends ref only with Shopify's order id (conversion-tracking.ts:119-120).
      • The test checks that the body has no ref and no token anywhere. The comment says why.
    3. Done (en.json:7961).
    4. Open, and noted by Cihan as owed: a run on a Shopify development store. It's kept below.
  • No regressions.
    • The two commits touch only the card and its test, conversion-tracking.ts and its test, and en.json.
    • Without conversions, the tags are as before.
    • The Shopify consent script is unchanged and still shows with Wait only.
  • Merges. fdfd09d, e517de2 and db54491 only merge their parents (re-merged with merge-tree: the trees match). The PR merges on main with a conflict only in schema.sql. CI passes at 08c24cf.
  • Before the API deploy. Same as round 30.
    • The old t.js ignores data-c.
    • The refusal call waits in the queue stub like the grant, and does nothing until the new t.js runs.
    • The pixel's post stores nothing.
    • No live feature changes.

Follow-ups:

  1. en.json:7969 (denyHelp): with Don't wait, one refusal call doesn't last beyond the page it's made on.
    • A visitor who refused and later comes back from an AI answer gets a new id, kept as soon as the page loads (tracking-script.js:152, :173 in #1528).
    • They're then followed for 30 days, unless the site calls the refusal on that page too.
    • Add "and on every page after, while they say no", as consentHelp does for the grant. Under Wait the extra calls do no harm: nothing is kept without a grant.
  2. Still owed from round 30: before brands are pointed at the pixel, run it once on a Shopify development store:
    • the pixel reading ansvisor_v through browser.localStorage at checkout;
    • the fetch from the pixel's sandbox;
    • loadFeatures and visitorConsentCollected in a theme.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged the PR below it forward (5d3db9c), 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

Copy link
Copy Markdown
Collaborator Author

Follow-up 1 is done (ee40a8e): denyHelp now reads "Call this when the visitor says no, or takes consent back, and on every page after while they say no: …", matching consentHelp's "on every page after". #1532's guide says the same.

Follow-up 2, the Shopify development store run, is still owed: it needs a store, so it's yours. The pixel isn't pointed at by any brand until then.

@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 follow-ups.

What I checked:

  • Earlier items.
    1. Done (3d79c0a, c67caab). denyHelp (web/messages/en.json:8008) now adds "and on every page after, while they say no", the way consentHelp (:8006) does for the grant.
      • The rest of the line matches #1528's deny() (tracking-script.js:143): the stored id is deleted, what waited is dropped, and nothing is sent from that page until a grant.
      • With Don't wait, repeating the call is what stops a returning AI visitor's new id from being kept at load (:152, :173).
      • With Wait, the card shows the same line. The extra calls do no harm, because nothing is kept without a grant.
    2. Still owed, as Cihan notes: the run on a Shopify development store. It stays below.
  • Merges. 5d3db9c, 0f1e974 and ee40a8e only merge #1528 forward.
    • Re-merged with merge-tree: the trees match.
    • Apart from denyHelp, the PR's own change is the same as at round 31.
    • schema.sql matches the build.
    • The PR merges cleanly on 4efa150. On today's main, only schema.sql conflicts.
    • CI passes at ee40a8e.
  • Before the API deploy. Same as round 31:
    • The card goes live with the merge.
    • The old t.js ignores data-c, and the calls wait in the queue stub.
    • No live feature changes. The new words are text only.

Follow-ups:

  1. Still owed from round 30: before brands are pointed at the pixel, run it once on a Shopify development store. Check:
    • that the pixel reads ansvisor_v through browser.localStorage at checkout;
    • that the fetch works from the pixel's sandbox;
    • that loadFeatures and visitorConsentCollected work in a theme.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 26, 2026
@gkhngyk
gkhngyk merged commit cd307a9 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants