Initialize InsiderUser
A proxy class for encapsulating user-related operations, such as login, logout, etc.
getCurrentUser() : InsiderUserconst user = window.insider.getCurrentUser();getInsiderID
This method returns the user's Insider ID information.
getInsiderID() : Promise<string>const insiderID = await window.insider.getInsiderID();login
This method logs the user in with the given identifiers.
Parameter | Type | Description | Required |
|---|---|---|---|
identifiers | InsiderIdentifiers | User identifiers encapsulating email, userID, phone, etc. | Yes |
login(InsiderIdentifiers identifiers) : Promise<string>const identifiers = window.insider.createIdentifiers()
.addEmail("john.doe@useinsider.com")
.addPhoneNumber("+1234567890")
.addUserID("454996")
.addCustomIdentifier("locale", "en_US");
const user = window.insider.getCurrentUser();
const insiderID = await user.login(identifiers);logout
This method logs the user out, clearing their identifiers.
logout() : Promise<void>const user = window.insider.getCurrentUser();
await user.logout();logoutResettingInsiderID
This method logs the user out, removing the given identifiers tied to them. Calling this method always results in a new Insider ID being generated.
Parameter | Type | Description | Required |
|---|---|---|---|
identifiers | InsiderIdentifiers | User identifiers encapsulating email, userID, phone, etc. | No |
logoutResettingInsiderID(InsiderIdentifiers identifiers) : Promise<string>const identifiers = window.insider.createIdentifiers()
.addEmail("john.doe@useinsider.com")
.addPhoneNumber("+1234567890")
.addUserID("454996")
.addCustomIdentifier("locale", "en_US");
const user = window.insider.getCurrentUser();
const newInsiderID = await currentUser.logoutResettingInsiderID([identifiers]);You can also pass an empty array or null if you do not want any identifiers to be removed from the current user:
newInsiderID = await currentUser.logoutResettingInsiderID([]);
newInsiderID = await currentUser.logoutResettingInsiderID(null); // works same as aboveSet promotional opt-in attribute
This method allows you to set the promotional opt-in (permission) attribute for your Insider user object. It stores the user's consent for promotional marketing messages so that it can be used for App Push targeting.
If you never call this method, or if you pass the value as false, the user is treated as not opted-in and will not be targeted by promotional App Push campaigns.
This attribute is stored at the user (profile) level, not per device, so its value applies to every device the user is identified on.
The method returns a Promise, so it should be awaited to make sure the value has been passed to the native SDK before the session ends.
The parameter is validated: passing a non-boolean value rejects the call instead of silently storing an invalid attribute.
Parameter | Data Type |
|---|---|
promotionalOptin | Boolean |
setPromotionalOptin(promotionalOptin: boolean): Promise<void>await window.insider.getCurrentUser().setPromotionalOptin(true);User attributes
You can use the following methods to attach attributes for the user:
Parameter | Type | Required |
|---|---|---|
setGender | String | Yes |
setBirthday | Date | Yes |
setName | String | Yes |
setSurname | String | Yes |
setAge | Integer | Yes |
setEmail | String | Yes |
setPhoneNumber | String | Yes |
setLanguage | String | Yes |
setLocale | String | Yes |
setSMSOptin | Boolean | Yes |
setEmailOptin | Boolean | Yes |
setWhatsappOptin | Boolean | Yes |
setPushOptin | Boolean | Yes |
setLocationOptin | Boolean | Yes |
setPromotionalOptin | Boolean | Yes |
Method example
const user = window.insider.getCurrentUser();
await user.setGender("female");
await user.setBirthday(new Date("1997-10-08"));
await user.setName("Jane");
await user.setSurname("Doe");
await user.setAge(28);
await user.setEmail("jane.doe@useinsider.com");
await user.setPhoneNumber("+1234567890");
await user.setLanguage("en");
await user.setLocale("en_US");
await user.setSMSOptin(true);
await user.setEmailOptin(true);
await user.setWhatsappOptin(false);
await user.setPushOptin(true);
await user.setLocationOptin(true);