# Exit conditions and goals

> Take contacts out of an automation the moment they buy or leave an audience, jump runs to a goal, and move contacts between automations.

A run normally works through its steps until the end of its branch. Exit conditions and goals change that as soon as the contact does something, wherever the run is, including while it waits: an **exit condition** ends the run, and a **goal** moves it forward to the goal step.

| You want | Use |
| --- | --- |
| Stop cart reminders when the contact buys | An [exit condition](#exit-conditions) on the purchase |
| Stop a sequence when the contact leaves the audience that started it | [Leave the audience](#leave-when-removed-from-the-audience) |
| Skip the remaining reminders and send a thank-you instead | A [goal](#goals) |
| Take buyers out of every promotional automation | A [Remove from automations](#move-contacts-between-automations) step |
| Stop one contact's run by hand or from your app | [Cancel the run or remove the contact](/docs/automations/runs/#cancel-a-run) |

**Goal** steps, and exit conditions, goals and waits on [workspace or custom events](/docs/events/), are included with Pro, Business and Custom plans. On Pay as you go, saving an automation that adds them returns `403` with `"error": "plan_required"`. Automations that already have them keep them after a downgrade.

## Exit conditions

Exit conditions are on the automation's **Settings** tab, under **Exit conditions**. When one matches for a contact, their run in this automation is canceled at once: waiting steps are dropped and no more steps run. The run's status becomes **Canceled**, with the note **Met an exit condition**.

There are two kinds:

- **When something happens:** an event for the contact, chosen like a [trigger](/docs/automations/triggers/#contact-triggers), with its options. For example **Custom event** `purchase` sent with the [Events API](/docs/events/send-events/) (events from the [tracking script](/docs/events/tracking-script/#identify-visitors) don't end runs), **Tag added** `customer`, **Contact updated** with **Field that changed** `Purchased`, or **Unsubscribed**. Custom events and orders take an optional filter, for example only orders with `total` greater than `50`.
- **When the contact matches:** rules on the contact, as in a [Condition](/docs/automations/steps/#condition-ifelse) step. For example "has tag `customer`" or "**Purchased** is true". These are checked every time the contact changes and before every step, so a contact who already qualifies never gets the next email, even if the change came in a moment earlier.

Exit conditions apply to runs already in progress as soon as you save them, keep working while the automation is paused, and need a Contact automation. An automation can have up to 20.

The Emailit team can also exit on **Placed an order** and **Abandoned a cart** from [Commerce](/docs/commerce/), on **Removed from segment** for a [tracked segment](/docs/segments/tracked/), and use **Segment** and **Purchases** rules in conditions. These are in alpha, like Commerce and segments. Contacts who leave a segment because someone edited its rules don't exit.

### Leave when removed from the audience

For automations started by **Added to audience**, turn on **Leave when removed or unsubscribed from the audience that started the run**. A contact's run is then canceled when they're removed from that audience, unsubscribe from it, or unsubscribe from all marketing email, for example when your shop removes them from an "Abandoned carts" audience after a purchase. The run's note is **Left the audience**. A **Remove from audience** or **Subscribe / unsubscribe** step of the run itself doesn't end that run.

Contact automations created in the dashboard have this turned on. Automations created with the API have it off unless you set `exit_on_audience_removal: true`. Without it, a run continues after the contact leaves; marketing emails still skip contacts who unsubscribed.

### With the API

Set `settings.exit_conditions` when you [create](/docs/api-reference/automations/create/) or [update](/docs/api-reference/automations/update/) the automation. Each entry is an event matcher (the trigger key in `event` and its options) or `{ "condition": { "match", "rules" } }`:

```json
{
  "settings": {
    "exit_on_audience_removal": true,
    "exit_conditions": [
      { "event": "contact.on_event", "event_name": "purchase" },
      { "event": "contact.on_event", "event_name": "c:order.completed", "filter": { "match": "all", "rules": [{ "field": "properties.total", "operator": "greater_than", "value": 50 }] } },
      { "event": "contact.tag_added", "tag": "customer" },
      { "condition": { "match": "all", "rules": [{ "field": "custom_fields.purchased", "operator": "is_true" }] } }
    ]
  }
}
```

## Goals

A **Goal** step marks a point the run should get to as soon as the contact meets the goal. When the contact meets it, their run jumps there from wherever it is: the steps and waits in between are skipped (marked **skipped** in the run), the goal is marked reached, and the run continues with the steps after the goal. Goals are included with Pro, Business and Custom plans.

For example, a trial sequence sends a tip every three days, with a goal "**Tag added** `paid`" near the end followed by a thank-you email. A contact who upgrades on day 2 skips the remaining tips and gets the thank-you right away.

| Setting | Notes |
| --- | --- |
| **Goal is met when** | **Something happens** (an event for the contact) or **The contact matches a condition** (checked on every contact change). |
| **When a contact reaches the goal without meeting it** | **Continue anyway**, **Wait until the goal is met** (up to 365 days, then the run ends), or **End the automation for them**. |

A run reaches each goal at most once, and goals inside a [random split](/docs/automations/steps/#api-only-steps) branch don't return to the split afterwards. Like exit conditions, goals keep working while the automation is paused.

With the API, a goal is a `goal` step: `{ "event": { "event": "contact.tag_added", "tag": "paid" }, "if_not_met": "continue" }` or `{ "condition": { ... } }`.

## Move contacts between automations

- **Start automation** starts another automation for the contact. Turn on **Move the contact** to end the current run afterwards.
- **Remove from automations** cancels the contact's runs in other automations you pick, or in **Every other automation**.

For example, when your shop tags buyers `customer` through the API, a "Buyers" automation started by that tag can remove them from every promotional automation and move them to onboarding:

```json
{
  "steps": [
    { "key": "bought", "type": "trigger", "trigger": "contact.tag_added", "config": { "tag": "customer" } },
    { "key": "leave", "type": "action", "action": "exit_automation", "config": { "all": true } },
    { "key": "onboard", "type": "action", "action": "run_automation", "config": { "automation_id": "aut_3Mv8Xq2nKp5Lt", "exit_current": true } }
  ],
  "connections": [
    { "from": "bought", "to": "leave", "branch": "default" },
    { "from": "leave", "to": "onboard", "branch": "default" }
  ]
}
```

## Related

  - [Steps](/docs/automations/steps/): Wait until, Goal, Remove from automations and more.
  - [Runs and stats](/docs/automations/runs/): See why a run was canceled, cancel runs.

---
Source: https://emailit.com/docs/automations/exits-and-goals/
