Set User Attributes in Android

Learn how to set user attributes on Android

User attributes, also referred to as profile properties and custom properties, are a set of key/value pairs that are specific to your application domain.

The system stores these key/value pairs under the properties field of an appUser. The attributes may have values of type Number, String, or Boolean.

The system limits user attributes to 4KB per user -- each key limited to 100B and each value limited to 800B. Exceeding characters are truncated. The system returns an error if an appUser the sum of all custom attributes exceeds the 4KB limit while an appUser is in the process of being created or updated.

We strongly recommend setting user attributes on your app user as directly after login. Any properties set prior to login are set to an anonymous entity and are then merged after the login has occured. This merging may introduce undesired results.

Key attributes to set include first name, last name, and email address.

Attributes are listed under userProperties and then to SMMuser.current() after they have been defined. In our example, we've laid out our recommended order and method of introducing these attributes.

       UserCredUtils.generateJwt(this, userId, loginName, ""),
       new BrandMessengerCallback() {
           public void run(Response response) {
               User user = User.getCurrentUser();
               // Identify user with default properties
               user.setSignedUpAt(new Date(1420070400000l));

               Map<String, Object> userProperties = new HashMap<>();
               userProperties.put("scope", "appUser");
               userProperties.put("platform", "android");
               userProperties.put("email", user.getEmail());
               userProperties.put("kh_prop_1", "prop1");

Metadata needs to also be defined in Metadata Visibility. You can find this within the Admin by navigating to Khoros Response > Admin and selecting Metadata Visibility in the sidebar.


Then, simply scroll down to the Display Fields in Author Profile and add Brand Messenger if it's not already present. You can then define Metadata Fields and the display name they will appear within the conversation in Agent view.

Update Attributes Mid-session

In the event that user attributes need updating during a session, it can be achieved at anytime using the example below. We recommend only doing this after a login and first attribute set has occurred.

Map<String, Object> userProperties = new HashMap<>();
userProperties.put("kh_prop_2", "prop2");