User properties are attributes you define to describe segments of your user base, such as language preference or geographic location.
Analytics automatically logs some user properties; you don't need to add any code to enable them. If your app needs to collect additional data, you can set up to 25 different Analytics user properties in your app.
Before you begin
Before you can use Google Analytics for Firebase, you need to:
Register your Unity project and configure it to use Firebase.
If your Unity project already uses Firebase, then it's already registered and configured for Firebase.
If you don't have a Unity project, you can download a sample app.
Add the Firebase Unity SDK (specifically,
FirebaseAnalytics.unitypackage) to your Unity project.
Note that adding Firebase to your Unity project involves tasks both in the Firebase console and in your open Unity project (for example, you download Firebase config files from the console, then move them into your Unity project).
Set user properties
You can set Analytics user properties to describe the users of your app. You can analyze behaviors of various user segments by applying these properties as filters to your reports.
Set a user property as follows:
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 example shows adding a hypothetical favorite food property, which
assigns the value in the string
mFavoriteFood to the active user:
Firebase.Analytics.FirebaseAnalytics.SetUserProperty("favorite_food", "ice cream");
You can access this data as follows:
- In the Firebase console, open your project.
- Select Analytics from the menu to view the Analytics reporting dashboard.
The User Properties tab 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 for Firebase. Read more about the Analytics reporting dashboard in the Firebase Help Center.