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:
- Create a new class that inherits from
RecsProductDataand annotate the class with the@Serializableannotation (https://github.com/Kotlin/kotlinx.serialization).
@Serializable
class CustomRecsProductData : RecsProductData() {
val color: String? = null
}- Set this class as the new default product data structure by calling
setDefaultProductDataType().
private fun changeTheDefaultRecsProductData() {
DYSdk.getInstance().setDefaultProductDataType(CustomRecsProductData.serializer())
}- After you call
setDefaultProductDataType(), every call tochooseVariations()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 theextramap.
Updated 4 days ago
Did this page help you?
