# Route leads by state

> Presets that send each state to the destinations that serve it.
> Source: https://www.eventsiq.io/docs/guide-route-by-state


Most home-services destinations only cover certain states. This guide builds presets that send
each state's leads to the destinations that serve it, with everything else going to your general
list.

The example is a roofing offer. `TX` and `FL` leads go to two destinations, and `AZ` leads go to a
third.

:::note{title="What you'll need"}
-   Your destinations already set up. If not, start with
    [Build your first waterfall (routing)](https://www.eventsiq.io/docs/guide-first-waterfall).
-   A routing setup to add the branches to.
-   A form that sends the lead's state, in a field set to `state`. See [Fields](https://www.eventsiq.io/docs/fields).
:::

## Step 1: Create a preset for each group of states

A preset is a saved rule. It does nothing until a branch uses it in step 2.

1. Go to **Routing** and open the **Presets** tab.
2. Click **New preset** and type a **Name**, for example `Texas and Florida`.
3. Click **Add rule** and pick **Field, location or parameter**.
4. In the new row, pick the field `state`, change the comparison to **is one of**, and type
   `TX, FL` as the values.
5. Click **Create preset**.
6. Repeat for `Arizona`, with `AZ` as the only value.

New presets made here are shared with **Every routing setup (shared)**, so you can use them in any
routing setup.

You do not have to worry about how the state was written. Form answers such as `Texas` and `tx` are
turned into `TX` when the lead arrives.

| The lead sends        | The lead holds              | Where it goes with these presets |
| --------------------- | --------------------------- | -------------------------------- |
| `TX`, `tx` or `Texas` | `TX`                        | Branch `Texas and Florida`       |
| `arizona`             | `AZ`                        | Branch `Arizona`                 |
| `Ohio`                | `OH`                        | **Everything else**              |
| `Tex.` or a typo      | No state, and a warning     | **Everything else**              |
| Nothing               | No state                    | **Everything else**              |

Full state names and two-letter codes are recognised in any mix of capitals, and so are DC, Puerto
Rico, Guam, the Virgin Islands, American Samoa and the Northern Mariana Islands. Anything else is
not kept as the state: the lead is still saved and routed, its row in [Lead logs](https://www.eventsiq.io/docs/logs) shows
a warning, and the open lead says **Some answers did not come through as expected.** with the
answer it could not read.

:::tip{title="Answered state, or the state from the IP?"}
`state` is what the person told you. To use where their connection came from instead, pick **State
or region, from the IP** in the field list. The two can differ, so choose one and use it for every
preset in the routing setup.
:::

## Step 2: Add a branch for each preset

A branch pairs one preset with the destinations that should be offered its leads.

1. Go to **Routing** and open your routing setup.
2. Click **Add a branch**.
3. Under **Which leads**, keep **Use a saved preset** selected and pick `Texas and Florida`.
4. Under **Offer to, in order**, use **Add a destination** to pick `Roofing Partner A`, then
   `Roofing Partner B`.
5. Click **Add branch**.
6. Repeat for `Arizona`, adding `Roofing Partner C`.

If a form attached to this routing setup does not send `state`, the sheet warns you that its leads
will never match this branch.

## Step 3: Check the order and Everything else

**Branches are checked top to bottom, and the first match wins.** The number on each branch is its
place in that order. Drag a branch to move it. These two presets do not share a state, so their
order does not matter here, but it will if you later add a preset that overlaps.

![Branches in the List view](https://www.eventsiq.io/docs-media/routing/routing-waterfall.png "A routing setup in List view: one branch with its state rules and Offer to, in order, then Everything else below it. Names are samples.")

Below the branches is **Everything else**, for leads no branch matched, including leads with no
state or one EventsIQ did not recognise. Add your general destinations there. With nothing in it,
those leads are saved but not sold.

:::important{title="Everything else is not a fallback"}
A lead that matches a branch stays in that branch. If `Roofing Partner A` and `Roofing Partner B`
both decline a `TX` lead, it is not passed to **Everything else**. If you want it to go on to your
general destinations, add them to the end of that branch's own list as well.
:::

## Step 4: Test each state

The test sends nothing to any destination, logs nothing and does not count against a cap.

1. Click **Test a lead** at the top. The **Test** tab opens on the right.
2. Keep **Type answers** selected and enter this under **Answers, as JSON**:

   ```json
   {
       "firstname": "Priya",
       "lastname": "Shah",
       "state": "TX"
   }
   ```

3. Click **Run test**. You should see **It matches branch 1: Texas and Florida.**, with your two
   destinations under **Offered to, in order**.
4. Change the state to `FL` and run it again. It should match the same branch.
5. Change the state to `AZ` and run it again. It should match **branch 2: Arizona**.
6. Remove the `state` line and run it once more. You should see **No branch matched.**, and
   **Everything else** takes the lead.

:::note{title="Type the code, as a lead will hold it"}
The Test tab uses your answers exactly as you type them, before the clean-up a real lead gets. So
type `TX` rather than `Texas` here. Capitals do not matter. To test with a real lead's answers, pick
**A past lead** instead of **Type answers**.
:::

**Branch by branch** in the result says what each branch decided. If the routing setup is still
paused and all four tests look right, click **Go live** at the top.

## Troubleshooting

:::warning{title="Every lead goes to Everything else"}
-   The form does not send `state`. A rule on a missing field is false, not an error, so the branch
    is passed over. Open the **Forms** tab in the routing setup to see what each form is missing.
-   The form's question is not set to the `state` field. On a website form, check **Destinations
    receive it as** on that question.
-   The branch's **Branch on** switch is off, or the preset's **Preset on** switch is off.
:::

:::warning{title="Go live says there are problems"}
-   **This branch has no destinations.** Add one to the branch, or remove the branch.
-   **Preset "Arizona" has no rules and can never match.** Open the preset and add a rule. A preset
    with no rules never matches, on purpose.
:::

:::warning{title="A lead matched the right branch but was not sold"}
Everyone in that branch declined. Open the lead in **Activity → Lead logs** and read **What
happened, in order**. If you want these leads to reach more destinations, add them to the end of
the branch.
:::

:::warning{title="A lead went to the wrong branch"}
Two presets probably share a state, and the first one won. Run the same answers under **Test a
lead**, read **Branch by branch**, and drag the branch you want higher.
:::

## Where to go next

-   [Build your first waterfall (routing)](https://www.eventsiq.io/docs/guide-first-waterfall): add destinations and set what a sale looks like.
-   [Report sales from your CRM](https://www.eventsiq.io/docs/guide-crm-postbacks): tell the ad network when a lead closes.
-   [Presets](https://www.eventsiq.io/docs/presets): time and day rules, and how shared presets save.
-   [Routing](https://www.eventsiq.io/docs/routing): branches, events, checks and overrides.
