Sitecore-how to create custom personalization rule

Personalization is the method for displaying targeted and relevant content to  website visitors based on different characteristics  like location, age, visits, etc.. There are several rules available out of the box in Sitecore which can be leveraged to personalize web pages.


It is also possible that we have to build and create custom personalization rules to support certain business requirements, Sitecore architecture is flexible enough to support this scenario and can be extended to implement custom rules based on the requirement.

As part of this post, i would like to show how we can extend and build custom personalization rules, we will take an example of creating a custom rule where based on querystring parameter value how we can display different content to our site visitors.

Let’s take an example where we would like to show website visitor component-1 when user search for keyword=”content” and show component-2 when user search for keyword “management”.

Here are the steps to follow:

Step 1- First step is to create a new tag for our Custom rule under “/sitecore/system/Settings/Rules/Definitions/Tags” based on template- “/sitecore/templates/System/Rules/Taxonomy/Tag”


Step 2- Next- create custom Element and personalization condition under “/sitecore/system/Settings/Rules/Definitions/Elements”


As part of personalization condition there are two fields to populate:

  • Text
    • It shows text that would be presented to content editors when using this condition with Rules Engine, this is what we have used in this example-
    • Where the querystring parameter search has a value that [operatorid,StringOperator,,compares to] [querystringvalue,,,Value]

    • Everything under square brackets []  would be replaced by Rules Enging as selectors.
  • Type
    • Type specifies fully qualified class and assembly names where we want to write/perform the business rule for the custom personalization condition.

Step 3- Next step is to assign custom tag which we created in step#1 to default element tag definition.


Step 4- Next- we would need to add this tag to conditional rendering such that this new rule is available in the rule editor for content editors to personalize the components, please make sure to name your tags and custom elements self explanatory as much as possible for better content editors experience.


Step 5- Once all the above changes are made content/business editors can configure this rule to personalize the components from experience editor or content editor from presentation->Personalize section.


In the below code snippet we can see that we have created a class SCCustomRule which inherits StringOperatorCondition class and override Execute(T ruleContext) method -as we are trying to compare the querystring value of what has been configured in the rule editor and what has been actually entered by end user.

If the parameter values matches the rule is satisfied and the personalized component will be displayed else it would display the default component.


Similarly we can create other custom rules to show more relevant and targeted content to our end users based on how they have interacted and what details they have stored in the system (internal/external)

Hope this helps.

Happy learning 🙂

Sitecore Basics- Introduction to Personalization

The scope of this blog post is to give an idea about personalization in Sitecore, why it’s required and steps to create  and configure personalization for the components, this is for beginners who are trying to understand the concept and how it can be implemented.

Personalization enables you to deliver targeted content to your visitors. For example, you can implement rules that show personalized content to visitors based on their browsing behavior and their accumulated profile values.
This is really important as you don’t want to show something to users which really doesn’t makes any sense to them.


As an example- For an e-Commerce application as an business you want to show relevant information to users to get most of the conversions, this depends on number of factors, some of them includes:

  • User behavior
  • Location
  • Goals users have triggered.
  • Anonymous Vs Logged in users
  • Based on Subscription
  • Showing different banner images.

Sitecore XP lets you choose from several personalization approaches:

  1. Rules-based personalization: You define the conditions under which content is delivered to a customer. For example, you can set rules based on the IP address or physical location of your visitors, the keywords they use to reach your site, their mobile device, or the goals that they achieve on your website to determine the content that is displayed.
  2. Adaptive personalization- Use visitor profiles and pattern-card matching to dynamically adapt the content shown to visitors in real time. You can set adaptive personalization rules in Sitecore XP’s Rules Set Editor.
  3. Historical personalization: You can set rules that personalize content based on a contact’s historical or past behavior, rather than their actions from the current session (after all, context is what comes before and after the present).
  4. Test and then personalize: With Sitecore XP, you can use A/B and multivariate testing to assess your content and use the test results to optimize for conversion rates against your site’s goals. You can also use testing to assess which type of content works best with certain segments of your visitors.
  5. Journey-based personalization: Design user journeys with Sitecore XP using advanced business logic, and use them to help assess where your customers are in their journey with your brand. Then you can use triggers to advance them through their journeys in context of how far along they are.

We use Rule set editor ( ) to set the rules and action to perform and configure personalization for the individual components.

There are several out of the box categories which we can use to personalize the components, which includes:

  1. Campaigns
  2. Channels
  3. Date
  4. Device
  5. Fields
  6. GeoIP
  7. Tracking
  8. Visit and etc.

Personalizing the Component:

In order to personalize the component we have to make sure that the component which you are targeting to personalize should support datasource, this would help us in assigning different contents based on different criteria set.

Here are the steps to configure personalization for specific component(s):

  1. Select the component that you want to personalize, you can select the component either from presentation or from Experience editor.Personalization-1
  2. Select the component and click on Personalize button.
  3. Click on the “New Condition” button and add the rule which you want to add based on the requirement.
  4. Click on Edit button and add the rule.Personalization-2
  5. As an example- i am adding the rule which is based on field name compares to specific value.Personalization-3
  6. We can also define the default or fallback component datasource, if none of the conditions matches the default will be used.Personalization-4
  7. Once the configurations are done on the component, we can see an indicator in the presentation which shows that personalization has been applied to the specific rendering/component.Personalization-5
  8. We can personalize the component from experience editor as well.Personalization-6
  9. Now based on the condition which is added on the component, related content will be rendered else the default content will be displayed.


Custom Personalization:

There are certain scenarios where out of the box personalization which are available are not enough to handle the business scenarios, in those cases we have to think about creating custom personalization rules.

We need to create a class that inherits from Sitecore.Rules.Context and implement the Execute() method,and this is where all the business rule exits for the custom rule. We will be covering in a separate blog post about how to create custom personalization rule and applying it on the renderings.

Hope this helps.

Happy learning and wish you all a very Happy New Year 2018 🙂


Sitecore best practice and guidelines

There are several useful articles and blogs about #Sitecore best practices, but I am trying to put together my learning on this area. Sitecore has different components shipped within it i.e “analytics“, “workflows“,”personalization” and others.

Before starting or working on any application, our main focus should be to understand application as a whole and not just part of it, believe me this is a key for overall success of your implementation, try to get involved and get more and more information about the solution as a whole.Once you have a big picture in mind, it’s easy to work on small features and then for integrations.

There are several categories we can have, when we talk about Sitecore best practices:

  1. Template.
  2. Content structure.
  3. Presentation.

Templates: Templates are the base for any Sitecore implementation, templates are grouping of certain fields that make one entity/table in Sitecore, which can have one or more then one field(s). There are few things which we should consider while designing a template.

  • Think about the entity first and all related fields which can be grouped.
  • List down all the fields which needs to be added to a particular entity.
  • Now identity if there are any set of fields which are common to other entities as well, at least to few, if not all, like “Headline”,”Teaser”, “Main Content” or “Image” fields.
  • If you get a list of common fields, then create a new “Base Template” and add all those fields in that template, this is also to make sure we are reusing the template and fields as much as possible.
  • You can use the “Display Name” property to provide a user-friendly name for any item.
  • Always try to group fields in section, this is logic separation of fields, still all the fields comes under same template only.
  • Try to give user friendly name for all sections,fields and templates so that business users/content authors can identify and understand them easily.
  • Always set default values in standard values of template, so that we can prepopulate some of the field values.
  • If there is predefined structure we have to follow, we should always consider branching template, this really helps content authors and they will love you for this.
  • Try to have unique icon added to you template, so that it is easy to recognize.
  • Presentation should be configured in standard values, so that it can be applied to all instances of that template.
  • Creation of “Base Templates” should always be in your radar, so that you can make use of Sitecore inheritance where required.

Content structure: This is the second step where we create items based on the template created, content structure helps content authors to look for the information or details they are interested, here are some of the things that we should consider while creating/designing content structure.

  • As a standard, try not to have more than 100 items under particular node, can be folder or page item, this can impact Sitecore performance.
  • If expecting more than 100, then consider using buckets or if not buckets create folders in a way that it doesn’t exceed more then 100 child per folder/item.
  • Try to have only page items created under home page, this can change, you can read my blog on different options for configuring content tree
  • Plan content structure based on site map, place all the items which are accessed using URL as descendants of the website, we should mimic sitemap structure in sitemap as well.
  • Make sure we have security added for items which which should not be accessed by specific user role(s).
  • Indexes should be configured for automatic updates,for better and faster content editor experience.
  • Make sure to consider multi-site environment as well, and create folder accordingly, this also helps in content sharing from one site to another.
  • Try to create folder template for structuring page items, should try for it as much as possible so that we have more control on the tree.
  • Maintain only a few versions of each item in the implementation- this is to improve the performance.

Presentation : Some of the things to consider while setting up the presentation:

  • Page should be Experience editor friendly.
  • Make sure to use Experience editor friendly tags like
  • Sublayout(s) and Rendering(s) should be configured to be cachable for better browsing experience.
  • Rendering should be added to page template standard values,when applied at an item level, any changes to the layouts require a lot of effort to make changes to all items. When applied at standard values, such modifications become easier.
  • Any updates to the specific should be done directly on final layouts, please read my blog for more details-
  • Rendering should have data source template and data source location defined, this helps personalizing the site and making sure the application is experience editor friendly, this is important configuration for Experience editor.
  • All the components/rendering(s) should have thumbnail image added to it, this helps CAs configuring dealing experience editor nicely.
  • Use placeholders settings and allowed control setting, so that CAs can add/create only those modules which are required for that page design to work.

General Practice:

  • Don’t allow a single template to contain two fields with the same name.
  • Use a source code management system to manage all code,this includes JavaScript and CSS as well.
  • Avoid hard-coding as much as possible so that we don’t have to update the code, if any change required.
  • Use IDs instead of paths/name whenever possible.
  • Avoid using any form of the descendant axix, like GetDescendents
  • Try not to modify Sitecore base files and use Sitecore patching for any updates to config files, this helps in upgrade process if required.
  • Content Editing should be done on the master database, and then pushed to web database.
  • Restrict access to content delivery servers.
  • Use the general best practices of developments applicable to C# with tools like Re-sharper.
  • Set up continuous integration.

As I mentioned before there are lot of articles that has more details on best practices and guidelines, please make sure to read those as well.

I hope this will give you some degree of information, which can be applied while designing any structuring your Sitecore site.

Please feel free to add feedback and comments, happy to discuss more.

Happy learning 🙂

Sitecore | Shared vs Final layouts

One of the new features of Sitecore 8 is the introduction of versioned layouts.

Language Version Layouts give content editors the ability to create different layout definitions for each language version for an item. In Sitecore 8 there is now a Shared Layout and a Final Layout tab in the presentation details dialogue of an item. This is where the magic for the versioning is configured.

The Shared Layout section stores the renderings that are shared across all language versions of an item, while the Final Layout section, stores the renderings that are specific to the current language version you are editing. The Final Layout details panel displays the final combination of presentation details, and determines what is rendered when viewing the current version of the item.


This new feature allows Sitecore users to design and market pages based on different languages. Content editors can now not only update the datasource on a component based on personalization rules, but can also present a different layout structure, including or removing components per language version.

This gives the content editor and marketing team a wider range of variations. If a multi-language site has a different marketing plan or promotional offers based on the language, marketers are no longer restricted to rendering the same components for all languages. The language version layouts open many doors for a customized user experience.

There are however some things that Sitecore users need to remember about this new tool. Currently there isn’t a way to update the shared layouts field from the Experience Editor.


Question : What layout do you modify when you edit a page in Experience Editor?

Answer: Final Layout

Before Sitecore 8 regardless of item or language version, it used to update the shared layout,as there was no final layout present.when we open a page item we basically create a delta against page template, and will be presented with the page layout with the delta merged which gets updated to _Renderings field.

From Sitecore 8, we still create delta of what we have in the page template, but the page layout will be presented and updated to _Final Renderings field, which is versioned per language.

Please share your feedback and comments, as how we can make this a great learning platform, much appreciated.

Happy learning 🙂