Pass in audience attributes
This topic describes possible user attribute values you can send to Optimizely through the Optimizely Swift SDK.
You can pass strings, numbers, Booleans, and null as user attribute values. If you want to target audiences based on the version of your application that they're using, you can also pass in a string formatted as a semantic version, then define a version
audience condition in the Optimizely app. The examples below show how to pass in attributes.
let attributes: [String: Any] = [
"device": "iPhone",
"lifetime": 24738388,
"is_logged_in": true,
"application_version": "4.3.0-beta",
]
// Conditionally activate an A/B test
let variationKey = try? optimizely.activate(experimentKey: experimentKey, userId: userId, attributes: attributes)
// Track a conversion event
try? optimizely.track(eventKey: eventKey, userId:userId, attributes:attributes)
NSDictionary *attributes = @{
@"device": @"iPhone",
@"lifetime": @24738388,
@"is_logged_in": @true
};
// Conditionally activate an A/B test
NSString *variationKey = [optimizely activateWithExperimentKey:experimentKey,
userId:userId,
attributes:attributes,
error:nil];
// Track a conversion event
[optimizely track:eventKey
userId:userId
attributes:attributes,
error:nil];
Important
During audience evaluation, note that if you don't pass a valid attribute value for a given audience condition—for example, if you pass a string when the audience condition requires a Boolean, or if you simply forget to pass a value—then that condition will be skipped. The SDK logs will include warnings when this occurs.
Updated over 2 years ago