XeniaXenia Docs

CMS page personalization

PreviousNext

Tell the SDK which CMS page to render. It fetches it from Contentful or Contentstack and swaps the entries a journey personalizes, at any depth.

A marketer personalizes a CMS page with a Personalization Trigger (the page's content key) and one or more Personalization Response steps that swap sections of the page. Your site asks the SDK for the page, and the SDK returns it with those sections already swapped, however deeply they are nested.

This page covers journeys whose Personalization Trigger has Server-side pull channel only switched off. With it on, the same page is served from your proxy: see Edge personalization.

Render a page

import { contentfulAdapter } from "@xenia-martech/sdk-js/cms/contentful";
 
const cms = contentfulAdapter({ space, accessToken, include: 6 });
const { content } = await xenia.personalizePage({ contentType: "page", fields: { slug } }, {
  cms,
  contentKey: "home-main", // the page's Personalization Trigger content key
  timeoutMs: 250,
});
// or by entry id: xenia.personalizePage("1Tl24n6FueOegEOALask0F", { cms, contentKey })

content is the page entry, or null when it doesn't exist or the CMS fetch failed. Already fetching the page yourself? Pass it in with xenia.personalizeContent(page, { cms, contentKey }). On Contentstack, fetch it with include_all=true so references come back as entries.

contentKey is required. It scopes the page to that one journey, so no other journey is consulted about its sections.

How it works

  • Marking. When a journey is published, Xenia marks the personalized entries in your CMS. The connector's publish stage decides whether that change is published, saved as a draft, or moved to a Contentstack workflow stage. Your site only sees a marker once it is published.
  • Static swaps cost no Xenia call. Their replacements come back with your own CMS fetch.
  • Runtime swaps cost one Xenia call per nesting level. Every runtime section the SDK finds goes to Xenia in one call, and the replacements load in one CMS call.
  • One-to-many swaps. A section can expand into several entries, or a list field (for example carousel slides) can be filled with chosen entries or a content-type query.
  • Same section, two steps. When two Personalization Response steps target one section, the trigger's Same-section conflicts setting picks the first or last.
  • Bounded and safe. All rounds share the timeoutMs budget (default 300 ms), capped by maxRounds (default 3). It never throws: anything undecided keeps its base content.

Where to run it

WhereHowTrade-off
Server (SSR)await xenia.personalizePage(ref, { cms, contentKey })No flicker. Adds one Xenia round trip per nesting level.
Next.js, streamedRender the page with maxRounds: 0, show pendingTargets() as skeletons in <Suspense>, and run the full call inside it. personalizeOnce from /next shares one run per request.Fast first byte. Skeletons fill in when ready.
Server and browserRun on the server with maxRounds: 1, then pass the result to usePersonalizedContentThe first screen is personalized on the server; deeper levels finish in the browser.
BrowserusePersonalizedPage(ref, { cms, contentKey, render })"base-first" shows the page at once; "hide-until-resolved" holds it back for a skeleton.

Other CMSs

Implement CmsAdapter for any other CMS. You write entryId, marker, staticVariants, getField / setField, and fetchEntries / queryEntries. The walk, the rounds, the budget and the splicing are shared.

Content Cloud

Content Cloud pages are personalized through resolve(), whose swaps name each section by its identifier. applyIdentifierSwaps replaces every swapped reference at any depth:

const { personalized, swaps } = await xenia.resolve(productId, { data });
const entry = await applyIdentifierSwaps(base, personalized ? swaps : [], (id) => fetchEntry(id, 3));

Each replacement loads once, a failed load keeps the base, and the input is never changed.