Pages

recommendation strategy provides the recommendation data that forms the core content of a recommendation: the details of the set of recommended items. To build the recommendation for display on the page, you need to retrieve the recommendation data from the Frosmo back end and populate the recommendation element with the data.

You retrieve the recommendation data and create the recommendation element in a template. You retrieve and process the data in the template prerenderer.

To retrieve the recommendation data for a strategy:

  1. Call the frosmo.easy.strategies.fetch() function with the strategy ID as a string parameter. For more information about the function, see fetch() request.
  2. Extract the data from the response object. For more information about the object, see fetch() response.

You can now use the data in your recommendation content.

For a practical example of retrieving and using recommendation data in a template, see Example: Recommending trending products in a category (strategy).

fetch() request

The frosmo.easy.strategies.fetch() function returns a Frosmo Core Promise (compatible with a Promise) that is either resolved with a response object containing the recommendation data or rejected with an error object.

frosmo.easy.strategies.fetch('strategy-id')
    .then(function (response) {
        console.log(response.data);
    })
    .catch(function (error) {
        console.error(error);
    });

The following table describes the parameters you can define for the frosmo.easy.strategies.fetch() function.

Table: Parameters for frosmo.easy.strategies.fetch()

ParameterDescriptionTypeRoleExample
strategy

ID of the recommendation strategy whose recommendation data to retrieve.

To find out the ID of a recommendation strategy, check the strategy settings.

StringRequired
frosmo.easy.strategies.fetch('strategy-id')
options

Options for configuring the fetch and response.

For more information, see the following table.

ObjectOptional
frosmo.easy.strategies.fetch('strategy-id', {shuffle: true})

Table: Options object properties

PropertyDescriptionTypeRoleExample
debug

Define whether to return debugging information about the recommendation data.

The possible values are:

  • false: Do not return debugging information.
  • true: Return debugging information.

The default value is false.

BooleanOptional
frosmo.easy.strategies.fetch('strategy-id', {debug: true})
shuffle

Define whether to randomly shuffle the order of items in the recommendation data.

By default, the items are in ranked order as determined by the recommendation strategy.

The possible values are:

  • false: Do not shuffle the order of items.
  • true: Shuffle the order of items.

The default value is false.

BooleanOptional
frosmo.easy.strategies.fetch('strategy-id', {shuffle: true})
timeout

Time in milliseconds that the fetch call waits for the Recommendations API to return the requested data. If the API does not return data in the specified time, the fetch call rejects the Promise.

The default value is undefined, meaning the fetch call waits forever.

NumberOptional
frosmo.easy.strategies.fetch('strategy-id', {timeout: 10000})

fetch() response

The response is a JSON object.

The response object contains the following properties:

  • data: Recommendation data as an array of objects, where each object contains the details of a single recommended item.
  • debug: Object containing the debugging information. This property is included only when the debug option is set to true in the fetch call.

The following examples show the same response without and with debugging information.

Example: Recommendation data in a response
{
  "data": [
    {
      "id": "1",
      "type": "Power Tools/Woodworking",
      "name": "Electric Planer Brandix KL370090G 300 Watts",
      "created_at": "2020-09-10T13:50:09+02:00",
      "updated_at": "2021-02-23T09:21:26+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [
          "new",
          "sale"
        ],
        "data": "{\"availability\":\"In stock\",\"stock\":7,\"rating\":4,\"reviews\":12,\"deliverTime\":3,\"badges\":[\"new\",\"sale\"],\"displayPrice\":\"€749.00\",\"displayDiscountPrice\":\"€509.32\"}",
        "deliverTime": 3,
        "discountPrice": "509.32",
        "displayDiscountPrice": "€509.32",
        "displayPrice": "€749.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-1.jpg",
        "manufacturer": "Wakita",
        "price": "509.32",
        "rating": 4,
        "reviews": 12,
        "stock": 7,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/1"
      }
    },
    {
      "id": "3",
      "type": "Power Tools/Drills",
      "name": "Drill Screwdriver Brandix ALX7054 200 Watts",
      "created_at": "2020-09-10T13:50:41+02:00",
      "updated_at": "2021-02-23T09:21:28+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [

        ],
        "data": "{\"availability\":\"In stock\",\"stock\":9,\"rating\":4,\"reviews\":8,\"deliverTime\":1,\"badges\":[],\"displayPrice\":\"€850.00\",\"displayDiscountPrice\":null}",
        "deliverTime": 1,
        "discountPrice": "0",
        "displayDiscountPrice": null,
        "displayPrice": "€850.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-3.jpg",
        "manufacturer": "Wakita",
        "price": "850",
        "rating": 4,
        "reviews": 8,
        "stock": 9,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/3"
      }
    },
    {
      "id": "2",
      "type": "Power Tools/Saws",
      "name": "Undefined Tool IRadix DPS3000SY 2700 Watts",
      "created_at": "2020-09-10T14:45:57+02:00",
      "updated_at": "2021-02-23T09:21:27+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [
          "hot",
          "sale"
        ],
        "data": "{\"availability\":\"In stock\",\"stock\":6,\"rating\":5,\"reviews\":3,\"deliverTime\":2,\"badges\":[\"hot\",\"sale\"],\"displayPrice\":\"€1019.00\",\"displayDiscountPrice\":\"€580.83\"}",
        "deliverTime": 2,
        "discountPrice": "580.8299999999999",
        "displayDiscountPrice": "€580.83",
        "displayPrice": "€1019.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-2.jpg",
        "manufacturer": "Wakita",
        "price": "580.8299999999999",
        "rating": 5,
        "reviews": 3,
        "stock": 6,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/2"
      }
    },
    {
      "id": "5",
      "type": "Power Tools/Woodworking",
      "name": "Brandix Router Power Tool 2017ERXPK",
      "created_at": "2020-09-10T15:48:12+02:00",
      "updated_at": "2021-02-23T09:21:30+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [

        ],
        "data": "{\"availability\":\"In stock\",\"stock\":7,\"rating\":4,\"reviews\":2,\"deliverTime\":1,\"badges\":[],\"displayPrice\":\"€1700.00\",\"displayDiscountPrice\":null}",
        "deliverTime": 1,
        "discountPrice": "0",
        "displayDiscountPrice": null,
        "displayPrice": "€1700.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-5.jpg",
        "manufacturer": "Wakita",
        "price": "1700",
        "rating": 4,
        "reviews": 2,
        "stock": 7,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/5"
      }
    }
  ]
}
Example: Recommendation data in a response with debugging information
{
  "data": [
    {
      "id": "1",
      "type": "Power Tools/Woodworking",
      "name": "Electric Planer Brandix KL370090G 300 Watts",
      "created_at": "2020-09-10T13:50:09+02:00",
      "updated_at": "2021-02-23T09:21:26+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [
          "new",
          "sale"
        ],
        "data": "{\"availability\":\"In stock\",\"stock\":7,\"rating\":4,\"reviews\":12,\"deliverTime\":3,\"badges\":[\"new\",\"sale\"],\"displayPrice\":\"€749.00\",\"displayDiscountPrice\":\"€509.32\"}",
        "deliverTime": 3,
        "discountPrice": "509.32",
        "displayDiscountPrice": "€509.32",
        "displayPrice": "€749.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-1.jpg",
        "manufacturer": "Wakita",
        "price": "509.32",
        "rating": 4,
        "reviews": 12,
        "stock": 7,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/1"
      }
    },
    {
      "id": "3",
      "type": "Power Tools/Drills",
      "name": "Drill Screwdriver Brandix ALX7054 200 Watts",
      "created_at": "2020-09-10T13:50:41+02:00",
      "updated_at": "2021-02-23T09:21:28+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [

        ],
        "data": "{\"availability\":\"In stock\",\"stock\":9,\"rating\":4,\"reviews\":8,\"deliverTime\":1,\"badges\":[],\"displayPrice\":\"€850.00\",\"displayDiscountPrice\":null}",
        "deliverTime": 1,
        "discountPrice": "0",
        "displayDiscountPrice": null,
        "displayPrice": "€850.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-3.jpg",
        "manufacturer": "Wakita",
        "price": "850",
        "rating": 4,
        "reviews": 8,
        "stock": 9,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/3"
      }
    },
    {
      "id": "2",
      "type": "Power Tools/Saws",
      "name": "Undefined Tool IRadix DPS3000SY 2700 Watts",
      "created_at": "2020-09-10T14:45:57+02:00",
      "updated_at": "2021-02-23T09:21:27+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [
          "hot",
          "sale"
        ],
        "data": "{\"availability\":\"In stock\",\"stock\":6,\"rating\":5,\"reviews\":3,\"deliverTime\":2,\"badges\":[\"hot\",\"sale\"],\"displayPrice\":\"€1019.00\",\"displayDiscountPrice\":\"€580.83\"}",
        "deliverTime": 2,
        "discountPrice": "580.8299999999999",
        "displayDiscountPrice": "€580.83",
        "displayPrice": "€1019.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-2.jpg",
        "manufacturer": "Wakita",
        "price": "580.8299999999999",
        "rating": 5,
        "reviews": 3,
        "stock": 6,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/2"
      }
    },
    {
      "id": "5",
      "type": "Power Tools/Woodworking",
      "name": "Brandix Router Power Tool 2017ERXPK",
      "created_at": "2020-09-10T15:48:12+02:00",
      "updated_at": "2021-02-23T09:21:30+01:00",
      "attributes": {
        "availability": "In stock",
        "badges": [

        ],
        "data": "{\"availability\":\"In stock\",\"stock\":7,\"rating\":4,\"reviews\":2,\"deliverTime\":1,\"badges\":[],\"displayPrice\":\"€1700.00\",\"displayDiscountPrice\":null}",
        "deliverTime": 1,
        "discountPrice": "0",
        "displayDiscountPrice": null,
        "displayPrice": "€1700.00",
        "image": "https://demo-retail-bp.docker-box.inpref.com/images/products/product-5.jpg",
        "manufacturer": "Wakita",
        "price": "1700",
        "rating": 4,
        "reviews": 2,
        "stock": 7,
        "url": "https://demo-retail-bp.docker-box.inpref.com/shop/product/5"
      }
    }
  ],
  "debug": {
    "slots": [
      {
        "dataPoint": {
          "id": "1",
          "weight": 348
        },
        "algorithm": "popular_viewed"
      },
      {
        "dataPoint": {
          "id": "3",
          "weight": 237
        },
        "algorithm": "popular_viewed"
      },
      {
        "dataPoint": {
          "id": "2",
          "weight": 228
        },
        "algorithm": "popular_viewed"
      },
      {
        "dataPoint": {
          "id": "5",
          "weight": 226
        },
        "algorithm": "popular_viewed"
      }
    ],
    "dataPoints": [
      {
        "id": "1",
        "weight": 348
      },
      {
        "id": "3",
        "weight": 237
      },
      {
        "id": "2",
        "weight": 228
      },
      {
        "id": "5",
        "weight": 226
      }
    ],
    "recos": [
      {
        "id": 2077,
        "name": "strategy43_position1_popular_viewed",
        "limit": 120,
        "mapping": "product",
        "filters": [
          {
            "Name": "Only include items that match the viewed category",
            "Rules": [
              {
                "Source": "context",
                "SourcePath": "page.category.categories",
                "Attribute": "type",
                "Operator": "in",
                "Value": ""
              }
            ]
          }
        ],
        "postDynamicFilters": [
          {
            "ParamName": "type",
            "Operator": "in",
            "Comparator": "[\"Power Tools/Woodworking\",\"Power Tools/Drills\",\"Power Tools/Saws\"]"
          }
        ],
        "modelUpdatedAt": "2021-02-22T15:34:24Z",
        "params": null,
        "excludeIds": null,
        "dataPoints": [
          {
            "id": "1",
            "weight": 348
          },
          {
            "id": "3",
            "weight": 237
          },
          {
            "id": "2",
            "weight": 228
          },
          {
            "id": "5",
            "weight": 226
          },
          {
            "id": "4",
            "weight": 117
          },
          {
            "id": "16",
            "weight": 114
          },
          {
            "id": "15",
            "weight": 112
          }
        ]
      },
      {
        "id": 2078,
        "name": "strategy43_position2_popular_bought",
        "limit": 120,
        "mapping": "product",
        "filters": [
          {
            "Name": "Only include items that match the viewed category",
            "Rules": [
              {
                "Source": "context",
                "SourcePath": "page.category.categories",
                "Attribute": "type",
                "Operator": "in",
                "Value": ""
              }
            ]
          }
        ],
        "postDynamicFilters": [
          {
            "ParamName": "type",
            "Operator": "in",
            "Comparator": "[\"Power Tools/Woodworking\",\"Power Tools/Drills\",\"Power Tools/Saws\"]"
          }
        ],
        "modelUpdatedAt": "2021-02-22T15:13:23Z",
        "params": null,
        "excludeIds": null,
        "dataPoints": null
      }
    ],
    "strategy": {
      "site_id": 2271,
      "id": 43,
      "id_string": "most-popular-in-category",
      "slots": [

      ],
      "positions": [
        {
          "id": 1,
          "items": 4,
          "algorithm": "popular_viewed",
          "reco_id": 2077,
          "anchor_source": "",
          "anchor_source_path": "",
          "anchor_items": 0
        },
        {
          "id": 2,
          "items": 4,
          "algorithm": "popular_bought",
          "reco_id": 2078,
          "anchor_source": "",
          "anchor_source_path": "",
          "anchor_items": 0
        }
      ],
      "updated_at": "2021-01-13T14:11:29Z"
    },
    "positions": [
      {
        "id": 1,
        "dataPoints": [
          {
            "id": "1",
            "weight": 348
          },
          {
            "id": "3",
            "weight": 237
          },
          {
            "id": "2",
            "weight": 228
          },
          {
            "id": "5",
            "weight": 226
          },
          {
            "id": "4",
            "weight": 117
          },
          {
            "id": "16",
            "weight": 114
          },
          {
            "id": "15",
            "weight": 112
          }
        ],
        "addedDataPoints": [
          {
            "id": "1",
            "weight": 348
          },
          {
            "id": "3",
            "weight": 237
          },
          {
            "id": "2",
            "weight": 228
          },
          {
            "id": "5",
            "weight": 226
          }
        ],
        "duplicateDataPoints": [

        ]
      },
      {
        "id": 2,
        "dataPoints": [

        ],
        "addedDataPoints": [

        ],
        "duplicateDataPoints": [

        ]
      }
    ],
    "context": {
      "page": {
        "type": "category",
        "cart": null,
        "category": {
          "name": "Power Tools/Woodworking",
          "categories": [
            "Power Tools/Woodworking",
            "Power Tools/Drills",
            "Power Tools/Saws"
          ]
        },
        "product": null,
        "search": null
      },
      "user": {
        "area": "",
        "lastBought": {
          "ids": [

          ],
          "categories": [

          ]
        },
        "lastViewed": {
          "ids": [

          ],
          "categories": [

          ]
        },
        "mostViewed": {
          "ids": [

          ],
          "categories": [

          ]
        }
      }
    },
    "productAPI": [
      {
        "id": "1",
        "message": "added product data"
      },
      {
        "id": "3",
        "message": "added product data"
      },
      {
        "id": "2",
        "message": "added product data"
      },
      {
        "id": "5",
        "message": "added product data"
      }
    ]
  }
}