User

Do not construct directly - use appboy.getUser to get the user object. User provides an object which lets you update the attributes stored by Braze for your user.

This class has been designed to provide fire and forget semantics and to not impact the performance or lifecycle of calling code. As such, changes made to an User are enqueued locally and flushed to Braze's servers asynchronously.

Hierarchy

  • User

Index

Properties

Static Genders

Genders: "m" | "f" | "o" | "u" | "n" | "p"

Enum to represent valid genders.

Static NotificationSubscriptionTypes

NotificationSubscriptionTypes: "opted_in" | "subscribed" | "unsubscribed"

Enum to represent notification status for email and push notifications.

Methods

addAlias

  • addAlias(alias: string, label: string): 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

    • 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 boolean

    Whether the update was successfully enqueued.

addToCustomAttributeArray

  • addToCustomAttributeArray(key: string, value: string): boolean
  • Adds a string to a custom attribute string array, or creates that array if one doesn't exist.

    Parameters

    • 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 boolean

    Whether the update was successfully enqueued.

addToSubscriptionGroup

  • addToSubscriptionGroup(subscriptionGroupId: string): boolean
  • Adds a user to an email or SMS subscription group.

    Parameters

    • subscriptionGroupId: string

      The unique identifier of the subscription group.

    Returns boolean

    Whether the update was successfully enqueued.

getUserId

  • getUserId(callback: (userId: string | null) => void): void
  • 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

    • callback: (userId: string | null) => void

      Asynchronous callback - this will be invoked with the userId.

        • (userId: string | null): void
        • Parameters

          • userId: string | null

          Returns void

    Returns void

incrementCustomUserAttribute

  • incrementCustomUserAttribute(key: string, incrementValue?: number): 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

    • 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.

    • Optional incrementValue: number

      Default 1. May be negative to decrement.

    Returns boolean

    Whether the update was successfully enqueued.

removeFromCustomAttributeArray

  • removeFromCustomAttributeArray(key: string, value: string): boolean
  • Removes a string from a custom attribute string array.

    Parameters

    • 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 begin with a $, and can only contain alphanumeric characters and punctuation.

    Returns boolean

    Whether the update was successfully enqueued.

removeFromSubscriptionGroup

  • removeFromSubscriptionGroup(subscriptionGroupId: string): boolean
  • Removes a user from an email or SMS subscription group.

    Parameters

    • subscriptionGroupId: string

      The unique identifier of the subscription group.

    Returns boolean

    Whether the update was successfully enqueued.

setAvatarImageUrl

  • setAvatarImageUrl(avatarImageUrl: string): 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

    • avatarImageUrl: string

    Returns boolean

    Whether the update was successfully enqueued.

setCountry

  • setCountry(country: string | null): boolean
  • Sets the country for the user.

    Parameters

    • country: string | null

      Limited to 255 characters in length. Accepts an explicit null value to null out attribute.

    Returns boolean

    Whether the update was successfully enqueued.

setCustomLocationAttribute

  • setCustomLocationAttribute(key: string, latitude: number | null, longitude: number | null): boolean
  • Sets a custom user location attribute.

    Parameters

    • 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: number | null

      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: number | null

      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 boolean

    Whether the update was successfully enqueued.

setCustomUserAttribute

  • setCustomUserAttribute(key: string, value: number | boolean | Date | string | string[] | null): boolean
  • Sets a custom user attribute. This can be any key/value pair and is used to collect extra information about the user.

    Parameters

    • 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: number | boolean | Date | string | string[] | null

      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 boolean

    Whether the update was successfully enqueued.

setDateOfBirth

  • setDateOfBirth(year: number | null, month: number | null, day: number | null): 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

    • year: number | null
    • month: number | null

      1-12

    • day: number | null

    Returns boolean

    Whether the update was successfully enqueued.

setEmail

  • setEmail(email: string | null): boolean
  • Sets the email address of the user.

    Parameters

    • email: string | null

      Must pass RFC-5322 email address validation. Accepts an explicit null value to null out attribute.

    Returns boolean

    Whether the update was successfully enqueued.

setEmailNotificationSubscriptionType

setFirstName

  • setFirstName(firstName: string | null): boolean
  • Sets the first name of the user.

    Parameters

    • firstName: string | null

      Limited to 255 characters in length. Accepts an explicit null value to null out attribute.

    Returns boolean

    Whether the update was successfully enqueued.

setGender

  • setGender(gender: Genders | null): boolean
  • Sets the gender of the user.

    Parameters

    • gender: Genders | null

      Generally 'm' or 'f'. Accepts an explicit null value to null out attribute. Use User.Genders enum when setting this value.

    Returns boolean

    Whether the update was successfully enqueued.

setHomeCity

  • setHomeCity(homeCity: string | null): boolean
  • Sets the home city for the user.

    Parameters

    • homeCity: string | null

      Limited to 255 characters in length. Accepts an explicit null value to null out attribute.

    Returns boolean

    Whether the update was successfully enqueued.

setLanguage

  • setLanguage(language: string | null): 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

    Returns boolean

    Whether the update was successfully enqueued.

setLastKnownLocation

  • setLastKnownLocation(latitude: number, longitude: number, accuracy?: number, altitude?: number, altitudeAccuracy?: number): boolean
  • Sets the last known location for the user.

    Parameters

    • latitude: number

      The latitude of the user's location in (valid values are between -90 to 90 degrees)

    • longitude: number

      The longitude of the user's location (valid values are between -180 to 180 degrees)

    • Optional accuracy: number

      The accuracy of the user's lat/long in meters.

    • Optional altitude: number

      The altitude of the user's location in meters above or below the WGS 84 reference ellipsoid.

    • Optional altitudeAccuracy: number

      The accuracy of the user's altitude in meters.

    Returns boolean

    Whether the update was successfully enqueued.

setLastName

  • setLastName(lastName: string | null): boolean
  • Sets the last name of the user.

    Parameters

    • lastName: string | null

      Limited to 255 characters in length. Accepts an explicit null value to null out attribute.

    Returns boolean

    Whether the update was successfully enqueued.

setPhoneNumber

  • setPhoneNumber(phoneNumber: string | null): boolean
  • Sets the phone number of the user.

    Parameters

    • phoneNumber: string | null

      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 boolean

    Whether the update was successfully enqueued.

setPushNotificationSubscriptionType