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 userId
The user ID to associate with the current user. authToken
A 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
,setUserId
creates one.They also add a placeholder
email
address 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
email
or auserId
, but not both. - Iterable's React Native SDK persists a
userId
oremail
across app sessions and restarts, until you manually change it. - Assuming
IterableConfig.autoPushRegistration
istrue
(its default value), setting auserId
oremail
automatically registers the device for push notifications and sends thedeviceId
andtoken
to Iterable. - Use the
authToken
parameter 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
userId
oftestUser123
. 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 email
The email address to associate with the current user. authToken
A 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
,setEmail
creates one.NOTES
- Specify an
email
or auserId
, but not both. - Iterable's React Native SDK persists a
userId
oremail
across app sessions and restarts, until you manually change it. - Assuming
IterableConfig.autoPushRegistration
istrue
(its default value), setting auserId
oremail
automatically registers the device for push notifications and sends thedeviceId
andtoken
to Iterable. - Use the
authToken
parameter 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
email
ofuser@example.com
.
userId
Getting the current 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
userId
your app associates with its current user. -
Example:
Iterable.getUserId().then(userId => { console.log("Current userId: " + userId); });
This example fetches the current
userId
and 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
email
your app associates with its current user. -
Example:
Iterable.getEmail().then(email => { console.log("Current email: " + email); });
This example fetches the current
email
and 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 email
The new email address to associate with the current user. authToken
A valid, pre-fetched JWT the SDK can use to authenticate API requests for this user. -
Description:
This method changes the value of the
email
field on the current user's Iterable profile. -
Example:
Iterable.updateEmail("newEmail@example.com")
This example changes the current user's
email
tonewEmail@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
or disableDeviceForAllUsers
method on the
Iterable
class.
Further reading
- React Native
- Iterable's React Native SDK (GitHub)
- Iterable's iOS SDK
- Iterable's iOS SDK (GitHub)
- Iterable's Android SDK
- Iterable's Android SDK (GitHub)
- API Overview