Question

I am looking for a way to allow visitors to select what content they want displayed on the site.

Is there a way to programatically trigger a profile in Sitecore DMS?

I've looked at relevant documentation on SDN (http://sdn.sitecore.net/Reference/Sitecore 6/DMS Documentation.aspx), but so far haven't found a way.

EDIT: Raised this on Sitecore Support Portal - will post an answer once I find out more.

Was it helpful?

Solution 2

I have received a response from Sitecore support on this question. Here it is:

"If you are using pattern cards for personalzation, then you can use the following code as the event handler for "item selected" event for the dropdown list:"

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();

This interferes with automatic profile matching, so I am not sure I want to use this approach.

OTHER TIPS

I have done something similar on my project. Check out this code sample and let me know if you have any questions. Also, make sure you add profiles to content items too. Call FilterItemByBehavior on a collection of items and it will filter them based on user's past browsing behavior.

 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();
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top