According to the following sitecore post: https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/personalization/insession_personalization/pattern_cards

"Sitecore calculates the average score that the visitor has accumulated for each profile and maps the visitor to the pattern card that is the closest match"

What i would like to do is personalize certain modules depending on a users pattern card and in order to do so, programmatically aquire the best matching pattern card for the current visitor.

I've tried looking under Tracking.Current.Interactions and Tracking.Current.Contact to find the best matching pattern card but to no avail.

Is such data available or am i approaching this the wrong way?

2 Answers 2


You have to take each profile and test it for a pattern match.

For each profile, you can run the code below against the profile name. userPattern.PatternId.HasValue tells you if the pattern is hit.

var interactionProfile = Tracker.Current.Interaction.Profiles[visibleProfileItem.Name];
if (interactionProfile != null)
    // load the details about the matching pattern
    if (interactionProfile.PatternId.HasValue)
        Item matchingPattern = Sitecore.Context.Database.GetItem(interactionProfile.PatternId.ToId());
        if (matchingPattern != null)
            //handle your patterns here    

Habitat Code

Here is the a link to the similar code in habitat. You can use this for almost anything you are trying to accomplish.


  • 1
    Great answer, Chris! +1 My only suggestion would be to change the name of the userPattern variable to interactionProfile to avoid confusion. Sep 11, 2017 at 16:07
  • 1
    Good idea @zachary, done. When you posted your answer, it made me wonder if they just wanted to switch out renderings, based on pattern in the UI. Thats the best practice way anyway and is available without any work. Either way, I think they are covered.
    – Chris Auer
    Sep 11, 2017 at 18:21

The answer provided by @ChrisAuer is 100% correct, but I wanted to share a little more detail with you, as well.

Taxonomy and Profiles

Sitecore includes support for personalizing and tracking a visitor against an indeterminate number of profiles at any given time. A profile can be thought of as a context for personalization.

As highlighted in the below image, Sitecore includes four different profiles out of the box: Focus, Function, Persona and Score. Each of these profiles have their own profile keys, pattern cards, and profile cards, and they can all be tracked and personalized against at the same time. This means that if you're tracking against 10 different profiles, then your visitor might actually have matched 10 different patterns, one for each profile.

enter image description here

Finding the Right Pattern

Given that your visitor might have any number of matched patterns but at most one for each profile, if you know the profile that you are looking to personalize against then you can find the singular pattern, if any, that the visitor matches for that profile.

This is where @ChrisAuer's solution comes into play:

  1. Retrieve the interaction profile from the visitor that matches the profile that you are looking to personalize against
  2. Ensure that the interaction profile is not null (it will be if the user has not yet been scoredfor the profile you are looking to personalize against)
  3. Check if the interaction profile has a PatternId (holds the ID of the matched pattern, if any - automatically updated when visitor is scored for the profile)
  4. Retrieve the pattern card with the PatternId from Sitecore and ensure that it is not null

Personalizing Components without Code

If you are looking to personalize renderings, you can use the native personalization tools to do so without any additional coding. You can do this using Conditional Renderings and the Rule Set Editor, which you can access from the page item's Layout Details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.