Repository navigation
Consent on headless storefronts: call the store's API host directly - #250
Merged
Merged
Conversation
ericingram
approved these changes
Nov 12, 2026
…rigin isn't Swell's consent.set() calls the page's origin first. It switches to `PUT <store>.swell.store/api/session/consent` with `direct: true` and the page's ad cookies only when the origin answers but not as Swell: a 404 or 405, a page that isn't Swell's answer, or Swell's refusal of a forwarded call (`storefront_origin_required`). Never on a 5xx, a 429 or a network failure, and only to a host on `.swell.store`. It keeps the visitor token it gets in the `swell-visitor` cookie of the page's domain. init() records an ad landing (a click id or UTM tags) without an answer, after the page's load, once per landing and store. The tab keeps, per API host in sessionStorage, that its calls go direct and that the store records nothing (`capture: false`), which stops the landings. A failing cookie adapter no longer fails a recorded call, and connection errors carry `err.status`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dminch
force-pushed
the
feature/attribution-headless
branch
from
November 12, 2026 14:21
d8b933c to
6a166c9
Compare
- A 429 or a 5xx never switches to the API host, whatever its code, and an answer with no effect counts as not Swell's. - A page on Swell's own domain never switches: an answer that seems not to be Swell's there is a failure, such as a body cut off. - A late answer keeps its flags for the API host it was sent to, not the one the client was initialized for since. - A landing queued behind an answer that nothing is recorded isn't sent, nor one whose client a later init pointed at the page's origin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Headless storefronts serve their pages themselves, so the storefront gateway never sees the ad landing and the consent call to the page's origin goes nowhere. With this change, swell-js records consent and ad landings on those storefronts by calling the store's API host directly.
consent.set()calls the page's origin first, as before. It switches toPUT <store>.swell.store/api/session/consentwithdirect: trueonly when the origin answers but not as Swell:storefront_origin_required. Any other refusal doesn't switch.It never switches on a 5xx or a 429 (whatever the code), on a network failure, or from a page on
*.swell.store, whose origin Swell serves.The direct call sends the page's ad cookies (
_fbp,_fbc,_ttp, …) in the body. It gets the visitor token back and sets it as theswell-visitorcookie on the page's domain, which swell-js already sends asX-Visitor.Only Swell's API host. The direct call goes only to a host on
.swell.store. With aurlthat points at the storefront's own server, the server would forward the call with its own IP and country, so nothing goes direct.init()records an ad landing (a click id or UTM tags) without an answer, once per landing and store. It waits for the page'sload, so the ad pixels have set their cookies first.Per tab and API host,
sessionStoragekeeps that the calls go direct (swell-consent-direct:<origin>) and that the store records nothing (swell-consent-off:<origin>, after an answer withcapture: false). The second one stops the landing calls, andconsent.set()still goes. TheConsenttype hascapture?: false.A failing cookie adapter no longer fails a call that Swell already recorded.
api.jsnow setserr.statuson connection errors too, so that 404 and 405 can be told from other failures.The gateway side is in swell-admin: schema/swell-admin!3468. The gateway accepts a direct call only when the browser made it:
Sec-Fetch-Site: cross-site, noCF-Worker, and no proxy named inX-Forwarded-Forbefore Cloudflare's address. Deploy the gateway first.Limits
Sec-Fetch-Site(Safari before 16.4) aren't recorded.Version
The dashboard and the docs say "swell-js 5.10.0 or later". Please confirm the release version, or tell me which one to use.
Testing
npm test: 457 tests pass. New tests cover:capture: falsestopping the landings;*.swell.storehost through the gateway: landing, consent, visitor cookie and order snapshot all checked. Aurlof a proxy makes no direct call.🤖 Generated with Claude Code