new User()
Do not construct directly - use appboy.getUser() to get the user object.
Members
-
<static, readonly> Genders :string
-
Enum to represent valid genders.
Type:
- string
Properties:
Name Type Default Description MALE
string m FEMALE
string f OTHER
string o UNKNOWN
string u NOT_APPLICABLE
string n PREFER_NOT_TO_SAY
string p -
<static, readonly> NotificationSubscriptionTypes :string
-
Enum to represent notification status for email and push notifications.
Type:
- string
Properties:
Name Type Default Description OPTED_IN
string opted_in SUBSCRIBED
string subscribed UNSUBSCRIBED
string unsubscribed
Methods
-
addAlias(alias, label) → {boolean}
-
Adds an an alias for the user. (alias, label) pairs can exist on one and only one user. If a different user already has this alias or external user id, the alias attempt will be rejected on the server.
Parameters:
Name Type Description alias
string An identifier for this user.
label
string A label for the alias. e.g. the source of the alias, like "internal_id"
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
addToCustomAttributeArray(key, value) → {boolean}
-
Adds a string to a custom atttribute string array, or creates that array if one doesn't exist.
Parameters:
Name Type Description key
string The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
value
string The string to be added to the array. Strings are limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
getUserId(callback)
-
Asynchronously retrieves the current user's id, or null if the user is anonymous / has not been identified. For example:
appboy.getUser().getUserId(function(userId) { console.log('The user is ' + userId); });
Parameters:
Name Type Description callback
function Asynchronous callback - this will be invoked with the userId.
-
incrementCustomUserAttribute(key, incrementValue) → {boolean}
-
Increment/decrement the value of a custom attribute. Only numeric custom attributes can be incremented. Attempts to increment a custom attribute that is not numeric will be ignored. If you increment a custom attribute that has not previously been set, a custom attribute will be created and assigned the value of incrementValue. To decrement the value of a custom attribute, use a negative incrementValue.
Parameters:
Name Type Argument Default Description key
string The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
incrementValue
integer <optional>
1 May be negative to decrement.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
removeFromCustomAttributeArray(key, value) → {boolean}
-
Removes a string from a custom attribute string array.
Parameters:
Name Type Description key
string The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
value
string The string to be removed from the array. Strings are limited to 255 characters in length, cannot beging with a $, and can only contain alphanumeric characters and punctuation.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setAvatarImageUrl(avatarImageUrl) → {boolean}
-
Sets the url for the avatar image for the user, which will be displayed on the user profile and throughout the Braze dashboard.
Parameters:
Name Type Description avatarImageUrl
string Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setCountry(country) → {boolean}
-
Sets the country for the user.
Parameters:
Name Type Description country
string Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setCustomLocationAttribute(key, latitude, longitude) → {boolean}
-
Sets a custom user location attribute.
Parameters:
Name Type Description key
string The identifier of the custom location attribute. Limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
latitude
float The latitude of the user's location in (valid values are between -90 to 90 degrees). Passing a null value for both latitude and longitude will remove this custom attribute from the user.
longitude
float The longitude of the user's location (valid values are between -180 to 180 degrees). Passing a null value for both latitude and longitude will remove this custom attribute from the user.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setCustomUserAttribute(key, value) → {boolean}
-
Sets a custom user attribute. This can be any key/value pair and is used to collect extra information about the user.
Parameters:
Name Type Description key
string The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
value
Can be numeric, boolean, a Date object, a string, or an array of strings. Strings are limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation. Passing a null value will remove this custom attribute from the user.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setDateOfBirth(year, month, day) → {boolean}
-
Sets the date of birth of the user. Alternatively takes in null values for all parameters to set date of birth to null.
Parameters:
Name Type Description year
integer month
integer 1-12
day
integer Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setEmail(email) → {boolean}
-
Sets the email address of the user.
Parameters:
Name Type Description email
string Must pass RFC-5322 email address validation. Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setEmailNotificationSubscriptionType(notificationSubscriptionType) → {boolean}
-
Sets whether the user should be sent email campaigns.
Parameters:
Name Type Description notificationSubscriptionType
ab.User.NotificationSubscriptionTypes Notification setting (explicitly opted-in, subscribed, or unsubscribed).
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setFirstName(firstName) → {boolean}
-
Sets the first name of the user.
Parameters:
Name Type Description firstName
string Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setGender(gender) → {boolean}
-
Sets the gender of the user.
Parameters:
Name Type Description gender
ab.User.Genders Generally 'm' or 'f'. Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setHomeCity(homeCity) → {boolean}
-
Sets the home city for the user.
Parameters:
Name Type Description homeCity
string Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setLanguage(language) → {boolean}
-
Sets the language for this user. By default, the user's language is detected automatically from the browser. If you call this method, Braze will ignore the detected language and use the language you have provided instead.
Parameters:
Name Type Description language
string An ISO 639-1 Language Code. Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setLastKnownLocation(latitude, longitude, accuracy, altitude, altitudeAccuracy) → {boolean}
-
Sets the last known location for the user.
Parameters:
Name Type Argument Description latitude
float The latitude of the user's location in (valid values are between -90 to 90 degrees)
longitude
float The longitude of the user's location (valid values are between -180 to 180 degrees)
accuracy
float <optional>
The accuracy of the user's lat/long in meters.
altitude
float <optional>
The altitude of the user's location in meters above or below the WGS 84 reference ellipsoid.
altitudeAccuracy
float <optional>
The accuracy of the user's altitude in meters.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setLastName(lastName) → {boolean}
-
Sets the last name of the user.
Parameters:
Name Type Description lastName
string Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setPhoneNumber(phoneNumber) → {boolean}
-
Sets the phone number of the user.
Parameters:
Name Type Description phoneNumber
string A phone number is considered valid if it is no more than 255 characters in length and contains only numbers, whitespace, and the following special characters +.-() Accepts an explicit null value to null out attribute.
Returns:
Whether the update was successfully enqueued.
- Type
- boolean
-
setPushNotificationSubscriptionType(notificationSubscriptionType) → {boolean}
-
Sets whether the user should be sent push campaigns.
Parameters:
Name Type Description notificationSubscriptionType
ab.User.NotificationSubscriptionTypes Notification setting (explicitly opted-in, subscribed, or unsubscribed).
Returns:
Whether the update was successfully enqueued.
- Type
- boolean