SaaS CMS has officially launched! Learn more now.

Manoj Kumawat
Jun 1, 2022
  1182
(1 votes)

Working with product recommendations - Wishlist Recommendations

One of the useful features of Optmizely personalized contents is Product Recommendations. With Optimizely Product Recommendations, you can provide a personalized shopping experience for visitors to your e-commerce website. Personalization is based on website interaction such as order history, visitor profiles, and intelligent algorithms to suggest products of interest. A developer must first configure the tracking, personalization service, and recommendation widgets, then you can start working with Product Recommendations to define recommendations strategies using the Personalization Portal

A couple of days ago we integrated a widget for wishlist, Where users would see product recommendation based on their wishlist history. Below are the steps how you can do it step by step. This is the same configuration you can follow to create other widgets. 

Step 1 - Login to Personalization portal > Product Recommendations > Widgets > Create a new widget
For us this was wishlistWidget we needed on wishlist page. 

Step 2 - Configure the type of recommendations you would like to display on your website 
The algorithms are set to show Popular  only 3  recommendations. That way it would show us only 3 product recommendations.

Code > Wishlist > enable tracking 

private readonly TrackingDataFactory _trackingDataFactory;
private readonly ITrackingService _trackingService;
private readonly ServiceAccessor<IContentRouteHelper> _contentRouteHelperAccessor;

public async Task<TrackingResponseData> TrackWishlist(HttpContextBase httpContext)
{
      var trackingData = _trackingDataFactory.CreateWishListTrackingData(httpContext);

      return await InternalTrackAsync(trackingData, httpContext);
}

private async Task<TrackingResponseData> InternalTrackAsync(CommerceTrackingData commerceTrackingData, HttpContextBase httpContext)
{
	if (commerceTrackingData == null || httpContext == null)
	{
		return null;
	}

	var scope = _trackingDataFactory.GetCurrentTrackingScope();

	if (!string.IsNullOrEmpty(scope))
	{
		return await _trackingService.TrackAsync(commerceTrackingData, httpContext, _contentRouteHelperAccessor().Content, scope);
	}
	else
	{
		return await _trackingService.TrackAsync(commerceTrackingData, httpContext, _contentRouteHelperAccessor().Content);
	}
}

Next > Get recommendations

using EPiServer.Personalization.Commerce.Tracking;

public static IEnumerable<Recommendation> GetRecommendations(this TrackingResponseData response, ReferenceConverter referenceConverter, string area) => response.GetRecommendationGroups(referenceConverter)
									.Where(x => (!string.IsNullOrEmpty(area) && x.Area.IsEqual(area)) 
									|| string.IsNullOrEmpty(area))
									.SelectMany(x => x.Recommendations);

This will fetch you configured recommendations on personlization portal. Similarly we can get recommendations wherever required. 

Here is the useful resource for enabling tracking for wishlist in commerce - https://github.com/episerver/Quicksilver/blob/master/Sources/EPiServer.Reference.Commerce.Site/Features/Cart/Controllers/WishListController.cs 

Thank you for reading.

Jun 01, 2022

Comments

Please login to comment.
Latest blogs
Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024

Integrate a CMP workflow step with CMS

As you might know Optimizely has an integration where you can create and edit pages in the CMS directly from the CMP. One of the benefits of this i...

Marcus Hoffmann | Jul 10, 2024

GetNextSegment with empty Remaining causing fuzzes

Optimizely CMS offers you to create partial routers. This concept allows you display content differently depending on the routed content in the URL...

David Drouin-Prince | Jul 8, 2024 | Syndicated blog

Product Listing Page - using Graph

Optimizely Graph makes it possible to query your data in an advanced way, by using GraphQL. Querying data, using facets and search phrases, is very...

Jonas Bergqvist | Jul 5, 2024