import { Layout } from "@/components/docs/Layout";

export const meta = {
  title: "Identifying Users",
  description:
    "Identify users with Formbricks by setting User ID, email, and custom attributes. Enhance survey targeting and recontacting while maintaining user privacy.",
};

At Formbricks, we value user privacy. By default, Formbricks doesn't collect or store any personal information from your users. However, we understand that it can be helpful for you to know which user submitted the feedback and also functionality like recontacting users and controlling the waiting period between surveys requires identifying the users. That's why we provide a way for you to share existing user data from your app, so you can view it in our dashboard.

Once the Formbricks widget is loaded on your web app, our SDK exposes methods for identifying user attributes. Let's set it up!

## Setting User ID

You can use the `setUserId` function to identify a user with any string. It's best to use the default identifier you use in your app (e.g. unique id from database) but you can also anonymize these as long as they are unique for every user. This function can be called multiple times with the same value safely and stores the identifier in local storage. We recommend you set the User ID whenever the user logs in to your website, as well as after the installation snippet (if the user is already logged in).

```javascript
formbricks.setUserId("USER_ID");
```

## Setting User Email

You can use the setEmail function to set the user's email:

```javascript
formbricks.setEmail("user@example.com");
```

### Setting Custom User Attributes

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

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

### 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:

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

export default ({ children }) => <Layout meta={meta}>{children}</Layout>;
