Repository navigation
✨ [Shopify] Allow a custom cookie store for session persistence - #5109
BeltranBulbarellaDD wants to merge 14 commits into
Conversation
Add an internal `sessionCookieAccess` init option and a `CookieApi.CUSTOM` cookie API, so integrations running where neither `document.cookie` nor the Cookie Store API is available (e.g. a Shopify Web Pixel worker) can persist the session in the top frame cookies. When provided, `selectCookieStrategy` only probes this access, and the legacy `_dd_s` cookie migration (read through `document.cookie`) is skipped. `buildCookieString` is extracted from `setCookie` so such accesses can format cookies the same way. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Bundles Sizes Evolution
|
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed 🎯 Code Coverage (details) Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: b318d3a | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3a193d5b2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Default workers to cookie persistence when a custom cookie access is provided, instead of memory. - Treat a throwing cookie access factory as unauthorized cookies in `areCookiesAuthorized`, so the next persistence fallback is tried. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@codex pls review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f17c11b037
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The strategy only serves the Shopify Web Pixel integration for now, so name it after it: `sessionInShopifyCookie.ts`, `ShopifySessionStoreStrategyType` (`type: 'shopify'`), `selectShopifyCookieStrategy` and `initShopifyCookieStrategy`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
| * | ||
| * @internal | ||
| */ | ||
| shopifyCookieAccessFactory?: CookieAccessFactory | undefined |
There was a problem hiding this comment.
❓ question: Would this option always provided in Shopify?
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b00fdc32b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| previousValues = values | ||
| } | ||
|
|
||
| // Custom stores have no change event: poll them, like the `document.cookie` access does |
There was a problem hiding this comment.
The thing with the function above, is that it is sync, ours is async. I could make them use the same reusable function but that would make both async.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9568c7e35d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Motivation
The upcoming Datadog Shopify App tracks checkout through a Web Pixel app extension (#5108), which runs in a strict sandbox Web Worker. There, neither
document.cookienor the Cookie Store API is available: cookies can only be accessed through Shopify's asynchronousbrowser.cookieAPI, which runs in the top frame.To attach checkout events to the session started by the storefront SDK, the Web Pixel SDK needs to read and write the same
_dd_s_v2cookie through that API. This PR lets the session store persist the session through such a host-provided cookie store.Changes
sessionPersistencenow also accepts an internal cookie store ({ get, set }), such as Shopify'sbrowser.cookie. It gets its owncustom-cookiestrategy, which reuses the cookie strategy's session logic (extracted tocreateCookieSessionStore()) on top of a newcreateCustomCookieAccess(). That way, the session cookie is read and written the same way, only through the provided store.document.cookieis._dd_scookie isn't read, since that needsdocument.cookie, which doesn't exist in a worker.How it's used in the Web Pixel SDK (#5108)
The Web Pixel SDK passes Shopify's cookie API as the persistence:
Tested end to end in a dev store with the POC app, with both the storefront theme block and the Web Pixel extension loading local builds of this branch:
_dd_s_v2cookie read on the storefront and on checkout has the sameid,aidandcreated. Onlyexpiremoves forward as checkout events expand the session._dd_s_v2on the checkout page and reloading, the Web Pixel creates a new session and writes the cookie throughbrowser.cookie.Checklist