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 the following parameters to the +reportUserProfile:onFailure: method of the AMAAppMetrica class:

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

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

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

  • userProfile: The UserProfile instance that contains an array of attribute updates. Profile attributes are created by methods of the ProfileAttribute 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 = MutableUserProfile()
// Updating a single user profile attribute.
let timeLeftAttribute: CustomCounterAttribute = ProfileAttribute.customCounter("time_left")
profile.apply(timeLeftAttribute.withDelta(-4.42))
// Updating multiple attributes.
profile.apply(from: [
    // Updating predefined attributes.
    ProfileAttribute.name().withValue("John"),
    ProfileAttribute.gender().withValue(GenderType.male),
    ProfileAttribute.birthDate().withAge(24),
    ProfileAttribute.notificationsEnabled().withValue(false),
    // Updating custom attributes.
    ProfileAttribute.customString("born_in").withValueIfUndefined("Moscow"),
    ProfileAttribute.customString("address").withValueReset(),
    ProfileAttribute.customNumber("age").withValue(24),
    ProfileAttribute.customCounter("logins_count").withDelta(1),
    ProfileAttribute.customBool("has_premium").withValue(true)
])
// ProfieID is set using the method of the AppMetrica class.
AppMetrica.userProfileID("id")

// Sending profile attributes.
AppMetrica.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