# Targeting your audience using events

Use event conditions in the dashboard or API to build audiences and to start, cancel, or exit automated messages.

Audience targeting evaluates historical event activity. Triggers and cancellation act on events as they occur.

## Segment evaluation

Airship uses a 90-day lookback for events and event properties used in segmentation. The exception is for first and last occurrences, which are stored even if they are more than 90 days old. For custom and predefined events, this window, and the storage of first and last occurrences, starts when the event is [activated for segmentation](https://www.airship.com/docs/guides/audience/events/adding/#add-an-event-to-your-project).

Last-performed occurrences are included when evaluating segmentation queries for events without properties, even when not using the **Last performed event** operator.

For example, if you target all users who performed `added_to_cart` one or more times, the audience includes users who performed the event one or more times in the last 90 days and users whose last performance of the event was before that 90-day period.

If the query includes a property, such as `added_to_cart` one or more times where `category` is `shoes`, the evaluation does not include last-performed occurrences outside the 90-day window.

## Targeting in the dashboard

In messages, [Scenes](https://www.airship.com/docs/reference/glossary/#scene), [In-App Automations](https://www.airship.com/docs/reference/glossary/#iaa), [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. 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.

Events can be combined with other segmentation data, such as attributes and tags. 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/).

When defining your audience, add each event as a condition. In the image below, the segment targets users with the `purchased` event occurring twice between September 1, 2020, and September 15, 2020.

![Targeting users by event count and date range](https://www.airship.com/docs/images/segment-builder-events_hu_ae0c1718df86005a.webp)

*Targeting users by event count and date range*

### Configure conditions

Follow these steps to configure event conditions for an audience:

1. Select **Performed event**, **First performed event**, **Last performed event**, or **Did not perform event**.
1. (For **Performed event** and **Did not perform event** only) Select the **Equals** or **Between** operator and configure the frequency of the event.
1. (Optional) Select **Specify when** to target when the event was performed, then select an operator and configure a date or range. Availability and requirements depend on the operator. For the **Between** operator, the end date is not inclusive. For example, `Between July 5 - July 17` includes dates July 5 to July 16.
1. (Optional) Filter events using numeric values associated with the events or by key/value properties attached to the events:
   1. Select **Add Property** and search for a property, or select **Add Event Value**.
   1. Where applicable, select the operator you want to use for evaluation. Use **Contains** for arrays of strings. Use **String contains** to match a substring in a string value, and enter at least one character.
   1. Enter a value, then select outside the field or press Enter on your keyboard to save it. Multiple values are evaluated as a boolean OR.
   1. Select **AND/OR** to determine how to evaluate multiple filters and alternatives within each filter. **AND** means all criteria must be met. **OR** means any criteria must be met.
   > **Note:** Array properties can have [multiple values for the same sub-property](https://www.airship.com/docs/guides/audience/events/adding/#defining-nested-array-properties). When filtering on those sub-properties, set AND/OR to match how you want multiple values evaluated.


## Targeting using the API

Use the [Event Segmentation schema](https://www.airship.com/docs/developer/rest-api/ua/schemas/event-segmentation/) 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 event as `activity`, then set `metric`, `operator`, and `value`.

Event names in [Real-Time Data Streaming](https://www.airship.com/docs/reference/glossary/#rtds) can differ from the `activity` name used for segmentation. For example, an email unsubscribe appears in Real-Time Data Streaming as a `COMPLIANCE` event with `registration_type` of `unsubscribe`, but you target it with `email_unsubscribe`.

**Target users who unsubscribed from email**

```json
{
   "audience": {
      "activity": "email_unsubscribe",
      "metric": "count",
      "operator": "equals",
      "value": 1
   }
}
```


Use Boolean `NOT`, `AND`, and `OR` operators to combine event conditions or mix events 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.

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.

### Filtering by event properties

In addition to targeting by how often or when an event occurred, you can filter on event properties. Use the [where object](https://www.airship.com/docs/developer/rest-api/ua/schemas/event-segmentation/#whereobject) and include the path to the property along with the values you are filtering for, such as a push ID, email address, or campaign category.

The following example targets users who opened the app by tapping a push notification with the `push_id` of `28e9d533-c8a7-4abf-93f4-4794b09391eb`.

**Filter an app open by push ID**

```json
{
   "audience": {
      "activity": "app_open",
      "value": 0,
      "operator": "greater",
      "metric": "count",
      "where": {
         "property": "/_triggering_push/push_id",
         "operator": "equals",
         "compare_as": "text",
         "value": "28e9d533-c8a7-4abf-93f4-4794b09391eb"
      }
   }
}
```


## Using events in automated messages

Events can act on automated messages at several points:

* **Trigger** — Start an [Automation](https://www.airship.com/docs/reference/glossary/#automation), [Sequence](https://www.airship.com/docs/reference/glossary/#sequence), [Scene](https://www.airship.com/docs/reference/glossary/#scene), or [In-App Automation](https://www.airship.com/docs/reference/glossary/#iaa).
* **Cancellation** — Prevent a pending Automation, Scene, or In-App Automation from sending or displaying.
* **Condition** — Require event criteria to deliver a Sequence message. Include events in a Segmentation condition. Users who do not meet the condition exit the Sequence.
* **Exit** — Remove users from a Sequence when an event occurs.

Automations and Sequences can use events from any source. Scenes and In-App Automations require events [tracked with an Airship SDK](https://www.airship.com/docs/guides/audience/events/tracking/#track-events-from-the-sdks): the Web SDK for Web Scenes, and the Mobile SDK for App Scenes and In-App Automations.

When an event starts an Automation or Sequence, you can personalize the message with [dynamic content](https://www.airship.com/docs/reference/glossary/#dynamic_content) from that event's properties. For example, if the event includes a `user_name` property, you can add `{{user_name}}` to the message.

### In the dashboard

Configure how events affect an In-App Automation or Scene:

* [Custom Event](https://www.airship.com/docs/guides/messaging/in-app-experiences/configuration/triggers/#custom-event) in *In-app experience triggers*
* [Cancellation events](https://www.airship.com/docs/guides/messaging/in-app-experiences/configuration/triggers/#cancellation-events) for Scenes and In-App Automations

Configure how events affect an Automation or Sequence:

* [Custom Event](https://www.airship.com/docs/guides/messaging/messages/sequences/triggers/#custom-event) in *Automation and Sequence triggers*
* [Cancellation events](https://www.airship.com/docs/guides/messaging/messages/sequences/create-automation/#cancellation-events) in *Create an Automation*
* [Conditions](https://www.airship.com/docs/guides/messaging/messages/sequences/create/add-messages/#conditions) in *Add Messages to a Sequence*, using a Segmentation condition that includes events
* [Exit events](https://www.airship.com/docs/guides/messaging/messages/sequences/create/outcomes/#exit-events) in *Sequence outcomes*, using a custom event 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 event-driven Automations. Sequences, Scenes, and In-App Automations cannot be created using the API.
