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.
DEFAULT & PREDEFINED USER ATTRIBUTESWe 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
You must handle user login and logout as mentioned below. There is a definite possibility that your data will get corrupted if this is not done properly.
- Make sure to get hold of a
unique idfor your app users and pass that information to our SDK using the
setUniqueID:method. We use this
unique idto 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
resetUsermethod 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.
MOAnalytics.sharedInstance.setUniqueID(UNIQUE_ID) // UNIQUE_ID is used to uniquely identify a user.
[[MOAnalytics sharedInstance] setUniqueID:UNIQUE_ID]; // UNIQUE_ID is used to uniquely identify a user.
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"
UNIQUE ID chaos
[[MOAnalytics sharedInstance] resetUser];
Updating User Attribute Unique ID
IMPORTANTPlease 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:
[[MOAnalytics sharedInstance] setAlias:UPDATED_UNIQUE_ID];
Default User Attributes
Some default SDK User Attribute 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 :
MOAnalytics.sharedInstance.setName(userName) MOAnalytics.sharedInstance.setLastName(userLastname) MOAnalytics.sharedInstance.setFirstName(userFirstName) MOAnalytics.sharedInstance.setEmailID(userEmailID) MOAnalytics.sharedInstance.setMobileNumber(userPhoneNo) MOAnalytics.sharedInstance.setGender(.male) //Use UserGender enumerator for this MOAnalytics.sharedInstance.setDateOfBirth(userBirthdate)//userBirthdate should be a Date instance MOAnalytics.sharedInstance.setLocation(MOGeoLocation(withLatitude: userLocationLat, andLongitude: userLocationLng)) //userLocationLat and userLocationLng are double values of the location coordinates
[[MOAnalytics sharedInstance] setName:userName]; [[MOAnalytics sharedInstance] setLastName:userLastname]; [[MOAnalytics sharedInstance] setFirstName:userFirstName]; [[MOAnalytics sharedInstance] setEmailID:userEmailID]; [[MOAnalytics sharedInstance] setMobileNumber:userPhoneNo]; [[MOAnalytics sharedInstance] setGender:UserGenderMale]; // Use UserGender enumerator for this [[MOAnalytics sharedInstance] setDateOfBirth:userBirthdate];//userBirthdate should be a NSDate instance [[MOAnalytics sharedInstance] setLocation:[[MOGeoLocation alloc] initWithLatitude:userLocationLat andLongitude:userLocationLng]];//userLocationLat and userLocationLng are double values of the location coordinates
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 :
MOAnalytics.sharedInstance.setUserAttribute("Bengaluru", withAttributeName: "Current_city")
[[MOAnalytics sharedInstance] setUserAttribute:@"Bengaluru" withAttributeName:@"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 a user attributes. For this refer to the methods in the code block below:
//1. Track UserAttribute using Date instance MOAnalytics.sharedInstance.setUserAttributeDate(Date(), withAttributeName: "Date Attr 1") //2. Track UserAttribute using ISO Date String in format "yyyy-MM-dd'T'HH:mm:ss'Z'" MOAnalytics.sharedInstance.setUserAttributeISODate("2020-01-12T18:45:59Z", withAttributeName: "Date Attr 2") //3. Track UserAttribute using Epoch value MOAnalytics.sharedInstance.setUserAttributeEpochTime(663333, withAttributeName: "Date Attr 3")
//1. Track UserAttribute using Date instance [[MOAnalytics sharedInstance] setUserAttributeDate:[NSDate date] withAttributeName:@"DateAttr1"]; //2. Track UserAttribute using ISO Date String in format "yyyy-MM-dd'T'HH:mm:ss'Z'" [[MOAnalytics sharedInstance] setUserAttributeISODate:@"2020-01-12T18:45:59Z" withAttributeName:@"DateAttr2"]; //3. Track UserAttribute using Epoch value double timestampEpochValue = [[NSDate date] timeIntervalSince1970]; [[MOAnalytics sharedInstance] setUserAttributeEpochTime:timestampEpochValue withAttributeName:@"LastPurchaseDate"];
Location of a user or any location can be set as a user attribute. For this use
setLocation:forKey: method and pass lat, the long value of the location as shown in the following example :
MOAnalytics.sharedInstance.setLocation(MOGeoLocation.init(withLatitude: 72.90909, andLongitude: 12.34567), withAttributeName: "attribute name")
[[MOAnalytics sharedInstance] setLocation:[[MOGeoLocation alloc] initWithLatitude:23.33 andLongitude:26.22] withAttributeName:@"attribute name"];
Tracking User Locale
For tracking the locale settings of the user device use
trackLocale method as shown below:
[[MOAnalytics sharedInstance] trackLocale];