Sitecore Conditional Renderings Rules aka custom Personalization rules

One of my favorite feature of Sitecore is the ability to create complex business rules to serve dynamic & personalised content to end users.

This functionality is available on almost all the version from Sitecore 6 unitl Sitecore 10 and it helped clients to deliver elegant solutions and deliver personalised experiences. Note that there are some limitations/differences in the XM Cloud version.

As you probably know on presentation details you can personalise renderings and have a set of predefined rules defined as conditional renderings. Within this post I will explain how you can extend the rules conditions so that you can and create your own custom rules to deliver personalised content to targeted users.

Within my example I am creating a custom rule to extend Salesforce personalisation, my hypotetical usecase is the following one, I want to display a personalised banner to customers enrolled in a custom Salesforce campaign and only for customers who have a specific cookie….

Steps to create your custom Rule

Create the element and point towards your Class / Assembly

Element got created in a folder under: /sitecore/system/Settings/Rules/Definitions/Elements/

Define the tags so that your rule will show in the correct category and in the right place

Create a Tag

Assign the tag to the conditional renderings

Implement your custom c# class to execute your business logic

this is the core of the logic to evaluate the rule, you can check external service, cookies, querystring or whatever custom code you need to implement (within my Salesforce extension I am checking some XDB facets but that’s not very useful to this post…)

Within the code, you can have your custom logic to check a specific cookie and XDB facet value and return true or false to evalute the rule just as an example…

using Sitecore.Analytics;
using Sitecore.Analytics.XConnect.Facets;
using Sitecore.Diagnostics;
using Sitecore.Rules;
using Sitecore.Rules.Conditions;
using Sitecore.XConnect;
using Sitecore.Xdb.Configuration;
using System.Collections.Generic;
using System.Linq;
namespace XXXX.Foundation.XConnect.Rules
{
public class SalesforceCustomCampaign<T> : StringOperatorCondition<T> where T : RuleContext
{
public string CampaignValue { get; set; }
protected override bool Execute(T ruleContext)
{
Assert.ArgumentNotNull(ruleContext, "ruleContext");
Log.Info($"[SalesforceCustomCampaignRule] EvaluatingRule", this);
/*Add your custom logic to return true if the rule is satisfied and false if it is not
eg. check cookies, querystring or any other fancy code you need…
*/
return false;
}
}
}

Once you have everything configured you can publish the items created and test your new rule in action

further reference on Custom personalised rules can be found here:

Sitecore- How to Create Custom Personalization Rules | Valtech

How to personalize callouts based on triggered goals in Sitecore (techguilds.com)

Personalization | Sitecore Documentation

One thought on “Sitecore Conditional Renderings Rules aka custom Personalization rules

Leave a comment