Skip to content

fix(personalize): render Personalize web experiences by providing the scCloudSDK global#497

Open
Robert-LerohDigital wants to merge 1 commit into
Sitecore:devfrom
Leroh-Digital:fix/personalize-web-experiences
Open

fix(personalize): render Personalize web experiences by providing the scCloudSDK global#497
Robert-LerohDigital wants to merge 1 commit into
Sitecore:devfrom
Leroh-Digital:fix/personalize-web-experiences

Conversation

@Robert-LerohDigital

Copy link
Copy Markdown

Summary

Sitecore Personalize interactive web experiences (banners, popups, takeovers) silently fail to render in any Content SDK 2.x app that enables webPersonalization on the personalize browser plugin — even though the personalize README documents it as a standalone, browser-side feature. The Sitecore-hosted web personalization library reads a window.scCloudSDK global that the Content SDK never set; this PR populates that global from the Content SDK's own identity.

Repro

personalizeBrowserPlugin({
  adapter: personalizeBrowserAdapter(),
  options: { enablePersonalizeCookie: true, webPersonalization: { language: 'en-us' } },
})

With webPersonalization set, 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:

  1. Uncaught TypeError: Cannot read properties of undefined (reading 'personalize')
  2. Uncaught TypeError: Cannot read properties of undefined (reading 'getGuestId')

Root cause

The Sitecore-hosted CDN library reads a browser global named window.scCloudSDK at load time. Verified against the live cloud-version.min.js / cloud-lib.min.js:

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.scCloudSDK from 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() (cookie sc_cid)
  • core.getGuestId()getProfileId() (customer.ref from /v1/events/v1.2/browser/{id}/show.json)
  • core.settings{ siteName, sitecoreEdgeContextId, sitecoreEdgeUrl }
  • personalize.settings → the resolved web personalization options

A window.scCloudSDK already registered by another script is preserved and never overridden. No public API-surface change.

window.scCloudSDK is the global name the external Sitecore-hosted library reads — it is not a dependency on any other SDK package. This change is self-contained in @sitecore-content-sdk/personalize.

Tests / verification

  • personalize unit tests: 138 passed / 12 suites — new set-web-personalization-global.spec.ts (8 tests) + extended plugin-browser.spec.ts (3 tests).
  • lint: ✅ · build: ✅ · api-extractor run: ✅ (no API-surface change).
  • Validated against the live CDN library contract (the exact property reads/calls above). A live end-to-end render against a tenant with a published web experience is the recommended final smoke test.

Changes

  • new packages/personalize/src/web-personalization/set-web-personalization-global.ts — populates the global.
  • edit packages/personalize/src/initialization/plugin-browser.ts — invoke it before injecting the CDN script.
  • new/edit tests + a patch changeset.

…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-bot

changeset-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3330f50

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sitecore-content-sdk/personalize Patch

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

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