export const metadata = {
  title: "Identifying Users in Formbricks App Surveys",
  description:
    "Dive into the importance of user identification in surveys. Boost your survey response rates and target the right users with Formbricks.",
};

#### App Surveys

# User Identification

User Identification helps you to not only segment your users but also to see more information about the user who responded to a survey. This helps you to target surveys to specific user segments and see more information about the user who responded to a survey.

### Understanding Identified vs Unidentified Users

<Note>
  Formbricks App Surveys can **only be used with identified users**. If you are looking to run surveys on your
  public-facing website, head over to the [Website Surveys](/website-surveys/quickstart) section.
</Note>

In Formbricks, understanding the distinction between identified and unidentified users is crucial for effective survey segmentation and targeted feedback collection.

| Feature                                                  | Unidentified Users | Identified Users |
| -------------------------------------------------------- | ------------------ | ---------------- |
| Show surveys based on **trigger** actions                | ✅                 | ✅               |
| Set **recontact details** to avoid survey fatique        | ✅                 | ✅               |
| Target a subset of users using **attributes & segments** | ❌                 | ✅               |
| Collect **user information** in Formbricks               | ❌                 | ✅               |
| Track **custom attributes**                              | ❌                 | ✅               |
| Counts towards your **monthly tacked user (MTU)** limit  | ❌                 | ✅               |
| Recommended for **public-facing websites**               | ✅                 | ❌               |
| Recommended for **web apps after login**                 | ❌                 | ✅               |

## Identified Users

Identified users are those for whom specific information has been set, notably the userId. This identification allows for more precise targeting of surveys and a deeper understanding of the feedback provided. When enabled, all information specified by you and all actions are sent to Formbricks.

This method is recommended for applications where users are required to log in and will often return.

### Setting User ID

To enable the User identification feature you need to set the `userId` in the init() call of Formbricks. Only when the `userId` is set the person will be visible in the Formbricks dashboard. The `userId` can be any string and it's best to use the default identifier you use in your app (e.g. unique id from database or the email address if it's unique) but you can also anonymize these as long as they are unique for every user.

<Col>
<CodeGroup title="Setting User ID">

```javascript
formbricks.init({
  environmentId: "<environment-id>",
  apiHost: "<api-host>",
  userId: "<user_id>",
});
```

</CodeGroup>
</Col>

### Enhanced Initialization with User Attributes

In addition to setting the `userId`, Formbricks allows you to set user attributes right at the initialization. This ensures that your user data is seamlessly integrated from the start. Here's how you can include user attributes in the `init()` function:

<Col>
<CodeGroup title="Enhanced Initialization with User Attributes">

```javascript
formbricks.init({
  environmentId: "<environment-id>",
  apiHost: "<api-host>",
  userId: "<user_id>",
  attributes: {
    // your custom attributes
    Plan: "premium",
  },
});
```

</CodeGroup>
</Col>

## Setting Custom User Attributes

You can use the setAttribute function to set any custom attribute for the user (e.g. name, plan, etc.):

<Note>
  Please note that the number of different attribute classes (e.g., "Plan," "First Name," etc.) is currently
  limited to 150 attributes per environment.
</Note>

<Col>
<CodeGroup title="Setting Custom Attributes">

```javascript
formbricks.setAttribute("Plan", "free");
```

</CodeGroup>
</Col>

Generally speaking, the setAttribute function works like this:

<Col>
<CodeGroup title="Setting Custom Attributes">

```javascript
formbricks.setAttribute("attribute_key", "attribute_value");
```

</CodeGroup>
</Col>
Where `attributeName` is the name of the attribute you want to set, and `attributeValue` is the value of the attribute you want to set.

### Logging Out Users

When a user logs out of your webpage, make sure to log them out of Formbricks as well. This will prevent new activity from being associated with an incorrect user. Use the logout function:

<Col>
<CodeGroup title="Logging out User">

```javascript
formbricks.logout();
```

</CodeGroup>
</Col>
