Loading...

Last updated: Jun 07 2018

Area: Episerver Commerce, Episerver Perform Applies to versions: EPiServer.Personalization.Commerce 1.0 and higher

Tracking and recommendations

This topic explains how tracking and recommendations work in Episerver Perform, the Episerver Commerce-specific part of the Episerver personalization suite.

Product recommendation tracking

Tracking is used for different purposes, for example to provide personalized product recommendations on an e-commerce site site. Tracking visitor activities and retrieving recommendations are performed simultaneously in a single round trip to the Episerver Perform environment. This round trip is made synchronously and adds a small processing overhead to all tracked requests. 

The following diagram describes the flow for page requests that end up in a controller action decorated with a CommerceTrackingAttribute. The flow is identical for tracking requests not triggered by the CommerceTrackingAttribute except the custom tracking code replaces the OnActionExecuting step.

To provide good recommendations, Episerver Perform tracks a visitor's activities over time. This is accomplished by assigning visitors a consolidated user ID (CUID), which is stored in a cookie. User activities that can be tracked are contained in the TrackingType enum. Track as many activities as possible - more tracked activities result in better recommendations.

Tracking here is done to the Episerver product recommendation service, but tracking of Episerver Commerce data can be consumed by any source.

See Product tracking for more details about tracking types and attributes for products, and how to install the core tracking.

Customizing tracking data

[New in EPiServer.Personalization.Commerce 1.2.0]

You can include custom tracking data in a tracking request by using the SetCustomAttribute extension method for CommerceTrackingData. Supported data types are limited to common numeric types, string, and DateTime.

An example usage of custom tracking attributes could be to configure recommendation widgets in the personalization service to filter recommendations based on a known customer preference or other data. For example, imagine a website for browsing or preordering duty free goods for an airport/airline, where the available products depend on flight type:

var trackingData = _trackingDataFactory.CreateCategoryTrackingData(category, httpContext);
trackingData.SetCustomAttribute("FlightType", "International"); var result = _trackingService.Track(trackingData, httpContext, currentContent);

Linking visitor actions with recommendations

Valuable business intelligence is based on knowing which recommended content a visitor acts upon. When the TrackingDataFactory creates ProductTrackingData, it uses an instance of IRecommendationContext to ask whether the current request was based on previous recommendations, by calling its GetCurrentRecommendationId method. If the value returned from the method is greater than zero, it is passed on as ClickInfo on the ProductTrackingData object.

The default implementation of this interface is NullRecommendationContext. It always returns zero. To allow ClickInfo to be sent as part of the ProductTrackingData, you must make a custom implementation of this interface and register it in your IoC container.

The Commerce reference site has a sample of such an implementation, storing the RecommendationId values using cookies, which are then read from the RecommendationContext when new ProductTrackingData is being instantiated.

Consuming recommendations

Depending on how the Episerver Perform environment is configured, different types of tracking events may or may not return recommendations. This section explains a general case where recommendations are returned and should be displayed to the visitor.

Using the CommerceTrackingAttribute

As the CommerceTrackingAttribute executes code in the OnActionExecuting method, the recommendations are available as soon as the controller action method is entered. To get recommendations, call the Controller extension method GetRecommendationGroups.

[CommerceTracking(TrackingType.Home)]
public ViewResult Index(StartPage currentPage)
{
    var recommendations = this.GetRecommendationGroups(); 
... }

The method returns a collection of Recommendation objects, where each object has an Area and a collection of ContentReferences referencing the recommended products. The Recommendation object can be used to create model data to display recommended products to a site visitor.

The number of Recommendation objects and the names of the areas are dependent on how the Episerver Perform environment is configured. The name for these recommendation groupings on the Episerver Perform side is widgets. A widget contains information about where recommendations should appear on a page (left, right, bottom, and so on.) and which algorithms are used to generate recommendations such as similar products, and cross sells.

var productRefs = widgetService.UpdateWidget().Where(x => x.Area == "someWidget").SelectMany(x => x.RecommendedItems); 

Without using the CommerceTrackingAttribute

Working with the recommendations returned from the ITrackingService.Track extension method is similar to working with the attribute. A GetRecommendationGroups extension method exists for the returned tracking response data and works the same way as with the controller.

Sample code

var trackingData = _trackingDataFactory.CreateCategoryTrackingData(category, httpContext);
var result = _trackingService.Track(trackingData, httpContext, currentContent);

var recommendations = result.GetRecommendationGroups();

Related topics


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/