HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Previously, client browser calls to the Optimizely Product Recommendation service directly with data were created on the server side, and the cuid/sessionid were included in the data. This created two problems when the rendered page got cached:

  • The wrong tracking data was sent to Product Recommendations. The call repeated what was rendered the first time, even though the page might have been served to a different user from cache.

  • After the first time, no tracking was sent to Profile Store since that happens on the server, which was not hit when the page was cached.

The client-side API was rewritten to be more full-featured, like the server side APIs: creating different types of tracking requests and populating them with data. Instead of calling to Recommendation directly, JS APIs call to Proxy. The Proxy is an asynchronous webapi controller that handles tracking request from Js APIs and forwards requests to the Product Recommendation service.

You can use JS Tracking APIs and Server Tracking APIs in parallel. On the client side, you can use JS TrackingDataFactory to create tracking data and epiRecommendations to send tracking requests to the Proxy. On the server side, you can use Tracking APIs, or TrackingAttribute for short.

## Changes to support the rewriting of the Client APIs

### TrackingMode

TrackingMode is obsolete. As mentioned above, JavaScript Tracking APIs and Server tracking APIs are independent and work in parallel.

### epiRecommendations

epiRecommendations now support setting scope when sending tracking data.

### JavaScript TrackingDataFactory

The JavaScript TrackingDataFactory class has been added to create js tracking data, which is sent to the Proxy. The following methods are available to create js TrackingData.

Create Home tracking data<br><br> TrackingDataFactory.createHomeTrackingData()<br><br>
Create Product tracking data<br><br> TrackingDataFactory.createProductTrackingData(productCode)<br><br>
Create SearchResult tracking data<br><br> TrackingDataFactory.createSearchResultTrackingData(term, productCodes)<br><br>
Create Checkout tracking data<br><br> TrackingDataFactory.createCheckoutTrackingData()<br><br>
Create Basket tracking data<br><br> TrackingDataFactory.createBasketTrackingData()<br><br>
Create Order tracking data<br><br> TrackingDataFactory.createOrderTrackingData(orderId)<br><br>
Create Brand tracking data<br><br> TrackingDataFactory.createBrandTrackingData(brandName)<br><br>
Create Category tracking data<br><br> TrackingDataFactory.createCategoryTrackingData(categoryCode)<br><br>
Create Attribute tracking data<br><br> TrackingDataFactory.createAttributeTrackingData(attributeName, attributeValue)<br><br>
Create Wishlist tracking data<br><br> TrackingDataFactory.createWishlistTrackingData()<br><br>

### The Proxy

The Proxy has only one endpoint to handle tracking requests sent from the client.

  • Endpoint url: episerverapi/commercetracking/track

  • Method: POST

### Handle recommendationId

In server-side mode, Optimizely uses cookies for handles. In client-side mode, Optimizely uses QueryString to handle RecommendationId.

  • When _clicking_ a product from a Recommendation, Optimizely passes the RecommendationId to the QueryString.

  • When _viewing_ a product, TrackingDataFactory gets RecommendationId from QueryString (if any), and sends the tracking request to the Proxy.