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.
info |
Default Predefined User Attributes We track certain user attributes by default in our SDK, and also we have predefined attribute names for certain common user info tracked by these SDK methods. Make sure to use these and not track the same info with the different attribute names. Find the list of default and predefined user attributes tracked by SDK here. |
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.
Make sure to get hold of a unique id
for your app users and pass that information to our SDK using the setUserUniqueID:
method. We use this unique id
to identify a user and also to merge user profiles across installs and platforms.
And also, once the user logs out of your app, it is necessary to call resetUser
method of SDK so that we create a new anonymous user and track the events following this to the new user's profile.
Kindly make sure that you call the following methods on user login/logout.
Login
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.
warning |
UNIQUE ID chaos
|
Logout
MoEngage.sharedInstance().resetUser()
[[MoEngage sharedInstance] resetUser];
Updating User Attribute Unique ID
warning |
Important Please make sure that you use |
In a scenario where you have to update the existing user's Unique ID value make use of setAlias:
method as shown below with the updated Unique ID value:
MoEngage.sharedInstance().setAlias(UPDATED_UNIQUE_ID)
[[MoEngage sharedInstance] setAlias:UPDATED_UNIQUE_ID];
Default User Attributes
Some default SDK User Attributes can be set for eg. email-id, mobile number, gender, user name, birthday. 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 Date instance
MoEngage.sharedInstance().setUserLocationLatitude(userLocationLat, andLongitude: userLocationLng) //userLocationLat and userLocationLng are double values of the location coordinates
[[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
warning |
Important We support strings and numbers as values for UserAttributes . NSURL is not supported. If you wish to use it, please convert them to string. User Phone No / Mobile Number must be tracked as a string to work properly in MoEngage systems. |
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 the 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 user attributes. For this refer to the methods in the code block below:
//1. Track UserAttribute using Date instance
MoEngage.sharedInstance().setUserAttributeDate(Date(), forKey: "DateAttr1")
//2. Track UserAttribute using ISO Date String in format "yyyy-MM-dd'T'HH:mm:ss'Z'"
MoEngage.sharedInstance().setUserAttributeISODateString("2020-01-12T18:45:59Z", forKey: "DateAttr2")
//3. Track UserAttribute using Epoch value
MoEngage.sharedInstance().setUserAttributeTimestamp(NSDate().timeIntervalSince1970, forKey:"DateAttr3")
double timestampEpochValue = [[NSDate date] timeIntervalSince1970];
[[MoEngage sharedInstance] setUserAttributeTimestamp:timestampEpochValue forKey:@"LastPurchaseDate"];
Location Attributes
The location of a user or any location can be set as a user attribute. For this use setUserAttributeLocationLatitude:longitude:forKey:
method and pass lat, the long value of the location as shown in the following example :
MoEngage.sharedInstance().setUserAttributeLocationLatitude(12.98798, longitude: 34.98789, forKey:"location_attribute_name")
[[MoEngage sharedInstance] setUserAttributeLocationLatitude:13.23 longitude:23.43 forKey:@"attribute name"];
Tracking User Locale
For tracking the locale settings of the user device, use trackLocale
method as shown below:
MoEngage.sharedInstance().trackLocale()
[[MoEngage sharedInstance] trackLocale];