User API

User API enables you track a users' activity as they move from device to device and attach attributes to their profiles. Attributes enrich user profiles and can be used in segmenting users and analytics.

webengage.user.login

This method should be called when the user is identified (mostly on login). This asks WebEngage to track this user henceforth with the passed identifier.

Parameters

Name
Type
Description

userId

String (maximum 100 characters)

A unique identifier for the user. The user's activity is then tracked with this ID

webengage.user.login('john@doe.com');

webengage.user.logout

This method lets you inform WebEngage that current user has logged out and treat the user as anonymous from this point onwards. This method has no parameters.

webengage.user.logout();

webengage.user.setAttribute

This method lets you set attributes for a logged-in or anonymous user. These attributes can be used for user segmentation and personalization.

This method has two different signatures.

Parameters when setting one attribute at a time

Name
Type
Description

attributeName

String

Name of the attribute

attributeValue

Any

Value of the attribute

webengage.user.setAttribute('Category', 'GOLD');

Parameters when setting multiple attributes at a time

Name
Type
Description

attributeKeyValueObject

Object

An object where properties and their value are attribute names and attribute values

webengage.user.setAttribute({
    'Category': 'GOLD'
});

Values

String, boolean and number attribute values should be passed in the form of Javascript strings, booleans and numbers respectively. Similarly date attribute values are expected in the form of Javascript date objects. Complex and nested data such as maps and lists can also be passed as plain Javascript objects and arrays.

Please take a note of the general restrictions on user attribute names and values

webengage.user.setAttribute({
    /* strings */
    "Category" : "GOLD",

    /* numbers */
    "Value Index" : 5.06,

    /* booleans */
    "Inactive" : false,

    /* dates */
    "Registered On" : new Date("2015-11-09T10:01:11.000Z"),

    /* objects or maps */
    "Address": {
        "Flat"     : "A-602",
        "Building" : "LCP",
        "Locality" : "Goregaon (E)",
        "City"     : "Mumbai",
        "State"    : "Maharashtra",
        "PIN"      : "400048"
    },

    /* arrays */
    "Contact Numbers Provided": [
        "+91628976359",
        "+91976977507"
    ]
});

Predefined attributes

You pass WebEngage predefined attributes prefixed with we_ as listed below.

Name
Type
Description

we_first_name

String

User’s first name

we_last_name

String

User’s last name

we_email

String

User's email address

we_birth_date

String

User’s birth date in yyyy-mm-dd format

we_phone

String

User’s phone number in E.164 format
eg. +551155256325

we_gender

String

User’s gender (values can only be male, female or other)

we_company

String

User’s company

we_hashed_email

String

Encrypted email address

we_hashed_phone

String

Encrypted phone number

Attribute names starting we_ are reserved for WebEngage predefined attributes and should not be used to name your own custom attributes.

webengage.user.setAttribute({
    'we_first_name' : 'Known',
    'we_last_name'  : 'Anonymous',
    'we_email'      : 'known.anonymous@spamandeggs.com',
    'we_gender'     : 'female',
    'we_phone'      : '+917850009678',
    'we_birth_date' : '2009-03-10'
});

User