Skip to main content

Identifying Users

You can identify users using the Nudge.getInstance().userIdentifier() method provided by our SDK. This method requires a unique identifier for your user.

You can send user properties to Nudge by passing properties inside a props object.

note

To see the name, email, and phone number of the user in Nudge's dashboard, make sure to pass these properties outside the props object.

var userProps: [String: Any] = [
"age": 50, // Int
"rate": 5.75, //Float
"status": "active", //String
"hasSubscribed":false //Boolean
]

// User Props can have String, Int, Float and Boolean

Nudge.getInstance().userIdentifier(
externalId: "unique_id_for_user", //String (Required)
name = "User Name", //String? (Optional)
email = "[email protected]", //String? (Optional)
phoneNumber = "9999999999" //String? (Optional)
properties: userProps, //[String: Any]? (Optional)
referralCode: String?, //String? (Optional)
completion: (Result<String, any Error>) -> Void
)

The completion handler is optional but, if provided, it will be called once the user identification process is complete. The Result type will return:

  • A String, containing the externalId on success.
  • An Error if something goes wrong during the process.
warning

Event name, event properties, and user properties all follow this regex : ^[a-z][a-z0-9_]99$

  • Only small alphabets, numbers and underscore (_) are allowed
  • Name cannot start with number, it needs to start with an alphabet only
  • The name should be between 2 and 99 characters in length
  • If any capital letter is sent, it will be converted to small case

Signing out users

Once the user signs out from your application, use the Nudge.getInstance.userSignOut method provided by Nudge to clear any cached data for that user.


Nudge.getInstance().userSignout { result in
switch result {
case .success(let success):
if success {
print("User signed out successfully.")
}
case .failure(let error):
print("Error signing out user: \(error)")
}
}