views:

25

answers:

1

Hello all,

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.

A: 

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

Jimmy