Настройка отправки атрибутов профилей
В AppMetrica SDK можно настроить отправку предопределенных и собственных атрибутов профиля. Предопределенные атрибуты поддержаны заранее и имеют установленный формат отправки. Для отправки собственных атрибутов необходимо добавить атрибут в настройках приложения.
Внимание
Не передавайте конфиденциальную информацию о пользователях в атрибутах профиля.
Ниже описаны этапы настройки отправки атрибутов:
Шаг 1. Добавьте атрибут в настройках приложения
- В интерфейсе AppMetrica перейдите в настройки приложения из меню слева.
- Откройте вкладку Атрибуты профилей.
- В разделе Собственные атрибуты введите название нового атрибута в соответствующее поле.
- Выберите тип переменной из выпадающего списка и нажмите Добавить.
В настройках Атрибуты профилей отображается список всех атрибутов и их статус. Чтобы прекратить сбор атрибута и убрать его из отчетов, нажмите кнопку .
Шаг 2. Настройте отправку значений атрибутов в AppMetrica SDK
Внимание
Если отправка ProfileId
не настроена, предопределенные атрибуты не отображаются в веб-интерфейсе.
Ниже представлены примеры отправки атрибутов профиля.
Чтобы отправить атрибуты профиля, передайте в объект UserProfile
необходимые атрибуты и отправьте этот объект с помощью метода AppMetrica.reportUserProfile(UserProfile profile)
. Атрибуты профиля создаются с помощью методов класса Attribute
.
// 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);
Чтобы отправить атрибуты профиля, передайте в метод +reportUserProfile:onFailure:
класса YMMYandexMetrica
следующие параметры:
userProfile
— объектYMMUserProfile
, который содержит массив обновлений атрибутов. Атрибуты профиля создаются с помощью методов классаYMMProfileAttribute
.onFailure
— блок, в который передается ошибка. Если вы не хотите отслеживать ошибку, то передайте в качестве блока значениеnil
.
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);
}];
Чтобы отправить атрибуты профиля, передайте в метод reportUserProfile(_:onFailure:)
класса YMMYandexMetrica
следующие параметры:
userProfile
— объектYMMUserProfile
, который содержит массив обновлений атрибутов. Атрибуты профиля создаются с помощью методов классаYMMProfileAttribute
.onFailure
— блок, в который передается ошибка. Если вы не хотите отслеживать ошибку, то передайте в качестве блока значениеnil
.
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)
})
Чтобы отправить атрибуты профиля, передайте в метод AppMetrica.reportUserProfile(UserProfile);
объект класса UserProfile
.
// 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);
См. также
Если вы не нашли ответ на свой вопрос, то вы можете задать его через форму обратной связи. Пожалуйста, опишите возникшую проблему как можно подробнее. Если возможно, приложите скриншот.