Setting up your project for attributes
Before you can target using attributes, some setup work may be required, and some steps must be performed by your mobile and web developers.
You can target an audience using default attributes now. They are automatically set on your audience by Airship.
To use custom attributes or predefined attributes, you must first add them to your project. Then you can set them on channels or named users.
For information about default vs. custom vs. predefined attributes, see: Attribute components and variations
Adding attributes to your project
You can add custom and predefined attributes to your Airship project at any time, but you set attributes on your audience by uploading a CSV, or from our SDKs or Channels API.
You can create up to 250 attributes per project.
Go to Audience » Attributes » Attribute List and click Create Attribute.
Search to see if Airship has predefined the attribute you want to create. Search does not return predefined attributes that have been archived or have already been added. See: List of predefined attributes.
Complete the attribute fields. You can only edit the name for predefined attributes.
- Attribute ID: Letters, numbers, and underscores only. 128 characters maximum.
- Name: All characters accepted. 64 characters maximum.
- Type: Date, Text, or Number.
Important The attribute ID is the key that Airship uses to reference the attribute in our SDKs and API; we recommend using lower-case characters with underscores for the ID, e.g.,
my_text_attribute
.Attribute IDs are case sensitive. If attributes exist in an external system, make sure they are always the same case in both systems.
Names and IDs must be unique. You cannot edit the ID or type after you create a custom attribute.
Click Add.
Setting attributes on your audience
You must define custom attributes or add predefined attributes in the dashboard before associating them with channels and named users. Trying to use a custom or predefined attribute that you haven’t yet set up in the dashboard will result in an error.
Use the attribute ID as the value for the key
when setting or removing attributes. Set attributes on channels or named users by uploading a CSV in the dashboard or using SFTP, or from our SDKs or Channels API.
Using a CSV file
Follow the steps in the SFTP tutorial, or follow the steps below for CSV upload in the Airship dashboard. When using email or SMS identifiers in your CSV file, Airship registers new channels for addresses or MSISDN/sender combinations that are new to your project. Additional fields indicate opt-in statuses, so that you can send messages to new channels generated from your CSV upload.
- Prepare your CSV file using the guidelines in Attributes CSV Format.
- Go to Audience » Attributes » Upload Attribute Data. You can click Download sample CSV file to see a formatted file.
- Click Choose file and select your CSV.
- Click Upload. Your dashboard and SFTP uploads are listed in Audience » Attributes » Upload History.
From the SDK
To set or remove attributes on a channel or a contact, use the Channel or Contact classes in our SDKs:
- iOS — UAContact UAChannel
- Android — Channel Contact
- Web — Attributes
The code examples below show how to set attributes using the provided methods. See the Mobile and Web SDK docs for more details.
UAirship.shared().getChannel().editAttributes()
.setAttribute("average_rating", 4.99)
.setAttribute("last_product_purchased", "A1234567")
.removeAttribute("purchase_pending")
.apply();
Airship.channel.editAttributes { editor in
editor.set(string: "cauldron", attribute: "last_product_purchased")
editor.set(number: 4.99, attribute: "average_rating")
editor.remove("purchase_pending")
}
[UAirship.channel editAttributes:^(UAAttributesEditor * editor) {
[editor setString:@"cauldron" attribute:@"last_product_purchased"];
[editor setNumber:@(4.99) attribute:@"average_rating"];
[editor removeAttribute:@"purchase_pending"];
}];
UA.then(function(sdk) {
sdk.channel.attributes
.set({last_product_purchased: "A1234567"})
.then(result => console.log("Last product purchase attribute updated!"))
.catch(err => console.error("An error occurred while setting attributes: %s", err))
})
UA.then(function(sdk) {
sdk.channel.attributes
.remove("purchase_pending")
.then(result => console.log("Purchase pending attribute has been removed!"))
.catch(err => console.error("An error occurred while removing 1 attribute: %s", err))
})
From the API
You can set attribute values from external sources, e.g., CRM or data warehouse, using the Channels API.
Use the Set or Remove Attributes endpoint to set
an attribute on, or remove
an attribute from, a channel or named user.
POST /api/channels/attributes HTTP/1.1
Authorization: Basic <App Auth>
Accept: application/vnd.urbanairship+json; version=3
Content-Type: application/json
{
"audience": {
"ios_channel": "b8f9b663-0a3b-cf45-587a-be880946e881"
},
"attributes": [
{
"action": "set",
"key": "favorite_actor",
"value": "chris_evans",
"timestamp": "2019-09-19 12:00:00"
},
{
"action": "remove",
"key": "favorite_color",
"timestamp": "2019-09-19 12:00:00"
},
{
"action": "set",
"key": "first_name",
"value": "Roger",
"timestamp": "2019-09-19 12:00:00"
}
]
}
Categories