excludeProducts()

Prev Next

excludeProducts() is used to exclude products from the prediction API recommendations.

Excluded products must be configured prior to the prediction API being called. Otherwise, the excluded products will not be included in the request.

Syntax

excludeProducts(productCodeArray)
excludeProducts(prodCode1, /* …, */ prodCodeN)

Parameters

prodCodeArray

type: array
description: An array of product codes that will be excluded from the recommendations.
items:

productCode

type: string
description: The product code to be excluded from the recommendations. Note: the product codes have to match exactly 1 to 1 what is mapped in XGen’s catalog. Otherwise the products will not be excluded.

prodCode1 … prodCodeN

type: string
description: Multiple product codes that will be excluded from the recommendations as separate parameters. Note: the product codes have to match exactly 1 to 1 what is mapped in XGen’s catalog. Otherwise the products will not be excluded.

Return Value

This function has no return value.

Examples

Set excluded products array

In this example, we get the products that are currently in the cart to ensure they will not show up in any recommendations with the array syntax.

// Create integration (use existing integration if you already created one)
const integration = new XG(...config);

// Get cart items and map them by ID
const cartItems = window.cartItems.map(prod => prod.id);

// Exclude cart items array
integration.excludeProducts(cartItems);
Set excluded products parameter list

In this example, we are excluding a hard-coded list of products using the parameter syntax.

// Create integration (use existing integration if you already created one)
const integration = new XG(...config);

// Exclude hard-coded items
integration.excludeProducts('abc123', 'def456', 'ghi789');