A pipeline dive into Sitecore Personalization using Conditional Renderings


“I have no special talents. I am only passionately curious.” -Albert einstein

I recently encountered a question in Sitecore.stackexchange.com. Question is about how to retrieve the Default Datasource and personalized datasource for a rendering component that has Conditional Rendering personalization rule. Link to Question is below


As the quote above says, I got passionately curious to understand How Sitecore Stuff works behind the scenes for personalization by Conditional Renderings. So, I started digging and opened my favorite .NET Tool dotPeek

So, here is the magic(read pipelines and processors) behind Conditional Renderings.


For those who are not aware,

Any renderings we add onto page resides in PlaceHolder. So, we will start looking from rendering them and go deeper. Though there is lot more that will happen ahead of placeholder rendering, we will omit it for keeping this post simple. Inside the <mvc.renderPlaceholder> pipeline there is a processor called "PerformRendering".

PerformRendering processor calls the pipeline <mvc.renderRendering> pipeline. This pipeline will call the corresponding render for rendering the content. And this is the point of discussion for this blog post.

In order to identify the Renderer Sitecore calls the <mvc.getRenderer> pipeline. There is a processor inside this pipeline called "Sitecore.Mvc.Analytics.Pipelines.Response.GetRenderer.CustomizeRendering".

This pipeline internally calls another pipeline <mvc.customizeRendering>. Inside this pipeline we have a processor called "Sitecore.Mvc.Analytics.Pipelines.Response.CustomizeRendering.Personalize". This is the processor checks if the Tracker is Active to run the pipeline and is responsible for running the rules and applying the actions.

This processor calls the <getRenderingRules> pipeline to get the rules from the underlying rendering. Here it looks in the rendering.Properties["RenderingXml"] for retrieving the personalization rules associated with in the rendering.

Perosonalization Rules from Rendering
 
 
There are 3 events  namely Evaluating, Evaluated and Applied. One can hook to these events and drive any custom tasks to perform. Out-of-Box Sitecore uses the Evaluated event and runs the <renderingRuleEvaluated> pipeline.

Because by the time the controller receives the Rendering details all the personalization rules are applied there is a pecking order for the Rendering DataSource and below is how it picks

  1. DataSource selected in the Action section of Rule that is applied
  2. The order of Default DataSource will be
    1. DS selected in the Action section
    2. If Action Section is empty, then DS selected from Rendering Parameters
    3. If none of them are set then RenderingReference.Settings.DataSource is empty. But the actual Rendering DataSource set to PageItem


Now that we know the pipelines and their relation it can be used to introduce custom rule evaluating or rule applied pipelines for further customization. 

Please share your thoughts on what you think about the blog.

Comments