# Requesting Recommendations

In order to get recommendations, you need to use the suggested `getRecommendation()` method from the [JavaScript SDK library](🔗) or directly use our [REST API](🔗).

You can find the code for requesting product recommendations using the Javascript SDK in the Web Deployment part of each of the recommendation engines.

Two versions of the code are available. One with preparation for an AB test, one without it.



The full specification of the request can be found in the [personalization guide](🔗), but below we describe the **three most important parts attributes**:

KeyValueDescriptionExample
_recommendationId_ **(Required)**StringEngine ID of an existing recommendation model. This ID is created when the engine is saved in Bloomreach Engagement. '5a7c4dfefb6009323d4c7311'
_fill_with_random_BooleanIf true and there are not enough recommended items by the model, Bloomreach Engagement fills the gap with random items from the catalog until the required size is reached. (NB. can also be _fillWithRandom_)'true'
_size_Integer **(Default value: 10)**Number of recommended items to return. The maximum suggested size to use is 100.'50'
_items_ObjectInformation about currently viewed product by the browsing user. Represented as dictionary 'product_id: weight.' Please use only a single item in the dictionary with weight = 1.{'item_123': 1}
_catalogFilter_Array of ObjectsDynamically adds additional constraints to the template's catalog filter (first step when setting the recommendations engine) when retrieving recommended items. The filter applies to the list returned by the recommendation.\[ { "property": "category_2", "constraint": { "type": "string", "operator": "contains", "operands": [{ "type": "constant", "value": "shoes" }] } } ]
_categoryNames_ **(Required for [Metric based category](🔗))**Array **(Max size: 10)**Currently viewed category or categories by the browsing user.['shoes', 'high heels']



The _recommendationid_ in the recommendation call must be a **constant string**.

Variables or parameters cannot be used instead of the _recommendationid_.

# Integration to Campaigns

The following two Jinja code snippets demonstrate how to integrate recommender engines into campaigns. One example shows a simple and another one advanced usage with an example engine ID `5a7c4dfefb6009323d4c7311`. Properties of retrieved items can be later obtained by calling `{{ item.<attribute> }}` convention.



The above snippet processes obtained recommendations (=10 items) from the engine _5a7c4dfefb6009323d4c7311_ and integrates them into HTML.



This snippet calls 50 products including a context item _item_123_ in the request that is already filtered down by the `category_2 contains "shoes"` rule.

If the recommendation model cannot return enough products, `fill_with_random = true` will fill the gap with randomly selected products that match the catalog filter conditions.

## Types and Operators for `catalog_filter`

### Type = "string"

**Operators:**

  • is set

  • is not set

  • has value

  • has no value

  • equals

  • does not equal

  • in

  • not in

  • contains

  • does not contain

  • starts with

  • ends with

  • regex

### Type = "number"

**Operators:**

  • equal to

  • in between

  • less than

  • greater than

  • is set

  • is not set

  • has value

  • has no value

example of catalog_filter with number type


example of `catalog_filter` with number type

For further information, see [Personalization in Jinja section](🔗).

# How to Evaluate Product Recommendations

It is suggested to compute metrics **revenue per visitor** and **click-through rate** using [Reports](🔗). A good practice is to carry out an AB test, either with your current model or if you do not have any, with any other model from Bloomreach Engagement. To learn how to set up the report, see our guide to [AB Test Basic Evaluation](🔗). In order to track recommendation-attributed revenue, please implement event tracking for clicks on any product which was generated by Engagement product recommendations.

# Event Tracking for Revenue Attributed to Recommendations

For evaluation purposes, it is needed to implement event tracking for product purchases, product views, and clicks on recommended products.

The snippet below demonstrates the following:

  • AB test

  • Load recommendations using a 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 an item is clicked (track every time, on both recommended and default items)

Don't forget to insert your `recommendation_id` in the code. See [how to find the ID](🔗).

### How It Works

  1. You can go to the “Web deployment” section and use the script example or auto-generated snippet.

  2. You can fetch the auto-generated snippet via the app, then you can do necessary adjustments with JS/HTML/CSS such as remove the unnecessary code, adjust the events tracking according to their needs, adjust A/B test variants, etc.



Using Recommendations in Campaigns

Recommendations are **reused by default at all places within one campaign (email, SMS, MMS) to the same customer.**

However, if you wish to display different recommendations within one campaign, you must set a parameter `cached=False` within the recommendation call, using this simple example:



Recommendations via Experiments

If you are interested in deploying recommendations without any coding via a predefined ready-to-use block, read our article about [Web Recommendations Blocks](🔗) which will walk you through the setup step-by-step.