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 possibility that your data gets corrupted if this is 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 setUserUniqueID: 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 resetUser 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.


[[MoEngage sharedInstance] setUserUniqueID:UNIQUE_ID]; // UNIQUE_ID is used to uniquely identify a user.
MoEngage.sharedInstance().setUserUniqueID(UNIQUE_ID) // UNIQUE_ID is used to uniquely identify a user.


  • When you go live with MoEngage iOS SDK for the first time, please ensure that you are setting the Unique ID of already logged in user along with other user attributes.

  • 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.


[[MoEngage sharedInstance] resetUser];

Updating User Attribute Unique ID


Please make sure that you use setAlias: for updating the User Attribute Unique ID and not setUserUniqueID: as calling setUserUniqueID: with a new value will reset the current user and lead to creation of unintended users in our system.

In a scenario where you have to update the User Attribute Unique ID value for a logged in user use setAlias: method as shown below:

[[MoEngage sharedInstance] setAlias:UPDATED_UNIQUE_ID];

Default User Attributes

There are few default SDK User Attribute which you can set for eg. email-id, mobile number, gender, user name, brithday. The default attributes tracked by SDK can be set as shown below :

[[MoEngage sharedInstance] setUserName:userName];
[[MoEngage sharedInstance] setUserLastName:userLastname];
[[MoEngage sharedInstance] setUserFirstName:userFirstName];
[[MoEngage sharedInstance] setUserEmailID:userEmailID];
[[MoEngage sharedInstance] setUserMobileNo:userPhoneNo];
[[MoEngage sharedInstance] setUserGender:MALE]; // Use UserGender enumerator for this 
[[MoEngage sharedInstance] setUserDateOfBirth:userBirthdate];//userBirthdate should be a NSDate instance
[[MoEngage sharedInstance] setUserLocationLatitude:userLocationLat andLongitude:userLocationLng]; //userLocationLat and userLocationLng are double values of the location coordinates
MoEngage.sharedInstance().setUserGender(MALE) //Use UserGender enumerator for this
MoEngage.sharedInstance().setUserDateOfBirth(userBirthdate)//userBirthdate should be a Date instance
MoEngage.sharedInstance().setUserLocationLatitude(userLocationLat, andLongitude: userLocationLng) //userLocationLat and userLocationLng are double values of the location coordinates

For SDK versions 3.2.2 and below the default attributes can be set using constants defined in MoEHelperConstants as mentioned below:

USER_ATTRIBUTE_USER_NAME   # incase you have full name
USER_ATTRIBUTE_USER_FIRST_NAME # incase you have first and last name separately
GENDER_MALE = "male";
GENDER_FEMALE = "female";

Below is an example of setting email id for a user using the constants mentioned above :

[[MoEngage sharedInstance]setUserAttribute:userEmailID forKey:USER_ATTRIBUTE_USER_EMAIL];
MoEngage.sharedInstance().setUserAttribute(userEmailID, forKey:USER_ATTRIBUTE_USER_EMAIL)


  • We support strings and numbers as values for UserAttributes . NSURL is not supported. If you wish to use it, please convert them to string.

Custom User Attributes

To set custom attributes just provide custom keys different to the ones present in MoEHelperConstants. Following is an example :

[[MoEngage sharedInstance]setUserAttribute:@"Bengaluru" forKey:@"Current_City"];
MoEngage.sharedInstance().setUserAttribute("Bengaluru", forKey: "Current_City")

User Attributes have following restrictions :

  • User Attribute Names should not contain dot(.)
  • User Attribute Names should not start with dollar sign($)
  • User Attribute Values should be a String or Number

Date and Time User Attributes

Date and time attributes can be set as an user attribute. For this use setUserAttributeTimestamp:forKey: method and pass the timestamp in epoch time format. For eg. If you want to track when a user had made his last purchase in the app, you can do it as shown below :

double timestampEpochValue = [[NSDate date] timeIntervalSince1970];
[[MoEngage sharedInstance] setUserAttributeTimestamp:timestampEpochValue forKey:@"LastPurchaseDate"];
MoEngage.sharedInstance().setUserAttributeTimestamp(NSDate().timeIntervalSince1970, forKey:"LastPurchaseDate")

Location Attributes

Location of a user or any location can be set as an user attribute. For this use setUserAttributeLocationLatitude:longitude:forKey: method and pass lat, long value of the location as shown in the following example :

[[MoEngage sharedInstance] setUserAttributeLocationLatitude:13.23 longitude:23.43 forKey:@"attribute name"];
MoEngage.sharedInstance().setUserAttributeLocationLatitude(12.98798, longitude: 34.98789, forKey:"location_attribute_name")

Tracking User Locale

For tracking the locale settings of the user device use trackLocale method as shown below:

[[MoEngage sharedInstance] trackLocale];

What's Next

Next we will see how to track events to know user's behaviour in the app.

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.