Audiences
Starting with the following versions of SDKs, you can set user attributes to create Audiences:
iOS: 3.4.0
Android: 3.4.0
ReactNative: 2.4.0
Cordova: 2.4.0
Flutter: 1.4.0
Audiences can be created in our Console and applied to specific placements so that in your application you have nothing to change to display a paywall for an audience, as usual you just decide when you want to display a specific placement that will automatically display the paywall depending on the user context (audiences and a/b test)
An audience is a combinaison of user attributes, you can create as many user attributes as you wish with those specific type:
String
Int
Float
Boolean
Date

Once you have created the user attributes you are interested in, in your application you send those attributes with their values to our SDK. Purchasely will then compute automatically the audience based on those attributes
Sending attributes
All values type must be the exact same than the ones you have set in Purchasely console, for exemple if you have setup an Age
property with the key age
and the type Int
then in your code your have to set it with an integer value like Purchasely.setUserAttribute("age", 21)
//Set one attribute by key and value
Purchasely.setUserAttribute(withIntValue: 20, forKey: "age")
Purchasely.setUserAttribute(withDoubleValue: 175.5, forKey: "size")
Purchasely.setUserAttribute(withBoolValue: true, forKey: "subscribed")
Purchasely.setUserAttribute(withDateValue: Date(), forKey: "date")
Purchasely.setUserAttribute(withStringValue: "Female", forKey: "gender")
//Remove one attribute
Purchasely.clearUserAttribute(forKey: "size")
//Set multiple attributes
Purchasely.setUserAttributes(
[
"age": 20,
"size": 175.5,
"subscribed": true,
"date": Date(),
"gender": "Female"
]
)
//Remove all attributes
Purchasely.clearUserAttributes()
Retrieving attributes
//return an int since it was set with that type
if let age = Purchasely.getUserAttribute(for: "age") as? Int {
// Do Something
}
//return a dictionary of all attributes
Purchasely.userAttributes.forEach { attribute in
print("Attribute \(attribute.key) = \(attribute.value)")
}
Last updated
Was this helpful?