Search code examples
sitecoreanalyticssitecore-dms

Get Profile Key Score for Individual Page in Sitecore


I have a question regarding Sitecore Analytics and user profile keys. I need to be able to get the score of a profile key for an individual page. For example, if I have a profile key called "traveler" that could have a value of 1-10 on a given page, I need to be able to get the value for that key that was assigned by the content author. I have found that by using the following:

Sitecore.Analytics.AnalyticsTracker.Current.Data.Profiles.GetProfile("Profile Name").GetProfileKeyValue("traveler")

I can get the total score that the user has accumulated throughout their session, but I cannot seem to find a way to get the score just for the current page.

Any insight anyone could offer would be greatly appreciated. Thanks.


Solution

  • I know this post is rather old, but for future references a lot has changed in Sitecore. I do not know if this was possible in 2010, but at least in 2013 there are API methods for extracting the Tracking values of a page.

    I would never recommend to manually parse the raw data in in the __Tracking Field.

    Here's how to read tracking data for the Persona Profile using the Sitecore Analytics API :

    public static string ProfileValues(this Item item)
    {
            StringBuilder sb = new StringBuilder();
    
            TrackingField trackingField = new TrackingField(item.Fields[Constants.Sitecore.FieldIDs.Tracking]);
            ContentProfile profile = trackingField.Profiles.FirstOrDefault(profileData =>
                                    profileData.Name.Equals("Persona") && profileData.IsSavedInField);
    
            ContentProfileKeyData[] profileKeys = profile.Keys;
    
            foreach (ContentProfileKeyData profileKey in profileKeys)
            {
                sb.AppendLine(string.Format("{0}:{1};", profileKey.Name, profileKey.Value));
            }
            return sb.ToString();
        }
    

    Best Regards Lasse Rasch