# Targeting your audience using tags

Target users with tags and tag groups, and create reusable segments based on tag data.

Airship evaluates tags by presence or absence, not by value. Target users by specifying a tag and the tag group it belongs to.

## Targeting in the dashboard

In messages, [A/B tests](https://www.airship.com/docs/guides/experimentation/a-b-tests/), [feature flags](https://www.airship.com/docs/reference/glossary/#feature_flag), and [Intelligent Rollouts](https://www.airship.com/docs/guides/experimentation/intelligent-rollouts/), select **Target by conditions** and **Target specific users** in the Audience step. You can configure logic that includes or excludes audience members based on whether or not they have specific tags. Instead of recreating the same audience each time, create [segments](https://www.airship.com/docs/reference/glossary/#segment). Configuration in the audience step uses the same interface and process as creating segments.

For full instructions and usage locations, see [Segments](https://www.airship.com/docs/guides/audience/segmentation/segments/) and [Targeting specific users](https://www.airship.com/docs/guides/audience/segmentation/target-specific-users/).

## Targeting using the API

Airship's audience selector accepts tag conditions, so you can target tags in any endpoint that takes an `audience` object, such as [Send a push](https://www.airship.com/docs/developer/rest-api/ua/operations/push/#sendpush). Specify the tag and the tag group it belongs to. The condition matches channels with that tag in that tag group, including channels that inherit from a [named user](https://www.airship.com/docs/reference/glossary/#named_user).

**Target users who like movies**

```json
{
   "audience": {
      "tag": "likes_movies",
      "group": "interests"
   }
}
```


Use Boolean `NOT`, `AND`, and `OR` operators to combine tag conditions or mix tags with other audience criteria. See [Audience Selection](https://www.airship.com/docs/developer/rest-api/ua/schemas/audience-selection/) in the Data Formats section of the API reference.

**Target movie or series fans who haven't tapped the promo**

```json
{
   "audience": {
      "AND": [
         {
            "OR": [
               { "tag": "likes_movies", "group": "interests" },
               { "tag": "likes_series", "group": "interests" }
            ]
         },
         { "NOT": { "tag": "tapped_movie_promo", "group": "engagement" } }
      ]
   }
}
```


As in the dashboard, you can save an audience as a reusable segment and reference it by segment ID from any `audience` selector. See [Segments](https://www.airship.com/docs/developer/rest-api/ua/operations/segments/) in the API reference.

## Triggering Automations and Sequences

[Automations and Sequences](https://www.airship.com/docs/guides/messaging/messages/sequences/about/) can act on tags at three points:

* **Trigger** — Start an Automation or Sequence when a tag changes.
* **Condition** — Require a tag to deliver a message.
* **Exit** — Remove users from a Sequence when a tag changes.

### In the dashboard

Configure tag-driven behavior in an Automation or Sequence:

* [Tag Change](https://www.airship.com/docs/guides/messaging/messages/sequences/triggers/#tag-change) in *Automation and Sequence Triggers*
* [Conditions](https://www.airship.com/docs/guides/messaging/messages/sequences/create-automation/#conditions) in the Setup section of *Create an Automation*, for gating an entire Automation
* [Conditions](https://www.airship.com/docs/guides/messaging/messages/sequences/create/add-messages/#conditions) in *Add Messages to a Sequence*, for gating a single message in a Sequence
* [Exit events](https://www.airship.com/docs/guides/messaging/messages/sequences/create/outcomes/#exit-events) in *Sequence outcomes*, using a tag change as the exit signal

### Using the API

Use the [Create an Automation](https://www.airship.com/docs/developer/rest-api/ua/operations/automation/#createpipeline) endpoint to create tag-driven Automations. Sequences cannot be created via the API.

To trigger on a tag change, include a `tag_added` or `tag_removed` selector in the `immediate_trigger` object. Both selectors take the same shape.

**Trigger an Automation when a tag is added to a custom tag group**

```http
POST /api/pipelines HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3
Content-Type: application/json

{
   "name": "Loyalty welcome",
   "enabled": true,
   "immediate_trigger": {
      "tag_added": {
         "tag": "gold",
         "group": "loyalty"
      }
   },
   "outcome": {
      "push": {
         "audience": "triggered",
         "device_types": ["ios", "android"],
         "notification": {
            "alert": "Welcome to Gold status."
         }
      }
   }
}
```


To gate delivery on a tag, add a `tag` object to the pipeline's `condition` array using the key `tag_name`, not `tag` (which is the key used in triggers). The `group` field is optional and defaults to `device`. The condition is evaluated before the outcome runs, so only users who meet it are messaged. Set `negated: true` to match on absence of a tag.

**Send only to movie fans who haven't tapped the promo**

```http
POST /api/pipelines HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3
Content-Type: application/json

{
   "name": "Movie promo welcome",
   "enabled": true,
   "immediate_trigger": "first_open",
   "condition": [
      {
         "and": [
            { "tag": { "tag_name": "likes_movies", "group": "interests" } },
            { "tag": { "tag_name": "tapped_movie_promo", "group": "engagement", "negated": true } }
         ]
      }
   ],
   "outcome": {
      "push": {
         "audience": "triggered",
         "device_types": ["ios", "android"],
         "notification": {
            "alert": "Check out this week's movie release."
         }
      }
   }
}
```

