Loading...

Last updated: Sep 27 2018

Area: Episerver Commerce Applies to versions: Tracking.Core 1.6 and higher

Product tracking

This topic describes the product-specific tracking for Episerver Commerce. Use tracking in Commerce to provide product recommendations, and for tracking data to any source for business intelligence data visualization purposes. 

Tracking

The tracking service supports product-specific tracking for Episerver Commerce. Depending on the setup,you can track Episerver Commerce data to any source, to the Episerver recommendation service (Episerver Perform), or to Episerver Profile Store. To get tracking running for a site, you need to configure access to the tracking API. 

Installation and configuration

See Install and configure tracking about installing and setting up the tracking.

Tracking types

Use the following tracking types and attributes for tracking to any source. See also Tracking and recommendations

Visitor activities that can be tracked are contained in the TrackingType enum, shown in the following table. The Attribute Support column indicates whether you can track the activity by decorating controller actions with an attribute. See CommerceTrackingAttribute.

TrackingType enum values

TrackingType Activity Attribute Support
Home View the start page. Yes
Product View a product. Yes
Category View a branch of the catalog tree, for example Fashion>Mens>Shoes. Yes
SearchResults Search for a term. No *
Wishlist Modify the wishlist. Yes
Basket Modify the basket/shopping cart. Yes
Checkout User is about to place order. Yes
Order User placed order. No *
Other View a page not covered by other tracking types. Yes

  
SearchResults and Order tracking cannot be tracked via the CommerceTrackingAttribute because the required data is not available when the CommerceTrackingAttribute code is executed. Track these activities  without using the tracking attribute.

Note: While the following tracking types are supported by the native integration API, they should not be used with the default widget setup for recommendations because they add overhead without improving recommendations.

TrackingType Activity Attribute Support
Attribute View products with a specific attribute value, for example Color: Red. No
Brand View products of a specific brand. No

Sending tracking information

Using the CommerceTrackingAttribute

The CommerceTrackingAttribute is an ActionFilterAttribute designed to be placed on controller actions. The parameter for the CommerceTrackingAttribute constructor is a TrackingType from the table above. If the passed TrackingType is supported by the CommerceTrackingAttribute, it automatically collects the necessary data and performs a tracking request in the OnActionExecuting method. In the following example, the Index method of the start page controller sends a home page tracking request when executed.

[CommerceTracking(TrackingType.Home)]
public ViewResult Index(StartPage currentPage)
{ ... }

Tracking without using the CommerceTrackingAttribute

If the TrackingType is not supported by the TrackingAttribute, or if the action to be tracked cannot be tied directly to a controller action, you need to handle tracking in a more hands-on way. In these cases, you must manually:

  1. Create the relevant TrackingData object.
  2. Pass the TrackingData object to the ITrackingService.Track extension method.

To construct TrackingData objects, call methods on TrackingDataFactory. This acts as a bridge between the Commerce system and the tracking system, accepting objects from the Commerce world as parameters and returning objects that are disconnected from Commerce. To send tracking data, call the ITrackingService Track extension method. In the following example, both TrackingDataFactory and ITrackingService are injected via constructor:

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

The Track extension method also has an asynchronous version, TrackAsync, that can be awaited in asynchronous controller actions for improved performance.

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/