import { MdxImage } from "@/components/MdxImage";

import QuestionId from "./question-id.webp";

export const metadata = {
  title: "URL Data Prefilling for Link Surveys in Formbricks",
  description:
    "Master the art of data prefilling in Formbricks link surveys. Dive into our guide on how to use URL parameters to prepopulate answers, boosting conversion rates and enhancing user experience. Learn through examples and ensure correct validation for each question type.",
};

#### Link Surveys

# Data Prefilling in Link Surveys

Data prefilling via the URL allows you to increase completion rate by prefilling data you already have in a different system. Formbricks allows you to prefill multiple questions in a survey.

## Purpose

Data prefilling via URL comes in handy when you:

- Have data for some of the respondents, but not all
- Have data you want the respondent to confirm or update
- Have data in a different system (e.g. your database) and want to add it to the user profile in Formbricks
- Want to embed a survey in an email and increase completion by prefilling the choice selected in the email

## Quick Example

<Col>
<CodeGroup title="Example URL">

```sh
https://app.formbricks.com/s/clin3dxja02k8l80hpwmx4bjy?question_id_1=answer_1&question_id_2=answer_2
```

</CodeGroup>
</Col>
## How it works

To prefill the questions of a survey, add query parameters to the survey URL. The query parameter should be in the format `questionId=answer`. The answer has to match the expected type of the question to pass through the [validation](/link-surveys/data-prefilling#validation). For example, if the first question is a rating question, the answer has to be a number. If the first question is a single select question, the answer has to be a string identical to one of the answer options.

<Note>Please make sure the answer is [URL encoded](https://www.urlencoder.org/).</Note>

## Prefilling Customisation

You can customize the prefilling behavior using the `skipPrefilled` parameter in the URL. If you want to skip the prefilled questions and show the next available question, you can add `skipPrefilled=true` to the URL. By default, the `skipPrefilled` parameter is set to `false`.

## Prefilling multiple values

Formbricks let's you prefill as many values as you want. You can combine multiple values in the URL using `&` so for example `name=Bernadette&age=18`. The order of the query parameters does not matter so you can always move around questions or add new ones without having to worry about the order of the query parameters.

## Where do I find my question Id?

You find the `questionId` in the **Advanced Settings** toggle at the bottom of each question card in the Survey Editor. As you see, you can update the `questionId` to any string you like. However, once you published your survey, this `questionId` cannot be updated anymore:

<MdxImage
  src={QuestionId}
  alt="The question Id is located at the bottom of each question card in the survey editor."
  quality="100"
  className="max-w-full rounded-lg sm:max-w-3xl"
/>

## Examples

Here are a few examples to get you started:

### Rating Question

Translates to 5 stars / points / emojis:

<Col>
<CodeGroup title="Rating Question">

```sh
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?rating_question_id=5
```

</CodeGroup>
</Col>

### NPS Question

Translates to an NPS rating of 10:

<Col>
<CodeGroup title="NPS Questions">

```sh
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?nps_question_id=10
```

</CodeGroup>
</Col>

### Single Select Question (Radio)

Chooses the option 'Very disappointed' in the single select question. The string has to be identical to the option in your question:

<Col>
<CodeGroup title="Single-select Question">

```sh
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?single_select_question_id=Very%20disappointed
```

</CodeGroup>
</Col>

### Multi Select Question (Checkbox)

Selects three options 'Sun, Palms and Beach' in the multi select question. The strings have to be identical to the options in your question:

<Col>
<CodeGroup title="Multi-select Question">

```sh
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?multi_select_question_id=Sun%2CPalms%2CBeach
```

</CodeGroup>
</Col>

### Open Text Question

Adds 'I love Formbricks' as the answer to the open text question:

<Col>
<CodeGroup title="Open Text Question">

```sh
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?openText_question_id=I%20love%20Formbricks
```

</CodeGroup>
</Col>

### CTA Question

Adds 'clicked' as the answer to the CTA question. Alternatively, you can set it to 'dismissed' to skip the question:

<Col>
<CodeGroup title="CTA Question">

```txt
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?cta_question_id=clicked
```

</CodeGroup>
</Col>

### Consent Question

Adds 'accepted' as the answer to the Consent question. Alternatively, you can set it to 'dismissed' to skip the question.

<Col>
<CodeGroup title="Consent Question">

```txt
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?consent_question_id=accepted
```

</CodeGroup>
</Col>

### Picture Selection Question

Adds index of the selected image(s) as the answer to the Picture Selection question. The index starts from 1

<Col>
<CodeGroup title="Picture Selection Question.">

```txt
https://app.formbricks.com/s/clin3yxja52k8l80hpwmx4bjy?pictureSelection_question_id=1%2C2%2C3
```

</CodeGroup>
</Col>
<Note>
All other question types, you currently cannot prefill via the URL.
</Note>

## Validation

Make sure that the answer in the URL matches the expected type for the questions.

The URL validation works as follows:

- For Rating or NPS questions, the response is parsed as a number and verified if it's accepted by the schema.
- For CTA type questions, the valid values are "clicked" (main CTA) and "dismissed" (skip CTA).
- For Consent type questions, the valid values are "accepted" (consent given) and "dismissed" (consent not given).
- For Picture Selection type questions, the response is parsed as an array of numbers and verified if it's accepted by the schema.
- All other question types are strings.

<Note>
  If an answer is invalid, the prefilling will be ignored and the question is presented as if not prefilled.
</Note>
