# Logic, Variables, and Hidden Fields

> Branch an Ours Privacy survey on answers, show follow-up questions, keep a score, pass in values like a campaign or location, fill earlier answers into later questions, and send each person to the right ending.

Source: https://docs.oursprivacy.com/docs/surveys/logic

Use this page to make a survey adapt to each person. Send a 9 or 10 to a "what do you value most?" follow-up and a 0 to 6 to "what disappointed you?", reveal an email field only when someone asks for a reply, tag every answer with the clinic from the link, and end each person on the right thank-you screen. Everything here lives under **Logic** and **Endings** in the builder, and the preview follows your rules as you build them.

**Survey logic, data, and endings in the builder**

* **Rules**: Each rule reads as a sentence: after a page, if an answer matches, set a value and jump to the next page or an ending.

  ![The Logic section of the Post-visit NPS survey with five Branch after a page rules that set an NPS segment and jump to the promoter, passive, or detractor follow-up, and a show or hide rule that reveals the email question when someone asks for a reply.](https://docs.oursprivacy.com/img/surveys/surveys-img-5.jpg)

* **Variables and hidden fields**: Variables keep a score or label while someone answers. Hidden fields read values like a campaign or a location from the URL.

  ![The Variables and hidden fields panel with an NPS segment text variable and two hidden fields, utm\_campaign and location with a default of downtown, beside an example URL parameter.](https://docs.oursprivacy.com/img/surveys/surveys-img-6.jpg)

* **Endings**: Thank-you screens or redirects. Logic decides which one each person sees.

  ![The Endings section with two thank-you screens, the second open for editing with its title Thank you for being honest with us and a message, plus Screen and Redirect options.](https://docs.oursprivacy.com/img/surveys/surveys-img-7.jpg)

---

## Rules

Select **Logic**, then **Add rule**. There are three kinds:

| Rule | Runs | Use it to |
| --- | --- | --- |
| **Branch after a page** | When a visitor leaves a page | Skip ahead, end early, or keep score based on answers so far. |
| **Show or hide questions** | As answers change | Reveal a follow-up as soon as an answer matches. |
| **When the survey starts** | Before the first page | Route by hidden fields, like a campaign or a plan. |

A rule's conditions check answers, variables, and hidden fields, and can require all conditions or any of them. Its actions jump to a page or an ending, show or hide questions, or change a variable. Rules run in order, and you can reorder, duplicate, or delete them.

---

## Variables

Variables hold a value you compute while someone answers, such as a running score or a label like "promoter". Each one has a name, a type, and a starting value. A **Branch after a page** rule can add to, subtract from, multiply, or divide a number, or set and append to a label. Later rules can branch on the result, and an ending can show it.

---

## Hidden fields

Hidden fields are values you pass in rather than ask for, such as a campaign, a location, or a plan. Declare each one under **Logic**, then pass it:

- On the [survey link](https://docs.oursprivacy.com/docs/surveys/display-and-install#survey-link), as a URL parameter with the same name, such as `?location=downtown`.
- In an embed, from the URL of the page the survey runs on.

Each response saves its hidden field values, so you can read results by them. A hidden field can have a default for when the value is missing.

---

## Answer recall

Question titles, descriptions, and ending text can fill in an earlier answer, a variable, or a hidden field. Type `{{` in the field, or use the picker, and choose what to insert. The line under the field shows what will be filled in.

For example, a follow-up titled `What made your visit to {{hidden:location}} great?` names the location from the link.

---

## Endings

Every survey has at least one ending. An ending is either a thank-you screen, with a title, a message, and an optional button and link, or a redirect that sends visitors to a URL. A redirect URL can include answers or variables, which are URL-encoded for you.

Visitors who finish see the default ending unless a logic rule sends them to another one. For example, send detractors to an ending that offers a callback and promoters to one that asks for a review.

---

## Next Steps

- **[Design and settings](https://docs.oursprivacy.com/docs/surveys/design-and-settings)**: page flow, colors, and language.
- **[Display and install](https://docs.oursprivacy.com/docs/surveys/display-and-install)**: pass hidden fields from your site.
- **[Survey recipes](https://docs.oursprivacy.com/docs/surveys/recipes)**: complete setups that use logic and endings.
