getXGenPrediction()

Prev Next

getXgenPrediction() is used to retrieve a single list of XGen’s personalized recommendation predictions. These predictions are used for rendering out personalized elements that are unique to each user.

This function gets a single element. If you want to retrieve more than one element, use getXGenPredictions() for a more efficient approach.

If the pages functionality is being used, this function will wait for a page to be matched before the promise resolves.

Syntax

getXgenPrediction(elementId);

Parameters

elementId

type: string
description: The ID of the element for the predictions that will be returned.

Return Value

A promise that resolves with an array of objects containing product information.

Example:

Examples

Get list of products:

In this example, we get a list of products for a specific element. When the returned promise resolves, we console log the prod_code (aka product ID) of each product recommended.

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

// Get list of products for an element
const products = await integration.getXgenPredictions('sm_el_b04ebc323ccb4f49bedcece7652e4fba');

// Console log prod_code of each product recommended
products.forEach(product => console.log(product.prod_code));