Sitecore CMS: Custom Personalization Rules in Sitecore 9

Personalization allows you to deliver the target the component in which your visitor showing interest. For example, visitor visits or browse specific product feature, specification, details, etc. on website.

So, you show personalized content to the visitor on the basis of his previous behavior on the website.

You can create a personalization rule on basis of the goal, Campaign, custom facet, etc. Your website will respond to the basis of the above-defined rules and display or hide specific components or change their behavior.


To start with custom personalization, you need to perform the below steps:

Step 1:   Go to the path “ /Sitecore/system/Settings/Rules/Definitions/Tags ” right-click on Tags and add a new customize Tag (I have given a name CustomPersonalization):



Step 2:
    Go to the path “ /Sitecore/system/Settings/Rules/Conditional Renderings ” and expand conditional rendering and add created tag into the Tags property of the default tag as below:



Step 3:
  Go to the path “/Sitecore/system/Settings/Rules/Definitions/Elements
  ·    Right-click on Elements and add a new Element folder (I have given the name CustomPersonalization).

Text property: Give the condition with the rule which will show to the content editor.

Type Property: Specify your class name with a namespace followed by the assembly name, where you will write your personalization rule business logic.





Step 4:   Now you need to add created tag into the default tag, Tags property of element folder:



Step 5:   Write your personalization rule business logic as below or update your code as per requirement:

public class PersonaliseRuleService<T> : StringOperatorCondition<T> where T : RuleContext
    {
        public string Value { get; set; }
        protected override bool Execute(T ruleContext)
        {
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            HttpCookie customCookie = HttpContext.Current.Request.Cookies["Custom_Personalization"];      
     if (Value.ToLower().Equals(customCookie.Value.ToLower()))
            {
                return true;
            }
            return false;
        }
    }

Step 6:
  
 After completion of all the above changes, you need to set our personalization rule on the component using experience editor.

Go to the page presentation details and select that rendering and click on personalize section.

Add your personalization rule and select Edit rule then select your created rule and update the data source from the content property.







Same you can create a more custom rule to show relevant content to the visitor.

Happy Sitecoreing 🌝



Comments