Setting custom attributes
Braze provides methods for assigning attributes to users. You’ll be able to filter and segment your users according to these attributes on the dashboard.
Before implementation, be sure to review examples of the segmentation options afforded by custom events, custom attributes, and purchase events in our Best practices.
Assigning default user attributes
To assign user attributes, you need to call the appropriate method on the BrazeBinding object. The following is a list of built-in attributes that can be called using this method.
First name
AppboyBinding.SetUserFirstName("first name");
Last name
AppboyBinding.SetUserLastName("last name");
User email
AppboyBinding.SetUserEmail("[email protected]");
It’s still valuable to set email addresses even if you’re not sending emails through Braze. Email makes it easier to search for individual user profiles and troubleshoot issues as they arise.
Gender
AppboyBinding.SetUserGender(Appboy.Models.Gender);
Birth date
AppboyBinding.SetUserDateOfBirth("year(int)", "month(int)", "day(int)");
User country
AppboyBinding.SetUserCountry("country name");
User home city
AppboyBinding.SetUserHomeCity("city name");
User email subscription
AppboyBinding.SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType);
User push subscription
AppboyBinding.SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType);
User phone number
AppboyBinding.SetUserPhoneNumber("phone number");
Assigning custom user attributes
Beyond the default user attributes, Braze also allows you to define custom attributes using a number of different data types: For more information regarding the segmentation options each of these attributes will afford you see our “Best Practices” documentation within this section.
Setting custom attribute values
1
AppboyBinding.SetCustomUserAttribute("custom boolean attribute key", 'boolean value');
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 string attribute key", "string custom attribute");
1
AppboyBinding.SetCustomUserAttributeToNow("custom date attribute key");
1
AppboyBinding.SetCustomUserAttributeToSecondsFromEpoch("custom date attribute key", 'integer value');
Dates passed to Braze must either be in the [ISO 8601][2] format, e.g
2013-07-16T19:20:30+01:00
or in theyyyy-MM-dd'T'HH:mm:ss:SSSZ
format e.g2016-12-14T13:32:31.601-0800
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")
Unsetting a custom attribute
Custom attributes can also be unset using the following method:
1
AppboyBinding.UnsetCustomUserAttribute("custom attribute key");
Setting a custom attribute via the REST API
You can also use our REST API to set user attributes. To do so refer to the user API documentation.
Custom attribute value limits
Custom attribute values have a maximum length of 255 characters; longer values will be truncated.
Setting up user subscriptions
To set up a subscription for your users (either email or push), call the functions
AppboyBinding.SetUserEmailNotificationSubscriptionType()
or AppboyBinding.SetPushNotificationSubscriptionType()
, respectively. Both of these functions take the parameters Appboy.Models.AppboyNotificationSubscriptionType
as arguments. This type has three different states:
Subscription Status | Definition |
---|---|
OPTED_IN |
Subscribed, and explicitly opted in |
SUBSCRIBED |
Subscribed, but not explicitly opted in |
UNSUBSCRIBED |
Unsubscribed and/or explicitly opted out |
No explicit opt-in is required by Windows to send users push notifications. When a user is registered for push, they are set to
SUBSCRIBED
rather thanOPTED_IN
by default. To learn more, check out our documentation on implementing subscriptions and explicit opt-ins.
EmailNotificationSubscriptionType
- 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 toOPTED_IN
upon receipt of explicit consent from your user. Visit our Changing User Subscriptions doc for more details.
- Users will be set to
PushNotificationSubscriptionType
- Users will be set to
SUBSCRIBED
automatically upon valid push registration. However, we suggest that you establish an explicit opt-in process and set this value toOPTED_IN
upon receipt of explicit consent from your user. Visit our Changing User Subscriptions doc for more details.
- Users will be set to
These types fall under
Appboy.Models.AppboyNotificationSubscriptionType
.
Example code
Email subscription:
1
AppboyBinding.SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType.OPTED_IN);
Push notification subscription:
1
AppboyBinding.SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType.OPTED_IN);