Repository navigation
✨ [Shopify] Share the storefront session in the app pixel - #5268
Draft
BeltranBulbarellaDD wants to merge 36 commits into
Draft
BeltranBulbarellaDD wants to merge 36 commits into
BeltranBulbarellaDD wants to merge 36 commits into
Conversation
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.
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 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
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.
Motivation
The Datadog Shopify app Web Pixel runs the RUM SDK in a sandboxed Web Worker, with no
document.cookieor Cookie Store API. Cookies are only reachable through Shopify's asyncbrowser.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
CookieAccessadapter through a plugin hook, carried on the configuration).Stacked on #5140.
Changes
browser-core,browser-rum-core)setSessionCookieAccess(factory)option in the pluginonInitAPI.sessionCookieAccessconfiguration 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.buildCookieStringis extracted fromsetCookie, so host adapters write the same cookie string.browser-rum-shopify)shopifyAppPixelPluginregisters the pixel with Shopify, reads the RUM configuration from therumConfigpixel setting, starts views frompage_viewedevents, and stores the session throughbrowser.cookie(createShopifyCookieAccess, which polls since there is no change event). Outside of a Web Pixel, it runs with a memory session.@shopify/web-pixels-extensionis added as a dev dependency, for its types only.withShopifyApp(store)can target a store. The existing live store test is renamedshopifyV1:, and a newshopifyV2: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.--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
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'yarn test:e2e -g "Web workers Rum"yarn build && yarn test:e2e -g "shopifyV2:"Checklist