Attributes

Set channel and contact attributes as key-value pairs for personalization.

View as Markdown

For information about attributes, including overview, use cases, and how to target attributes, see About attributes.

Channel attributes

Channel attributes are attributes managed on the channel by the SDK.

Channel attributes

Airship.channel.editAttributes {
    setAttribute("device_name", "Bobby's Phone")
    setAttribute("average_rating", 4.99)
    removeAttribute("vip_status")
}
Airship.getChannel().editAttributes()
    .setAttribute("device_name", "Bobby's Phone")
    .setAttribute("average_rating", 4.99)
    .removeAttribute("vip_status")
    .apply();

Contact attributes

Contact attributes are attributes managed on the contact by the SDK.

Contact attributes

Airship.contact.editAttributes {
    setAttribute("first_name", "Bobby")
    setAttribute("birthday", Instant.ofEpochMilli(524300400000))
}
Airship.getContact().editAttributes()
    .setAttribute("first_name", "Bobby")
    .setAttribute("birthday", Instant.ofEpochMilli(524300400000))
    .apply();

JSON attributes

JSON attributes are data objects containing one or more string, number, date, or Boolean key-value pairs.

You can set and remove JSON attributes on a channel or a contact.

Setting a JSON attribute enforces a few constraints:

  • The json payload can’t be empty, and can’t contain a top-level exp key, which is reserved for the expiration.
  • attribute and instanceId can’t be empty or contain #.
  • expiration, if provided, must be in the future and no more than 731 days out.

Modifying JSON attributes

Airship.contact.editAttributes {
    setAttribute(
        attribute = "attribute_name",
        instanceId = "instance_id",
        expiration = Instant.now().plusSeconds(60 * 60 * 24 * 30), // 30 days from now
        json = jsonMapOf(
            "key" to "value",
            "another_key" to "another_value"
        )
    )
}

Verifying attributes

To verify that attributes are set correctly, look up the channel or contact in the Contact Management view. Search by channel ID or named user ID to view the attributes associated with a channel or contact.