Appearance
Product recommendations with our .NET client
Relewise has a .NET SDK which, among other things, will make implementing recommendations very easy.
It is available via NuGet.
Start by making an IRecommender
-instance.
csharp
IRecommender recommender = new Recommender(
new Guid("00000000-0000-0000-0000-000000000001"),
"your api key",
"server-url");
Before going any further, make sure you have read the following:
- Read about how to authenticate against our API here.
- Read about handling different types of users here.
Product Details Page (PDP)
On the Product Details Page (PDP), the most commonly used recommendations are PurchasedWithProduct
and ProductsViewedAfterViewingProduct
. Here are examples on how to implement those requests. We recommend that you batch the request into a single request. Read more about why and how here.
PurchasedWithProduct
csharp
var id = new ProductAndVariantId("productId", "variantId");
var purchasedWithProductRequest = new PurchasedWithProductRequest(
new Language("da"),
new Currency("DKK"),
"Product details page",
GetUser(),
id);
purchasedWithProductRequest.Settings.SelectedProductProperties = new SelectedProductPropertiesSettings
{
DisplayName = true
};
purchasedWithProductRequest.Settings.SelectedVariantProperties = new SelectedVariantPropertiesSettings
{
DisplayName = true
};
ProductRecommendationResponse response = await recommender.RecommendAsync(
purchasedWithProductRequest,
cancellationToken);
ProductsViewedAfterViewingProduct
csharp
var id = new ProductAndVariantId("productId", "variantId");
var productsViewedAfterViewingProductRequest = new ProductsViewedAfterViewingProductRequest(
new Language("da"),
new Currency("DKK"),
"Product details page",
GetUser(),
id);
productsViewedAfterViewingProductRequest.Settings.SelectedProductProperties = new SelectedProductPropertiesSettings
{
DisplayName = true
};
productsViewedAfterViewingProductRequest.Settings.SelectedVariantProperties = new SelectedVariantPropertiesSettings
{
DisplayName = true
};
ProductRecommendationResponse response = await recommender.RecommendAsync(
productsViewedAfterViewingProductRequest,
cancellationToken);
By using SelectedProductPropertiesSettings
or SelectedVariantPropertiesSettings
it is posible to select the specific properties, from Relewise, that you need for rendering a product tile, list etc.,. That way we can store fields that make the filtering or merchandising better, but maybe is not needed when rendering the actual product. So we can reduce the HTTP responses by only returning a minimum set of the information that is needed.
Power Step
On the Power Step the most used recommendation is PurchasedWithProduct
.
csharp
var id = new ProductAndVariantId("productId", "variantId");
var purchasedWithProductRequest = new PurchasedWithProductRequest(
new Language("da"),
new Currency("DKK"),
"Product details page",
GetUser(),
id);
purchasedWithProductRequest.Settings.SelectedProductProperties = new SelectedProductPropertiesSettings
{
DisplayName = true
};
purchasedWithProductRequest.Settings.SelectedVariantProperties = new SelectedVariantPropertiesSettings
{
DisplayName = true
};
ProductRecommendationResponse response = await recommender.RecommendAsync(
purchasedWithProductRequest,
cancellationToken);
Cart / Basket Page
On the Basket Page the most commonly used recommendation is the PurchasedWithMultipleProducts
. This algorithm works for both identified and anonymous users, making it easy to use a recommendation slider on your basket page to boost your conversions.
csharp
var id1 = new ProductAndVariantId("123456789", "variantId1");
var id2 = new ProductAndVariantId("987654321", "variantId2");
var request = new PurchasedWithMultipleProductsRequest(
new Language("da"),
new Currency("DKK"),
"Basket page",
GetUser(),
new[] { id1, id2 });
ProductRecommendationResponse response = await recommender.RecommendAsync(request, cancellationToken);
Batching recommendation requests.
It's best practice to batch all recommendation requests on a page into a single request against the Relewise API. This has the benefit of ensuring unique products between different recommendations - and also minimizing network traffic.
csharp
var collection = new ProductRecommendationRequestCollection(
requireDistinctProductsAcrossResults: true,
purchasedWithProductRequest,
productsViewedAfterViewingProductRequest);
recommender.RecommendAsync(collection, cancellationToken);
The example here uses product recommendations, but the same can be done for product categories, content, and content categories.