Configuring sending profile attributes

You can configure the AppMetrica SDK to send predefined and custom profile attributes. Predefined attributes are already defined in the SDK and have a special format of sending. To send your own custom attributes, you must add the attribute in the application settings.

Attention. Do not pass personal or confidential user information in profile attributes.

This section explains the steps for setting up AppMetrica to send attributes:

Step 1. Adding an attribute in the app settings

  1. Go to the app settings from the menu on the left.
  2. Open the Profile Attributes tab.
  3. In the Custom attributes section enter the name of the new attribute in the corresponding field.
  4. Select a variable type from the drop-down list and click Add.

There is a list of all attributes of the app and their status in the Profile attributes settings section. To stop collecting an attribute and remove it from reports, click .

Step 2. Setting up the attribute values sending in AppMetrica SDK

There are examples below of how to send profile attributes.

To send profile attributes, pass to the instance of the UserProfile class required attributes and send this instance using the YandexMetrica.reportUserProfile(UserProfile profile) method. To create profile attributes, use methods of the Attribute class.

// Creating the UserProfile instance.
UserProfile userProfile = UserProfile.newBuilder()
        // Updating predefined attributes.
        .apply(Attribute.name().withValue("John"))
        .apply(Attribute.gender().withValue(GenderAttribute.Gender.MALE))
        .apply(Attribute.birthDate().withAge(24))
        .apply(Attribute.notificationsEnabled().withValue(false))
        // Updating custom attributes.
        .apply(Attribute.customString("string_attribute").withValue("string"))
        .apply(Attribute.customNumber("number_attribute").withValue(55))
        .apply(Attribute.customCounter("counter_attribute").withDelta(1))
        .build();// Setting the ProfileID using the method of the YandexMetrica class.
YandexMetrica.setUserProfileID("id");

// Sending the UserProfile instance.
YandexMetrica.reportUserProfile(userProfile);