Transferring Recommendations Using the JavaScript API

In order to use Reteno product recommendation algorithms and customize their display on your side (appearance of blocks, display pages, etc.), follow these steps:

  • install the script on the site to track the behavior of site visitors;
  • upload product data feed to your Reteno account;
  • set up the passing of recommendations from Reteno to your website.

Settings Description

The JS API function is required to receive recommendations and their further use in product blocks on the site.

Scripts for receiving recommendations

On the home page and 404 page

eS('getRecommendations', {
  'variantId': 'r554v778'
  }, function(error, products) {

  if (error) {
            console.error(error);
            return ;
        }

});

On the product page

eS('getRecommendations', {
  'variantId': 'r554v778',
  'productId': 'MX-1512\42'
  }, function(error, products) {

  if (error) {
            console.error(error);
            return ;
        }

});

On the cart page

eS('getRecommendations', {
  'variantId': 'r554v778',
  'productIds': ['123', '543534']
  }, function(error, products) {

  if (error) {
            console.error(error);
            return ;
        }

});

Use the StatusCartPage event to determine the page type and display recommendations on the cart pop-up. Example:

eS('sendEvent', 'StatusCartPage');

On the categories page

eS('getRecommendations', {
  'variantId': 'r554v778',
  'categoryKey': 'cK'
  }, function(error, products) {


  if (error) {
            console.error(error);
            return ;
        }
});

The JS API method is asynchronous, which allows not to wait for the execution of other functions on the site.

Request parameters

Response example

Upon successful submission of the request, you will receive a response similar to the following:

Response body:

[
 {
 "product_id": "02G439",
 "container_type": "19534_r24v435",
 "url": "https://…?sc_content=19534_r24v435"
  // and other product attributes from the feed
  }
]

Type: List

Description:

  • product_id - recommended product ID
  • container_type must be used when passing the event ProductImpression
  • URL contains a link to the product, with an additional parameter for proper web tracking

❗️

Important

Don’t edit the return value in the URL field for web tracking to work correctly.

Error example

ExampleTypeDescription
variantId r262v361 was not found in configStringNo such recommendation variant identifier was found.

📘

Important

Send the ProductImpressions event after calling and displaying the recommendations block for proper tracking.

Filtering Recommendations

Filtering recommendations through the JavaScript API allows you to show products on your site by filtering recommendations based on data from the feed or contact information stored on your side. For example, you can filter recommendations by the city of residence, clothing size, favorite brand, promotional offer, etc.

Filtering recommendations through JS API saves you from changing the filtering rules in the data source in Reteno account every time.

Request format:

eS('getRecommendations', {
    variantId: 'r362v614',
                'filters': {
                       'include': [{'name': 'city', values: ['Kiev','Kharkiv']}]
                }
  },
  function(error, products) {
    if (error) {
      console.error(error);
      return;
    }
  }
);

Request parameters:

NameTypeDescription
filtersOptional
Object
A parameter that includes filtering rules.
includeOptional
List
Strict filtering: recommend only products according to the given parameters. For example, show only products of a certain brand.
excludeOptional
List
Strict filtering: products with specified parameters are not shown. For example, do not show discount items.
shouldOptional
List
Non-strict filtering: products with specified parameters
shown in priority, others by default
(if there should be 20 recommendations in the search results, 5 products with the specified parameters will be shown, the remaining 15 — without applying the filter). For example, include products from a new collection in recommendations.
nameRequired
String
The name of the product parameter from the product feed.
valuesRequired Listist of values to filter. The comma in values is the OR operator (values: ['Kiev','Kharkiv']).

To set the appearance of recommendation blocks in Reteno, please read this guide.