PersonalizationΒΆ
By adding a custom condition for the Sitecore Rules Editor you can allow content authors to personalize web pages using the visitor’s account.
- In Visual Studio, add the following references to the project:
- Sitecore.Analytics.dll
- Add the following class:
using Examples.DynamicsCrm.Models;
using Sitecore.Analytics.DynamicsCrm.Rules.Contacts.Conditions;
using Sitecore.Analytics.Tracking;
using Sitecore.Rules;
using System;
namespace Examples.DynamicsCrm.Rules
{
public class PersonalizationAccountCondition<T> : BaseMembershipCondition<T> where T : RuleContext
{
public PersonalizationAccountCondition() : base("AccountId")
{
}
protected override bool DoesMatch(Guid entityId, Contact contact)
{
var facet = contact.GetFacet<ICrmContactDataEx>(this.ContactFacetName);
if (facet == null)
{
return false;
}
return facet.AccountId == entityId;
}
}
}
- Compile the project.
- Deploy Examples.DynamicsCrm.dll to your Sitecore server.
- In Content Editor, navigate to sitecore > system > Settings > Rules > Definitions > Elements > Dynamics CRM Visitor.
- Add the following item:
Template Condition Name Dynamics CRM Account
- For the field Text, set the following value:
where the visitor is a member of the account [externalentityid,CRM Connect/DependentTree,dependency=tenant&mode=descendant&templateid={0DE319D9-125C-42F3-B330-05C30D1B42D3}&rootitemname=Accounts&selection=[ACCOUNT-TEMPLATE-ID]&setRootAsSearchRoot=true,specific account] from the tenant [tenant,Tree,root={5EE8330D-E35E-433B-9BA6-DAF87ED38867}&selection={327A381B-59F8-4E88-B331-BEBC7BD87E4E}&setRootAsSearchRoot=true,specific tenant]
- In the field Text, change [ACCOUNT-TEMPLATE-ID] to the ID of the template created in Add Templates for CRM Entity Data.
- Set the following field value:
Field Type Value Examples.DynamicsCrm.Rules.PersonalizationAccountCondition, Examples.DynamicsCrm
- Save the item.
Now you can configure a personalization condition based on whether or not the visitor is a member of a specific CRM account.