Skip to content

✨ [Shopify] Allow a custom cookie store for session persistence - #5109

Open
BeltranBulbarellaDD wants to merge 14 commits into
mainfrom
beltran.bulbarella/custom-session-store
Open

BeltranBulbarellaDD wants to merge 14 commits into
mainfrom
beltran.bulbarella/custom-session-store

Conversation

@BeltranBulbarellaDD

@BeltranBulbarellaDD BeltranBulbarellaDD commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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.cookie nor the Cookie Store API is available: cookies can only be accessed through Shopify's asynchronous browser.cookie API, 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_v2 cookie through that API. This PR lets the session store persist the session through such a host-provided cookie store.

Changes

sessionPersistence now also accepts an internal cookie store ({ get, set }), such as Shopify's browser.cookie. It gets its own custom-cookie strategy, which reuses the cookie strategy's session logic (extracted to createCookieSessionStore()) on top of a new createCustomCookieAccess(). That way, the session cookie is read and written the same way, only through the provided store.

  • The store has no change event, so it's polled for changes from other contexts, like document.cookie is.
  • The legacy _dd_s cookie isn't read, since that needs document.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:

validateAndBuildConfiguration({ ...initConfiguration, sessionPersistence: browser.cookie }, WEB_PIXEL_SCHEMA, display)

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:

  • Shared session: after browsing the storefront, the _dd_s_v2 cookie read on the storefront and on checkout has the same id, aid and created. Only expire moves forward as checkout events expand the session.
  • No session cookie on checkout: after deleting _dd_s_v2 on the checkout page and reloading, the Web Pixel creates a new session and writes the cookie through browser.cookie.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

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>
@BeltranBulbarellaDD
BeltranBulbarellaDD requested a review from a team as a code owner October 5, 2026 12:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T17:54:37.555412Z 9568c7e New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce N/A 186.62 KiB N/A N/A N/A
Rum 185.61 KiB 186.60 KiB +1018 B +0.54% ✅
Rum-salesforce Profiler N/A 8.38 KiB N/A N/A N/A
Rum Profiler 8.38 KiB 8.38 KiB +1 B +0.01% ✅
Rum-salesforce Recorder N/A 31.94 KiB N/A N/A N/A
Rum Recorder 31.94 KiB 31.94 KiB +1 B +0.00% ✅
Logs 59.53 KiB 60.50 KiB +994 B +1.63% ✅
Rum Slim 143.61 KiB 144.58 KiB +995 B +0.68% ✅
Worker 22.96 KiB 22.96 KiB 0 B 0.00% ✅
Rum Shopify N/A 217.01 KiB N/A N/A N/A
Rum-shopify Profiler N/A 8.38 KiB N/A N/A N/A
Rum-shopify Recorder N/A 4.77 KiB N/A N/A N/A

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

DataDog/browser-sdk | check-staging-merge — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 82.22%
• Overall Coverage: 77.19% (+0.02%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b318d3a | Docs | View more details | Give us feedback!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/browser-core/src/domain/session/storeStrategies/sessionInCookie.ts Outdated
Comment thread packages/browser-core/src/domain/session/storeStrategies/sessionInCookie.ts Outdated
BeltranBulbarellaDD and others added 3 commits October 5, 2026 14:29
- 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>
@BeltranBulbarellaDD

Copy link
Copy Markdown
Contributor Author

@codex pls review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 475fdce9ec

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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>
@BeltranBulbarellaDD BeltranBulbarellaDD changed the title ♻️ Allow a custom cookie access for the cookie session store ♻️ Add a session store strategy for Shopify Web Pixel cookies Oct 6, 2026
*
* @internal
*/
shopifyCookieAccessFactory?: CookieAccessFactory | undefined

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.

❓ question: ‏Would this option always provided in Shopify?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/browser-core/src/domain/session/storeStrategies/sessionInCustomCookie.ts Outdated
Comment thread packages/browser-core/src/domain/configuration/configuration.ts Outdated
@BeltranBulbarellaDD BeltranBulbarellaDD changed the title ♻️ Add a session store strategy for Shopify Web Pixel cookies ✨ [Shopify] Allow a custom cookie store for session persistence Oct 8, 2026
previousValues = values
}

// Custom stores have no change event: poll them, like the `document.cookie` access does

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/browser-core/src/domain/configuration/configuration.ts
Comment thread packages/browser-core/src/browser/cookieAccess.ts
Comment thread packages/browser-core/src/browser/cookieAccess.spec.ts Outdated

This branch has not been deployed

No deployments
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