Ever since I read that in a SUGCON Europe someone told, “The Answer to the Question, ” Can you customize in Sitecore the option to….?????” is always YES!! Irrespective how the question is finished ” in some random posts(Excuse me for the poor choice of words to recreate the context), I always wanted to extend some OOTB functionalities with custom logic. Hence, I wrote about Sitecore Custom Command, Sitecore Custom Workflow and others. This post is a new arrival to the that line up.
I have always wanted to write about personalization. How it can be useful and what difference does it really make. Instead of just writing about the steps and procedures I wanted to write a post along with the Business Case.
Also,
Rather than starting of with existing OOTB Rules, I thought I would start with a custom rule to personalize the contents of a page in Sitecore.
In this post, we will see what is personalization how and when to personalize the contents. Finally, we will work on creating a custom personalization rule.
Personalization
Personalization is the method for displaying targeted, relevant content to your contacts based on their characteristics and behavior, such as location, gender, or previous visits. With personalization, you can ensure that the right content reaches the right contacts, for example, by showing, hiding, or adjusting content.
That’s it. As Simple as it is. Delivering right content to right visitors.
In this post, we wont be working with Contacts or any other xdb data for personalizing the contents. As this would require a more vast preface. Will work on writing posts related to this down the line.
So, if not based on xdb data what else can be used to deliver a personalized content? Sitecore do come with some OOTB personalization rules and with SXA installed, this rule set now has everything needed.
In Sitecore, any content – data (template->item) is presented to users via renderings (Presentation Component). This Presentation Component has the data fed either from Context Item or via Data Source.
To start with the Basics, Personalization is nothing but showing/hiding or adjusting this Data Source based on certain rules set. So that when the rules are met a particular data is fed as source, if it’s not met, a different data is set as source or may be show/hide based on this rule.
So in the outlook, we will be delivering the perfect contents to right users .
As I mentioned, a few OOTB sitecore rules are based on xDB, GeoIP, visitors previous interaction data or current visits data. These are pretty much straight forward and can be implemented without any catalog.
Business case, when the HTTP Request has the parameter name State and it’s value is Tamil Nadu show one hero image if not show another image.
Let’s create the rule. HTTP Request Parameter Rule.
The Objective is, this rule checks for certain key value pair – HTTP Request Parameter and it’s value and returns true or false by comparing them. Based on this true/false (Bool) response, we will personalize the component (Set the Data Source for the Rendering)
To create a custom personalization rule,
- First, we have to create a tag (/sitecore/system/Settings/Rules/Definitions/Tags/HttpRequest Parameter) based on the template tag, /sitecore/templates/System/Rules/Taxonomy/Tag

- Now, create the corresponding element /sitecore/system/Settings/Rules/Definitions/Elements/HttpRequest Parameter based on the template /sitecore/templates/System/Rules/Taxonomy/Element Folder
- Under this HttpRequest Parameter, create a condition

- This is where, we will write the rule condition.
![Email
Federated Experience Manager
Federated Experience Manager -
Federated Experience Manager -
fields
HttpRequest Parameter
O Check Parameter
Tags
'vtsibility
Indexing & Search
Insert Options
Item Attributes
Item Hierarchy
Item Information
Item security
Item Version
Item Version CM
Marketing Automation
Item path:
Template:
Created from:
Item owner:
Check Parameter
Isitecore/systemJSettingsJRuIes}DefinitionsJEIements/HttpRequest Parameter/Check Parameter
(unknown]
sitecore%Admin
mere the http request [ParameterName„.name] parameter (Operatorld. Stringoperator„compares to] [Value„.specific value]
Type [snared]:
Mark3 Websites. Guardian. CustomRules. HttpRequestParameterValueCheck.Ma rk3 .Websites. Guardian](https://pushpaganan.home.blog/wp-content/uploads/2020/01/image-10.png?w=1024)
- Here, fill in the Text Field. This is what will be displayed in the Rule Set Dialog Box once we have completely configured our custom rule.
where the http request [ParameterName,,,name] parameter [OperatorId, StringOperator,,compares to] [Value,,,specific value]
- A Few Notes on the keywords I have used in the Text Field Value
- [ParameterName,,,name] ParameterName is used to store the HTTPRequest Parameter Name.
- [OperatorId, StringOperator,,compares to] this is used to set the comparison operator between the ParameterName and Value.
- [Value,,,specific value] is used to store the Value of the HTTPRequest Parameter.
- A Sneak Peak on the final output of how this rule will look like – when it’s deployed.

- The Second Field – Type in Script Section. Here we’ll add the Namespace, assembly of the class that contains the business logic to check whether this rule is passed (return true) or not (returns false)
Mark3.Websites.Guardian.CustomRules.HttpRequestParameterValueCheck,Mark3.Websites.Guardian
- Now, include the created HTTPRequest Parameter tag which we created in the default tag.

- Finally, include the tag created in the conditional rendering for the rule which we created to appear in the specify rules section of personalization window.

The Business Logic, It is pretty much straight forward. The class which we create must override the Execute Method, where we check the ParameterName and Value which is passed via Personalize the Component Dialog Box.
Here we use StringOperatorCondition and it’s Compare class to compare the two strings with the String Comparison operator we set in the GUI.

Now, let’s add this rule to one of our component and personalize it and check the results.
We will personalize the Hero Image component.

- One key point is that we should enable the personalize the presentation of the component switch and include the default rule set aka when the mentioned rules are not passed and the component’s default state has to be presented.
- Now, add the rule and set the HTTPRequest Parameter and it’s Value

- When the condition is met show the same rendering with different data source

We can set this State – Tamil Nadu parameter to the request while hitting/redirecting to the target URL. And the page component would be personalized based on that. Sitecore do has Query String based rule similar to this, but this rule can be used in cases where Query String is not an option.
Page with Personalized Hero Image aka HTTPRequest with State Parameter Equals to Tamil Nadu

Page without Personalized Hero Image – Aka HTTPRequest without State Parameter equals Tamil Nadu

Pardon me for the poor choice of images and relative news article. This Personalization Rule can much better be put in to great use.
3 thoughts on “Sitecore Personalization -Using Custom Personalization Rule”