The pdpProduct
value 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.
Syntax
pdpProduct: pdpProductCode
pdpProduct: () => pdpProductCode
pdpProduct: async () => pdpProductCode
Usage
The value of pdpProduct
should be a string
containing the product code for the PDP that is currently being viewed. Additionally, you can pass in a function or an async function that returns the product code and that function will get called at runtime and the return value will be used. If the function is async or returns a promise, it will be awaited before calling XGen’s primary API.
Examples
With a string
pdpProduct: 'abc123'
In this example, pdpProduct is set to the string of the PDP product that is currently being viewed.
With a synchronous function
pdpProduct: () => 'abc123'
In this example, pdpProduct is set to a function and the return value of this function will be set to the PDP product.
With an async function
pdpProduct: async () => {
const pdpItem = fetch('/product').then(r => r.json());
return pdpItem.id;
}
In this example, pdpProduct is set to an asynchronous function that calls an API. This function will be awaited and the value from the API will be set to the PDP product.