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 the API, go to the Settings › General Settings › Product Performance API, and click Enable. You need Admin permissions.
Setting product properties
When the API is enabled, product views and purchases are returned in the API response. If you want to also retrieve product properties, you can list up to 15 properties to get data for. If more than 15 product properties are needed, contact your Technical Account Manager.
Click Select Product Properties, and in the popup, select the properties you want to include in the API call.
These properties are retrieved when the attribute includeProductData is set to "true". If the attribute is set to "false", you retrieve only product views and purchases, no product data.
Note: If you enabled this API before July 2022, you are currently receiving data for all the products in your feed if includeProductData is set to "true". By September 2022 this behavior will be phased out, and only the defined properties will be returned. We recommend that you set up your properties now, so that when this capability is enabled, you will continue to receive product data seamlessly. Meanwhile, note that retrieving all data can affect latency and page load time. If you select a list of properties, you won't be able to go back to retrieving data for all your product properties.
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, and so on. The values can be true or false. Note that only listed product properties are returned in the API.
- 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": {}
}
}
}
}