Author : Vikas Kumar
Director - Customer Experience, Espire | Sitecore MVP 2021

Vikas is a Sitecore MVP who heads the Digital Experience Platform (DXP) initiatives at Espire. A skilled craftsman in competency building, Vikas is a go-to-CMS expert, known for designing & developing best practices, that consistently transforms digital journey for clients.

Driving personalization with xConnect APIs and custom facet data | Part 2


This blog post is in continuation to the post 'Driving Personalization with xConnect APIs and Custom Facet Data | Part 1'.

The previous post described how to create a custom facet in Sitecore xConnect, utilizing xConnect API to create a custom console application to create contacts in XDB and saving data in custom facets for those contacts.

This post will focus on the steps required to use the custom data captured to identify the contact visiting the website and rendering personalized content with the help of custom personalization rules.

Follow our session on YouTube

Deploy Model to Sitecore

This step is for enabling Sitecore to account for the new collection model and facets to be loaded when contact data is fetched from XDB for tracking.

  • Add reference to the library containing the model details to your website application
  • Create the following patch file and publish to your Sitecore instance

Sitecore Blog

Identifying the contact

While creating the contact, we added a unique ID as the identifier instead of the email. In our demo scenario we want the visitor to be identified using this unique ID which is available I the query string of the URL that was provided to the student to access the website.

1. We now add a processor the ‘mvc.requestBegin’ pipeline, which would identify the used based on the query string value as soon as the page loads.

 public class IdentifyContactOnLoad : RequestBeginProcessor 
        readonly string source = Sitecore.Configuration.Settings.GetSetting("UIDSource"); 
        readonly string uidQueryString = Sitecore.Configuration.Settings.GetSetting("QueryString"); 
        public override void Process(RequestBeginArgs args) 

            if (HttpContext.Current.Request.QueryString.HasKeys()) 

                var uid = HttpContext.Current.Request.QueryString[uidQueryString]; 
                if (!string.IsNullOrEmpty(uid)) 
                    XConnectHelper.IdentifyUser(uid, source); 

    public class XConnectHelper 
        public static string facetName = Sitecore.Configuration.Settings.GetSetting("FacetName"); 
        public static string redirectUrl = Sitecore.Configuration.Settings.GetSetting("RedirectUrl"); 
        readonly static string uidQueryString = Sitecore.Configuration.Settings.GetSetting("QueryString"); 
        public static void IdentifyUser(string uid, string source) 

                if (Tracker.Current != null) 

                if (Tracker.Current == null && Tracker.Enabled) 

                if (Tracker.Current != null && Tracker.Current.IsActive && Tracker.Current.Session != null) 
                    Tracker.Current.Session.IdentifyAs(source, uid); 

            catch (Exception ex) 

2. Add the following patch in a config file to patch the processor created to the pipeline:

Sitecore Blog 2-2

Creating custom personalization rule

We now want to create a custom personalization rule that would work on the custom facet value to deliver personalized content to the students.

Application changes

1. Extended helper method to retrieve custom facet data from Tracker
Add the following method to the XConnectHelper class to retrieve custom facet data from the tracker.

 public static string GetCourseName() 
            return string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[uidQueryString]) ? "" : StudentInfoFacets().Courses; 

        public static string GetCountry() 
            return string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[uidQueryString]) ? "" : StudentInfoFacets().Country; 

        private static StudentInfo StudentInfoFacets() 
            var xConnectFacets = Tracker.Current.Contact.GetFacet("XConnectFacets"); 
            return xConnectFacets.Facets[StudentInfo.DefaultFacetKey] as StudentInfo; 

2. Create custom condition class for the rule

Create a custom rule which would enable rendering different content based on the Course that the student has registered for.

public class DegreeRule : StringOperatorCondition where T : RuleContext 
        public string DegreeValue { get; set; } 
        protected override bool Execute(T ruleContext) 
            string studyArea = XConnectHelper.GetCourseName(); 
            if (!string.IsNullOrEmpty(XConnectHelper.GetCourseName())) 
                if (DegreeValue.ToString().ToLower() == studyArea.ToLower()) 
                    return true; 
            return false; 

3. Publish the changes to the Sitecore instance

Sitecore Changes

  • Create a custom condition in Sitecore at ‘/sitecore/system/Settings/Rules/Definitions/Elements'
  • In the text field mention the rule text, which would show up in the Personalization Editor
  • In the type field enter the custom condition class created and the library name
  • Save the item

Sitecore blog1

  • Use the rule set editor to setup personalized variants for content based on the Course selected by the student

Sitecore blog2

That's it, create more rules to utilize the custom data captured and deliver a highly personalized experience for your visitors.


Optimized data and content management with Azure-based solutions for a leading Singapore-headquartered transshipment hub

The customer's existing website was deployed on-premises and leveraged a WCM platform, Joomla. They required a strategic technology partner to carry out Azure migration and eliminate on-premise hosting environment. They also needed managed support services for monitoring website up-time and efficient incident management.

Developed Automation Testing Framework for Sitecore Application to Improve Operational Efficiency

Espire created automated scripts for their daily regression suite for improving operational efficiency & Successfully integrated the automation testing framework with the Sitecore application for easily identifying the CX problems faced by the customers

Designed a DXP Platform to Enhance CX for a UK-based Integrated Marketing & Communications Company

A leading UK-based integrated marketing & communications company which assists businesses in brand deployment, digital transformation, marketing communications and driving customer experience across all digital channels, One of the primary challenge sighted by the client was an absence of an Intranet Portal, which would act as a scalable DXP solution to onboard as many clients as needed

Insurance claims management system top 5 ways to maximize business growth

Insurance companies have been struggling with disparate systems and outdated claims processes for decades. Leveraging claims management software can help brands in the insurance industry automate manual processes and optimize workflows, while improving staff efficiency and reducing operational costs

Top 5 reasons how sitecore experience edge enhances content delivery and digital experiences

Sitecore Experience Edge is a revolutionary SaaS-based platform with headless content delivery capability, which will help brands drive engaging digital experiences and maximize revenue growth. Aimed at improving content delivery across touchpoints, Sitecore Experience Edge does not add any architectural complexity, maximizing both marketing and IT efficiencies

Mitigating the problem of unallocated cash in insurance industry with digital transformation

Businesses in the insurance sector need to deploy agile technology solutions to reinvent complex operational processes and adopt an aggressive strategy for the efficient management of unallocated cash, to strengthen their credit position and build lasting customer relationships

How sitecore dxp platform can help banking and financial sector to drive future ready digital

As more and more brands in the banking and financial sector are adopting a ‘phygital’ operating model, it has become imperative for them to get a 360-degree view of their customer behavior across touchpoints to drive contextual communications catering to their dynamic needs. In this blog, we discuss how the Sitecore DXP Platform is helping brands in the BFSI sector drive personalized digital experiences across touchpoints to bolster growth.

Subscribe To Our Blog

By clicking on "SUBSCRIBE NOW" you acknowledge having read our Privacy Notice.