如何在Sitecore DMS中触发配置文件?

时间:2012-08-09 10:05:40

标签: sitecore sitecore-dms

我正在寻找一种方法,允许访问者选择他们想要在网站上显示的内容。

有没有办法在Sitecore DMS中以编程方式触发配置文件?

我查看了有关SDN(http://sdn.sitecore.net/Reference/Sitecore 6/DMS Documentation.aspx)的相关文档,但到目前为止还没有找到方法。

编辑:在Sitecore支持门户网站上提出此问题 - 我会在找到更多内容后发布答案。

2 个答案:

答案 0 :(得分:2)

我在我的项目上做了类似的事情。查看此代码示例,如果您有任何疑问,请与我们联系。此外,请确保您还向内容项添加配置文件。在一组项目上调用FilterItemByBehavior,它将根据用户过去的浏览行为对其进行过滤。

 private static Dictionary<string, List<string>> AnalyticsFilter()
    {
        Dictionary<string, List<string>> filter = new Dictionary<string, List<string>>();

        if (Tracker.CurrentVisit.Profiles.Count() > 0)
        {
            foreach (VisitorDataSet.ProfilesRow row in Tracker.CurrentVisit.Profiles)
            {
                List<string> keys = new List<string>();
                foreach (var key in row.Values)
                {
                    if (key.Value >= ResourceHelper.GetInt(new ID(Resources.Settings.AnalyticsProfileSetMinValGuid)))
                        keys.Add(key.Key);
                }
                filter.Add(row.ProfileName, keys);
            }
        }
        if(ResourceHelper.IsTurnedOn(new ID(Resources.Settings.AnalyticsUserProfileEnableSwitch)))
            filter = ApplyUserProfile(filter);
        return filter;
    }


    public static List<Item> FilterItemByBehavior(List<Item> items, int count)
    {
        try
        {
            var filter = AnalyticsFilter();
            foreach (var profile in filter)
            {
                int counter = ResourceHelper.GetInt(new ID(Resources.Settings.AnalyticsProfileTagsFilterMaxGuid));
                if (items.Count <= count) break;
                foreach (string key in profile.Value)
                {
                    if (items.Count <= count || counter == 0) break;
                    items = items.Where(i => (((MultilistField)i.Fields[profile.Key]).GetItems().ToList().Select(x => x.Name).Contains(key))).ToList();
                    counter--;
                }
            }
            return items.Count <= count ? items : items.Take(count).ToList();
        }
        catch (System.Exception ex)
        {
            Sitecore.Diagnostics.Log.Error(ex.Message, ex, new AnalyticsHelper());
            return items.Count <= count ? items : items.Take(count).ToList();
        }
    }

答案 1 :(得分:1)

我收到了Sitecore对此问题的回复。这是:

“如果您使用模板卡进行个性化,那么您可以使用以下代码作为下拉列表中”项目选择“事件的事件处理程序:”

var profile = Sitecore.Analytics.Tracker.CurrentVisit.GetOrCreateProfile("<Profile Name>");
profile.BeginEdit();
profile.Score("<profile key>",<profile key value you want to set>);
profile.Score("<profile key>",<profile key value you want to set>);
profile.UpdatePattern(); //sets the appropriate pattern based on the current profile keys values you have just set.
profile.EndEdit();

这会干扰自动配置文件匹配,因此我不确定是否要使用此方法。