Get Profile Key Score for Individual Page in Sitecore

房东的猫 提交于 2019-12-06 04:16:32
Lasse Rasch

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

Jimmy

After some research, I found that this is stored as an XML string in a field called __Tracking on each item. It can be accessed just like any other data field, using the Fields collection. For example:

Item itemToCheck = Sitecore.Context.Database.GetItem("/path to item/");
string trackingXml = itemToCheck.Fields["__Tracking"].ToString();

The XML in the string is structured like this:

<tracking>
    <profile name="profile1">
        <key name="key1" value="1" />
        <key name="key2" value="10" />
    </profile>
    <profile name="profile2">
        <key name="key3" value="12" />
        <key name="key4" value="4" />
    </profile>
</tracking>

This string can be converted to an XmlDocument and processed using SelectNodes like normal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!