Friday, March 29, 2024

How to Integrate Sitecore Personalize with Sitecore XM Cloud

How to Integrate Sitecore Personalize with Sitecore XM Cloud

Sitecore Personalize is a powerful tool for delivering personalized content experiences across various touchpoints, making sure your audience receives the right content at the right time. On the other hand, Sitecore XM Cloud is a cloud-native version of Sitecore’s Experience Manager (XM), offering scalability and flexibility to deliver digital experiences.

In this blog post, we'll walk through the steps to integrate Sitecore Personalize with Sitecore XM Cloud to leverage both platforms for a unified and personalized digital experience.

What is Sitecore Personalize?

Sitecore Personalize is a cloud-based solution designed to provide real-time, data-driven personalization across web, mobile, email, and other channels. It collects and analyzes data from customer interactions, enabling marketers and content managers to deliver personalized content and offers dynamically based on customer behavior, preferences, and segmentation.

What is Sitecore XM Cloud?

Sitecore XM Cloud is Sitecore’s Content Management System (CMS) built for the cloud, designed to provide flexibility and scalability to businesses that need to create, manage, and deliver digital experiences quickly. It focuses on content management, delivering websites, and enabling digital experiences on a global scale without the complexities of on-premises infrastructure.

Why Integrate Sitecore Personalize with XM Cloud?

By integrating Sitecore Personalize with Sitecore XM Cloud, you can:

  • Deliver hyper-personalized experiences to users across your digital channels.
  • Use real-time behavioral data to dynamically serve content and offers.
  • Seamlessly sync content, audience segments, and personalization rules between the two platforms.
  • Benefit from scalability and flexibility with the power of cloud architecture.

Steps to Integrate Sitecore Personalize with Sitecore XM Cloud

Step 1: Set Up Sitecore XM Cloud

Before you can integrate Sitecore Personalize, make sure your Sitecore XM Cloud instance is set up and running. If you're new to Sitecore XM Cloud, follow these initial setup steps:

  1. Create an XM Cloud instance: Set up a new Sitecore XM Cloud instance through the Sitecore Cloud Portal.
  2. Configure your environment: Set up content management and content delivery configurations in your Sitecore XM Cloud instance.
  3. Ensure you have the required roles and permissions: You need appropriate permissions to manage integrations and access data between Sitecore Personalize and XM Cloud.

Step 2: Set Up Sitecore Personalize

Once your Sitecore XM Cloud instance is ready, the next step is setting up Sitecore Personalize:

  1. Create a Sitecore Personalize account: Go to Sitecore Personalize’s portal and create an account if you haven't already.
  2. Configure your personalizations: Create audience segments, define personalization rules, and map data sources within the Personalize portal.
  3. Set up tracking: Ensure that Sitecore Personalize is tracking user activity on your digital properties. This can involve setting up the JavaScript SDK or other tracking mechanisms.

Step 3: Install and Configure the Sitecore Personalize Connector

To connect Sitecore Personalize with Sitecore XM Cloud, you need to use the Sitecore Personalize connector. This allows Sitecore XM Cloud to pull personalized content data from Sitecore Personalize and deliver it seamlessly to your site visitors.

  1. Download the Sitecore Personalize Connector: The connector is available from the Sitecore Experience Platform (XP) and can be installed into your Sitecore XM Cloud environment.

    To download and install the connector:

    • Go to the Sitecore Developer Portal and locate the Sitecore Personalize connector for XM Cloud.
    • Follow the installation instructions provided in the documentation.
  2. Configure the Connector in XM Cloud: After installation, configure the connector by providing authentication keys, specifying the Personalize environment, and enabling data synchronization between Sitecore Personalize and Sitecore XM Cloud.

Step 4: Sync Data Between Sitecore Personalize and XM Cloud

Now that you have both Sitecore Personalize and Sitecore XM Cloud connected, it’s time to sync the data.

  1. Sync Audience Segments: Ensure that the audience segments you created in Sitecore Personalize are synced with Sitecore XM Cloud. This will allow you to serve personalized content based on user behaviors, interests, and preferences.

  2. Enable Personalization Rules: Create or import personalization rules from Sitecore Personalize into XM Cloud. These rules will govern how content is presented to users on your site.

  3. Synchronize Content: Sync personalized content data such as articles, offers, or banners, ensuring that Sitecore Personalize data is available in XM Cloud when needed.

Step 5: Test and Validate the Integration

Before you go live with your integration, it’s essential to test the integration thoroughly.

  1. Validate Data Flow: Ensure that personalized content is being delivered to the site and that audience segments are correctly reflected in Sitecore XM Cloud.
  2. Test Real-Time Personalization: Use test cases or sandbox environments to verify that personalization is happening in real time based on user interactions.
  3. Monitor Analytics: Use Sitecore’s built-in analytics tools to track how personalized content is performing and make adjustments as needed.

Step 6: Go Live with the Integration

Once you’ve thoroughly tested the integration and validated all data flows, it’s time to go live with the integration.

  1. Monitor Performance: Keep an eye on site performance, ensuring the integration does not affect the speed or responsiveness of your site.
  2. Track Engagement: Use Sitecore Personalize’s analytics capabilities to measure user engagement with the personalized content and adjust campaigns accordingly.

Best Practices for Maximizing the Integration

  1. Use Clear Personalization Goals: Define the goals of your personalization strategy, such as increasing engagement, boosting conversions, or improving customer satisfaction. This will help you focus on delivering relevant content.
  2. Optimize Personalization for Mobile: Ensure that personalized content is optimized for different screen sizes, as mobile traffic is a significant part of most digital experiences.
  3. Leverage AI and Machine Learning: Sitecore Personalize uses AI and machine learning to help deliver smarter personalization. Take advantage of these features to automatically adjust content recommendations based on user behavior.

Integrating Sitecore Personalize with Sitecore XM Cloud provides you with a powerful combination of content management and real-time personalization. By following the steps outlined above, you can create a seamless experience for your users, delivering dynamic and relevant content across all touchpoints.

Personalization is no longer a luxury; it’s a necessity in today’s digital landscape. With Sitecore Personalize and Sitecore XM Cloud, you can ensure that your users receive the most relevant, engaging content, enhancing their experience and driving better business outcomes.

Now that you have a better understanding of how to integrate Sitecore Personalize with Sitecore XM Cloud, it’s time to start creating those personalized experiences and see the difference they make for your brand.

                                                            Happy personalizing!

How to extend Sitecore JSS Layout service context and check the user authorization?

  This blog can help you work with Sitecore JSS and extend the layout service context. The following steps will guide you to create the pipeline processor and patch it in the right place in order to work appropriately.

Layout service is an open REST API and by default, it does not expect username as part of query string params. This approach/solution will help you to create a virtual user/assign the appropriate roles in order to leverage the Sitecore OOTB authorization capabilities.

Use Case: If there are multiple user groups and you want to manage the access at the item or folder level, Sitecore can make the decision either to redirect the 401-Unauthorised Access page or allow that user to access the requested page.

1. Create a pipeline/processor(C# class)

  C# class code:    

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using Sitecore.Data.Managers;
using Sitecore.Kernel;
using Sitecore.JavaScriptServices.Configuration;
using Sitecore.JavaScriptServices.ViewEngine.LayoutService.Pipelines.GetLayoutServiceContext;
using Sitecore.LayoutService.ItemRendering.Pipelines.GetLayoutServiceContext;
using Sitecore.Data;
using Sitecore.Security.Accounts;
using Newtonsoft.Json;
using Sitecore.Security;
using Sitecore.Eventing.Remote;
using System.Diagnostics.Eventing.Reader;

namespace ABC.Pipelines
{
public class VirtualUserAuth : JssGetLayoutServiceContextProcessor { protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) {            bool isSecureAccessEnabled = false;            //Add condition and call the method-CreateVirtualUser()              // Pass userObject as argument              //Parsing the query string parameters from layout service api call var userId = Convert.ToString(HttpContext.Current.Request.Params["userid"]);                var user = CreateVirtualUser(userObject);
              //Read a custom property from the user object and assign it to the layout service context object                              
                isSecureAccessEnabled = user.Profile.GetCustomProperty("eligibility");
                
           //Modifying the response payload
args.ContextData.Add("userAccess", new { enabled = isSecureAccessEnabled });        }
public User CreateVirtualUser(string userObject) { //Deserializing the received userObject LoggedUser loggedUser = JsonConvert.DeserializeObject<LoggedUser>(userObject); //Parsing the data for creation of virtual user string userId = loggedUser.EmailId; string domain = loggedUser.Domain; string domainUser = string.Format(@"{0}\{1}", domain, userId); //Check if such a user already exists if (Sitecore.Security.Accounts.User.Exists(domainUser)) { return Sitecore.Security.Accounts.User.FromName(domainUser, true); } //Create virtual user based on the emailid User user = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(string.Format(@"{0}\{1}", domain, userId), true); user.RuntimeSettings.Load(); user.RuntimeSettings.AddedRoles.Clear(); user.Roles.RemoveAll(); if (loggedUser.IsEligible) { //Assign User Roles AssignUserRoles(user, userRole); } //Set the user profile and return return SetupVirtualUserProfile(user, loggedUser); } //Method to set the user role public void AssignUserRoles(User user, string userRole) { Role role = Role.FromName(userRole); if (role != null) { //Assign the role user.Roles.Add(Role.FromName(userRole)); } } //Method to setup the Virtual User Profile public User SetupVirtualUserProfile(User user, LoggedUser loggedUser) { //Set default values for custom properties user.Profile.FullName = loggedUser.EmailId; user.Profile.Email = loggedUser.EmailId; //Set custom properties for the user profile user.Profile.SetCustomProperty("isMaxUser", loggedUser.Eligibility.isISOnetUser.ToString()); user.Profile.SetCustomProperty("hasAddOnPermissions", loggedUser.Eligibility.hasAddOnPermissions()); //Save the profile user.Profile.Save(); user.RuntimeSettings.IsVirtual = true; user.RuntimeSettings.Save(); user.Profile.Reload(); return user; } }}

2. Create a patch Config file       

<?xml version="1.0" encoding="utf-8" ?>
<!--
Purpose: This include file configures the Layout service extension getLayoutServiceContext to verify user's access on Sitecore Item
-->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"  xmlns:role="http://www.sitecore.net/xmlconfig/role/" >
	<sitecore role:require="Standalone or ContentDelivery or ContentManagement">
		<pipelines>
			<group groupName="layoutService">
				<pipelines>
					<getLayoutServiceContext>
						<processor type="ABC.Pipelines.UserItemAuthorization, ABC.Pipelines"
								   resolve="true">							
						</processor>
					</getLayoutServiceContext>
				</pipelines>
			</group>
		</pipelines>		
	</sitecore>
</configuration>

3. Layout service API call with userId

/sitecore/api/layout/render/default?item={Page Item ID}&sc_apikey=67HJK9-2EB0-DFG67-AAA5-DFG789KJL&userid=abc@xyz.com


                                                        Happy Learning!

How to Create a Public Link Using the Sitecore Content Hub REST API

Creating a public link using the Sitecore Content Hub REST API is a straightforward process that enables you to share content externally whi...