Sitecore 个性化首次访问规则



我想知道 Sitecore 8.2 中内置的个性化规则是否符合我正在寻找的要求。使用个性化,我正在尝试使页面上的模块在您第一次访问该页面时显示。随后在当前会话中对该页面的任何访问都不会呈现该模块。

我认为内置规则">在当前访问期间访问过 [特定页面] 的位置"会起作用,但它在我的场景中不起作用。如果 [特定页面] 参数不是当前页面,它有效,但这不是我需要的。

似乎在验证规则之前记录了访问,

因此当最终验证规则时,它会认为该页面之前已经访问过,而实际上这可能是第一次页面访问。

除了创建自定义规则之外,还有其他想法吗?提前谢谢。

我认为Sitecore中没有任何OOTB。您是对的 - Sitecore 首先计算页面访问量,然后执行规则。

我创建了一篇博客文章,描述了您的需求: https://www.skillcore.net/sitecore/sitecore-rules-engine-has-visited-certain-page-given-number-of-times-condition

在快捷方式中:

  1. 创建新的状况项目:

    文本:当前访问期间访问过 [PageId,Tree,root=/sitecore/content,specific] 页面的位置 [运算符 ID,运算符,,与] [索引,整数,,,次数] 次

    比较

    类型:YourAssembly.YourNamespace.HasVisitedCertainPageGivenNumberOfTimesCondition,YourAssembly

  2. 使用它来个性化您的组件:

    在当前访问期间访问 [YOUR_PAGE] 页面 [等于] [1] 次的地方

  3. 创建代码:

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;
        }
    }
}

最新更新