Segmentation

Addressing Devices

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

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

Note

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

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).

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. Please visit the Settings documentation to enable this option.

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. Please visit the Settings documentation 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.

})