A 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 a page or in an application UI, you need to first retrieve the recommendation data from the Frosmo back end and then populate the recommendation element with the data.
To return the correct recommendation data, some algorithms require extra information about the current page or visitor. This information is known as the context for a strategy. On a website, the context can be set programmatically with Frosmo Core, so that pages load with the correct context automatically available. Frosmo developers create the correct context setup for a site. In cases where this setup is not available or possible, you must explicitly provide the context when retrieving the recommendation data for a strategy. For more information about the context, see the
context parameter documentation in the Recommendations API guide.
You have two options for retrieving the recommendation data:
- Frosmo Core fetch function. Use this option if you're retrieving the data on a website that has a context setup in place. For more information, see the following section.
Recommendations API. Use this option if you're retrieving the data in a native mobile application or a server-side application, or on a website without a context setup. You must provide the context as part of the API request. For more information, see the Recommendations API guide.
The API does not currently support algorithms that require context information about the current visitor. You cannot use the API to retrieve data for strategies that use these algorithms.
If you're using a modification to display the recommendation on a website, you retrieve the recommendation data and create the recommendation element in a template. You retrieve and process the data in the template prerenderer.
Frosmo Core fetch function
To retrieve the recommendation data for a strategy using Frosmo Core:
- Call the
frosmo.easy.strategies.fetch()function with the strategy ID as a string parameter. Make sure that the page where you call the function matches the page type defined for the strategy. For more information about the function, see fetch() request.
- 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).
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() function expects that the context for the strategy has been set and that the context matches the page type defined for the strategy. If the correct context is not available, the function fails. For example, if the page type of the strategy is product, the function expects that it's called on a product page that has the correct product context set.
You can check the context set for the current page by calling the
The following table describes the parameters you can define for the
Table: Parameters for frosmo.easy.strategies.fetch()
ID of the recommendation strategy whose recommendation data to retrieve.
To find out the ID of a recommendation strategy, check the strategy settings.
Options for configuring the fetch and response.
For more information, see the following table.
Table: Options object properties
Define whether to return debugging information about the recommendation data.
The possible values are:
The default value is
Define whether to randomly shuffle the order of items in the recommendation data.
By default, the items are in descending order of rank, with the most recommended item (as defined by the strategy) ranked highest.
The possible values are:
The default value is
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.
The response is a JSON object.
The response object contains the following root properties:
data: Recommendation data as an array of objects, where each object contains the details of a single recommended item. Unless shuffled, the items are in descending order of rank, with the most recommended item (as defined by the algorithms) ranked highest.
debug: Object containing the debugging information. This property is included only when the
debugoption is set to
truein the fetch call.
The following examples show the same response without and with debugging information.