In-App Surveys

Attributes

Surveying your user base without segmentation leads to weak results and survey fatigue. Attributes help you segment your users into groups.

How do Attributes work?

Attributes are key-value pairs that you can set for each person individually. Attributes are sent from your application to Formbricks and are associated with the current user. We store it in our database and allow you to use it the next time you create a survey. They help show surveys to the right group of people.

Identifying Users

To use the User Identification feature of Formbricks, target surveys to specific user segments and see more information about the user who responded to a survey, you can identify users by setting a User ID, email, and custom attributes. Below is how to do that.

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.

Setting User ID

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

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:

Enhanced Initialization with User Attributes

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

Setting User Email

The userId is the main identifier used in Formbricks and user identification is only enabled when it is set. In addition to the userId you can also set attributes that describes the user better. The email address can be set using the setEmail function:

Setting Email

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.):

Setting Custom Attributes

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

Generally speaking, the setAttribute function works like this:

Setting Custom Attributes

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

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:

Logging out User

formbricks.logout();

Was this page helpful?