# Register a user

To register a user you can either send information about the user, or create a new anonymous user without providing any data. Usually you send information about a user when he's logging into the app or registering - that's when the user passes some data in forms - but before that you might want to create a new user just to gather information about user's events and screen views.

Registering anonymous user

To register anonymous user use ping() method - it will create a user if no attributes were set before.

  • Swift
  • Objective C
To initialize User.com SDK, you need to add the following line of code to the top of your AppDelegate.swift file:
UserSDK.default?.ping()

Set standard and custom attributes

You can add any number of custom customer attributes, or use predefined standard attributes

  • Swift
  • Objective C
UserSDK.default?.setUserData([
    UserSDK.UserDataKey.firstName : "Test",
    UserSDK.UserDataKey.lastName : "User",
    UserSDK.UserDataKey.email : "test@user.com",
    UserSDK.UserDataKey.phone : "+1222333444",
    UserSDK.UserDataKey.userId : "yourcustomerid"
])

UserSDK.default?.setCustomUserData([
    "custom attribute name" : "custom attribute value"
])

Logout

To logout and clear all user-related resources within SDK, invoke:

  • Swift
  • Objective C
UserSDK.default?.logout()