This API returns the views and purchases of one or more products over different time periods. This allows you to create custom use cases that leverage this data, whether for display or for other cases.
Native alternatives to the API:
- "Product Performance" template variable allows you to display product performance data inside Dynamic Yield campaigns. For example, a notification on a product page with the number of purchases it had in the past 24 hours). Product performance is shown on the group ID level and not the SKU level.
- "Product Popularity" targeting conditions allows you to target experiences based on the performance of the product page. For example, show a "Popular product" badge only on products that were purchased at least X times in the past week.
Enabling the API
To enable or disable the API, go to the Settings › General Settings, and turn on or off the toggle under "Product Data API". You need an Admin permission to enable it.
API Parameters
function getProductsData(skus, timeframes, includeProductInterest, includeProductData, callback)
Parameters
- skus. Syntax: List[String]. An array of up to 20 product SKUs.
- timeframes. Syntax: List[String]. An array of one or more values defining the timeframe going back. If undefined, returns values for all time periods. The values can be:
- daily (last 24 hours)
- twoDays (last 48 hours)
- weekly (last 168 hours)
- twoWeeks (last 336 hours)
- monthly (last 720 hours)
- includeProductInterest. Determines if viewing data, purchase data, or both are returned. If undefined, both are returned. The values can be:
- View
- Purchase
- includeProductData. Determines whether or not to display product attributes and details such as color, style, etc. The values can be true or false.
- callback. The callback function
Example Call
DY.ServerUtil.getProductsData(["1217282-400", "1217282-600"], ['daily', 'twoDays'], 'view', false, function(err, res) { console.log(res)})
Example Response
{
"1217282-400": {
"productInterest": {
"view": {
"daily": 1,
"twoDays": 1
},
"city": {
"view": {},
"purchase": {}
}
}
},
"1217282-600": {
"productInterest": {
"view": {
"daily": 1,
"twoDays": 1
},
"city": {
"view": {},
"purchase": {}
}
}
}
}