# 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](🔗). The code for requesting product recommendations using Javascript SDK could be found in the Web Deployment part of each of the recommendation engines in Bloomreach Engagement. 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 our [personalization guide](🔗), but below we describe the **three most important parts attributes**:

_recommendationId_ **(Required)**StringEngine ID of an existing recommendation model. This ID is created when the engine is saved in Bloomreach Engagement.'5a7c4dfefb6009323d4c7311'
_fillWithRandom_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.'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 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 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](🔗) and [Personalized category page](🔗) engines)**Array **(Max size: 10)**Currently viewed category or categories by the browsing user.['shoes', 'high heels']

# Integration to campaigns

Here we present two Jinja code snippets in order to demonstrate how to integrate recommender engines into campaigns. We will demonstrate one simple and 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](🔗). It is good practice 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 clicking on any product which was generated by Bloomreach 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 removing unnecessary code, adjusting the events tracking according to their needs, adjusting 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 calling, using this simple example:

Recommendations via Experiments

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