Skip to content

Configuración de los atributos del usuario

Aprende a configurar atributos de usuario a través del SDK de Braze.

Requisitos previos

Antes de poder utilizar esta característica, tendrás que integrar el SDK de Android Braze.

Atributos predeterminados del usuario

Para establecer un atributo predeterminado para un usuario, llama al método getCurrentUser() en tu instancia de Braze para obtener una referencia al usuario actual de tu aplicación. A continuación, puedes llamar a los métodos para establecer un atributo de usuario.

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 proporciona métodos predefinidos para configurar los siguientes atributos de usuario dentro de la clase BrazeUser. Para las especificaciones del método, consulta nuestro KDoc.

  • Nombre
  • Apellido
  • País
  • Idioma
  • Fecha de nacimiento
  • Correo electrónico
  • Género
  • Ciudad de origen
  • Número de teléfono

Atributos personalizados del usuario

Además de los atributos predeterminados de usuario, Braze también te permite definir atributos personalizados utilizando varios tipos de datos diferentes. Para más información sobre la opción de segmentación de cada atributo, consulta Recopilación de datos de usuario.

Establecer atributos personalizados

Para establecer un atributo personalizado con un valor 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")
}

Para establecer un atributo personalizado con un valor 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)
}

Para establecer un atributo personalizado con un valor entero 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)
}

Para establecer un atributo personalizado con un valor 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)
}

Para establecer un atributo personalizado con un valor 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)
}

Para establecer un atributo personalizado con un valor 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)
}

El número máximo de elementos de las matrices de atributos personalizadas está predeterminado en 25. El máximo para matrices individuales puede aumentarse hasta 100 en el panel de Braze, en Configuración de datos > Atributos personalizados. Las matrices que superen la cantidad máxima de elementos se truncarán para contenerla. Para obtener más información sobre las matrices de atributos personalizadas y su comportamiento, consulta nuestra documentación sobre Matrices.

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")
}

Desactivar un atributo personalizado

Los atributos personalizados también se pueden desactivar utilizando el siguiente método:

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")
}

Utilizar la API REST

También puedes utilizar nuestra API REST para establecer o desestablecer atributos de usuario. Para más información, consulta Puntos finales de datos de usuario.

Configuración de las suscripciones de los usuarios

Para configurar una suscripción para tus usuarios (por correo electrónico o push), llama a las funciones setEmailNotificationSubscriptionType() o setPushNotificationSubscriptionType(), respectivamente. Estas dos funciones toman como argumento el tipo de enumeración NotificationSubscriptionType. Este tipo tiene tres estados diferentes:

Configuración de las suscripciones por correo electrónico

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)
}

Configuración de la suscripción a notificaciones 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)
}

Requisitos previos

Antes de poder utilizar esta característica, tendrás que integrar el SDK de Swift Braze.

Default user attributes

Supported attributes

The following attributes should be set on the Braze.User object:

  • firstName
  • lastName
  • email
  • dateOfBirth
  • country
  • language
  • homeCity
  • phone
  • gender

Setting default attributes

To set a default user attribute, set the appropriate field on the shared Braze.User object. The following is an example of setting the first name attribute:

1
AppDelegate.braze?.user.set(firstName: "Alex")
1
[AppDelegate.braze.user setFirstName:@"Alex"];

Unsetting default attributes

To unset a default user attribute, pass nil to the relevant method.

1
AppDelegate.braze?.user.set(firstName: nil)
1
[AppDelegate.braze.user setFirstName:nil];

Custom user attributes

In addition to the default user attributes, Braze also allows you to define custom attributes using several different data types. For more information on each attribute’s segmentation option, see User data collection.

Setting custom attributes

To set a custom attribute with a string value:

1
AppDelegate.braze?.user.setCustomAttribute(key: "your_attribute_key", value: "your_attribute_value")
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" stringValue:"your_attribute_value"];

To set a custom attribute with an integer value:

1
AppDelegate.braze?.user.setCustomAttribute(key: "your_attribute_key", value: yourIntegerValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andIntegerValue:yourIntegerValue];

Braze treats float and double values the same within our database. To set a custom attribute with a double value:

1
AppDelegate.braze?.user.setCustomAttribute(key: "your_attribute_key", value: yourDoubleValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andDoubleValue:yourDoubleValue];

To set a custom attribute with a boolean value:

1
AppDelegate.braze?.user.setCustomAttribute("your_attribute_key", value: yourBoolValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andBOOLValue:yourBOOLValue];

To set a custom attribute with a date value:

1
AppDelegate.braze?.user.setCustomAttribute("your_attribute_key", dateValue:yourDateValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andDateValue:yourDateValue];

The maximum number of elements in custom attribute arrays defaults to 25. Arrays exceeding the maximum number of elements will be truncated to contain the maximum number of elements. The maximum for individual arrays can be increased to up to 100. If you would like this maximum increased, reach out to your customer service manager.

To set a custom attribute with an array value:

1
2
3
4
5
6
// Setting a custom attribute with an array value
AppDelegate.braze?.user.setCustomAttributeArray(key: "array_name", array: ["value1",  "value2"])
// Adding to a custom attribute with an array value
AppDelegate.braze?.user.addToCustomAttributeArray(key: "array_name", value: "value3")
// Removing a value from an array type custom attribute
AppDelegate.braze?.user.removeFromCustomAttributeArray(key: "array_name", value: "value2")
1
2
3
4
5
6
7
8
// Setting a custom attribute with an array value
[AppDelegate.braze.user setCustomAttributeArrayWithKey:@"array_name" array:@[@"value1",  @"value2"]];
// Adding to a custom attribute with an array value
[AppDelegate.braze.user addToCustomAttributeArrayWithKey:@"array_name" value:@"value3"];
// Removing a value from an array type custom attribute
[AppDelegate.braze.user removeFromCustomAttributeArrayWithKey:@"array_name" value:@"value2"];
// Removing an entire array and key
[AppDelegate.braze.user setCustomAttributeArrayWithKey:@"array_name" array:nil];

Incrementing or decrementing custom attributes

This code is an example of an incrementing custom attribute. You may increment the value of a custom attribute by any integer or long value:

1
AppDelegate.braze?.user.incrementCustomUserAttribute(key: "your_attribute_key", by: incrementIntegerValue)
1
[AppDelegate.braze.user incrementCustomUserAttribute:@"your_attribute_key" by:incrementIntegerValue];

Unsetting custom attributes

To unset a custom attribute, pass the relevant attribute key to the unsetCustomAttribute method.

1
AppDelegate.braze?.user.unsetCustomAttribute(key: "your_attribute_key")

To unset a custom attribute, pass the relevant attribute key to the unsetCustomAttributeWithKey method.

1
[AppDelegate.braze.user unsetCustomAttributeWithKey:@"your_attribute_key"];

Nesting custom attributes

You can also nest properties within custom attributes. In the following example, a favorite_book object with nested properties is set as a custom attribute on the user profile. For more details, refer to Nested Custom Attributes.

1
2
3
4
5
6
7
let favoriteBook: [String: Any?] = [
  "title": "The Hobbit",
  "author": "J.R.R. Tolkien",
  "publishing_date": "1937"
]

braze.user.setCustomAttribute(key: "favorite_book", dictionary: favoriteBook)
1
2
3
4
5
6
7
NSDictionary *favoriteBook = @{
  @"title": @"The Hobbit",
  @"author": @"J.R.R. Tolkien",
  @"publishing_date": @"1937"
};

[AppDelegate.braze.user setCustomAttributeWithKey:@"favorite_book" dictionary:favoriteBook];

Using the REST API

You can also use our REST API to set or unset user attributes. For more information, refer to User Data Endpoints.

Setting user subscriptions

To set up a subscription for your users (either email or push), call the functions set(emailSubscriptionState:) or set(pushNotificationSubscriptionState:), respectively. Both of these functions take the enum type Braze.User.SubscriptionState as arguments. This type has three different states:

Users who grant permission for an app to send them push notifications default to the status of optedIn as iOS requires an explicit opt-in.

Users will be set to subscribed automatically upon receipt of a valid email address; however, we suggest that you establish an explicit opt-in process and set this value to optedIn upon receipt of explicit consent from your user. Refer to Managing user subscriptions for more details.

Setting email subscriptions

1
AppDelegate.braze?.user.set(emailSubscriptionState: Braze.User.SubscriptionState)
1
[AppDelegate.braze.user setEmailSubscriptionState: BRZUserSubscriptionState]

Setting push notification subscriptions

1
AppDelegate.braze?.user.set(pushNotificationSubscriptionState: Braze.User.SubscriptionState)
1
[AppDelegate.braze.user setPushNotificationSubscriptionState: BRZUserSubscriptionState]

Refer to Managing user subscriptions for more details.

Prerequisites

Before you can use this feature, you’ll need to integrate the Web Braze SDK.

Atributos predeterminados del usuario

Para establecer un atributo predeterminado para un usuario, llama al método getCurrentUser() en tu instancia de Braze para obtener una referencia al usuario actual de tu aplicación. A continuación, puedes llamar a los métodos para establecer un atributo de usuario.

1
braze.getUser().setFirstName("SomeFirstName");
1
braze.getUser().setGender(braze.User.Genders.FEMALE);
1
braze.getUser().setDateOfBirth(2000, 12, 25);

Al utilizar Google Tag Manager, los atributos estándar de usuario (como el nombre de pila de un usuario), deben registrarse del mismo modo que los atributos personalizados de usuario. Asegúrate de que los valores que pasas para los atributos estándar coinciden con el formato esperado especificado en la documentación de la clase Usuario.

Por ejemplo, el atributo género puede aceptar cualquiera de los siguientes valores: "m" | "f" | "o" | "u" | "n" | "p". Por lo tanto, para establecer el sexo de un usuario como femenino, crea una etiqueta HTML personalizada con el siguiente contenido:

1
2
3
<script>
window.braze.getUser().setGender("f")
</script>

Braze proporciona métodos predefinidos para configurar los siguientes atributos de usuario dentro de la claseUser:

  • Nombre
  • Apellido
  • Idioma
  • País
  • Fecha de nacimiento
  • Correo electrónico
  • Género
  • Ciudad natal
  • Número de teléfono

Atributos personalizados del usuario

Además de los métodos predeterminados de atributos de usuario, también puedes establecer atributos personalizados para tus usuarios. Especificaciones completas del método, consulta nuestros JSDocs.

Para establecer un atributo personalizado con un valor string:

1
2
3
4
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  YOUR_STRING_VALUE
);

Para establecer un atributo personalizado con un valor integer:

1
2
3
4
5
6
7
8
9
10
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  YOUR_INT_VALUE
);

// Integer attributes may also be incremented using code like the following
braze.getUser().incrementCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  THE_INTEGER_VALUE_BY_WHICH_YOU_WANT_TO_INCREMENT_THE_ATTRIBUTE
);

Para establecer un atributo personalizado con un valor date:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  YOUR_DATE_VALUE
);

// This method will assign the current time to a custom attribute at the time the method is called
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  new Date()
);

// This method will assign the date specified by secondsFromEpoch to a custom attribute
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  new Date(secondsFromEpoch * 1000)
);

Puedes tener hasta 25 elementos en matrices de atributos personalizadas. Las matrices individuales que se establecen manualmente (no se detectan automáticamente) para el Tipo de datos pueden aumentarse hasta 100 en el panel de Braze, en Configuración de datos > Atributos personalizados . Si quieres aumentar este máximo, ponte en contacto con tu director de cuentas Braze.

Las matrices que superen la cantidad máxima de elementos se truncarán para contener el número máximo de elementos.

Para establecer un atributo personalizado con un valor array:

1
2
3
4
5
6
7
braze.getUser().setCustomUserAttribute(YOUR_ATTRIBUTE_KEY_STRING, YOUR_ARRAY_OF_STRINGS);

// Adding a new element to a custom attribute with an array value
braze.getUser().addToCustomAttributeArray(YOUR_ATTRIBUTE_KEY_STRING, "new string");

// Removing an element from a custom attribute with an array value
braze.getUser().removeFromCustomAttributeArray(YOUR_ATTRIBUTE_KEY_STRING, "value to be removed");

Los atributos personalizados de usuario no están disponibles debido a una limitación del lenguaje de programación de Google Tag Manager. Para registrar atributos personalizados, crea una etiqueta HTML personalizada con el siguiente contenido:

1
2
3
4
5
<script>
  // Note: If using SDK version 3.x or below, use `window.appboy` instead of `window.braze`
  // Version 4 or greater should use `window.braze`
window.braze.getUser().setCustomUserAttribute("attribute name", "attribute value");
</script>

Desactivar un atributo personalizado

Los atributos personalizados pueden desactivarse estableciendo su valor en null.

1
braze.getUser().setCustomUserAttribute(YOUR_ATTRIBUTE_KEY_STRING, null);

Utilizar la API REST

También puedes utilizar nuestra API REST para establecer o desestablecer atributos de usuario. Para más información, consulta Puntos finales de datos de usuario.

Configuración de las suscripciones de los usuarios

Para configurar una suscripción para tus usuarios (por correo electrónico o push), llama a las funciones setEmailNotificationSubscriptionType() o setPushNotificationSubscriptionType(), respectivamente. Ambas funciones toman como argumentos el tipo enum braze.User.NotificationSubscriptionTypes . Este tipo tiene tres estados diferentes:

Cuando un usuario se registra para recibir notificaciones push, el navegador le obliga a elegir entre permitir o bloquear las notificaciones, y si elige permitir las notificaciones push, éstas se configuran por defecto en OPTED_IN.

Visita Gestionar las suscripciones de los usuarios para obtener más información sobre la implementación de las suscripciones y las adhesiones voluntarias explícitas.

Cancelar suscripción de un usuario a un correo electrónico

1
braze.getUser().setEmailNotificationSubscriptionType(braze.User.NotificationSubscriptionTypes.UNSUBSCRIBED);

Cancelar suscripción de un usuario desde push

1
braze.getUser().setPushNotificationSubscriptionType(braze.User.NotificationSubscriptionTypes.UNSUBSCRIBED);

Requisitos previos

Antes de poder utilizar esta característica, tendrás que integrar el SDK de Flutter Braze.

Atributos predeterminados del usuario

Para configurar los atributos de usuario recogidos automáticamente por Braze, puedes utilizar los métodos de configuración que vienen con el SDK.

1
braze.setFirstName('Name');

Se admiten los siguientes atributos:

  • Nombre
  • Apellido
  • Género
  • Fecha de nacimiento
  • Ciudad natal
  • País
  • Número de teléfono
  • Idioma
  • Correo electrónico

Atributos personalizados del usuario

Establecer atributos personalizados

Además de los atributos de usuario predeterminados, Braze también te permite definir atributos personalizados utilizando distintos tipos de datos:

Para establecer un atributo personalizado con un valor string:

1
braze.setStringCustomUserAttribute("custom string attribute", "string custom attribute");

Para establecer un atributo personalizado con un valor integer:

1
2
3
4
// Set Integer Attribute
braze.setIntCustomUserAttribute("custom int attribute key", integer);
// Increment Integer Attribute
braze.incrementCustomUserAttribute("key", integer);

Para establecer un atributo personalizado con un valor double:

1
braze.setDoubleCustomUserAttribute("custom double attribute key", double);

Para establecer un atributo personalizado con un valor boolean:

1
braze.setBoolCustomUserAttribute("custom boolean attribute key", boolean);

Para establecer un atributo personalizado con un valor date:

1
braze.setDateCustomUserAttribute("custom date attribute key", date);

Para establecer un atributo personalizado con un valor array:

1
2
3
4
// Adding to an Array
braze.addToCustomAttributeArray("key", "attribute");
// Removing an item from an Array
braze.removeFromCustomAttributeArray("key", "attribute");

Desactivar un atributo personalizado

1
braze.unsetCustomUserAttribute('attribute_key');

Prerequisites

Before you can use this feature, you’ll need to integrate the Roku Braze SDK.

Default user attributes

Predefined methods

Braze provides predefined methods for setting the following user attributes using the m.Braze object.

  • FirstName
  • LastName
  • Email
  • Gender
  • DateOfBirth
  • Country
  • Language
  • HomeCity
  • PhoneNumber

Setting default attributes

To set a default attribute, call the relevant method on the m.Braze object.

1
m.Braze.setFirstName("Alex")
1
m.Braze.setLastName("Smith")
1
m.Braze.setGender("m") ' Accepts: "m", "f", "o", "n", "u", "p"
1
m.Braze.setDateOfBirth(1990, 5, 15) ' Year, month, day
1
m.Braze.setCountry("United States")
1
m.Braze.setLanguage("en")
1
m.Braze.setHomeCity("New York")
1
m.Braze.setPhoneNumber("+1234567890")

Custom user attributes

In addition to the default user attributes, Braze also allows you to define custom attributes using several different data types.

Settings custom attributes

To set a custom attribute a string value:

1
m.Braze.setCustomAttribute("stringAttribute", "stringValue")

To set a custom attribute with an integer value:

1
m.Braze.setCustomAttribute("intAttribute", 5)

Braze treats float and double values exactly the same. To set a custom attribute with either value:

1
m.Braze.setCustomAttribute("floatAttribute", 3.5)

To set a custom attribute with a boolean value:

1
m.Braze.setCustomAttribute("boolAttribute", true)

To set a custom attribute with a date value:

1
2
3
dateAttribute = CreateObject("roDateTime")
dateAttribute.fromISO8601String("1992-11-29 00:00:00.000")
m.Braze.setCustomAttribute("dateAttribute", dateAttribute)

To set a custom attribute with an array value:

1
2
3
4
5
stringArray = createObject("roArray", 3, true)
stringArray.Push("string1")
stringArray.Push("string2")
stringArray.Push("string3")
m.Braze.setCustomAttribute("arrayAttribute", stringArray)

Incrementing and decrementing custom attributes

This code is an example of an incrementing custom attribute. You may increment the value of a custom attribute by any positive or negative integer value.

1
m.Braze.incrementCustomUserAttribute("intAttribute", 3)

Unsetting custom attributes

To unset a custom attribute, pass the relevant attribute key to the unsetCustomAttribute method.

1
m.Braze.unsetCustomAttribute("attributeName")

Using the REST API

You can also use our REST API to set or unset user attributes. For more information, refer to User Data Endpoints.

Setting email subscriptions

You can set the following email subscription statuses for your users programmatically through the SDK.

The method for setting email subscription status is setEmailSubscriptionState(). Users will be set to Subscribed automatically upon receipt of a valid email address, however, we suggest that you establish an explicit opt-in process and set this value to OptedIn upon receipt of explicit consent from your user. For more details, visit Managing user subscriptions.

1
m.Braze.setEmailSubscriptionState(BrazeConstants().SUBSCRIPTION_STATES.OPTED_IN)

Requisitos previos

Antes de poder utilizar esta característica, tendrás que integrar el SDK Braze de Unity.

Atributos predeterminados del usuario

Para establecer los atributos del usuario, tienes que llamar al método apropiado del objeto BrazeBinding. La siguiente es una lista de atributos incorporados que pueden invocarse mediante este método.

Atributos personalizados del usuario

Además de los atributos predeterminados de usuario, Braze también te permite definir atributos personalizados utilizando varios tipos de datos diferentes. Para más información sobre la opción de segmentación de cada atributo, consulta Recopilación de datos de usuario.

Establecer atributos personalizados

1
AppboyBinding.SetCustomUserAttribute("custom string attribute key", "string custom attribute");
1
2
3
4
// Set Integer Attribute
AppboyBinding.SetCustomUserAttribute("custom int attribute key", 'integer value');
// Increment Integer Attribute
AppboyBinding.IncrementCustomUserAttribute("key", increment(int))
1
AppboyBinding.SetCustomUserAttribute("custom double attribute key", 'double value');
1
AppboyBinding.SetCustomUserAttribute("custom boolean attribute key", 'boolean value');
1
AppboyBinding.SetCustomUserAttributeToNow("custom date attribute key");
1
AppboyBinding.SetCustomUserAttributeToSecondsFromEpoch("custom date attribute key", 'integer value');
1
2
3
4
5
6
// Setting An Array
AppboyBinding.SetCustomUserAttributeArray("key", array(List), sizeOfTheArray(int))
// Adding to an Array
AppboyBinding.AddToCustomUserAttributeArray("key", "Attribute")
// Removing an item from an Array
AppboyBinding.RemoveFromCustomUserAttributeArray("key", "Attribute")

Desactivar atributos personalizados

Para desactivar un atributo personalizado de usuario, utiliza el siguiente método:

1
AppboyBinding.UnsetCustomUserAttribute("custom attribute key");

Utilizar la API REST

También puedes utilizar nuestra API REST para establecer o desestablecer atributos de usuario. Para más información, consulta Puntos finales de datos de usuario.

Configuración de las suscripciones de los usuarios

Para configurar una suscripción por correo electrónico o push para tus usuarios, llama a una de las siguientes funciones.

1
2
3
4
5
// Email notifications
AppboyBinding.SetUserEmailNotificationSubscriptionType()

// Push notifications
AppboyBinding.SetPushNotificationSubscriptionType()`

Ambas funciones toman como argumento Appboy.Models.AppboyNotificationSubscriptionType, que tiene tres estados diferentes:

Configuración de las suscripciones por correo electrónico

1
AppboyBinding.SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType.OPTED_IN);

Configuración de suscripciones a notificaciones push

1
AppboyBinding.SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType.OPTED_IN);

Default User Attributes

Supported attributes

The following attributes should be set on the UBrazeUser object:

  • SetFirstName
  • SetLastName
  • SetEmail
  • SetDateOfBirth
  • SetCountry
  • SetLanguage
  • SetHomeCity
  • SetPhoneNumber
  • SetGender

Setting default attributes

To set a default attribute for a user, call the GetCurrentUser() method on the shared UBrazeUser object to get a reference to the current user of your app. Then you can call methods to set a user attribute.

1
2
3
4
5
UBraze->GetCurrentUser([](UBrazeUser* BrazeUser) {
    if (BrazeUser) {
        BrazeUser->SetFirstName(TEXT("Alex"));
    }
});

Custom User Attributes

In addition to the default user attributes, Braze also allows you to define custom attributes using several different data types. For more information on each attribute’s segmentation option, see User data collection.

To set a custom attribute with a string value:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), TEXT("your_attribute_value"));

To set a custom attribute with an integer value:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), 42);

Braze treats float and double values the same within our database. To set a custom attribute with a double value:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), 3.14);

To set a custom attribute with a boolean value:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), true);

To set a custom attribute with a date value:

1
2
FDateTime YourDateTime = FDateTime(2023, 5, 10);
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), YourDateTime);

To set a custom attribute with an array value:

1
2
3
4
5
6
7
8
9
// Setting a custom attribute with an array value
TArray<FString> Values = {TEXT("value1"), TEXT("value2")};
UBrazeUser->SetCustomAttributeArray(TEXT("array_name"), Values);

// Adding to a custom attribute with an array value
UBrazeUser->AddToCustomAttributeArray(TEXT("array_name"), TEXT("value3"));

// Removing a value from an array type custom attribute
UBrazeUser->RemoveFromCustomAttributeArray(TEXT("array_name"), TEXT("value2"));

Setting user subscriptions

To set up an email or push subscription for your users, you can use the following methods.

Setting email subscription

1
2
3
4
5
UBraze->GetCurrentUser([](UBrazeUser* BrazeUser) {
    if (BrazeUser) {
        BrazeUser->SetEmailSubscriptionType(EBrazeSubscriptionType::Subscribed);
    }
});

Setting attribution data

1
2
3
4
5
UBraze->GetCurrentUser([](UBrazeUser* BrazeUser) {
    if (BrazeUser) {
        BrazeUser->SetPushSubscriptionType(EBrazeSubscriptionType::OptedIn);
    }
});
¿QUÉ TAN ÚTIL FUE ESTA PÁGINA?
New Stuff!