The XRecommend service lets you fetch AI-driven product recommendations either for multiple slots at once or for a single slot, using context and merchandising rules to tailor results for each shopper.
Methods
// Returns a recommendation response mapped by element IDs.
xg.recommend.getResults({ elementIds: ['<element_id_1>', '<element_id_2>'], { pathname: '/en-us/' } });
// Returns a recommendation response for the given element ID.
xg.recommend.getResultsById({ elementId: '<element_id>', { pathname: '/en-us/' } });
getResults
getResults
Description: Fetches recommendation results for multiple elements at once.
Think of an “element” as a recommendation slot, like “You May Also Like” on a product page or “Trending Now” on your homepage.Gets recommendation results by a list of elementIds.
Parameters
Name | Type | Required | Description |
| string[] | ✅ | The IDs of the elements |
| object | ✅ | Options object that allows you to control the search result response |
↳ | string | ❌ | The pathname that includes the locale (default to 'default' locale) |
| object | ❌ | Dynamic context object |
| string | ❌ | An optional queryId passed to cancel a request |
Returns
A Promise
resolving to a Recommendations
object:
{
[key: string]: {
items: RecommendProduct[];
ruleEngine: string;
ruleset: string;
};
}
getResultsById
getResultsById
Description: Fetches recommendation results for a single elementId.
Parameters
Name | Type | Required | Description |
| string | ✅ | The ID of the element |
| object | ✅ | Options object that allows you to control the search result response |
↳ | string | ❌ | The pathname that includes the locale (default to 'default' locale) |
| object | ❌ | Dynamic context object |
| string | ❌ | An optional queryId passed to cancel a request |
Returns
A Promise
resolving to a Recommendations
object:
{
items: RecommendProduct[];
ruleset: string;
ruleEngine: string;
}