# Use variables to personalise and branch your story

Source: https://knowledge.intractive.app/en/articles/variables-and-logic

Variables hold what a visitor tells you, such as their name or answers. Use them to greet visitors by name, send them down a path that fits them, or pass their details to another tool.

## What a variable is

A variable is a data point in your story. It lets the story remember things about a visitor as they move through it. Once a value is in a variable, you can use it again anywhere in the story:

- Personalise the story: show the visitor's name or answer in a later text block.
- Score answers: add points each time the visitor answers correctly.
- Branch on it: send visitors down different paths depending on their answers.
- Gate content: only let a visitor reach a content block if they've made a particular choice.
- Send it onward: pass the data to another tool, such as your CRM or ATS.
- Track it: see the values in story analytics.

## Where to find your variables

You'll find your variables in the story block and in the **Variables** tab. The tab is your overview of every variable in the story, where you can rename or delete one whenever you need to.

![](https://storage.googleapis.com/intractive-knowledge-media/f8c9884c742d2defc99d7e37e82e7136f80c16f2a644a4bcac4007a9c49d8697.png)

Each story has its own list of variables, but values are shared between the stories of a project. When a story sets a variable, the value is saved in the visitor's browser under the project, and new sessions of any story in that project load it. A story's own values take precedence. This only works on the same device and browser. Every variable has a name and a type: **Text**, **Number** or **True/False**. Names may only contain lowercase letters, numbers and underscores, such as `score`, `partner_name` or `level_2`. Spaces, dashes and capitals aren't allowed.

## Fill a variable with an answer

Variables get their values from what visitors enter, so you create them where you collect the data.

Other content blocks can set a variable too:

- **Multiple Choice**, **True or False** and **Poll** can add points or set a value based on the answer.
- **Hotspot Finder** can write to a variable when a visitor taps a hotspot.
- **Branch Choice** can set a variable when the visitor picks a path.
- **Image download**, the outcome block, can work out a result from other variables and show it.

You can also fill variables from the link a visitor opens, before they tap anything. See Personalise a story or start it at a specific point through its link.

## Show a variable in your text

Once you've collected an answer, you can show it anywhere later in your story to make it feel personal. Say your second content block is a **Form** that asks for the visitor's name and email. A later block can then greet them by name.

You reference a variable with double curly braces and an `@`:

```javascript
{{@variable}}
```

In this case that's `{{@name}}` and `{{@email}}`.

## Send visitors down different paths

Variables can also decide where a visitor goes next. Collect a score or a choice in a variable, and you can build paths that adapt to each visitor.

The **Logic Branch** content block does this. It sends the visitor to a different branch or content block depending on the value of a variable. For example: if `score` is more than 10, go to the expert ending. Otherwise, go to the beginner ending. A **Logic Branch** works in one of two ways, set under **Logic Type**:

- **Conditions**: compare a variable with a value. A condition can be **equal to**, **not equal to**, **greater than**, **lesser than**, **greater or equal to** or **lesser or equal to** a value. You can chain several conditions. The first true condition runs, and if none is true, the **Fallback** runs.
- **Scoring test**: list several variables. The visitor goes down the branch of the variable with the highest value. Use it for a quiz where each category keeps its own score.

In a **Branch Choice** block, the visitor picks a path themselves. A **Logic Branch** decides the path for them, based on the values in your variables. Use a **Logic Branch** when the route should depend on answers given earlier.

## Send variables to another tool

The data you collect doesn't have to stay in the story. You can pass it to another tool through an integration, for example to send a visitor's name and email to your recruitment ATS.

The variables under **Trigger condition** decide when the integration runs, not what it sends. A webhook sends every session variable, and CRM and ATS fields are mapped separately. The integration sends data when one of the variables it watches gets a new value during a session. Turn on **All required** if it should only send once every selected variable has a value, for example first name, last name and email together.

## See the values visitors gave

Every session records the variables that were set while the visitor played the story. In story analytics, admins can browse them per session under **Sessions**. Everyone with access can see them all together in the **Submissions** tab.

\[screenshot: the Submissions tab in story analytics with variable values\]

## Ideas to try

- Personalised recap: collect a name and a favourite topic early, then use both in a closing text block for a personal send-off.
- Job or study matching: score answers across a few questions and use a **Logic Branch** to send each visitor to the vacancy or course that fits them best.
- Warm lead hand-off: gather contact details in a **Form** and send them to your CRM or ATS automatically, so you can follow up straight away.
- Adaptive quiz: sort visitors into categories based on their answers and show a different result path for each.

## Connect an answer to a variable

1. Add a **Form** or **Open Question** content block where you want to ask the visitor something, for example a form that asks for their name and email.
2. Select **Set variables** on the field (**Logic** in the classic editor).
3. Optional: if you don't have a variable yet, create one here with a clear name, such as `name` or `email`.
4. Connect the answer to the variable.

   ![](https://storage.googleapis.com/intractive-knowledge-media/e5e1e7fddbe2e02b522e6aedebe40587ccc232ceb6c4b1c4703b23e1f8319846.png)

   ![](https://storage.googleapis.com/intractive-knowledge-media/305404b05e04927a76e83010959f8b8fdd54195d7278b97a36b29e9cd4d56611.png)

## Add a variable to a text block

1. Collect the answer in a **Form** or another content block that collects data.
2. Connect it to a variable, as in Fill a variable with an answer.
3. Add a **Text** block further along and type the reference where you want the value to appear. For example: Hey `{{@name}}`, we'll reach out to you at `{{@email}}`.

> **Tip:** On an **Open Question**, add fallback text such as Buddy or Friend in the **Fallback** column of its **Set variables** window. It shows when the visitor left the field empty, so your story still reads well without an answer.

> **Note:** A variable only shows once its value is known. If you preview a single content block, the fields haven't been filled in yet, so the reference stays empty. To test it, use the full story preview and fill in the required fields first.

![](https://storage.googleapis.com/intractive-knowledge-media/55813319f512463805c59f9b1c264b9e03630ef12aba51e8a63d987f8c6e2ffd.png)

![](https://storage.googleapis.com/intractive-knowledge-media/e48a82343a161eae57fb4132f8374c9de3c42209b9bcacfb9d4c7b67ca42bab3.png)

![](https://storage.googleapis.com/intractive-knowledge-media/c847b4db353066bc4aa441b6b1d18abf65361a2fa7a09ba974dfe36c8600b50c.png)

## Build a quiz that uses variables

### Example: a five-question match quiz

Say each of five questions can give a match point, and a visitor with three points or more is a match.

1. Add five questions with **Multiple Choice** or **True or False** blocks.
2. Create a number variable called `score`, in the **Variables** tab or with **+ Create new variable** in a block's **Set variables** window.
3. On each question, give the answer that counts as a match one point for `score`. On **Multiple Choice**, use **Set variables** below **Answers**: pick the variable, then **Add** and the points for that answer. **True or False** has its own **Logic** field.\
   \[screenshot: a Multiple Choice block with one answer adding a point to the score variable\]
4. Create two branches, one for a match and one for no match. See Creating branches.
5. After the last question, add a **Logic Branch** block.
6. Add a condition that checks whether `score` is **greater than** 2.
7. Point the condition at the branch for a match.\
   \[screenshot: a Logic Branch block with the score condition pointing at the match branch\]
8. Send every other visitor to the branch for no match, using the **Fallback**.
9. Play the quiz in the full story preview, once with three or more match answers and once with fewer, and check that you land on the right branch.\
   \[screenshot: the full story preview showing the match ending after the quiz\]

### Example: a personality-style quiz that sorts visitors into categories

Say you want an internal quiz that sorts visitors into one of four categories.

1. Build your questions with question blocks, such as **Poll**, **True or False** and **Multiple Choice**.
2. Create four variables, one for each category (A, B, C and D).
3. Connect each answer to a category variable, so an answer tied to category A scores a point for A.
4. Add a **Logic Branch** block after the questions, so all the answers come together in one place.
5. Set **Logic Type** to **Scoring test** and add the four category variables. Each visitor goes down the branch of the category with the most points.

![](https://storage.googleapis.com/intractive-knowledge-media/77579163ee4cff7a5ffbebe6b5140faf1cc1e48c7925f623a732df4d85d8f2b5.png)

![](https://storage.googleapis.com/intractive-knowledge-media/59f31134538ac52c8a35311a02e9155242c4f9562213db2916edcc42d1708bef.png)

![](https://storage.googleapis.com/intractive-knowledge-media/e43392fd7f24bab47986622ce914f4696ca21fc7832f9f2b8bac8d3f9b1d9f0d.png)

## Send variables to your CRM or ATS

1. Add a **Form** block with the fields you need, such as name and email.
2. Connect each field to a variable, as in Fill a variable with an answer.

   ![](https://storage.googleapis.com/intractive-knowledge-media/e5e1e7fddbe2e02b522e6aedebe40587ccc232ceb6c4b1c4703b23e1f8319846.png)

   ![](https://storage.googleapis.com/intractive-knowledge-media/305404b05e04927a76e83010959f8b8fdd54195d7278b97a36b29e9cd4d56611.png)
3. Click **Integrations** in the story's top bar.
4. Select the integration you're using. In this example that's our **Recruitee** integration (Tellent Recruitee), but it can be any tool you've connected.
5. In the integration, find your variables under **Trigger condition**.
6. Tick the ones that should start the integration, such as `@name` and `@email`.
7. Use field mapping to match each variable to the right field in the other tool.

![](https://storage.googleapis.com/intractive-knowledge-media/44f691d3fe868bf69f41777069af8f59ab21b88caa3af6b39eee59eed8affdb3.png)

![](https://storage.googleapis.com/intractive-knowledge-media/65f7b33baa5d3c483e2c34d24f96a2be600551b48a5e6a13ac2a2df8148a0203.png)

## Next

- Personalise a story or start it at a specific point through its link
- Creating branches
