Sitecore 个性化首次访问规则
Sitecore Personalization First Visit Rule
我想知道 Sitecore 8.2 中是否有任何内置的个性化规则符合我正在寻找的要求。使用个性化,我试图在您第一次访问页面时显示页面上的模块。当前会话中对该页面的任何后续访问都不会呈现该模块。
我认为内置规则“在当前访问期间访问了[特定页面]”会起作用,但它不在我的场景中。如果 [特定页面] 参数不是当前页面,它会起作用,但这不是我需要的。
似乎在验证规则之前记录了访问,因此当最终验证规则时,它认为该页面之前已经访问过,而实际上这可能是第一次页面访问。
除了创建自定义规则之外还有什么想法吗?提前致谢。
我认为 Sitecore 中没有任何 OOTB。你是对的 - Sitecore 首先计算页面访问,然后执行规则。
我创建了一个博客 post 来描述您的需求:https://www.skillcore.net/sitecore/sitecore-rules-engine-has-visited-certain-page-given-number-of-times-condition
在快捷方式中:
创建新条件项:
文本:[PageId,Tree,root=/sitecore/content,specific] 页面在当前访问期间已被访问 [OperatorId,Operator,compares to] [Index,Integer,number] 次
类型:YourAssembly.YourNamespace.HasVisitedCertainPageGivenNumberOfTimesCondition,你的程序集
使用它来个性化您的组件值:
[YOUR_PAGE] 页面在当前访问期间被访问 [等于] [1] 次
创建代码:
public class HasVisitedCertainPageGivenNumberOfTimesCondition<T> : OperatorCondition<T> where T : RuleContext
{
public string PageId { get; set; }
public int Index { get; set; }
protected override bool Execute(T ruleContext)
{
Assert.ArgumentNotNull(ruleContext, "ruleContext");
Assert.IsNotNull(Tracker.Current, "Tracker.Current is not initialized");
Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session is not initialized");
Assert.IsNotNull(Tracker.Current.Session.Interaction, "Tracker.Current.Session.Interaction is not initialized");
Guid pageGuid;
try
{
pageGuid = new Guid(PageId);
}
catch
{
Log.Warn(string.Format("Could not convert value to guid: {0}", PageId), GetType());
return false;
}
var pageVisits = Tracker.Current.Session.Interaction.GetPages().Count(row => row.Item.Id == pageGuid);
switch (GetOperator())
{
case ConditionOperator.Equal:
return pageVisits == Index;
case ConditionOperator.GreaterThanOrEqual:
return pageVisits >= Index;
case ConditionOperator.GreaterThan:
return pageVisits > Index;
case ConditionOperator.LessThanOrEqual:
return pageVisits <= Index;
case ConditionOperator.LessThan:
return pageVisits < Index;
case ConditionOperator.NotEqual:
return pageVisits != Index;
default:
return false;
}
}
}
我想知道 Sitecore 8.2 中是否有任何内置的个性化规则符合我正在寻找的要求。使用个性化,我试图在您第一次访问页面时显示页面上的模块。当前会话中对该页面的任何后续访问都不会呈现该模块。
我认为内置规则“在当前访问期间访问了[特定页面]”会起作用,但它不在我的场景中。如果 [特定页面] 参数不是当前页面,它会起作用,但这不是我需要的。
似乎在验证规则之前记录了访问,因此当最终验证规则时,它认为该页面之前已经访问过,而实际上这可能是第一次页面访问。
除了创建自定义规则之外还有什么想法吗?提前致谢。
我认为 Sitecore 中没有任何 OOTB。你是对的 - Sitecore 首先计算页面访问,然后执行规则。
我创建了一个博客 post 来描述您的需求:https://www.skillcore.net/sitecore/sitecore-rules-engine-has-visited-certain-page-given-number-of-times-condition
在快捷方式中:
创建新条件项:
文本:[PageId,Tree,root=/sitecore/content,specific] 页面在当前访问期间已被访问 [OperatorId,Operator,compares to] [Index,Integer,number] 次
类型:YourAssembly.YourNamespace.HasVisitedCertainPageGivenNumberOfTimesCondition,你的程序集
使用它来个性化您的组件值:
[YOUR_PAGE] 页面在当前访问期间被访问 [等于] [1] 次
创建代码:
public class HasVisitedCertainPageGivenNumberOfTimesCondition<T> : OperatorCondition<T> where T : RuleContext
{
public string PageId { get; set; }
public int Index { get; set; }
protected override bool Execute(T ruleContext)
{
Assert.ArgumentNotNull(ruleContext, "ruleContext");
Assert.IsNotNull(Tracker.Current, "Tracker.Current is not initialized");
Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session is not initialized");
Assert.IsNotNull(Tracker.Current.Session.Interaction, "Tracker.Current.Session.Interaction is not initialized");
Guid pageGuid;
try
{
pageGuid = new Guid(PageId);
}
catch
{
Log.Warn(string.Format("Could not convert value to guid: {0}", PageId), GetType());
return false;
}
var pageVisits = Tracker.Current.Session.Interaction.GetPages().Count(row => row.Item.Id == pageGuid);
switch (GetOperator())
{
case ConditionOperator.Equal:
return pageVisits == Index;
case ConditionOperator.GreaterThanOrEqual:
return pageVisits >= Index;
case ConditionOperator.GreaterThan:
return pageVisits > Index;
case ConditionOperator.LessThanOrEqual:
return pageVisits <= Index;
case ConditionOperator.LessThan:
return pageVisits < Index;
case ConditionOperator.NotEqual:
return pageVisits != Index;
default:
return false;
}
}
}