setPdpProduct()

Prev Next

setPdpProduct() is used to tell the prediction API what product page is currently being viewed. This information is used for recommendation types such as co-viewed, co-purchased, and recently viewed. The prediction API will also exclude this product from recommendations automatically.

PDP product must be set prior to the prediction API being called. Otherwise, the PDP product will not be included in the request.

Syntax

setPdpProduct(prodCode)

Parameters

prodCode

type: string
description: The product code of the product page that the user is currently viewing. Note: the product code has to match exactly 1 to 1 what is mapped in XGen’s catalog. Otherwise this functionality will not work.

Return Value

This function has no return value.

Examples

Set the PDP product

In this example, we will get the product ID from the window object and set that ID as the current PDP product.

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

// Get the product code
const pdpProductId = window.product.id

// Set the pdp product
integration.setPdpProduct(pdpProductId);