Recommendations

Recommendations is the feature intended for improving user interaction with client’s service by personalizations. Its main purpose is to offer items from catalog to the user according to client’s preferences.

Use-cases

For e-commerce, newspapers, etc.:

  • Personalised homepage with the most relevant products for each individual customer
  • Section with similar, “bought together” or “others also viewed” products on product page or in the cart
  • Section with latest articles or recently added items on homepage
  • “Most read articles” or “popular items” sections on homepage
  • Email campaign with personalised offer (regular or for reactivation of user)

Templates

Templates capture different ways to suggest items to users. The most powerful one is Personalized recommendations for you and generally that is the best pick. In some scenarios, such as lack of historical data for new products, the results might turn out unsatisfactory. The next best choice for recommendations in context of a currently viewed product is Similar items.

The others are a good choice when you have a clear use case in mind, such as showing an exit banner when user navigates a cursor to the top section of the website with Customer recent interactions or displaying items which are Popular right now within some category.

Personalized recommendations for you

Ideal for homepage or email campaigns.

The model considers the previous actions of a user such as product views or purchases and suggests the most appropriate recommendations, which are based on preferences of other users with similar taste.

The configuration requires selecting the events for: detail view, add to cart and purchase. When choosing these events always select attribute with item ID which can be found also in catalog. It is also possible to include events for wishlist or rating.

These events define interactions between users and items: the more two users interact with the same items, the more we consider their taste similar. This machine learning approach is called collaborative filtering.

Customers who bought this item also bought

Similar to Personalized recommendations for you, but only considers purchase events as a metric of similarity between users.

Customers who viewed this item also viewed

Similar to Personalized recommendations for you, but only considers detail view events as a metric of similarity between users.

Similar items

Ideal for product view.

Recommend items similar to a currently viewed item based on attributes. Select required and optional attributes which will be considered for measuring the similarity. Required fields have to match all, match in optional fields will be preferred (these items will be put first) but items without these fields can be returned. Select the minimum number of optional attributes which have to match.

Customers recent interactions

Ideal for exit banners or recurring purchases.

Items customer recently viewed or purchased. Select type of event which describes this interaction.

New items

Recommend new items on stock. Select which attribute will be used for filtering.

Recommend top selling or top viewed. Select which attribute will be used for sorting.

Advanced

Combine recommendations from different engines and set additional options.

Engines

Content-based

Same as Similar items.

Preferences of many users

Similar to Personalized recommendations for you. You can additionally select custom weights for different events to set their strength for indicating user similarity. You can select values between 0 and 1. For example, a purchase is a stronger indicator of similarity than product view, so you can set weights to 1 and 0.1 respectively.

Manual selection

Cherry-pick the items that you want to promote by their item ID.

New on stock

Same as New items.

Previously seen items

Items the user has interacted with in the past and we can offer them again. Select type of event which describes this interaction (typically a purchase or a view) and date interval to pick these events from. You can also set order in which the events (and items in them) will be considered. Possible options are: by frequency – items found more times are preferred (items user buys often), or order by time of event – newer first or older first.

Chosen by metric

Select an event attribute identifying the item, then define a metric specifying how well this item performs. You can use this engine to recommend items with the most purchases, that brought the most revenue or fulfill any other goal (highest metric value is best). Note that the calculation is subject to a 5 minute cache.

Configuration

You can find Recommendations section under Campaigns -> Recommendations.

Catalog

Choose a catalog with items to be displayed in recommendations.

Choosing event attributes

When using model utilizing events in configuration, make sure that IDs used in these events are the same as IDs in catalog (item_id) that is linked with one model.

For example: when model Personalized recommendations for you is trained on event purchase_item with attribute product_id then ensure that selected catalog contains primary key (item_id) that matches purchase_item.product_id.

Learning window

When using model utilizing events in configuration, you have the option to select the time period for these events. This allows you to distinguish recommendations based on immediate interests from those based on long term preferences.

Blacklist

Blacklisting of recommended items based on user-item interactions defined by event attribute item ID, for example to exclude recently viewed or purchased items.

Customer preferences

Narrow down recommendations to individual preferences of customers. Select a catalog attribute and match it with a customer preference using various operators. Matching recommendations will come on top, followed by those which do not.

Advanced template

Combination strategy

Combine multiple uses recommendations from all engines and shows combined results with equal proportions.

Order by priority of models returns all results from the most preferred engine. If the requested number of items cannot be fulfilled, it will use the others as a backup strategy.

Only the best one will select the most performing variant and show recommendations only from this variant.

Implementation

Website

After your recommendation model is ready, you can use Exponea SDK and call getRecommendation method or use REST API directly (API docs not covered here).

Basic snippet

<div id="recommendations">
    Preparing recommendations just for you...
</div>
<script>
    var options = {
        // Required parameters:
        recommendationId: "RECOMMENDATIONS ID HERE",
        callback: onRecommendationsLoaded,
        // Optional parameters:
        //size: 10, // Specifies upper limit of the recommendations to return. Defaults to 10.
        //anti: false, // Returns items most surprising to the customer. `similarity`, `anti` and `anonymous` are mutually exclusive. Defaults to false.
        //similarity: false, // Tries to find similar items regardless of customer, based on provided items. `similarity`, `anti` and `anonymous` are mutually exclusive. Defaults to false.
        //anonymous: false, // Tries to find similar items regardless of customer. `similarity`, `anti` and `anonymous` are mutually exclusive. Defaults to false.
        //consider_known_items: false, // If true, include items that the customer has interacted with in the past. Defaults to false.
        //items: [item_id], // Required if `similarity` is true. Maps item id to its weight. For example: {"items": {"the_item": 1, "other_item": 4.7}}
        //strategy: "winner", // If specified, overrides the predefined value of the recommendation. Corresponds to the setting in the application. Can be one of "winner" or "mix".
    };
    exponea.getRecommendation(options);

    // render loaded items
    function onRecommendationsLoaded(data) {
        // check if enough items are loaded ...
        if (data && data.length > 0) {
            var element = document.getElementById('recommendations'); // recommendations target element
            // rendering...
            var ul = document.createElement('ul');
            element.appendChild(ul);
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                var li = document.createElement('li'),
                    a = document.createElement('a');
                a.id = item.item_id;
                a.setAttribute('href', item.url);
                a.innerText = a.textContent = item.title;
                li.appendChild(a);
                ul.appendChild(li);
            }
        } else {
            // ... keep default items or print funny message
            document.getElementById('recommendations').innerHTML =
                'Nothing could be recommended for you!';
        }
    }
</script>

Event tracking

For evaluation purposes you should implement also event tracking

Tracking with AB test

Snippet below demonstrates following:

  • AB test
  • load recommendations using timeout
  • tracking
    • event recommendation action=show when recommended items are loaded
    • event recommendation action=timeout when loading times out (1000ms)
    • event recommendation action=click when item is clicked (track every time, on both recommended and default items)
var PLACEMENT = "homepage";
// get variant for AB test
exponea.getAbTest("rcm_" + PLACEMENT, {
    "Variant A": 50,
    "Control Group": 50
}, function (variant) {
    if (variant == "Variant A") {
        var RCM_STATUS = 0;
        // render items when loaded
        var onRecommendationsLoaded = function (data) {
            if (RCM_STATUS !== "TIMED_OUT") {
                RCM_STATUS = "LOADED";
                // track event recommendation action=show
                exponea.track("recommendation", {
                    action: "show",
                    variant: variant,
                    item_ids: itemIds,
                    // other required properties: placement, recommendation_id, ...
                });
                // render items ...
                // add click listeners ...
                // track event recommendation action=click when item is clicked
                exponea.track("recommendation", {
                    action: "click",
                    variant: variant,
                    item_id: itemId,
                    // other required properties: placement, recommendation_id, ...
                });
            }
        };

        // start loading recommendations
        var options = {
            recommendationId: "RECOMMENDATION ID HERE",
            callback: onRecommendationsLoaded,
            // ... add optional parameters as required by your use case, ie item_id, size, ...
        };
        exponea.getRecommendations(options);

        // start timeout to discard rendering when recommendations are loaded too late
        setTimeout(function () {
            if (RCM_STATUS !== "LOADED") {
                RCM_STATUS = "TIMED_OUT";
                // track event recommendation action=timeout
                exponea.track("recommendation", {
                    action: "timeout",
                    variant: variant,
                    // other required properties: placement, recommendation_id, ...
                });
            }
        }, 1000);
    } else if (variant == "Control Group") {
        // track event recommendation action=show
        exponea.track("recommendation", {
            action: "show",
            variant: variant,
            // other required properties: placement, recommendation_id, ...
        });
        // add click listeners to fallback items ...
        // track event recommendation action=click when item is clicked
        exponea.track("recommendation", {
            action: "click",
            variant: variant,
            item_id: itemId,
            // other required properties: placement, recommendation_id, ...
        });
    }
});

Required event structure

Event name Trigger Property name Description Data type Example
recommendation recommendation loading times out recommendation_id ID of recommendation model String 590b121683043403ab2de9eb
action action performed, in this case “timeout” String timeout
variant AB test variant name String Variant A
placement Visual placement of recommended items String “homepage” | “product” | “cart” | …
recommendation recommendation is rendered recommendation_id ID of recommendation model String 590b121683043403ab2de9eb
action action performed, in this case “show” String show
item_ids IDs of items recommended List of strings [“1”, “2”, “3”]
variant AB test variant name String Variant A
placement Visual placement of recommended items String “homepage” | “product” | “cart” | …
recommendation rcm item is clicked on website recommendation_id ID of recommendation model String 590b121683043403ab2de9eb
engine_name name of engine for clicked recommended item String up_sale_121212
action action performed, in this case “click” String click
item_id ID of clicked item String “1”
variant AB test variant name String Variant A
placement Visual placement of recommended items String “homepage” | “product” | “cart” | …
Updated on October 26, 2017

Was this article helpful?

Related Articles