The Recommendations API allows you to promote and recommend items to your customers. You can get item recommendations from catalogs on your site using algorithms provided by apps.
Note: Currently, the Recommendations API is for use with Wix Stores only.
With the Recommendations API, you can:
Algorithms are programs that identify and return a set of item recommendations based on a catalog. There are different types of algorithms, identified by their algorithmType
that calculate different kinds of recommendations. For example, Algorithms with the RELATED_ITEMS
algorithmType
also take a list of items as input and use those to calculate recommendations.
For example, Wix Stores provides the following algorithms:
Name | Description | Algorithm Type |
---|---|---|
“From the same categories” | Returns items that share the most categories with items in the list provided. | RELATED_ITEMS |
“Frequently bought together” | Returns items that are frequently bought together with the first item in the list provided. | RELATED_ITEMS |
“Frequently viewed together” | Returns items that are frequently viewed together with the first item in the list provided. | RELATED_ITEMS |
“Best sellers” | Returns the items from the catalog with the highest number of sales. | GLOBAL |
Tip: If you want to display item recommendations on your site, you can use the Wix Stores “Slider Product Gallery” and “Related Products” elements. These elements use Recommendations API functionality without the need for manual coding. In these elements' settings, you can choose which algorithm to use from among those available on your site.
On your Product, Cart, and Thankyou pages you can use RELATED_ITEMS
type algorithms to get recommendations related to the product/s shown on the page.
On other pages, you can get recommendations from GLOBAL
type algorithms.
listAvailableAlgorithms()
. Currently, the only app providing algorithms and their supported catalogs is Wix Stores.We To use the Recommendations API,
import { recommendations }
from wix-ecom-backend
:
import { recommendations } from "wix-ecom-backend";
Send emails to customers recommending related products.
Functions in the Recommendations API are restricted and only run if you elevate permissions using the wix-auth
elevate()
function.
Warning: Elevating a function allows it to be called by any site visitor. Exercise caution to prevent security vulnerabilities.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Returns a recommendation object containing a list of items to recommend to the customer.
getRecommendation()
determines which items to recommend based on the given recommendation algorithms.
getRecommendation()
doesn’t run the algorithms. It calls the installed apps that provide them.
Apps may provide algorithms for use with their own catalogs, or for use with catalogs from other apps.
For example, Wix Stores provides algorithms that can only be used on its own catalogs.
To run an algorithm, the app providing it must be installed, and an app providing a supported catalog must be installed.
For more information and to see which algorithms are available on your site or project, call listAvailableAlgorithms()
.
getRecommendation()
operates as follows:
getRecommendation()
receives as input a list of algorithms as an array. These algorithms can be provided by different apps and can apply to different catalogs.getRecommendation()
calls the app that corresponds to the appId
of the first algorithm in the list of algorithms. It passes that algorithm’s ID and the IDs of any subsequent algorithms in the array for the same app.getRecommendation()
returns items recommendations from the first algorithm (according to its position in the algorithms
array) that meets the minimum number of recommendations. At that point getRecommendation()
stops calling other apps.getRecommendation()
finds the next algorithm in the array with a new appId
(an ID of an app that has not yet been called), and repeats the process.algorithms
array recommend at least the minimum recommended items, getRecommendation()
returns an empty array.function getRecommendation(
algorithms: Array<Algorithm>,
options: GetRecommendationOptions,
): Promise<GetRecommendationResponse>;
A list of algorithms checked in a specific order determined by their appID
and their position in the algorithms
array.
See the method description for more information.
If no algorithm is able to return at least minimumRecommendedItems
items, an empty array is returned.
Get recommendation options.
/**************************************
* Backend code - recommendations.web.js *
*************************************/
import { Permissions, webMethod } from "wix-web-module";
import { recommendations } from "wix-ecom-backend";
export const getRecommendation = webMethod(
Permissions.Anyone,
async (algorithms, options) => {
try {
const result = await recommendations.getRecommendation(
algorithms,
options,
);
return result;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
/*************
* Page code *
************/
import { getRecommendation } from "backend/recommendations.web";
$w.onReady(async function () {
let algorithm = {
appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
id: "68ebce04-b96a-4c52-9329-08fc9d8c1253",
};
let item = {
appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
catalogItemId: "11e2ffb7-2520-3c21-051e-1f05486b9061",
};
let options = {
items: [item],
minimumRecommendedItems: 1,
};
let recommendations = await getRecommendation([algorithm], options);
console.log(recommendations);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Returns a list of recommendation algorithms that can be used on your Wix site or project. These algorithms can be used with getRecommendation()
to provide item recommendations to the customer.
Algorithms are run by the apps that provide them, and can only be used on catalogs they support. Apps may provide algorithms for use with their own catalogs and/or catalogs from other apps.
The app which provides an algorithm is referenced by that algorithm’s appId
. The apps whose catalogs are supported by an algorithm are referenced by the IDs in that algorithm’s catalogAppIds
array.
For an algorithm to be considered “Available” and returned in this method’s response, the algorithm must meet the following conditions:
appId
must match the ID of an installed Wix app.catalogAppIds
must match the ID of an installed Wix app.Wix app IDs are listed here.
function listAvailableAlgorithms(): Promise<ListAvailableAlgorithmsResponse>;
import { recommendations } from "wix-ecom-backend";
async function listAvailableAlgorithms() {
try {
const result = await recommendations.listAvailableAlgorithms();
return result;
} catch (error) {
console.error(error);
// Handle the error
}
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.