User attributes are specific traits of a user such as an email, username, mobile, gender, and so on. User Attributes help target users based on these attributes across devices or installs or to personalize the messages.
User Login and 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.
Ensure that you have the unique id for your app users and pass that information to MoEngage SDK using the setUniqueId(). The unique id is used to identify a user across installs and platforms and provide a unified view. After the user logs out of your app, it is necessary to call logout() so that we create a new user.
Ensure that you call the following methods on user log in or log out.
Login
var moe = MoECordova.init(YOUR_Workspace_ID);
moe.setUniqueId(uniqueID);
info |
Note The following values are not allowed in the UniqueID field: "unknown", "guest", "null", "0", "1", "true", "false", "user_attribute_unique_id", "(empty)", "na", "n/a", "", "dummy_seller_code", "user_id", "id", "customer_id", "uid", "userid", "none", "-2", "-1", "2" |
Logout
The application needs to notify the MoEngage SDK whenever the user is logged out of the application. To notify the SDK, call the API whenever the user is logged out of the application.
var moe = MoECordova.init(YOUR_Workspace_ID);
moe.logout();
info |
Note To clear out the existing user's data and identity, call the logout method. This will clear the data for the current user and create a new one, when you re-login as explained in the above log-in scenario your user will be merged (if already exist in our system) |
Updating User Attribute Unique ID
In a scenario where you have to update the User Attribute Unique ID value for a logged-in user use setAlias() as shown below:
var moe = MoECordova.init(YOUR_Workspace_ID);
moe.setAlias("updatedUniqueID");
warning |
Warning Please make sure that you use setAlias() for updating the User Attribute Unique ID and not setUserAttribute() with USER_ATTRIBUTE_UNIQUE_ID attribute and a new value, as this will reset the current user and lead to the creation of unintended users in our system. |
SDK User Attributes Keys
You can also set the default user attributes like mobile number, gender, user name, birthday, location, etc using the below APIs
var moe = MoECordova.init(YOUR_Workspace_ID);
moe.setUserName("abc");
moe.setFirstName("abc");
moe.setLastName("xyz");
moe.setEmail("abc@xyz.com");
moe.setPhoneNumber(1234567890);
moe.setGender("Male"); // OR Female
moe.setLocation(25.23, 73.23);
// Format - ISO-8601 String
moe.setBirthdate("1970-01-01T12:00:00Z");
For setting custom user attributes, use the method setUserAttribute(key, value).
var moe = new MoECordova.init(YOUR_Workspace_ID);
moe.setUserAttribute("<attribute_name>", "<attribute_value>");
Date attributes and Birthday in ISO-8601 format - yyyy-MM-dd'T'HH:mm:ss'Z'
var moe = MoECordova.init(YOUR_Workspace_ID);
moe.setUserAttributeLocation("attribute", 25.23, 73.23);
You can use the following method set the timestamp user attribute :
var moe = MoECordova.init(YOUR_Workspace_ID);
moe.setUserAttributeISODateString("LastPurchaseDate", "1970-01-01T12:00:00Z");
info |
Note You can not use "moe_" as a prefix while naming events, event attributes, or user attributes. It is a system prefix and using it might result in periodic blacklisting without prior communication. |
Reserved keywords for User Attributes
Below is the list of keys that should not be used when tracking user attributes.
- 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