Tracking User Attributes

User attributes are specific traits of a user, like email, username, mobile, gender etc.
This information is helpful in order to targeting users based on these attributes across devices or installs.

Track User Attribute

The below example outlines the how to track a user attribute in MoEngage.

Moengage.add_user_attribute("ATTRIBUTE_NAME_1", "value");                 // string value
Moengage.add_user_attribute("ATTRIBUTE_NAME_2", 1);                       // numeric value
Moengage.add_user_attribute("ATTRIBUTE_NAME_3", 5.99);                    // numeric value
Moengage.add_user_attribute("ATTRIBUTE_NAME_4", new Date(2017, 0, 31));   // JavaScript Date Object

// Example
Moengage.add_user_attribute("totem", "spinning top");

Pre-defined User Attributes

Please use the following helper functions to make use of the MoEngage reserved attributes which are available by default in the segmentation options.

Moengage.add_email("[email protected]");
Moengage.add_user_name("Dominick (Dom) Cobb");         // Full name for user
Moengage.add_birthday(new Date(1980, 2, 31));

Tracking Date/Time Attributes

Moengage.add_user_attribute("replenishment_date", new Date(2019,0,31)); // JavaScript Date Object



User Phone No / Mobile Number must be tracked as a string to work properly in MoEngage systems.

User Login/Logout

It is important that you handle user login and logout as mentioned below. There is a definite chance that your data can get corrupted if not done properly.

Whenever your app can get hold of the unique id set for the user, pass that information to our SDK using the login method. We use the unique id information that you pass to our SDK, to identify a user. Once the user logs out of your app, It is necessary to call logout method of MoEngage, so that we track it as a new user. If you pass 2 different unique id information without calling logout method in between, older user information will be overwritten by the new user which is undesired.

When you go live with MoEngage web SDK for the first time, please ensure that you are setting the unique id of your existing website users on page load.

Kindly make sure that you call the following methods on user login/logout.


Moengage.add_unique_user_id(UNIQUE_ID); // UNIQUE_ID is used to uniquely identify a user.


Calling Moengage.add_unique_user_id(NEW_UNIQUE_ID); with a new unique id will forcefully logs out the current user and create a new user. If you want to do this, then Moengage.update_unique_user_id(NEW_UNIQUE_ID); is the correct way



Updating User Attribute Unique ID




Please make sure that you use update_unique_user_id() for updating the User Attribute Unique ID and not add_unique_user_id: as calling add_unique_user_id with a new value will reset the current user and lead to creation of unintended users in our system.

When to track user attributes

Please ensure that you are tracking user attributes in the following cases -

  1. When a new attribute is set for a user. For example, set the Email Id / Mobile No. attribute for the user after a user logs in or signs up on the website.

  2. When the value of an existing attribute is updated.

  3. When you go live for the first time with MoEngage web SDK integration, please ensure that you are passing the user attributes set for your existing website users once on page load (if they are not already sent to MoEngage).



Kindly make sure that you are not using a single unique id for all the users, this can happen if you hard code the value, instead of fetching it from your servers.


Before you take your Website LIVE

In case you are taking your website live, do ensure -

  1. To pass debug_logs: 0 parameter in Moengage initialization in HTML code as mentioned below to send website data to LIVE environment on Dashboard (top toggle switch on Dashboard to right).
        app_id: "YOUR_APP_ID_GOES_HERE",
        debug_logs: 0
  1. To configure the Web Push Settings in the LIVE environment by navigating to Settings -> Channel -> Push -> Web Push. Read more about TEST/LIVE environment here

User Attribute tracking via Google Tag Manager (GTM)

You can also place the above function as a Custom HTML Tag inside GTM. This Tag can be fired once per event/page and triggered on the elements where you wish to track website user attributes. These attributes can be picked up from GTM Data Layer.


These are the default data collected by SDK. Please go through this before adding any events:

What’s Next