Sitecore Rules Integration

The Send2CRM personalization cookie can be used to integrate with Sitecore rules in the Experience Editor for a seamless user interface.

Create Sitecore Rules items

  1. Create a new Tag named send2crm under /sitecore/system/Settings/Rules/Definitions/Tags.

  2. Add this Tag to the Selected items for /sitecore/system/Settings/Rules/Conditional Renderings/Tags/Default.

  3. Create an Element Folder named send2crm under /sitecore/system/Settings/Rules/Definitions/Elements.

  4. Add the Tag from step 1 to the Selected items for /sitecore/system/Settings/Rules/Definitions/Elements/send2crm/Tags/Default.

  5. Create a Condition named CookieValue under /sitecore/system/Settings/Rules/Definitions/Elements/send2crm:

    • Text: “where Send2CRM Personalization [OperatorId,StringOperator,,compares to] [Value,,,personalize value]”

    • Code: all code below including the namespace

    • References: “bin/Sitecore.Kernel.dll,bin/System.Web.Http.dll”

    • Language: “C#”

  6. Save and publish all above.

namespace send2crm { public class CookieValue<T> : Sitecore.Rules.Conditions.StringOperatorCondition<T> where T : Sitecore.Rules.RuleContext { public string Value { get; set; } protected override bool Execute(T ruleContext) { Sitecore.Diagnostics.Assert.ArgumentNotNull(ruleContext, "ruleContext"); System.Web.HttpCookie customCookie = System.Web.HttpContext.Current.Request.Cookies.Get("send2crmPersonalization"); if (customCookie == null) return false; return Compare(customCookie.Value, Value); } } }

Apply the Rule

When using the Experience Editor, the new condition should now be visible under the send2crm heading.

The personalization cookie includes all Segments for the visitor in a pipe-separate (|) string. For example |SEGMENT1|SEGMENT2|SEGMENT3|. Generally the easiest way to match an entire Segment is to use the Contains operator and enclose the target Segment name in pipes, for example contains “|SEGMENT2|” would evaluate to true.