Is it possible to use the Segment Builder rule "Matches Pattern" as a page editor personalisation option?

546 views Asked by At

We want to match visitors to pattern cards based on all visits they've made, not just the current visit. The Segment Builder rule "Matches Pattern" is:

where the visitor matches the [PatternName,Pattern,selectprofilefirst=1&resulttype=Name,specific] pattern card in the [ProfileName,Profile,resulttype=Name,specific] profile

This is from

Sitecore.Analytics.Rules.SegmentBuilder.Conditions.HasPatternCondition,Sitecore.SegmentBuilder

Is it possible to add this to the available personalisation rules a page editor can choose for a component, and to have it evaluated at runtime?

Sitecore.NET 7.2 (rev. 140526)

1

There are 1 answers

0
Derek Hunziker On BEST ANSWER

The Segment Builder rules are designed to match large collections of existing visitors based on your criteria. If you inspect the code for any of the Segment Builder conditions, you'll see that they build up a clause that is eventually executed against the Visitors table.

You are right about the OOTB Conditional Rendering rule only matching Pattern Cards for the current visit. Thankfully, it's pretty easy to extend the rule to include profiles across all visits:

using Sitecore.Analytics;
using Sitecore.Analytics.Data.DataAccess;
using Sitecore.Analytics.Rules.Conditions;
using Sitecore.Rules;

namespace MyProject.Web.Analytics.Rules.Conditions.Patterns
{
    public class VisitorHasPatternCondition<T> : HasPatternCondition<T> where T : RuleContext
    {
        protected override bool Execute(T ruleContext)
        {
            // Load all profiles into current dataset
            Tracker.Visitor.LoadAll(VisitLoadOptions.Profiles, VisitorOptions.None);

            return base.Execute(ruleContext);
        }
    }
}

The LoadAll() method will load all of visitor's profiles into the current DataSet. We then call the base Execute() method which checks the DataSet for matching Pattern Cards.