首先,您需要将用户角色字段添加到 sitecore_analytics_index 中的联系人。为此,您应该在Sitecore.ContentSearch.Lucene.Index.Analytics.config 的<fields hint="raw:AddComputedIndexField"> 部分添加一个新的计算字段(我假设您使用的是Lucene)。
以下是示例:
<field fieldName="Contact.ProfileProperties.UserRole" emptyString="_EMPTY_" nullValue="_NULL_" storageType="YES" indexType="UNTOKENIZED">Your.Type.Name, Your.Assembly</field>
您的类型应该通过 id 获取索引用户的角色。
之后,将名为“UserRole”的新条件添加到 /sitecore/system/Settings/Rules/Definitions/Elements/Segment Builder,其中“Text”字段为:
where the userrole [operatorid,StringOperator,,compares to] [value,,,specific userrole]
并且“类型”指向您的自定义类,如下所示:
public class UserRoleCondition<T> : TypedQueryableStringOperatorCondition<T, IndexedContact> where T : VisitorRuleContext<IndexedContact>
{
protected override Expression<Func<IndexedContact, bool>> GetResultPredicate(T ruleContext)
{
var userrole = this.Value ?? string.Empty;
return
this.GetCompareExpression(
c => (string)c[(ObjectIndexerKey)"contact.profileproperties.userrole"], userrole);
}
}
现在您可以在分段列表中使用新的用户角色条件。