Setting the Returned Product Attributes in Recommendations in Kotlin SDK

Dynamic Yield provides a default structure for product attributes returned in recommendation campaign responses. You can fine-tune these product attributes to match your business needs as described in this article. Note that when you use the chooseVariation function , you can override this default by creating a dedicated recsProductData object.

The default product attribute structure

The following is the default product structure (based on the Dynamic Yield product feed structure):

Open class DefaultRecsProductData : RecsProductData() { 
    var product_type: ProductType? = null 
    var group_id: String? = null 
    var name: String? = null 
    var url: String? = null 
    var price: Float? = null 
    var in_stock: Boolean? = null 
    var image_url: String? = null 
    var categories: List<String?>? = null 
    var keywords: List<String?>? = null 
    var extra: MutableMap<String, Any?> = mutableMapOf()
} 

Changing the default using Kotlin SDK

To add more fields to the product structure:

  1. Create a new class that inherits from RecsProductData and annotate the class with the @Serializable annotation (https://github.com/Kotlin/kotlinx.serialization).
@Serializable
class CustomRecsProductData : RecsProductData() {
    val color: String? = null
}
  1. Set this class as the new default product data structure by calling setDefaultProductDataType().
private fun changeTheDefaultRecsProductData() {
    DYSdk.getInstance().setDefaultProductDataType(CustomRecsProductData.serializer())
}
  1. After you call setDefaultProductDataType(), every call to chooseVariations() for recommendation campaigns returns the fields you added to the new class. Values for standard attributes (such as product type, price, and keywords) appear in their own dedicated fields. Values for any additional custom attributes appear inside the extra map.

Did this page help you?