1

I need to extend the interactions object so I can add some custom data for the user's interactions. The data isn't page related, so I can't use a page event. And its in the tracker initialized pipeline, so I don't even have a page yet.

I can't find much information on extending the interactions object. I imagined it is similar to extended the contact object, but none of the interaction properties (browser version, geoip, region, etc...) are in configs. All there are is the fields on the analytics index.

1
  • Tracker.Current.Interaction.CustomValues.Add("my_key", new object());
    – Vlad Shpak
    Apr 26 '17 at 13:02
3

Persisting data with an interaction

If you want your custom data to be stored as part of every interaction in the Collection database, then you should use the CustomValues dictionary.

Tracker.Current.Interaction.CustomValues["CUSTOM_DATA_KEY"] = someObject;

Since CustomValues does not restrict what you can store, your custom data type will need to meet some requirements:

  1. It has to be marked as [Serializable].
  2. It needs to be registered in the MongoDB driver like this:

    using Sitecore.Analytics.Data.DataAccess.MongoDb;
    
    // [...]
    
    MongoDbObjectMapper.Instance.RegisterModelExtension<YourCustomClassName>();
    

    This only needs to be done once per application lifetime—for example, in an initialize pipeline processor.

Temporary interaction data

Some data you might only need during an interaction's session, and such data should not be stored in the Collection database. Then you can use the tracker session API:

Tracker.Current.Session.CustomData["CUSTOM_DATA_KEY"] = someObject;

Also, you don't even have to use the xDB API for this. You can just store your data in the ASP.NET session:

HttpContext.Current.Session["CUSTOM_DATA_KEY"] = someObject;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.