Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Tracking users

All user related APIs are part of WebEngage Android SDK's User object. You get an instance of WebEngage User object as follows.

// import WebEngage 'User'
import com.webengage.sdk.android.User;

// Get an instance of 'User' object
User weUser = WebEngage.get().user();

Identifying users

WebEngage SDK automatically creates a unique ID (LUID) which the WebEngage backend uses to uniquely identify users. These are “anonymous” profiles to which you can assign unique User IDs (CUID). Assigning a CUID helps collect the user's activity and information across systems in a single unified profile.

A user profile's ID once assigned, cannot be changed. Although ID can be any String that uniquely identifies users in your system, we recommend using system generated user IDs from your database instead of information that can change over time such as email addresses, usernames or phone numbers.

The usual places to assign IDs are

  • On user signups
  • On user logins
  • On screen or page views where user identity becomes known
  • When the user context changes

Constraint:

  • An ID can be of maximum 100 characters.

You can assign an ID by calling the login method. All attributes, events and session information accumulated before this API has been called get associated to an anonymous user created by default. Once login is called, all of this stored information is attributed to this identified user.

weUser.login("9SBOkLVMWvPX");

Make sure you call login as soon as the user logs in to your application, or whenever earliest you are able to identify the user.

weUser.logout();

Make sure you call logout when the logged-in user logs out, or you do not want to attach any future event, session or user data with this user, until login is called again.

User attributes

There is often additional identifying information, such as name and email address, associated with user profiles. WebEngage provides setters for assigning these attributes to users. These attributes can be used to segment users and target campaigns to a specific group. Additionally, they can be referred to personalize campaign messages to each user.

Attributes can be set on “anonymous” profiles as well.

Each session has its own user attributes, but they get copied from one session to the next. This is in contrast to event parameters, which may take on different values per event. For this reason, you generally use user attributes for things that do not change much within the session, or with which you want the entire session associated.

Setting system attributes

Constraint:

  • String type attribute values must be less than 1000 characters long. Any characters beyond that will be truncated.

Email

weUser.setEmail("john@doe.com");

Hashed Email

If you are averse to passing your users' personally identifiable information, WebEngage enables you to pass hashed email IDs and to set up private Email Service Provider API endpoints at your end.

weUser.setHashedEmail("144e0424883546e07dcd727057fd3b62");

Birth Date with year, month and day as Integer objects

//Deprecated. Use weUser.setBirthDate(String birthDate) instead.
weUser.setBirthDate(1996, 8, 19); // Month is index 1 based: January = 1

Birth Date in yyyy-mm-dd format

weUser.setBirthDate("1986-08-19"); //yyyy-mm-dd

Phone Number

If you are averse to passing your users' personally identifiable information, WebEngage enables you to pass hashed phone numbers and to set up private SMS Service Provider API endpoints at your end.

weUser.setPhoneNumber("+551155256325");

The String phoneNumber must be in E.164 format, eg. +551155256325, +917850009678.

Hashed Phone Number

weUser.setHashedPhoneNumber("e0ec043b3f9e198ec09041687e4d4e8d");

Gender

weUser.setGender(Gender.MALE);

First Name

weUser.setFirstName("John");

Last Name

weUser.setLastName("Doe");

Company

weUser.setCompany("Alphabet Inc.");

Opt In Status

To set the subscription preference of your users (for Push, In-app, SMS and Email) use setOptIn. Users who are opted out of a particular channel will not receive any communication on that channel. Users are by default opted in to all channels.

weUser.setOptIn(Channel.PUSH, true);

Channel is an enum and can have four values: PUSH, IN_APP, SMS, EMAIL. Setting setOptIn to false for a particular channel opts the user out of that channel.

In addition to these individual setters, you can also set the user profile in one go using Java builder pattern.

weUser.setUserProfile(new UserProfile.Builder()
				.setFirstName("John")
				.setLastName("Doe")
				.setEmail("john@doe.com")
				.setBirthDate("1986-08-19")
				.setPhoneNumber("+551155256325")
				.setGender(Gender.MALE)
				.setCompany("Alphabet Inc.")
				.build());

Setting custom attributes

Use these APIs to attach custom attributes to the user. These Java data types are allowed for below APIs: String, Integer, Long, Double, Boolean, Date, List, Map. List can contain one of these data types.

Constraints:

  • Attribute names must be less than 50 characters long. String type attribute values must be less than 1000 characters long. Any characters beyond that will be truncated.
  • In addition to the system attributes, you can create at most 25 user attributes of each data type.
  • You cannot start your attribute names with we_.
  • If attribute value is List or Map, it cannot be used to create user segments. It can only be used to personalize campaigns.

String attribute

weUser.setAttribute("Twitter username", "@origjohndoe86");

Boolean attribute

weUser.setAttribute("Subscribed to email", true);

Long attribute

weUser.setAttribute("Points earned", 78732);

Double attribute

weUser.setAttribute("Dollars spent", 461.93);

Integer attribute

weUser.setAttribute("Age", 31);

Date attribute

String dateStr = "2017-10-06T09:27:37Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
    Date date = format.parse(dateStr);
    weUser.setAttribute("Last order date", date);
} catch (ParseException e) {
    e.printStackTrace();
}

List attribute

The List values must not contain any data type other than ones specified above.

weUser.setAttribute("Brand affinity", Arrays.asList("Hugo Boss", "Armani Exchange", "GAS", "Brooks Brothers"));

1. User attribute names are case sensitive.
2. attributeName must not start with we_. Attribute names starting with we_ are reserved for WebEngage's internal use, and will be ignored if used for custom attributes.
3. For custom user attributes, the first datapoint synced to WebEngage defines the data type for that attribute in WebEngage. Therefore, data types must be consistent with the data that you want to store for the attribute. If you change the data type later, attribute data will stop flowing to WebEngage.

You can define multiple user attributes in one go using Map. The keys of this Map will be attribute names and values will be respective attribute values. These attribute values must be one of the above specified data types or Map.

Map<String, Object> customAttributes = new HashMap<>();
        customAttributes.put("Age", 31);
        customAttributes.put("Twitter username", "@origjohndoe86";
        customAttributes.put("Subscribed to email", true);
        customAttributes.put("Dollars spent", 461.93);
        customAttributes.put("Points earned", 78732);
        customAttributes.put("Brand affinity", Arrays.asList("Hugo Boss", "Armani Exchange", "GAS", "Brooks Brothers"));

Deleting Custom User Attributes

WebEngage allows you to delete any custom attributes that you had created previously if you no longer need them.

weUser.deleteAttribute("Points earned");
weUser.deleteAttributes(Arrays.asList("Twitter username", "Subscribed to email", "Points earned"));

What's Next

Tracking events

Tracking users