User data

tjuric edited this page Apr 13, 2018 · 43 revisions

You can provide additional user's data to the server, so that you will be able to send personalised targeted messages to exact user and have other nice features. Library supports a set of predefined attributes as well as custom ones.

Predefined user data

It is possible to set following user details as part of predefined user data:


The User Data API is strict about data types and formatting. It is not allowed to change the type of an existing custom user data attribute. It is also not allowed to provide invalid value format for some predefined attributes (i.e. email and MSISDN). Mobile Messaging SDK will report an appropriate error in case of data format violations and will not retry to save invalid user data on a server. However, it is the responsibility of the library to send your user's data to the server and you don't have to worry about retrying in case of network connectivity issues (i.e. connection problems, server errors etc.).

Updating predefined user data

In order to set values to multiple user's attributes you set the values and call the syncUserData(UserData) method:

Calendar calendar = Calendar.getInstance();
Date birthdate = new Date(calendar.getTimeInMillis());

UserData userData = new UserData();


Fetching user data from the server

User data can be fetched from the server. In this case library will contact the server and report what is currently saved for this user on the server.


The result of fetch operation will be returned via Event.USER_DATA_REPORTED event.

You can also receive the result of fetch operation by supplying a ResultListener.

MobileMessaging.getInstance(getActivity()).fetchUserData(new MobileMessaging.ResultListener<UserData>() {
    public void onResult(UserData userData) {

    public void onError(MobileMessagingError e) {

External user ID

You can use an external user ID to uniquely target your user. External user ID is meant to be an ID of a user in an external (non-Infobip) service. It can be any string and can be shared across different instances of your app, so that a user with multiple devices can still be targeted as a single user of your app.



Custom user data

It is possible to set custom parameters as part of user data. The custom parameters may be of following types:

In order to represent the custom attribute value, use CustomUserDataValue class, which wraps the aforementioned types. For example:

UserData userData = new UserData();
userData.setCustomUserDataElement("favouriteMeal", new CustomUserDataValue("pizza"));
userData.setCustomUserDataElement("bootSize", new CustomUserDataValue(9));
userData.setCustomUserDataElement("installationDate", new CustomUserDataValue(new Date()));


For getting single custom user data parameter use either:

String favoriteMeal = userData.getCustomUserDataValue("favoriteMeal").stringValue();
Integer bootSize = userData.getCustomUserDataValue("bootSize").numberValue().intValue();
Date installationDate = userData.getCustomUserDataValue("installationDate").dateValue();

Using custom user data for tagging and subscriptions

You can utilise this data to add support for tags:

Map<String, CustomUserDataValue> customDataMap = new HashMap<>();
CustomUserDataValue tagsValue = new CustomUserDataValue("tags");
customDataMap.put("funny", tagsValue);
customDataMap.put("cool", tagsValue);
customDataMap.put("interesting", tagsValue);

UserData userData = new UserData();


...and subscriptions:

Map<String, CustomUserDataValue> customDataMap = new HashMap<>();
CustomUserDataValue subscriptionsValue = new CustomUserDataValue("subscriptions");
customDataMap.put("technology", subscriptionsValue);
customDataMap.put("humour", subscriptionsValue);
customDataMap.put("gaming", subscriptionsValue);

UserData userData = new UserData();


With this data, you can segment users by using Segments and target them by their subscriptions:

Create a Segment

User data storage

By default, user data is stored on a device, so it can be available even when the device is offline. Also, we store unreported user data, so we can automatically retry sending it to our server. In order to change default behaviour and disable storing user data on device use withoutStoringUserData():

new MobileMessaging.Builder(application)

Note: when storing user data is disabled, automatic retries will not be applied. It should be handled manually using MobileMessaging.getInstance(context).syncUserData(userData, listener) method, where you can check error in callback and retry accordingly.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.