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
}
Changing the default using Kotlin SDK
To add more fields to the product structure:
- Create a new class that inherits from
RecsProductData
and annotate the class with the@Serializable
annotation (org.jetbrains.kotlinx:kotlinx-serialization-json).
@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 calling
setDefaultProductDataType()
, wheneverchooseVariations
is called for recommendations campaigns, the return value includes the fields you added to the new class.
Updated 16 days ago