Conditions préalables
Avant de pouvoir utiliser cette fonctionnalité, vous devrez intégrer le SDK Android Braze.
Attributs par défaut de l’utilisateur
Pour définir un attribut par défaut pour un utilisateur, appelez la méthode getCurrentUser()
sur votre instance Braze pour obtenir une référence à l’utilisateur actuel de votre application. Vous pouvez ensuite appeler des méthodes pour définir un attribut utilisateur.
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setFirstName("first_name");
}
}
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setFirstName("first_name")
}
|
Braze fournit des méthodes prédéfinies pour définir les attributs utilisateur suivants dans la classe BrazeUser. Pour les spécifications de la méthode, reportez-vous à notre KDoc.
- Prénom
- Nom
- Pays
- Langue
- Date de naissance
- E-mail
- Genre
- Ville d’origine
- Numéro de téléphone
note:
Toutes les valeurs de chaîne de caractères telles que le prénom, le nom de famille, le pays et la ville d’origine sont limitées à 255 caractères.
Attributs utilisateur personnalisés
Outre les attributs par défaut, Braze vous permet de définir des attributs personnalisés à l’aide de différents types de données. Pour plus d’informations sur l’option de segmentation de chaque attribut, voir Collecte de données sur les utilisateurs.
Définition des attributs personnalisés
Pour définir un attribut personnalisé avec une valeur string
:
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setCustomUserAttribute("your_attribute_key", "your_attribute_value");
}
}
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setCustomUserAttribute("your_attribute_key", "your_attribute_value")
}
|
Pour définir un attribut personnalisé avec une valeur int
:
1
2
3
4
5
6
7
8
9
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_INT_VALUE);
// Integer attributes may also be incremented using code like the following:
brazeUser.incrementCustomUserAttribute("your_attribute_key", YOUR_INCREMENT_VALUE);
}
}
|
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_INT_VALUE)
// Integer attributes may also be incremented using code like the following:
brazeUser.incrementCustomUserAttribute("your_attribute_key", YOUR_INCREMENT_VALUE)
}
|
Pour définir un attribut personnalisé avec une valeur entière long
:
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_LONG_VALUE);
}
});
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_LONG_VALUE)
}
|
Pour définir un attribut personnalisé avec une valeur float
:
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_FLOAT_VALUE);
}
});
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_FLOAT_VALUE)
}
|
Pour définir un attribut personnalisé avec une valeur double
:
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DOUBLE_VALUE);
}
});
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DOUBLE_VALUE)
}
|
Pour définir un attribut personnalisé avec une valeur boolean
:
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_BOOLEAN_VALUE);
}
});
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_BOOLEAN_VALUE)
}
|
1
2
3
4
5
6
7
8
9
10
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DATE_VALUE);
// This method will assign the current time to a custom attribute at the time the method is called:
brazeUser.setCustomUserAttributeToNow("your_attribute_key");
// This method will assign the date specified by SECONDS_FROM_EPOCH to a custom attribute:
brazeUser.setCustomUserAttributeToSecondsFromEpoch("your_attribute_key", SECONDS_FROM_EPOCH);
}
});
|
1
2
3
4
5
6
7
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DATE_VALUE)
// This method will assign the current time to a custom attribute at the time the method is called:
brazeUser.setCustomUserAttributeToNow("your_attribute_key")
// This method will assign the date specified by SECONDS_FROM_EPOCH to a custom attribute:
brazeUser.setCustomUserAttributeToSecondsFromEpoch("your_attribute_key", SECONDS_FROM_EPOCH)
}
|
warning:
Les dates transmises à Braze avec cette méthode doivent être au format ISO 8601 (e.g 2013-07-16T19:20:30+01:00
) ou au format yyyy-MM-dd'T'HH:mm:ss:SSSZ
(e.g 2016-12-14T13:32:31.601-0800
).
Le nombre maximum d’éléments dans les tableaux d’attributs personnalisés est par défaut de 25. Le maximum pour les tableaux individuels peut être augmenté jusqu’à 100 dans le tableau de bord de Braze, sous Paramètres des données > Attributs personnalisés. Les tableaux dépassant le nombre maximum d’éléments seront tronqués pour contenir le nombre maximum d’éléments. Pour plus d’informations sur les tableaux d’attributs personnalisés et leur comportement, consultez notre documentation sur les tableaux.
1
2
3
4
5
6
7
8
9
10
11
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
// Setting a custom attribute with an array value
brazeUser.setCustomAttributeArray("your_attribute_key", testSetArray);
// Adding to a custom attribute with an array value
brazeUser.addToCustomAttributeArray("your_attribute_key", "value_to_add");
// Removing a value from an array type custom attribute
brazeUser.removeFromCustomAttributeArray("your_attribute_key", "value_to_remove");
}
});
|
1
2
3
4
5
6
7
8
| Braze.getInstance(context).getCurrentUser { brazeUser ->
// Setting a custom attribute with an array value
brazeUser.setCustomAttributeArray("your_attribute_key", testSetArray)
// Adding to a custom attribute with an array value
brazeUser.addToCustomAttributeArray("your_attribute_key", "value_to_add")
// Removing a value from an array type custom attribute
brazeUser.removeFromCustomAttributeArray("your_attribute_key", "value_to_remove")
}
|
Enlever la configuration d’un attribut personnalisé
Les attributs personnalisés peuvent également être annulés à l’aide de la méthode suivante :
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.unsetCustomUserAttribute("your_attribute_key");
}
});
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.unsetCustomUserAttribute("your_attribute_key")
}
|
Utiliser l’API REST
Vous pouvez également utiliser notre API REST pour définir ou désactiver les attributs des utilisateurs. Pour plus d’informations, reportez-vous aux Endpoints de données utilisateur.
Pour configurer un abonnement pour vos utilisateurs (par e-mail ou notification push), appelez les fonctions setEmailNotificationSubscriptionType()
ou setPushNotificationSubscriptionType()
, respectivement. Ces deux fonctions considèrent le type de enum NotificationSubscriptionType
comme arguments. Ce type a trois états différents :
Statut d’abonnement |
Définition |
OPTED_IN |
Inscrit et explicitement abonné |
SUBSCRIBED |
Inscrit et pas explicitement abonné |
UNSUBSCRIBED |
Désinscrit ou explicitement désabonné |
important:
Aucun abonnement explicite n’est requis par Android pour envoyer des notifications push aux utilisateurs. Lorsqu’un utilisateur est enregistré pour les notifications push, il est défini sur SUBSCRIBED
plutôt que OPTED_IN
par défaut. Reportez-vous à la gestion des inscriptions des utilisateurs pour plus d’informations sur la mise en œuvre des inscriptions et des abonnements explicites.
Définir des inscriptions par e-mail
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setEmailNotificationSubscriptionType(emailNotificationSubscriptionType);
}
});
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setEmailNotificationSubscriptionType(emailNotificationSubscriptionType)
}
|
Définir de l’inscription aux notifications push
1
2
3
4
5
6
| Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setPushNotificationSubscriptionType(pushNotificationSubscriptionType);
}
});
|
1
2
3
| Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setPushNotificationSubscriptionType(pushNotificationSubscriptionType)
}
|
guide/swift/analytics/setting_user_attributes.md developer_ %}
guide/web/analytics/setting_user_attributes.md developer_ %}
guide/unity/analytics/setting_user_attributes.md developer_ %}
guide/unreal_engine/analytics/setting_user_attributes.md developer_ %}