MoEngage Docs

Tracking User Attributes

User attributes are specific traits of a user, like email, username, mobile, gender etc.
This information is helpful in order to targeting 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(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

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

Alternatively, one can use the helper methods for the same as shown in the sample below.

Note : These helper methods are available only from SDK version 7.0.00 and above

public class MainActivity extends AppCompatActivity {

	protected MoEHelper helper = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		helper = MoEHelper.getInstance(this);
		setUserAttribute();
	}

	private void setUserAttribute(){
		// Helper method to set User uniqueId. Can be String,int,long,float,double
		helper.setUniqueId("abc@moengage.com");
    // If you have first and last name separately
		helper.setFirstName("Aaron");
		helper.setLastName("Finch");
    // If you have full name
		helper.setFullName("Aaron Finch");
		helper.setBirthDate("01/01/1990");
		helper.setUserLocation(40.77,73.98);
		helper.setEmail("abc@moengage.com");
		helper.setGender("Male");
		//Helper method to set mobile number
		helper.setNumber("12345612345");
	}
}

For setting other User Attributes you can use generic method setUserAttribute(key,value)
Date user attribute values need to be passed as date or pass the format to the setUserAttribute method.

To set a custom user attribute locality as SF use the following code

MoEHelper.getInstance(mCurrentContext).setUserAttribute("locality", "SF");
MoEHelper.getInstance(mCurrentContext).setUserAttribute("signedUpOn", new Date());

User Attributes names have following restrictions

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

Tracking User Location

For tracking location as an attribute

MoEHelper.getInstance(mCurrentContext).setUserAttribute("lastSeen", new GeoLocation(40.77, 73.98));

Below are some of the reserved keywords which should be used to track things like first name, last name, gender, etc

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


What's Next

Track Event