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. To enable this option, go to Settings » APIs & Integrations » 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.

Associating the Named User
UAirship.shared().getNamedUser().setId("NamedUserID");
UAirship.shared().namedUser.id = "NamedUserID"
Disassociating the Named User
UAirship.shared().getNamedUser().setId(null);
UAirship.shared().namedUser.id = null

Attributes

Attributes are metadata that you can use to group and target your audience. 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
UAirship.shared().getChannel().editAttributes()
        .setAttribute("device_name", "Bobby's Phone")
        .setAttribute("average_rating", 4.99)
        .removeAttribute("connection_type")
        .apply();
UAirship.shared().channel.editAttributes()
        .setAttribute("device_name", "Bobby's Phone")
        .setAttribute("average_rating", 4.99)
        .removeAttribute("connection_type")
        .apply()
Named User Attributes Example
UAirship.shared().getNamedUser().editAttributes()
        .setAttribute("first_name", "Bobby")
        .setAttribute("birthday", Date(524300400000))
        .apply();
UAirship.shared().namedUser.editAttributes()
        .setAttribute("first_name", "Bobby")
        .setAttribute("birthday", Date(524300400000))
        .apply()

Tags

Tags allow you to attribute arbitrary metadata to a specific device. Common examples include favorites such as sports teams or news story categories.

Modifying tags
UAirship.shared().getChannel().editTags()
    .addTag("some_tag")
    .removeTag("some_other_tag")
    .apply();
UAirship.shared().channel.editTags()
        .addTag("some_tag")
        .removeTag("some_other_tag")
        .apply()

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. The Create and push to a tag group guides you through creating and using Tag Groups.

 Note

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

Channel Tag Group Example
UAirship.shared().getChannel().editTagGroups()
                .addTag("loyalty", "bronze-member")
                .removeTag("loyalty", "bronze-member")
                .setTag("games", "bingo")
                .apply();
UAirship.shared().channel.editTagGroups()
        .addTag("loyalty", "bronze-member")
        .removeTag("loyalty", "bronze-member")
        .setTag("games", "bingo")
        .apply()
Named User Tag Group Example
UAirship.shared().getNamedUser().editTagGroups()
                .addTag("loyalty", "bronze-member")
                .removeTag("loyalty", "bronze-member")
                .setTag("games", "bingo")
                .apply();
UAirship.shared().namedUser.editTagGroups()
        .addTag("loyalty", "bronze-member")
        .removeTag("loyalty", "bronze-member")
        .setTag("games", "bingo")
        .apply()

By default, Tag Groups cannot be modified from the device. In this case if a device attempts to modify Tag Groups, the modification will fail and the SDK will log an error. In order to change this setting, follow the steps in Manage Tag Groups.

Airship Channel IDs

The Channel ID is a unique identifier that ties together an application/device pair on Android and Amazon devices. The Channel ID is used to target pushes to specific devices using the Airship API. Once a Channel ID is created, it will persist the application until it is either reinstalled, or its internal data is cleared.

String channelId = UAirship.shared().getChannel().getId();
Logger.info("My Application Channel ID: " + channelId);
val channelId = UAirship.shared().channel.id
Logger.info("My Application Channel ID: $channelId")

Don’t worry if this value initially comes back as null on the app’s first run (or after clearing the application data), as the Channel ID will be created and persisted during registration. To receive an event when the Channel ID is available, add an AirshipChannelListener on the Channel instance.

Example RegistrationListener
UAirship.shared().getChannel().addChannelListener(new AirshipChannelListener() {
    @Override
    public void onChannelCreated(@NonNull String channelId) {
        // created
    }

    @Override
    public void onChannelUpdated(@NonNull String channelId) {
        // updated - tags, tokens, opt-in status changed
    }
});
UAirship.shared().channel.addChannelListener(object : AirshipChannelListener {
    override fun onChannelCreated(channelId: String) {
        // created
    }

    override fun onChannelUpdated(channelId: String) {
        // updated - tags, tokens, opt-in status changed
    }
})