- 22 Aug 2023
- 6 Minutes to read
User object
- Updated on 22 Aug 2023
- 6 Minutes to read
Initialize user object
Whenever you initialize Insider SDK, you also initialize a new Insider user object. You can set attributes for this object and get this object with getCurrentUser method.
Insider user object represents the current user of your app. It is the main object that you can use for attribution (e.g. age, email, opt-in, etc.).
Method Signature
getCurrentUser(): User
Method Example
window.Insider.getCurrentUser();
Set email as user identifier
This method allows you to set the user identifier attribute of your Insider user object for data unification. With this attribute, you can unify your user data within Insider products and reach this user via different channels such as mobile app and web.
Method Signature
addEmail(email: string): Identifier;
Method Example
var identifiers = Insider.identifier();
identifiers.addEmail('sample@mail.com');
Set phone number as user identifier
This method allows you to set the user identifier attribute of your Insider user object for data unification. With this attribute, you can unify your user data within Insider products and reach this user via different channels such as mobile app and web.
Method Signature
addPhoneNumber(phoneNumber: string): Identifier;
Method Example
var identifiers = Insider.identifier();
identifiers.addPhoneNumber('+6501234567');
Phone numbers are required to start with a + (plus) sign followed by a country code. The country code should start with a number between 1-9.
Set user ID as user identifier
This method allows you to set the user identifier attribute of your Insider user object for data unification. With this attribute, you can unify your user data within Insider products and reach this user via different channels such as mobile app and web.
Method Signature
addUserID(userID: string): Identifier;
Method Example
var identifiers = Insider.identifier();
identifiers.addUserID('USER_ID);
Set name attribute
This method allows you to set the name attribute for your Insider user object.
Parameter | Data Type |
---|---|
name | String |
Method Signature
setName(name: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setName("John");
Set surname attribute
This method allows you to set the surname attribute for your Insider user object.
Parameter | Data Type |
---|---|
surname | String |
Method Signature
setSurname(name: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setSurname("Doe")
Set gender attribute
This method allows you to set the gender attribute for your Insider user object. You need to pass Gender enum object as a parameter.
Parameter | Enum values |
---|---|
gender | Insider.gender.FEMALE Insider.gender.MALE Insider.gender.OTHER |
Method Signature
setGender(gender: Gender): User;
Method Example
// Insider.gender.MALE
// Insider.gender.FEMALE
// Insider.gender.OTHER
currentUser = window.Insider.getCurrentUser();
currentUser.setGender(Insider.gender.FEMALE)
Set age attribute
This method allows you to set the age attribute for your Insider user object.
Parameter | Data Type |
---|---|
age | Number |
Method Signature
setAge(age: number): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setAge(25);
Set birthday attribute
This method allows you to set the birthday attribute for your Insider user object.
Parameter | Data Type |
---|---|
birthday | Date |
Method Signature
setBirthday(birthday: Date): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setBirthday(new Date())
Select language attribute
This method allows you to set the language attribute for your Insider user object.
Parameter | Data Type |
---|---|
language | String |
Method Signature
setLanguage(language: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setLanguage("EN");
Set Facebook ID attribute
This method allows you to set the Facebook ID attribute for your Insider user object.
Parameter | Data Type |
---|---|
facebookID | String |
Method Signature
setFacebookID(facebookID: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setFacebookID("Facebook-ID");
Set Twitter ID attribute
This method allows you to set the Twitter ID attribute for your Insider user object.
Parameter | Data Type |
---|---|
twitterID | String |
Method Signature
currentUser.setTwitterID(twitterID: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setTwitterID("Twittter-ID");
Set email opt-in attribute
This method allows you to set the email opt-in (permission) attribute for your Insider user object.
Parameter | Data Type |
---|---|
emailOptIn | Boolean |
Method Signature
setEmailOptin(emailOptIn: boolean): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setEmailOptin(true);
Set sms opt-in attribute
This method allows you to set the sms opt-in (permission) attribute for your Insider user object.
Parameter | Data Type |
---|---|
smsOptIn | Boolean |
Method Signature
setSmsOptin(smsOptIn: boolean): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setSMSOptin(false);
Set WhatsApp opt-in attribute
This method allows you to set the WhatsApp opt-in (permission) attribute for your Insider user object.
Parameter | Data Type |
---|---|
whatsAppOptIn | Boolean |
Method Signature
setWhatsappOptin(whatsappOptIn: boolean): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setWhatsappOptin(true);
Set push opt-in attribute
This method allows you to set the push opt-in (permission) attribute for your Insider user object.
Parameter | Data Type |
---|---|
pushOptIn | Boolean |
Method Signature
setPushOptin(pushOptIn: boolean): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setPushOptin(true);
Set location opt-in attribute
This method allows you to set the location opt-in (permission) attribute for your Insider user object.
Parameter | Data Type |
---|---|
locationOptIn | Boolean |
Method Signature
setLocationOptin(locationOptIn: boolean): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setLocationOptin(true);
Set login attribute
This method allows you to set the login status attribute for your Insider user object.
Parameter | Data Type |
---|---|
identifiers | Object |
insiderIDResult | Function |
Method Signature
login(identifiers:object, insiderIDResult: Function): void;
Method Example
currentUser = window.Insider.getCurrentUser();
var identifiers = Insider.identifier();
identifiers.addEmail('mobile@useinsider.com');
identifiers.addPhoneNumber('+901234567');
identifiers.addUserID('USER_ID');
currentUser.login(identifiers.getIdentifier(), (id) => alert(id));
Set logout attribute
This method allows you to set the login status attribute for your Insider user object.
Method Signature
logout(): void;
Method Example
var identifiers = Insider.identifier();
currentUser.logout();
Set locale attribute
This method allows you to set the locale attribute for your Insider user object.
Parameter | Data Type |
---|---|
locale | String |
Method Signature
setLocale(locale: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setLocale("en_US");
Set custom string attribute
This method allows you to set the custom string attribute for your Insider user object.
Parameter | Data Type |
---|---|
key | String |
value | String |
Method Signature
setCustomAttributeWithString(key: string, value: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setCustomAttributeWithString('string_parameter', 'This is Insider.');
Set custom integer attribute
This method allows you to set the custom integer attribute for your Insider user object.
Parameter | Data Type |
---|---|
key | String |
value | Number |
Method Signature
setCustomAttributeWithInt(key: string, value: number): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setCustomAttributeWithInt('integer_parameter', 10);
Set custom boolean attribute
This method allows you to set the custom boolean attribute for your Insider user object.
Parameter | Data Type |
---|---|
key | String |
value | Boolean |
Method Signature
setCustomAttributeWithBoolean(key: string, value: boolean): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setCustomAttributeWithString('bool_parameter', true);
Set custom double attribute
This method allows you to set the custom double attribute for your Insider user object.
Parameter | Data Type |
---|---|
key | String |
value | Double |
Method Signature
setCustomAttributeWithString(key: string, value: double): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setCustomAttributeWithDouble('string_parameter', 10.5);
Set custom date attribute
This method allows you to set the custom string attribute for your Insider user object.
Parameter | Data Type |
---|---|
key | String |
value | Date |
Method Signature
setCustomAttributeWithString(key: string, value: Date): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.setCustomAttributeWithString('date_parameter', new Date());
Set custom array attribute
This method allows you to set the custom array attribute for your Insider user object.
Parameter | Data Type |
---|---|
key | String |
value | Array (of string) |
Method Signature
setCustomAttributeWithString(key: string, value: object): User;
Method Example
currentUser = window.Insider.getCurrentUser();
const arr = ['value1', 'value2', 'value3'];
window.Insider.getCurrentUser().setCustomAttributeWithArray('key', arr);
Unset custom attribute
This method allows you to unset any custom attribute of your Insider user object. This method will remove the respective the custom attribute of your user for the given key permanently.
Parameter | Data Type |
---|---|
key | String |
Method Signature
unsetCustomAttribute(key: string): User;
Method Example
currentUser = window.Insider.getCurrentUser();
currentUser.unsetCustomAttribute('key');