This information is helpful in order to targeting users based on these attributes across devices or installs.
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.
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.
UNIQUE ID chaos
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.
If you pass 2 different unique id information without calling
resetUser
method in between, the SDK will internally force logout the existing user.
Logout
MoEngage.sharedInstance().resetUser()
[[MoEngage sharedInstance] resetUser];
IMPORTANT :
Please make sure that you use
setAlias:
for updating the User Attribute Unique ID and notsetUserUniqueID:
as callingsetUserUniqueID:
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 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];
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 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
️ NOTE:
We support strings and numbers as values for UserAttributes . NSURL is not supported. If you wish to use it, please convert them to string.
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 :
Date and time attributes can be set as a user attribute. For this refer 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 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(12.98798, longitude: 34.98789, forKey:"location_attribute_name")
[[MoEngage sharedInstance] setUserAttributeLocationLatitude:13.23 longitude:23.43 forKey:@"attribute name"];
For tracking the locale settings of the user device use trackLocale
method as shown below:
MoEngage.sharedInstance().trackLocale()
[[MoEngage sharedInstance] trackLocale];
Updated 8 months ago