This API returns the number of users who viewed and purchased one or more products over different time periods. This enables you to create custom use cases that leverage this data, whether for display or other use cases.
Native alternatives to the API:
- The Product Performance template variable lets you display product performance data inside Dynamic Yield campaigns. For example, a notification on a product page with the number of unique users who purchased it in the past 24 hours. Product performance is shown at the group ID level and not the SKU level.
- The Product Popularity targeting condition enables 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 by at least X unique users 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 also to retrieve product properties, you can list up to 15 properties to get data for.
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.
If your business use case isn't fully supported by the limitations of this feature, contact your Technical Account Manager.
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
Call example
DY.ServerUtil.getProductsData(["1217282-400", "1217282-600"], ['daily', 'twoDays'], 'view', false, function(err, res) { console.log(res)})
Response example
{
"1217282-400": {
"productInterest": {
"view": {
"daily": 1,
"twoDays": 1
},
"city": {
"view": {},
"purchase": {}
}
}
},
"1217282-600": {
"productInterest": {
"view": {
"daily": 1,
"twoDays": 1
},
"city": {
"view": {},
"purchase": {}
}
}
}
}