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.
Table of contents
Identifying users by user ID
To identify a user for whom you don't have an email address, call the static
setUserId
method on the Iterable
class.
-
Method declaration:
static setUserId(userId: string | undefined)
Parameter Name Description userId
The user ID to associate with the current user. -
Description:
This method associates the current user with the specified
userId
. If your Iterable project doesn't yet have a user with thatuserId
,setUserId
creates ones.It also adds a placeholder
email
address to the user's Iterable profile, of the formuserId
+ hash +@placeholder.email
.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.
- 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)
Parameter Name Description email
The email address to associate with the current user. -
Description:
This method associates the app's 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.
- Specify an
-
Example:
Iterable.setEmail("docs@iterable.com");
This example associates the app's current user with an
email
ofdocs@iterable.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
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)
Parameter Name Description email
The new email address to associate with the current user. -
Description:
This method changes the value of the
email
field on the current user's Iterable profile. -
Example:
Iterable.updateEmail("docs+2@iterable.com")
This example changes the current user's
email
todocs+2@iterable.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.
Comments
0 comments
Article is closed for comments.