Sitecore has a large number of personalization and automation conditions. Understanding how conditions work and the data behind each condition is essential for successful experience optimization.
Contact profile values are stored in multiple locations in the Collections database. Historical data is stored in a ProfileScores facet for each interaction. It is also cached in a contact InteractionsCache facet. Final contact behaviour profile is stored in a contact Behavior profile facet.
What important is that next to each Profile Score, Sitecore stores matching profile pattern.
Once any interaction matches profile pattern such pattern will be listed in the ProfileScores facet.
During one of our projects, we found some conditions don't behave according to our expectations.
We used the following out of the box conditions:
- /sitecore/system/Settings/Rules/Definitions/Elements/XConnect - Visit Conditions/Where Contact Has Matched Profile Key Value in Profile
- /sitecore/system/Settings/Rules/Definitions/Elements/XConnect - Visit Search Queries/Where Contact Has Matched Pattern Card In Profile
Sitecore evaluates an entire interactions history for the above conditions.
Doing some tests we found that both conditions are evaluated against all interactions available in Sitecore Collection DB. So if a contact has ever matched a pattern in the past, the above mentioned conditions will be evaluated to True. While this is reasonable in some profiling and personalization scenarios it did not quite match our project needs. Instead, we needed a condition like Where Contact Matches Pattern Card In Profile Now. i.e. instead of checking all historical data, we wanted to evaluate the current state (or final state of the contact).
Consider the following sample scenario where Product Profile score is collected as a summary between interactions.
|Product Profile score||Interaction 1||Interaction 2||Interaction 3||Interaction 4||Interaction 5|
Notice that for product B contact is progressing much better collecting higher profile score. According to project marketing definitions, this contact matched Awareness Stage pattern after 2 interactions, Evaluation Stage pattern after 4 interactions, Action Stage pattern after Interaction 5.
If you were to use out of the box Where Contact Has Matched Pattern Card condition for segmentation to show different message for a contact matching Product B Awareness Stage you condition will always be True even when contact progressed to the Action Stage pattern match. Same issue will apply if you try to evaluate pattern match in the Marketing Automation plan definition (entry condition or custom listener).
So we get to a point where a custom condition has to be created.
Instead of checking historical data we can check final state data available in a ContactBehaviourProfile facet.
Implementation is fairly easy and this post is not intended to go into implementation details. You can find the source code and configuration files on GitHub. Once you get to the code you will find two sets of conditions:
- a traditional ComparisonCondition for RulesContext which has to be used for in-session personalization.
- an ICondition + IContactSearchQuery implementation which can be used for List Segmentation and Marketing Automation conditions.
Be sure to follow Sitecore documentation for rules definition and deployment.