Attributes
Set channel and contact attributes as key-value pairs for personalization.
For information about attributes, including overview, use cases, and how to target attributes, see About attributes.
Channel attributes
Channel attributes are attributes managed on the channel by the SDK.
Channel attributes
Airship.channel.editAttributes { editor in
editor.set(string: "Bobby's Phone", attribute: "device_name")
editor.set(number: 4.99, attribute: "average_rating")
editor.remove("vip_status")
}@import AirshipObjectiveC;
[UAirship.channel editAttributes:^(UAAttributesEditor * editor) {
[editor setString:@"Bobby's Phone" attribute:@"device_name"];
[editor setNumber:@(4.99) attribute:@"average_rating"];
[editor removeAttribute:@"vip_status"];
}];Contact attributes
Contact attributes are attributes managed on the contact by the SDK.
Contact attributes
Airship.contact.editAttributes { editor in
editor.set(string: "Bobby", attribute: "first_name")
}@import AirshipObjectiveC;
[UAirship.contact editAttributes:^(UAAttributesEditor * editor) {
[editor setString:@"Bobby" attribute:@"first_name"];
}];JSON attributes
JSON attributes are data objects containing one or more string, number, date, or Boolean key-value pairs.
You can set and remove JSON attributes on a channel or a contact.
Setting a JSON attribute enforces a few constraints:
- The
jsonpayload can’t be empty, and can’t contain a top-levelexpkey, which is reserved for the expiration. attributeandinstanceIDcan’t be empty or contain#.expiration, if provided, must be in the future and no more than 731 days out.
Modifying JSON attributes
Airship.contact.editAttributes { editor in
try! editor.set(
json: [
"key": .string("value"),
"another_key": .string("another_value")
],
attribute: "attribute_name",
instanceID: "instance_id",
expiration: Date().addingTimeInterval(60 * 60 * 24 * 30) // 30 days from now
)
}Verifying attributes
To verify that attributes have been set correctly, look up the channel or contact in the Contact Management view. You can search by channel ID or named user ID to view the attributes associated with a channel or contact.