Setting the Returned Product Attributes in Recommendations in Swift 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):

  public class DefaultRecsProductData: RecsProductData {
        let productType: ProductType?
        let groupId: String?
        let name: String?
        let url: String?
        let price: Float?
        let inStock: Bool?
        let imageUrl: String?
        let categories: [String?]?
        var keywords: [String?]?
    }

Changing the default using Swift SDK

To add more fields to the product structure:

  1. Create a new class that inherits from RecsProductData.
    public class CustomRecsProductData: RecsProductData {
        var shortColor: String = "yellow"
        var tShirtNumber: Int = 8
        var initials: String = "A.N"
    }
  1. Set this class as the new default product data structure by calling setDefaultProductDataType().
  DYSdk.shared().setDefaultProductDataType(defaultRecsProductData: CustomRecsProductData.self)
  1. After calling setDefaultProductDataType(), whenever chooseVariations is called for recommendation campaigns, the return value includes the fields you added to the new class.