Segmentation

You can define your audience based on named users, attributes, tags, tag groups, and Airship channel IDs.

Named Users

Named Users allow you to associate multiple devices to a single user or profile that may be associated with more than one device, e.g., an end-user’s tablet and phone. A device can have only one Named User, and a single Named User should not be associated with more than 50 devices. Named Users provide the ability to directly set tags on them.

By default, Named Users can only be associated server-side. A 403 Forbidden response is returned if Named User association is attempted when client-side association is disabled. In order to associate a Named User through the application, you must change the application’s Named User security setting to allow Named Users to be set from devices. See: Enable Named Users.

 Note

Associating the channel with a Named User ID will implicitly disassociate the channel from the previously associated Named User ID, if an association existed.

Assigning an external ID (Named User)
Airship.contact.identify("NamedUserID")
[UAirship.contact identify:@"NamedUserID"];
Resetting the contact
Airship.contact.reset()
[UAirship.contact reset];

Attributes

Attributes are metadata that you can use for audience segmentation. Attributes differ from tags in that when evaluating users with attributes, Airship uses operators, e.g., equals, less than/greater than, contains, before/after, to determine whether or not to target a user. Supported attribute types are TEXT, NUMBER, and DATE. For more information see the attributes guide.

Channel Attributes Example
Airship.channel.editAttributes { editor in
    editor.set(string: "Bobby's Phone", attribute: "device_name")
    editor.set(number: 4.99, attribute: "average_rating")
    editor.remove("connection_type")
}
[UAirship.channel editAttributes:^(UAAttributesEditor * editor) {
    [editor setString:@"Bobby's Phone" attribute:@"device_name"];
    [editor setNumber:@(4.99) attribute:@"average_rating"];
    [editor removeAttribute:@"connection_type"];
}];
Contact Attributes Example
Airship.contact.editAttributes { editor in
    editor.set(string: "Bobby", attribute: "first_name")
}
[UAirship.contact editAttributes:^(UAAttributesEditor * editor) {
    [editor setString:@"Bobby" attribute:@"first_name"];
}];

Tags

Tags are an easy way to group channels. Many tags can be applied to one or more devices. Then, a message sent to a tag will be sent out to all devices that are associated with that tag.

Modifying tags
// Edit tags
Airship.channel.editTags { editor in 
    editor.set(["one", "two", "three"])
    editor.add("a_tag")
    editor.remove("three")
}
[UAirship.channel editTags:^(UATagEditor *editor) {
    [editor setTags:@[@"one", @"two", @"three"]];
    [editor addTag:@"a_tag"];
    [editor removeTag:@"three"];
}];

Tag Groups

Tag groups are configurable namespaces for organizing tags for the channel and Named User. Please view the Tag Groups documentation for more details.

 Note

If setting channel tags is enabled on the device, the predefined device Tag Group cannot be modified from the device and will log an error message. Disable channel tags by disabling channelTagRegistrationEnabled on the UAPush instance if you want to modify this “default” Tag Group.

Channel Tag Group Example
Airship.channel.editTagGroups { editor in
    editor.add(["silver-member", "gold-member"], group:"loyalty")
    editor.remove(["bronze-member", "club-member"], group:"loyalty")
    editor.set(["bingo"], group:"games")
}
[UAirship.channel editTagGroups:^(UATagGroupsEditor *editor) {
    [editor addTags:@[@"silver-member", @"gold-member"] group:@"loyalty"];
    [editor removeTags:@[@"bronze-member", @"club-member"] group:@"loyalty"];
    [editor setTags:@[@"bingo"] group:@"games"];
}];
Contact Tag Group Example
Airship.contact.editTagGroups { editor in
    editor.add(["silver-member", "gold-member"], group:"loyalty")
    editor.remove(["bronze-member", "club-member"], group:"loyalty")
    editor.set(["bingo"], group:"games")
}
[UAirship.contact editTagGroups:^(UATagGroupsEditor *editor) {
    [editor addTags:@[@"silver-member", @"gold-member"] group:@"loyalty"];
    [editor removeTags:@[@"bronze-member", @"club-member"] group:@"loyalty"];
    [editor setTags:@[@"bingo"] group:@"games"];
}];

By default, Tag Groups can only be modified from the server. A 403 Forbidden response is returned if Tag Groups modification is attempted when client-side Tag Groups is disabled. In order to modify Tag Groups through the application, you must change the application’s Tag Group security settings to allow these tags to be set from devices. Follow the steps in Manage Tag Groups to enable this option.

Airship Channel IDs

The Channel ID is a unique identifier that ties together an application/device pair on iOS devices. The Channel ID is used to target pushes to specific devices using the Airship API.

The Channel ID will be logged for all apps. You can get the identifier with a couple of extra lines to your application:

Channel ID Access
let channelID = Airship.channel.identifier
print("My Application Channel ID: \(channelID)")
NSString *channelID = UAirship.channel.identifier;
NSLog(@"My Application Channel ID: %@", channelID);

Don’t worry if this value initially comes back as null on your app’s first run as the Channel ID will be created and persisted during registration.

You can listen for channel creation by adding an NSNotificationCenter observer for Channel.channelCreatedEvent.