Set user properties

User properties are attributes you define to describe segments of your user base, such as language preference or geographic location. These can be used to define audiences and segments. This article describes how to set user properties. To learn more about user properties, see Predefined user dimensions.

Before you begin

Add the global site tag to your website and make sure you can access Analytics and the website source code.

Set user properties

  1. Register the property in the User Properties of Analytics in the Firebase console. For more information, see Set and register a user property.
  2. Add code to set an Analytics user property with the setUserProperty() method. You can use the name and value of your choosing for each property.

The following shows how to add a favorite-food property, which assigns the value in the string food to the active user:

Swift

Note: This Firebase product is not available on the macOS target.

Analytics.setUserProperty(food, forName: "favorite_food")

Objective-C

Note: This Firebase product is not available on the macOS target.

[FIRAnalytics setUserPropertyString:food forName:@"favorite_food"];

Java

mFirebaseAnalytics.setUserProperty("favorite_food", mFavoriteFood);

Kotlin

firebaseAnalytics.setUserProperty("favorite_food", food)

Web version 9

Learn more about the tree-shakeable Web v9 modular SDK and upgrade from version 8.

import { getAnalytics, setUserProperties } from "firebase/analytics";

const analytics = getAnalytics();
setUserProperties(analytics, { favorite_food: 'apples' });

Web version 8

firebase.analytics().setUserProperties({favorite_food: 'apples'});

You can access this data from the User Properties dashboard in the Firebase console. This dashboard shows a list of user properties that you have defined for your app. You can use these properties as a filter on many of the reports available in Google Analytics. Read more about the Analytics reporting dashboard in the Firebase Help Center.