Examples
3 min
Modify Recommendations
Below are some common uses of modifying the Klevu Smart Recommendations data objects.
Please review : The Modify Recommendations Overview for complete details and options.
Modify Recommendations API Request
The below snippet contains a few examples of API query modifications using the Recommendations webhook
<script type = "text/javascript" >
function klevu_processRECSRecordQueries(recordQueries, recsKey)
{
var recsQuery = recordQueries[0];
// eg. change the result limit to 10
klevu.setObjectPath(recsQuery, "settings.limit", 10);
// eg. add a category context of "Clothing"
klevu.setObjectPath(recsQuery, "settings.query.categoryPath", "Your Category");
// eg. exclude some results for a specific banner only
if (recsKey == 'abc-123-xyz-321') {
var excludeIds = [
{
key: "id", // or itemGroupId
value: "the-id-to-exclude"
}
];
klevu.setObjectPath(recsQuery, "settings.excludeIds", excludeIds);
}
// Klevu Recommendations utilise Klevu API,
// you can therefore modify any of the params in our Docs.
// See https://developers.klevu.com/api for all available parameters!
}
</script>
Modify Recommendations Template Object
The below example changes the configured title for a specific Recommendation banner
function klevu_processRECSTemplateData(templateData, recsKey) {
/* apply only to the specified recsKey <id> */
if (recsKey == 'abc-123-xyz-321') {
/* replace the title as desired */
templateData.metadata.title = 'Just For You!';
}
}}