A headless A/B test in SitecoreAI lets you show two versions of any content, measure them against your own goal, and keep each visitor on the same version on every page. In this post I walk through how I set one up end to end, the test in SitecoreAI, the front-end code, and how to read the result.
The test started from two common questions. Can we measure success with our own goal, not just page views or bounce rate? And can a visitor see the same version on several pages, like the home page and an events page? With a headless A/B test, the answer to both is yes.
The example is simple. A banner shows on two pages, with two versions of its text. Version A says "Explore our services". Version B says "Talk to our experts". Both link to the Services page, and reaching that page is the goal.
How a visitor gets a version
Every decision comes from one value: the visitor's browser ID. Here is how it works, step by step.
- A browser ID. On the first visit, the Sitecore Cloud SDK gives the browser an ID and stores it in a first-party cookie that starts with sc_.
- A bucket. SitecoreAI turns that ID into a number from 1 to 120. The same ID always gives the same number, on every page and every visit.
- A version. The traffic split decides who sees what. With 50/50, buckets 1 to 60 see version A and buckets 61 to 120 see version B.
- A success. When the visitor reaches the goal, your code sends a custom event. SitecoreAI counts it for the version that visitor saw.
Because the bucket never changes, the visitor keeps the same version on the home page, on the events page, today and tomorrow. A new visitor in another browser gets a new ID, and may get the other version.
Set up the test in SitecoreAI
In SitecoreAI, a headless A/B test starts as a headless personalization. It becomes a test when you add a second variant.
- Create it. Go to Optimization, then Tests & personalizations, then Headless, and click Create. Give it a clear name, for example "Service Banner Test". Note the friendly ID it generates (here service_banner_test), because your code uses it and it can't be changed later. Avoid dashes and slashes in the name: they turn into odd characters in the ID.
Configure the first version. Under API response, click Configure and write a small JavaScript function that returns what the banner should show:
(function () { return { variant: 'A', bannerText: 'Explore our services', ctaLabel: 'Explore now', ctaUrl: '/Services' }; })();- Add the second version. Click Create variant. SitecoreAI converts the personalization into an A/B/n test, and the first version becomes the control. Use the same fields, with different text: variant: 'B', bannerText: 'Talk to our experts', ctaLabel: 'Talk to us'.
- Set the split. Keep 50% / 50%.
- Choose the assignment method. Under Advanced options, the default is Unique to A/B/n test: each test splits visitors on its own. Universal shares the split across all Universal tests, so a visitor in version B of one test gets version B in the others too. I picked Universal, so the experience stays consistent if more tests are added later.
- Set the goal. Under Goals, choose Track performance, then Custom goal. Name it "Services page views", set it to Increase per session, and set Track event to equals SERVICES_PAGE_VIEW. This name is not built into Sitecore: it's the event type your own code sends, so the two must match exactly.
- Publish. The test runs only once it shows Live.
Wire it into the front end
The front end needs three small pieces, all with the Sitecore Cloud SDK. The code below is simplified to show the idea.
Turn on personalize. Where the Cloud SDK is initialized (in the starter kits, Bootstrap.tsx), add the personalize package next to events:
CloudSDK({ sitecoreEdgeContextId, siteName, enableBrowserCookie: true }) .addEvents() .addPersonalize({ enablePersonalizeCookie: true }) .initialize();Ask for the version. On the pages that show the banner, call personalize() with the test's friendly ID, and render what comes back:
import { personalize } from '@sitecore-cloudsdk/personalize/browser'; const result = await personalize({ friendlyId: 'service_banner_test', channel: 'WEB', currency: 'USD', language: 'EN', }); // result holds variant, bannerText, ctaLabel and ctaUrl from the API responseSend the goal. On the goal page, send the custom event the test listens for:
import { event } from '@sitecore-cloudsdk/events/browser'; event({ type: 'SERVICES_PAGE_VIEW', channel: 'WEB', page: 'Services' });
Keep the banner pages and the goal page separate. If the banner were on the Services page too, a visitor who lands there directly would count as a success, even though the banner never influenced them.
Check it works, then wait for a winner
You can check the setup in a few minutes:
- Open the site in one browser. The banner shows one version, and the next page shows the same one.
- Open it in a second browser. A new visitor may get the other version. With a 50/50 split, try a fresh private window if both look the same.
- Click the banner through to the goal page. In the browser's Network tab, filter by edge-platform: a request with status 201 and SERVICES_PAGE_VIEW in its payload means the goal was sent.
- In Optimization, Profiles, search for the visitor by the value of the sc_ cookie. The Engagement tab shows the page views and the goal event in order.
The winner takes longer. The test's results are processed data, so they appear after a few hours. And SitecoreAI only declares a winner once it has enough visits for the difference to be real. With real traffic, that takes days. Once it's decided, automated actions can roll the winning version out to everyone.

