【问题标题】:How do I trigger a profile in Sitecore DMS?如何在 Sitecore DMS 中触发配置文件?
【发布时间】:2012-08-09 10:05:40
【问题描述】:

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

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

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

编辑:在 Sitecore 支持门户上提出这个问题 - 我会在发现更多信息后发布答案。

【问题讨论】:

    标签: sitecore sitecore-dms


    【解决方案1】:

    我在我的项目中做了类似的事情。查看此代码示例,如果您有任何问题,请告诉我。此外,请确保您也将配置文件添加到内容项。对一组项目调用 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();
            }
        }
    

    【讨论】:

      【解决方案2】:

      我已收到 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();
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多