Fetch Data

Fetch data from Bloomreach Engagement using the iOS SDK

The SDK provides methods to retrieve data from the Engagement platform. Responses are available in a completion handler closure.

Fetch Recommendations

Use the fetchRecommendation method to get personalized recommendations for the current customer from an Engagement recommendation model.

The method returns a RecommendationResponse object containing the system data (the recommendation engine data and recommended item IDs) and, if applicable, the user-defined data. To specify user-defined properties, you can use the generic type parameter T: RecommendationUserData. It's a simple struct with coding keys representing your custom properties. If you only need the system properties, you can use EmptyRecommendationData.

Arguments

NameTypeDescription
optionsRecommendationOptionsRecommendation options (see below for details )

RecommendationOptions

NameTypeDescription
id (required)StringID of your recommendation model.
fillWithRandomBoolIf true, fills the recommendations with random items until size is reached. This is utilized when models cannot recommend enough items.
sizeIntSpecifies the upper limit for the number of recommendations to return. Defaults to 10.
items[String: String]If present, the recommendations are related not only to a customer, but to products with IDs specified in this array. Item IDs from the catalog used to train the recommendation model must be used. Input product IDs in a dictionary as [product_id: weight], where the value weight determines the preference strength for the given product (bigger number = higher preference).

Example:
["product_id_1": "1", "product_id_2": "2",]
noTrackBoolDefault value: false
catalogAttributesWhitelist[String]Returns only the specified attributes from catalog items. If empty or not set, returns all attributes.

Example:
["item_id", "title", "link", "image_link"]

Example

struct MyRecommendation: RecommendationUserData {
    // put all the custom properties on your recommendations into a struct
    // and call fetchRecommendation with it in results callback
    let 
}

typealias MyRecommendationResponse = RecommendationResponse<MyRecommendation>

// Prepare the recommendation options
let recommendationOptions = RecommendationOptions(
    id: "65c2a2bc0827bbe25d2b67cc",
    fillWithRandom: true,
    size: 5,
    items: ["product456":"10", "product123":"1"]
)

// Get recommendations for the current customer
Exponea.shared.fetchRecommendation(with: recommendationOptions) { (result: Result<MyRecommendationResponse>) in
    if case .success(let recommendation) = result {
        // In case of success, value contains list of recommendations
        print(recommendation.value?[0].userData)
        print(recommendation.value?[0].systemData)
    }
}

Return Object

RecommendationResponse

NameTypeDescription
successBoolWhether fetching recommendations was successful.
errorStringError message if not successful.
value[Recommendation]An array of recommendations.

Recommendation

NameTypeDescription
systemDataRecommendationSystemDataSystem data returned from the server.
userDataT: RecommendationUserDataUser-defined data returned from the server. Use your own struct implementing RecommendationUserData, data will be decoded into it.

RecommendationSystemData

NameTypeDescription
engineNameStringName of the recommendation engine used.
itemIdStringID of the recommended item.
recommendationIdStringID of the recommendation engine (model) used.
recommendationVariantIdStringID of the recommendation engine variant used.

Fetch Consent Categories

Use the fetchConsents method to get a list of your consent categories and their definitions.

Use when you want to get a list of your existing consent categories and their properties, such as sources and translations. This is useful when rendering a consent form.

The method returns a ConsentsResponse object containing an array of Consent objects.

Example

// Fetch consents to get existing consent categories.
Exponea.shared.fetchConsents { (result) in
    switch result {
    case .success(let response):
        print(response.consents)
        
    case .failure(let error):
        print(error.localizedDescription)
    }
}

Result Object

ConsentsResponse

NameTypeDescription
consents[Consent]Contains an array of consent categories.

Consent

NameTypeDescription
idStringName of the consent category.
legitimateInterestBoolIf the user has legitimate interest.
sourcesConsentSourcesThe sources of this consent.
translations[String: [String: String]]Contains the translations for the consent.

Keys of this dictionary are the short ISO language codes (eg. "en", "cz", "sk"...) and the values are dictionaries containing the translation key as the dictionary key and translation value as the dictionary value.

ConsentSources

NameTypeDescription
isCreatedFromCRMBoolManually created from the web application.
isImportedBoolImported from the importing wizard.
isFromConsentPageBoolTracked from the consent page.
privateAPIBoolAPI which uses basic authentication.
publicAPIBoolAPI which only uses public token for authentication.
isTrackedFromScenarioBoolTracked from the scenario from event node.