Run Sitecore Personalize personalizations
Using the Cloud SDK, you can personalize content for your site visitors by, for example, running interactive experiences that are live in Sitecore Personalize. To run this type of experience in your JSS Next.js app, you use the browser module of the Cloud SDK personalize packagepackage. Running the experience will return an API response, which contains the personalized content.
SitecoreAI personalizations run automatically in JSS Next.js apps, with no coding required.
This walkthrough describes how to:
-
Have a live interactive experience in Sitecore Personalize to work with.
-
Make sure you're prepared for development with the Cloud SDK.
-
In your code editor, open the rendering app root folder
sxastarter.
Install and initialize @sitecore-cloudsdk/personalize/browser
The first step to running personalization is to install the @sitecore-cloudsdk/personalize package and initialize its browser modulemodule in your app.
To install the package and initialize the module:
-
In your code editor, in the
sxastarterfolder, open the terminal and install thepersonalizepackage by running the following command: -
In
src/pages/[[...path]].tsx, import the initializer function of thebrowsermodule:src/pages/[[...path]].tsxis a catch-all route. The code you add to it will run on all the webpages of your app. -
Inside the
SitecorePageconstant, directly before thereturnstatement, paste the following code then save your changes:Replace the placeholder values with environment variable values from your SitecoreAI instance.
This code initializes the module using your Context ID and site name, and it sets cookies from the browser side.
Find the friendly ID in Sitecore Personalize
After initializing the module, you need to find the friendly IDfriendly ID of the live interactive experience you want to run on your site.
To find the friendly ID:
-
In Sitecore Personalize, click Experiences.
-
Click the live interactive experience you want to run.
-
On the page of the experience, click Build summary. The friendly ID is in the Details pane.

-
Make a note of the friendly ID. You'll use it in the next procedure to run the experience.
Run the experience on your site
After finding the friendly ID of the experience, you return to your code editor and run the experience on your site.
To run the experience:
-
In your code editor, in
src/pages/[[...path]].tsx, modify the import statement for thepersonalize/browsermodule to also import thepersonalizefunction:NoteIn production, you typically run the
personalizefunction in the component you want to personalize, not in[[...path]].tsx. -
Inside the
initPersonalizefunction, directly after the existingconsole.log()statement, paste the following code:Replace the placeholder value with the friendly ID of your experience.
See all the possible values for
channelandcurrencyin the reference documentation for thepersonalizepackage.This code runs the experience and logs its API response to the console.
-
Save your changes.
Verify that the experience is running
After updating your code, it's a good idea to check that the experience is running on your site.
To verify that the experience is running:
-
Start your rendering app by entering the following command in your terminal:
-
In your web browser, navigate to your JSS Next.js app, typically at
http://localhost:3000. -
In your web browser's developer tools, on the Console tab, verify that you see the following logs in the console:
The second log contains the response that was created for this experience in Sitecore Personalize.
-
In the developer tools, on the Network tab, in the Filter field, paste the following URL:
edge-platform.sitecorecloud.io.Doing this lists the network requests made to Sitecore.
-
In the list of requests, click a
POSTrequest with a status of200 OKand a name that starts with personalize. -
In the request details pane, click the Response tab for the request.
The API response appears. This is the response that was created for this experience in Sitecore Personalize.
Next steps
You've now successfully run the experience on your site and received the API response for the experience in your web app. You can now proceed to work with the response, for example, by displaying its content on your site.
Next, you can:
-
Learn more about running personalization in JSS Next.js apps.
-
Explore the reference documentation for the
personalizepackage. -
Implement other Cloud SDK functionality, such as using data collection to capture custom events.