# About attributes

Use attributes to target audiences with comparison operators and personalize message content.

## How attributes work

Attributes are metadata you attach to a [channel](https://www.airship.com/docs/reference/glossary/#channel_term) or [named user](https://www.airship.com/docs/reference/glossary/#named_user) for audience segmentation and personalization. Airship evaluates attributes by comparing stored values with operators, not by presence or absence, so use them to store values such as `lifetime_purchase_total` or `favorite_movie`.

When targeting your audience, you can refine with operators such as equals, contains, greater than, and before or after. For JSON attributes, target individual properties within the object. You can also store responses to single choice questions in [Scenes](https://www.airship.com/docs/reference/glossary/#scene) as attributes. Personalize message content with the same values and properties.

Add attributes to your project, and set them on or remove them from users using the SDK or API, or by uploading a CSV in the dashboard. Airship also sets some attributes automatically, such as device locale and the Named User ID attribute.

When you only need presence or absence for future campaigns, such as `wine_enthusiast`, use a [tag](https://www.airship.com/docs/reference/glossary/#tag) instead.

### Attributes versus tags

Targeting with attributes can be more precise than with tags. For example, a theater promoter announcing a screening wants to target fans of the movie Jaws 3-D, so they send a message to users with the tag `jaws_3_d`. Audience members either have the tag or they do not.

**Tag audience**

```json
{
   "audience": {
      "tag": "jaws_3_d"
   }
}
```


For a festival running Jaws, Jaws 2, Jaws 3-D, and Jaws: The Revenge, instead of specifying a separate tag for each movie, they would target users whose `favorite_movie` attribute contains the value `jaws`, and reach all of them with one audience selector.

**Attributes audience**

```json
{
   "audience": {
      "attribute": "favorite_movie",
      "operator": "contains",
      "value": "jaws"
   }
}
```


It's a light example, but it shows the power of comparison operators for attributes. These API examples can also be used in the dashboard.

## Using attributes with messaging

Attributes support the following messaging capabilities:

- **Targeting** — Target audiences for messages, [feature flags](https://www.airship.com/docs/reference/glossary/#feature_flag), [A/B tests](https://www.airship.com/docs/guides/experimentation/a-b-tests/), and [Intelligent Rollouts](https://www.airship.com/docs/guides/experimentation/intelligent-rollouts/) based on attribute values and comparison operators. You can also include attributes in [segments](https://www.airship.com/docs/reference/glossary/#segment). See [Targeting your audience using attributes](https://www.airship.com/docs/guides/audience/attributes/targeting/).
- **Personalization** — Use attribute values in message content with [Handlebars](https://www.airship.com/docs/reference/glossary/#handlebars). See [Personalizing messages using attributes](https://www.airship.com/docs/guides/personalization/sources/attributes/).

## Attribute types

User information can be stored in an attribute as text or as a number, date, or JSON object. Each attribute type is named for the schema that defines what values it accepts. Text, Number, and Date schemas are determined by Airship. You provide your own schema for JSON attributes.

Values accepted for each attribute type:

| Attribute type | Value format | Comments |
| --- | --- | --- |
| **Text** | String | Text strings can be a maximum of 255 characters. |
| **Number** | Number or float value | When setting Number attributes, you can provide your value as an integer, float, or string. |
| **Date** | ISO 8601 date-time formatted string: `YYYY-MM-DDTHH:MM:SS` | You can set an offset by appending the date-time with `+HH:MM`. For example, `2020-07-20T12:35:42+08:00`. Date attributes are converted to and stored as UTC. |
| **JSON** | An object containing one or more string, number, date, or Boolean key-value pairs, individually or within objects or arrays | JSON attributes are not available in [Performance Analytics](https://www.airship.com/docs/reference/glossary/#pa). See following page section for additional information. |

### JSON attributes

JSON attributes are data objects containing one or more string, number, date, or Boolean key-value pairs. The pairs can be added individually or within objects or arrays.

You can think of them as collections of information you can assign to a user. Example use cases:

* **Retailer** — Store user preferences and send sale or discount messages about items you know a user will be interested in and with personalized content for their preferred brands, colors, etc.

* **Airline** — Store a user's booking information and send confirmation and update messages leading up to, during, and after their trip. Messages would contain their confirmation code, flight numbers, origin and destination airport codes, and departure and arrival times.

For each JSON attribute, you create a template for the structure and what data to store. The template is the *schema* and the data is defined as *properties*. Using the above airline use case, you could have an attribute with ID `reservation` and create a schema for the confirmation code and lists of like data types (departures and arrivals) with properties for flight numbers, airport codes, and times.

In addition to the properties defined in your provided schema, each JSON attribute has a property `exp` for its expiration date, represented as the number of seconds since the epoch (January 1st, 1970). After expiration, Airship ignores the attribute where used in segmentation and personalization. When setting a JSON attribute on a user, if a value for `exp` is not provided, Airship automatically sets a value of 90 days from the current date and time. The maximum expiry delay for a JSON attribute is 731 days.

Each instance of setting a JSON attribute on a user is defined by an *instance ID*, which is used as a reference for the property values set for that user.

The following describes associating the data with users and targeting and personalization options:

| Topic | How it works | Airline use case example |
| --- | --- | --- |
| **Setting the attribute on your audience** | Use the SDKs or API to set JSON attributes on a user, specifying an instance ID and values for properties. | When a user books a round-trip flight, you could assign the `reservation` attribute with instance ID `a001`. The JSON data assigned for instance `reservation#a001` would contain a list of each flight leg going to the destination and each returning flight leg. |
| **Targeting the attribute** | You target a JSON attribute's properties, not the object as a whole. All instances of the attribute are evaluated for matches. Any user that matches the target is included in the message audience. | For a flight update message, you could target any user with the attribute `reservation` where the initial leg of their trip departs from airport `PDX`. Any user with that attribute and value `PDX` for the airport code property would be included in the message audience. |
| **Personalizing content** | In message content, you can reference JSON attributes by instance ID or evaluate all instances of the attribute. In both cases, the message content populates with the property values set for a user. | In a flight update message, you could reference `reservation` properties, and the message would contain user-specific details about how the change affects their trip. |

## Categories, data sources, and setup

Attributes can come from the Airship SDKs, users, and you. The following table shows the data sources, descriptions, and setup required for each attribute category:

| Category | Data source | Description | Setup |
| --- | --- | --- | --- |
| **Default** | Airship SDKs or customer | The Airship SDKs automatically set default attributes on your audience based on device data such as locale, time zone, and OS. For email, SMS, and open channels, you can assign values that do not come from a device. See [Device properties](https://www.airship.com/docs/guides/audience/device-properties/). | None. |
| **Named user ID** | Airship | If a channel has a [named user](https://www.airship.com/docs/reference/glossary/#named_user), Airship automatically generates this attribute, with the named user ID as its value. See [Named user ID attribute](https://www.airship.com/docs/reference/data-collection/attributes/#named-user-id-attribute) in the _Attributes Reference_. | None. |
| **NPS survey** | User answers to Net Promoter Score (NPS) surveys in [Scenes](https://www.airship.com/docs/reference/glossary/#scene) | Airship automatically generates attributes based on the NPS score or category. See [NPS Segmentation](https://www.airship.com/docs/guides/features/messaging/scenes/surveys-stories/#nps-segmentation) in _Surveys and Stories_ and [NPS survey attributes](https://www.airship.com/docs/reference/data-collection/attributes/#nps-survey-attributes) in the _Attributes Reference_. | None. |
| **Predefined** | Customer | Preformatted Text and Number attributes you can use to ensure consistency across reports and [Performance Analytics](https://www.airship.com/docs/reference/glossary/#pa). For example, ID `first_name` for first name, and ID `last_name` for last name. See [Predefined attributes](https://www.airship.com/docs/reference/data-collection/attributes/#predefined-attributes) in the _Attributes Reference_. | Add attributes in your project settings, then set them on your audience. |
| **Custom** | Customer | You can add any attribute type to your project. | Add attributes in your project settings, then set them on your audience. |
| **Zero-copy data integration** | Data partner | Directly access user data from external systems. The data remains in its original location instead of being copied or imported into Airship. | See [Zero-copy data integration](https://www.airship.com/docs/guides/features/data-integration/zero-copy-data-integration/). |

> **Warning:** Do not use custom attributes to identify or target a specific person. Use [named user](https://www.airship.com/docs/reference/glossary/#named_user) instead.

## Where attributes are stored

You can set attributes on a channel or a named user. An attribute on a named user applies across the contact's associated channels. Those channels inherit it, and Airship removes it from a channel when you disassociate that channel. An attribute on a channel applies only to that channel. Named users do not inherit attributes from channels.

In most cases, set attributes on the named user so you can target the person on any of their channels. See [Channels versus named users](https://www.airship.com/docs/guides/audience/attributes/setting/#channels-versus-named-users) in *Setting and removing attributes*.

For the broader audience-data storage model, see [Data storage](https://www.airship.com/docs/guides/audience/your-audience/#data-storage) in *Your audience*. For where custom attributes can be set under each audience evaluation system, see [Audience evaluation](https://www.airship.com/docs/guides/audience/your-audience/#audience-evaluation) in *Your audience*.
