Segmentation

Addressing Devices

To help target specific devices or users for a notification, we have Tags, Named Users, Tag Groups, and Attributes.

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
// Set tags
UA.then(function(sdk) {

  // List all tags
  sdk.channel.tags.list // Returns {device: [tag1, tag2, ...], custom-group: [tag]}

  // Check for a specific tag
  sdk.channel.tags.has(tag, group) // Returns bool

  // Add a tag
  sdk.channel.tags.add(tag, group) // Returns true if successful

  // Remove a tag
  sdk.channel.tags.remove([tag1, tag2, ...], group) // Returns True if successful

  // Set tags
  sdk.channel.tags.set(tags, group) // Returns true if successful
  // Resets all tags for the given tag group.

  // `group` is optional in all tag functions and defaults to `device` if not specified

})

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 Chrome browser on their laptop and their iPhone. 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 (see Tag Groups).

 Note

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

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 project, you must change the project’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.

Setting the named user
UA.then(function(sdk) {

  // Return the current Named User
  sdk.channel.namedUser.id  // Returns null or string

  // Set the Named User to a String
  sdk.channel.namedUser.set(name) // associates this channel with a named user

  // Remove the currently associated Named User
  sdk.channel.namedUser.remove() // Disassociates the channel from the named user
  // Returns true if successful

})

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.

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.

Channel Tag Group Example
UA.then(function(sdk) {

  // Add a tag to a group
  sdk.channel.tags.add('tag-name', 'group-name')

  // Remove a tag from a group
  sdk.channel.tags.remove('tag-name', 'group-name')

  // Set tags on a group
  sdk.channel.tags.set(['silver-member', 'gold-member'], 'group-name')
  // Resets all tags for the given tag group.

})

Attributes

Attributes are key-value pairs that you associate with your audience to help better target them with messages. Use attributes to target audiences with greater specificity than you would with tags.
 Important

Attributes are a new feature in Airship. Some aspects of the feature are under development as a part of our beta program. If you want to participate in the beta program, complete our signup form.

Currently in beta:

  • Targeting your audience using attributes
    • In the API:
      • You can target text, number, and date attributes.
      • Attributes can be combined with tags and audience lists.
    • In the dashboard:
      • You can target text and number attributes only.
      • You can combine multiple attributes, but attributes cannot be combined with other data types, e.g., tags and audience lists.

See our API Reference:

Attributes Example
UA.then(function(sdk) {
   sdk.channel.attributes
     .set({firstName: "John", lastName: "Doe"})
     .then(result => console.log("Firstname and lastname set!"))
     .catch(err => console.error("An error occured while setting attributes: %s", err))
})