MoEngage Docs

Tracking User Attributes

User attributes are specific traits of a user, like an email, username, mobile, gender, etc. This information is helpful in order to target users based on these attributes across devices or installs.

User Login/Logout

It is important that you handle user login and logout as mentioned below. There is a definite chance that your data can get corrupted if not done properly.

Whenever your app can get hold of the unique id set for the user, pass that information to our SDK using the login method. We use the unique id information that you pass to our SDK, to identify a user. Once the user logs out of your app, It is necessary to call logout method of MoEngage, so that we track it as a new user. If you pass 2 different unique id information without calling logout method in between, older user information will be overwritten by the new user which is undesired.

Kindly make sure that you call the following methods on user login/logout.

Login

//UNIQUE_ID is used to uniquely identify a user.
MoEHelper.getInstance(applicationContext).setUniqueId(UNIQUE_ID)
//UNIQUE_ID is used to uniquely identify a user.
MoEHelper.getInstance(getApplicationContext()).setUniqueId(UNIQUE_ID);

❗️

In case you need to update unique-id please do not call the above method with the new unique id value. Refer to this document for more details.
Calling setUniqueId() with a new value will lead to creation of unintended users in our system.

Logout

Application needs to notify the MoEngage SDK whenever the user is logged out of the application. To notify the SDK call the below API whenever the user is logged out of the application.

MoEHelper.getInstance(applicationContext).logoutUser();
MoEHelper.getInstance(getApplicationContext()).logoutUser();

Note: In case the application is registering for push token it should pass the new push token to MoEngage SDK after user logout. Refer this link to know more about passing push token

❗️

UNIQUE ID chaos

Kindly make sure that you are not using a single unique id for all the users, this can happen if you hard code the value, instead of fetching it from your servers.

Tracking User Attributes

The SDK provides APIs to track commonly tracked user attributes like First Name, Last Name, Email-Id, etc. Please use the provided methods for tracking those attributes.

MoEHelper.getInstance(applicationContext).setFirstName()
MoEHelper.getInstance(applicationContext).setLastName()
MoEHelper.getInstance(applicationContext).setFullName()
MoEHelper.getInstance(applicationContext).setUserLocation()
MoEHelper.getInstance(applicationContext).setGender()
MoEHelper.getInstance(applicationContext).setNumber()
MoEHelper.getInstance(applicationContext).setBirthDate()
MoEHelper.getInstance(applicationContext).setEmail()
MoEHelper.getInstance(getApplicationContenxt()).setFirstName();
MoEHelper.getInstance(getApplicationContenxt()).setLastName()
MoEHelper.getInstance(getApplicationContenxt()).setFullName()
MoEHelper.getInstance(getApplicationContenxt()).setUserLocation()
MoEHelper.getInstance(getApplicationContenxt()).setGender()
MoEHelper.getInstance(getApplicationContenxt()).setNumber()
MoEHelper.getInstance(getApplicationContext()).setBirthDate()
MoEHelper.getInstance(getApplicationContext()).setEmail()

For setting other User Attributes you can use generic method setUserAttribute(key,value)

// Tracking a String Attribute
MoEHelper.getInstance(getApplicationContenxt()).setUserAttribute("locality", "SF");
// Tracking a Date Attribute
MoEHelper.getInstance(mCurrentContext).setUserAttribute("signedUpOn", new Date());
// Tracking a location attribute
MoEHelper.getInstance(mCurrentContext).setUserAttribute("lastLocation", new GeoLocation(40.77, 73.98));

Date attributes can be passes as Date objects or

🚧

User Attributes names have following restrictions

  1. Name should not contain dot(.)
  2. Name should not start with dollar sign($)

Below are set of the reserved keywords which are used by the SDK and should not be used to tracking user attributes.

📘

Reserved keywords

USER_ATTRIBUTE_UNIQUE_ID
USER_ATTRIBUTE_USER_EMAIL
USER_ATTRIBUTE_USER_MOBILE
USER_ATTRIBUTE_USER_NAME
USER_ATTRIBUTE_USER_GENDER
USER_ATTRIBUTE_USER_FIRST_NAME
USER_ATTRIBUTE_USER_LAST_NAME
USER_ATTRIBUTE_USER_BDAY
MOE_TIME_FORMAT
MOE_TIME_TIMEZONE
USER_ATTRIBUTE_NOTIFICATION_PREF
USER_ATTRIBUTE_OLD_ID
MOE_TIME_FORMAT
MOE_TIME_TIMEZONE
USER_ATTRIBUTE_DND_START_TIME
USER_ATTRIBUTE_DND_END_TIME
MOE_GAID
MOE_ISLAT
status

Updated 28 days ago


What's Next

Tracking Events

Tracking User Attributes


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.