fix(personalize): render Personalize web experiences by providing the scCloudSDK global#497
Open
Robert-LerohDigital wants to merge 1 commit into
Open
Conversation
…global When webPersonalization is enabled, the personalize browser plugin injects the Sitecore-hosted web personalization library (cloud-version.min.js / cloud-lib.min.js), which reads a window.scCloudSDK global at load time. The Content SDK only set window.scContentSDK, so the library threw "Cannot read properties of undefined (reading 'personalize')" and the same for "getGuestId", and no web experiences (banners, popups, takeovers) rendered. The browser plugin now populates window.scCloudSDK (core.getBrowserId / getGuestId / settings + personalize.settings) entirely from the Content SDK's own identity functions (getClientId, getProfileId) immediately before the CDN script is injected. No additional Sitecore Edge calls are made, nothing outside @sitecore-content-sdk/* is used, and a window.scCloudSDK already registered by another script is left untouched.
🦋 Changeset detectedLatest commit: 3330f50 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Summary
Sitecore Personalize interactive web experiences (banners, popups, takeovers) silently fail to render in any Content SDK 2.x app that enables
webPersonalizationon the personalize browser plugin — even though the personalize README documents it as a standalone, browser-side feature. The Sitecore-hosted web personalization library reads awindow.scCloudSDKglobal that the Content SDK never set; this PR populates that global from the Content SDK's own identity.Repro
With
webPersonalizationset, the plugin fetches the Personalize web-flow CDN URL and injects:…/web-flow-libs/<clientKey>/cloud-version.min.js(bootstrap), which loads…/web-flow-libs/<clientKey>/<v>/cloud-lib.min.js(runtime)No web experience renders, and two console errors fire, in order:
Uncaught TypeError: Cannot read properties of undefined (reading 'personalize')Uncaught TypeError: Cannot read properties of undefined (reading 'getGuestId')Root cause
The Sitecore-hosted CDN library reads a browser global named
window.scCloudSDKat load time. Verified against the livecloud-version.min.js/cloud-lib.min.js:window.scCloudSDK.personalize.settings && (…)→ error [v2] Apply old fork changes into react and nextjs packages #1 when the global is undefined.var cloudSDK = window.scCloudSDK || {personalize:{settings:{}}}— the fallback has nocore— thencloudSDK.core.getGuestId().then(...)→ error Synccreate-sitecore-jsswith WIP repo #2. It also readscloudSDK.core.getBrowserId()andcloudSDK.core.settings.{sitecoreEdgeContextId, sitecoreEdgeUrl, siteName}.Content SDK 2.x only sets
window.scContentSDK(grep -r "scCloudSDK" packages/→ 0 hits before this change), so the library finds no global to read and throws.User impact: Personalize interactive web experiences silently fail to render on all Content SDK 2.x apps using
webPersonalization— no banner/popup/takeover appears, with the two TypeErrors above in the console.Fix
Populate
window.scCloudSDKfrom the personalize browser plugin, immediately before the CDN script is injected, entirely from the Content SDK's own identity functions — no additional Sitecore Edge calls, and nothing outside@sitecore-content-sdk/*is used:core.getBrowserId()→getClientId()(cookiesc_cid)core.getGuestId()→getProfileId()(customer.reffrom/v1/events/v1.2/browser/{id}/show.json)core.settings→{ siteName, sitecoreEdgeContextId, sitecoreEdgeUrl }personalize.settings→ the resolved web personalization optionsA
window.scCloudSDKalready registered by another script is preserved and never overridden. No public API-surface change.Tests / verification
personalizeunit tests: 138 passed / 12 suites — newset-web-personalization-global.spec.ts(8 tests) + extendedplugin-browser.spec.ts(3 tests).lint: ✅ ·build: ✅ ·api-extractor run: ✅ (no API-surface change).Changes
packages/personalize/src/web-personalization/set-web-personalization-global.ts— populates the global.packages/personalize/src/initialization/plugin-browser.ts— invoke it before injecting the CDN script.