Skip to content

✨ [Shopify] Share the storefront session in the app pixel - #5268

Draft
BeltranBulbarellaDD wants to merge 36 commits into
mainfrom
beltran.bulbarella/shopify-session-plugin-hook
Draft

BeltranBulbarellaDD wants to merge 36 commits into
mainfrom
beltran.bulbarella/shopify-session-plugin-hook

Conversation

@BeltranBulbarellaDD

Copy link
Copy Markdown
Contributor

Motivation

The Datadog Shopify app Web Pixel runs the RUM SDK in a sandboxed Web Worker, with no document.cookie or Cookie Store API. Cookies are only reachable through Shopify's async browser.cookie, so today the pixel uses a memory session and checkout starts a new session instead of continuing the storefront one.

Options and decision: Sharing the storefront session in the Shopify app pixel (inject a CookieAccess adapter through a plugin hook, carried on the configuration).

Stacked on #5140.

Changes

  • Core (browser-core, browser-rum-core)
    • New setSessionCookieAccess(factory) option in the plugin onInit API.
    • The factory reaches the session manager on an internal sessionCookieAccess configuration field (not an init option), and the cookie strategy reads and writes the session cookie through it. The rest of the cookie session logic is unchanged.
    • buildCookieString is extracted from setCookie, so host adapters write the same cookie string.
  • Shopify (browser-rum-shopify)
    • shopifyAppPixelPlugin registers the pixel with Shopify, reads the RUM configuration from the rumConfig pixel setting, starts views from page_viewed events, and stores the session through browser.cookie (createShopifyCookieAccess, which polls since there is no change event). Outside of a Web Pixel, it runs with a memory session.
    • @shopify/web-pixels-extension is added as a dev dependency, for its types only.
  • E2E
    • withShopifyApp(store) can target a store. The existing live store test is renamed shopifyV1:, and a new shopifyV2: test runs against the dev store where the Datadog Shopify app is installed: it checks that the app pixel continues the storefront session at checkout, accepting the cookie consent banner when shown.
    • Both are excluded from the PR e2e job (--grep-invert "shopifyV[12]:") and run on the scheduled job.

Not included yet: session expansion on Shopify events, consent from Shopify customerPrivacy, checkout event bindings.

Test instructions

  • Unit: yarn test:unit --spec packages/browser-core/src/domain/session/storeStrategies/sessionInCookie.spec.ts --spec packages/browser-rum-core/src/boot/preStartRum.spec.ts --spec 'packages/browser-rum-shopify/src/**/*.spec.ts'
  • Worker e2e: yarn test:e2e -g "Web workers Rum"
  • Live app store e2e (needs the app deployed with the CDN SDK URL): yarn build && yarn test:e2e -g "shopifyV2:"

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

BeltranBulbarellaDD and others added 30 commits October 14, 2026 15:48
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ature

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the display context, navigation resource and initial view metrics
feature guards. Without a window the display context leaves `display`
undefined, and getNavigationEntry() returns undefined without a document
so callers skip the navigation resource and navigation timings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep `addEventListener(s)` and `instrumentMethod` targets required so
missing browser APIs aren't silently hidden, and restore the stable
`@datadog/js-core/dom` signatures.

Check for a missing window once at the top of each page-only feature:
window open, location change, page state history, display context and
bfcache restore. Skip initial view metrics in trackViews without a
document, and keep a window check in trackFirstHidden, which is also
used by loading time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clocksOrigin() returned getTimeOrigin() unrounded. Without
`performance.timing` (e.g. in a Web Worker), the origin comes from
`performance.timeOrigin`, which is fractional, so the initial view
`date` was not an integer and failed the RUM event schema. Round it
like the other timestamp helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fallback is used precisely when there is no cookie store, which is
the Web Worker case, and getCookie() reads `document.cookie` without a
check, so it threw at RUM start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Let `createWorker({ dedicated: true })` run the worker with
`new Worker()` and `withRum(config, { sdk })` pick the bundle. The test
starts rum-shopify in a dedicated worker and expects a view event.
Allow the rum-shopify SDK to start in a worker, since Shopify App Pixels
run in a Web Worker sandbox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR e2e jobs exclude tests matching "shopify", which only run on a
schedule against a live store. The test title contained "rum-shopify",
so it never ran in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round `performance.timeOrigin` only when falling back to it, and cache
the rounded value, instead of rounding in clocksOrigin(). Add an
internal resetTimeOrigin() so tests can reach the fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Flooring matches `navigationStart`, which truncates `timeOrigin` in
Chromium, so the origin is never later than the actual one: worker
timestamps then have the same at most 1 ms error as pages, never above
the exact value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…origin' into beltran.bulbarella/shopify-regular-sdk
…opify-regular-sdk

# Conflicts:
#	packages/browser-core/src/browser/cookie.ts
Firefox reports the `event` entry type as supported in workers, so the
check reached `window.PerformanceEventTiming` and threw, preventing any
view from being created. Use `globalObject` instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Skip the sandboxed iframe patches (they access `document`) and use memory
persistence (no cookies) when running in a worker. Also reword the worker
guard comment to say Shopify is expected to run in a worker in the future.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add the internal `betaTrackViewMetrics` option (default true) and gate
initial, route change and common view metrics (scroll, CLS, INP) on it,
instead of checking for `globalObject.document`. Loading time and manual
`setViewLoadingTime()` are always kept. The Shopify plugin disables it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…opify-regular-sdk

# Conflicts:
#	packages/browser-rum-core/src/domain/view/trackViews.ts
#	packages/browser-rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts
The load event is only reported by trackInitialViewMetrics, which is
skipped when `betaTrackViewMetrics` is false, so the activity-based
loading time of initial views was never reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Manually

INP support is only checked by trackInteractionToNextPaint, which is
skipped when `betaTrackViewMetrics` is false, and onBFCacheRestore only
runs when views are tracked automatically. Both files match main again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Skip the navigation resource in startResourceCollection when there is
no document, and restore getNavigationEntry to always return an entry.
Its other callers (LCP, navigation timings) only run with view metrics,
so they no longer need to handle a missing entry.
Add shopifyAppPixelPlugin, which forces the configuration RUM needs in
the Shopify app Web Pixel worker (manual views, memory persistence, no
view metrics, no DOM-based features), and only allow RUM to start in a
worker when this plugin is used.

Restore shopifyPlugin to its main version, so existing consumers are
not affected. The dedicated worker e2e now initializes RUM with the new
plugin, through a worker `withRumInit()` mirroring the page one.
Add a `setSessionCookieAccess` option to the plugin `onInit` API, for
environments where cookies are only reachable through a host API (ex:
Shopify Web Pixels `browser.cookie`).

The factory is passed to the session manager on an internal
`sessionCookieAccess` configuration field, and the cookie strategy reads
and writes the session cookie through it. Extract `buildCookieString`
from `setCookie` so host adapters can write the same cookie string.
The app pixel plugin now registers the pixel with Shopify, reads the RUM
configuration from the `rumConfig` pixel setting, starts views from
`page_viewed` events, and stores the session in the checkout page cookie
through Shopify `browser.cookie`. Outside of a Web Pixel, it runs with a
memory session.

Add `@shopify/web-pixels-extension` as a dev dependency for its types.
Let `withShopifyApp` target a store, and add the dev store where the
Datadog Shopify app is installed. The new `shopifyV2:` test checks that
the app pixel continues the storefront session at checkout, accepting
the cookie consent banner when shown.

Rename the existing live store test to `shopifyV1:` and exclude both
from the PR e2e job: they run on the scheduled job.
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce 192.81 KiB 193.02 KiB +209 B +0.11% ✅
Rum 192.79 KiB 193.00 KiB +209 B +0.11% ✅
Rum Salesforce Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.59 KiB 32.59 KiB 0 B 0.00% ✅
Rum Recorder 32.59 KiB 32.59 KiB 0 B 0.00% ✅
Logs 60.16 KiB 60.30 KiB +139 B +0.23% ✅
Rum Slim 148.64 KiB 148.83 KiB +199 B +0.13% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 224.13 KiB 225.83 KiB +1.70 KiB +0.76% ✅
Rum Shopify Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 89.09%
• Overall Coverage: 77.39% (-0.52%)

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

Base automatically changed from beltran.bulbarella/shopify-regular-sdk to main November 18, 2026 16:31

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.

1 participant