As people use your mobile apps, you'll likely want to save data and events to their Iterable user profiles. Your marketing team can then use this data to send relevant, personalized messages.
Before you can save data, you'll need to identify the user it belongs to. This guide describes how to do so.
# In this article
# Identifying users by user ID
To identify a user by the userId field, call the static setUserId method on
the Iterable class.
-
Method declaration:
static setUserId(userId: string | undefined) static setUserId(userId: string | undefined, authToken?: string | undefined)
Parameter Name Description userIdThe user ID to associate with the current user. authTokenA valid, pre-fetched JWT the SDK can use to authenticate API requests for this user. -
Description:
These methods associate the current user with the specified
userId. If your Iterable project doesn't yet have a user with thatuserId,setUserIdcreates one.They also add a placeholder
emailaddress to the user's Iterable profile, in the form:userId+ hash +@placeholder.email(email-based projects only). To learn more, read Handling Anonymous Users.NOTES
- Specify an
emailor auserId, but not both. - Iterable's React Native SDK persists a
userIdoremailacross app sessions and restarts, until you manually change it. - Assuming
IterableConfig.autoPushRegistrationistrue(its default value), setting auserIdoremailautomatically registers the device for push notifications and sends thedeviceIdandtokento Iterable. - Use the
authTokenparameter to pass in a pre-fetched JWT, as needed, to avoid race conditions.
- Specify an
-
Example:
Iterable.setUserId("testUser123");
This example associates the app's current user with a
userIdoftestUser123. The placeholder email it creates would look something liketestUser123+1033671565@placeholder.email.
# Identifying users by email
To identify a user by their email address, call the static setEmail method
on the Iterable class:
-
Method declaration:
static setEmail(email: string | undefined) static setEmail(email: string | undefined, authToken?: string | undefined)
Parameter Name Description emailThe email address to associate with the current user. authTokenA valid, pre-fetched JWT the SDK can use to authenticate API requests for this user. -
Description:
These methods associates the current user with the specified
email. If your Iterable project doesn't yet have a user profile with thatemail,setEmailcreates one.NOTES
- Specify an
emailor auserId, but not both. - Iterable's React Native SDK persists a
userIdoremailacross app sessions and restarts, until you manually change it. - Assuming
IterableConfig.autoPushRegistrationistrue(its default value), setting auserIdoremailautomatically registers the device for push notifications and sends thedeviceIdandtokento Iterable. - Use the
authTokenparameter to pass in a pre-fetched JWT, as needed, to avoid race conditions.
- Specify an
-
Example:
Iterable.setEmail("user@example.com");
This example associates the app's current user with an
emailofuser@example.com.
# Getting the current userId
To get the userId your app associates with the current user, call the static
getUserId method on the Iterable class.
-
Method declaration:
static getUserId(): Promise<string | undefined>
-
Description:
Returns the
userIdyour app associates with its current user. -
Example:
Iterable.getUserId().then(userId => { console.log("Current userId: " + userId); });
This example fetches the current
userIdand outputs it to the console.
# Getting the current email
To get the email associated with the current user, call the static getEmail
method on the Iterable class.
-
Method declaration:
static getEmail(): Promise<string | undefined>
-
Description:
Returns the
emailyour app associates with its current user. -
Example:
Iterable.getEmail().then(email => { console.log("Current email: " + email); });
This example fetches the current
emailand outputs it to the console.
# Modifying an email address
To modify a user's email address, or to give a real (non-placeholder) email
address to a user identified by userId, call the static updateEmail method on
the Iterable class.
-
Method declaration:
static updateEmail(email: string, authToken?: string | undefined)
Parameter Name Description emailThe new email address to associate with the current user. authTokenA valid, pre-fetched JWT the SDK can use to authenticate API requests for this user. -
Description:
This method changes the value of the
emailfield on the current user's Iterable profile. -
Example:
Iterable.updateEmail("newEmail@example.com")
This example changes the current user's
emailtonewEmail@example.com.
# Signing out
To tell the SDK that the current user has signed out, set email or userId
(whichever is currently set) to null:
Iterable.setEmail(null)
Iterable.setUserId(null)
Assuming IterableConfig.autoPushRegistration is true (its default value),
setting email or userId to null prevents Iterable from sending further push
notifications to that user, for that app, on that device. On the user's Iterable
profile, in the devices array, notice that endpointEnabled is false for the
device in question.
TIP
To manually disable push notifications to the device, call the static
disableDeviceForCurrentUser method on the Iterable class.