Skip to main content

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 setUniqueID(_:) [Link]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() [Link]of SDK so that we create a new anonymous user and track the events following this to the new user’s profile.
Kindly ensure you call the following methods on user login/logout.

Login

MoEngageSDKAnalytics.sharedInstance.setUniqueID(UNIQUE_ID) // UNIQUE_ID is used to uniquely identify a user.
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
  • When you go live with MoEngage iOS SDK for the first time, please ensure that you are setting the Unique ID of the 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

MoEngageSDKAnalytics.sharedInstance.resetUser()

Updating User Attribute Unique ID

ImportantPlease make sure that you use setAlias(_:)[Link] for updating the User Attribute Unique ID and not setUniqueID(_:) [Link]as calling setUniqueID(_:) [Link]with a new value will reset the current user and lead to the 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(_:) [Link]method as shown below with the updated Unique ID value:
MoEngageSDKAnalytics.sharedInstance.setAlias(UPDATED_UNIQUE_ID)