Tracking interaction facets

Current version: 9.1

This topic describes how to add facets to an interaction in the context of the tracker. For more information about facets, see the following topics:

Store facet data in custom values

  1. Create an interaction facet and register it in the model.

  2. Create an instance of an interaction facet in a tracking context. The facet must be marked [Serializable].

  3. Add the facet to Sitecore.Analytics.Tracker.Current.Interaction.CustomValues as shown. In this example, the facet key is used as a dictionary key:

RequestResponse
namespace Documentation
{
    public class Tracking
    {
        public void Example()
        {
            CustomerMood mood = new CustomerMood()
            {
                MoodDescription = "Super happy!"
            };

            Sitecore.Analytics.Tracker.Current.Interaction.CustomValues[CustomerMood.DefaultFacetKey] = mood;
        }
    }
}

Create an interaction conversion processor

  1. Create a processor that inherits ConvertToXConnectInteractionProcessorBase

  2. Implement the Process() method as shown. Copy the CustomerMood facet from args.TrackerVisitData.CustomValues to args.Facets.

RequestResponse
using Sitecore.Analytics.XConnect.DataAccess.Pipelines.ConvertToXConnectInteractionPipeline;

namespace Documentation
{
    public class ConvertInteractionFacet : ConvertToXConnectInteractionProcessorBase
    {
        public override void Process(ConvertToXConnectInteractionPipelineArgs args)
        {
            if (args != null)
            {
                var customValues = args.TrackerVisitData.CustomValues;

                var moodFacet = customValues[CustomerMood.DefaultFacetKey];

                if (moodFacet != null && moodFacet is CustomerMood)
                {
                    args.Facets.Add(CustomerMood.DefaultFacetKey, moodFacet);
                }
            }
        }
    }
}
Note

Custom values (args.TrackerVisitData.CustomValues) are not saved to xConnect. If custom values are not converted into a format that is supported by xConnect, the data will be lost.

Register the interaction conversion processor

Patch your processor in the main ConvertToXConnectInteractionProcessor as shown:

RequestResponse
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
        <convertToXConnectInteraction>
            <processor patch:after="processor[@type='Sitecore.Analytics.XConnect.DataAccess.Pipelines.ConvertToXConnectInteractionPipeline.ConvertToXConnectInteractionProcessor, Sitecore.Analytics.XConnect']" type="Documentation.ConvertInteractionFacet, Documentation"/>
        </convertToXConnectInteraction>
        </pipelines>
    </sitecore>
</configuration>

Do you have some feedback for us?

If you have suggestions for improving this article,