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.

Alert

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. Add an attribute in the app settings

  1. In the AppMetrica interface, 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

Alert

AppMetrica doesn't display predefined attributes in the web interface if ProfieId sending isn't configured.

There are examples below of how to send profile attributes.

To send profile attributes, pass the required attributes to the instance of the UserProfile class and send the instance using the AppMetrica.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 AppMetrica class.
AppMetrica.setUserProfileID("id");

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

To send profile attributes, pass in the method +reportUserProfile:onFailure: of the YMMYandexMetrica class the following parameters:

  • userProfile: The YMMUserProfile instance that contains an array of attribute updates. To create profile attributes, use methods of the YMMProfileAttribute class.
  • onFailure: The block the error is passed to. If you do not want to track the error, pass nil for this block.
YMMMutableUserProfile *profile = [[YMMMutableUserProfile alloc] init];
// Updating a single user profile attribute.
id<YMMCustomCounterAttribute> timeLeftAttribute = [YMMProfileAttribute customCounter:@"time_left"];
[profile apply:[timeLeftAttribute withDelta:-4.42]];
// Updating multiple attributes.
[profile applyFromArray:@[
    // Updating predefined attributes.
    [[YMMProfileAttribute name] withValue:@"John"],
    [[YMMProfileAttribute gender] withValue:YMMGenderTypeMale],
    [[YMMProfileAttribute birthDate] withAge:24],
    [[YMMProfileAttribute notificationsEnabled] withValue:NO],
    // Updating custom attributes.
    [[YMMProfileAttribute customString:@"born_in"] withValueIfUndefined:@"Moscow"],
    [[YMMProfileAttribute customString:@"address"] withValueReset],
    [[YMMProfileAttribute customNumber:@"age"] withValue:24],
    [[YMMProfileAttribute customCounter:@"logins_count"] withDelta:1],
    [[YMMProfileAttribute customBool:@"has_premium"] withValue:YES]
]];
// ProfieID is set using the method of the YMMYandexMetrica class.
[YMMYandexMetrica >setUserProfileID:@"id"];

// Sending profile attributes.
[YMMYandexMetrica reportUserProfile:[profile copy] onFailure:^(NSError *error) {
    NSLog(@"Error: %@", error);
}];

To send profile attributes, pass in the method reportUserProfile(_:onFailure:) of the YMMYandexMetrica class the following parameters:

  • userProfile: The YMMUserProfile instance that contains an array of attribute updates. To create profile attributes, use methods of the YMMProfileAttribute class.
  • onFailure: The block the error is passed to. If you do not want to track the error, pass nil for this block.
let profile = YMMMutableUserProfile()
// Updating a single user profile attribute.
let timeLeftAttribute: YMMCustomCounterAttribute = YMMProfileAttribute.customCounter("time_left")
profile.apply(timeLeftAttribute.withDelta(-4.42))
// Updating multiple attributes.
profile.apply(from: [
    // Updating predefined attributes.
    YMMProfileAttribute.name().withValue("John"),
    YMMProfileAttribute.gender().withValue(YMMGenderType.male),
    YMMProfileAttribute.birthDate().withAge(24),
    YMMProfileAttribute.notificationsEnabled().withValue(false),
    // Updating custom attributes.
    YMMProfileAttribute.customString("born_in").withValueIfUndefined("Moscow"),
    YMMProfileAttribute.customString("address").withValueReset(),
    YMMProfileAttribute.customNumber("age").withValue(24),
    YMMProfileAttribute.customCounter("logins_count").withDelta(1),
    YMMProfileAttribute.customBool("has_premium").withValue(true)
])
// ProfieID is set using the method of the YMMYandexMetrica class.
YMMYandexMetrica.setUserProfileID("id")

// Sending profile attributes.
YMMYandexMetrica.report(profile, onFailure: { (error) in
    print("REPORT ERROR: %@", error.localizedDescription)
})

To send profile attributes, pass an object of the UserProfile class to the AppMetrica.reportUserProfile(UserProfile); method.

// Creating the UserProfile instance.
UserProfile userProfile = UserProfile([
// Updating predefined attributes.
NameAttribute.withValue("John"),
GenderAttribute.withValue(Gender.MALE),
BirthDateAttribute.withAge(24),
NotificationEnabledAttribute.withValue(false),
// Updating custom attributes.
StringAttribute.withValue("string_attribute", "string"),
NumberAttribute.withValue("number_attribute", 55),
CounterAttribute.withDelta("counter_attribute", 1)
]);

// Setting the ProfileID using the method of the YandexMetrica class.
AppMetrica.setUserProfileID("id");

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

See also

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.

Contact support