Skip to main content

Setting the actual user ID

Browser monitoring is basically managed by issuing user IDs with random numbers. However, it provides an additional function to collect data by setting the user ID via the actual user's login ID or email address. By setting the actual user ID, you can see the user session performance and event information and additionally see the browser errors based on the actual login ID or email address.

By identifying users through the browser monitoring, it can be used for custom analysis, accurate user experience analysis, marketing strategy planning, and security enhancement.

Setting the actual user ID​

Interfaces​

The interface provided by the browser agent is contained in the WhatapBrowserAgent object of window. See the interface of setUserID provided by WhatapBrowserAgent.

Typescript
setUserID: (userID: string) => void;

Application example​

You can apply the interface provided by the browser agent as an example code.

Typescript
const loginComplete = (data) => {
if (data) {
/*
* @description Setting the user ID of the WhaTap browser agent
*/
window?.WhatapBrowserAgent?.setUserID?.(data?.email);
}
};

When the loginComplete function runs, the actual user's email address is set as the user ID to be used for browser monitoring.

If your service stores the logged-in user's ID in a cookie, you can collect the cookie value as the user ID without calling setUserID. Specify the cookie name with the userIdCookieName option in the config object of the installation script. Supported from browser agent 3.4.0. Version 3.3.1 and earlier ignore this option.

userIdCookieName example
config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}",
userIdCookieName: "login_id"
}
ItemDescription
When the cookie is readOn page open, every second while the page is visible, when the page becomes visible again, and on SPA screen transitions
Cookie value changesThe new value is used as the user ID. Data collected within 1 second after the change may carry the previous ID
Cookie is removedReverts to the user ID stored in this browser: usually the anonymous ID, or the ID set by an earlier setUserID call in that browser
Used with setUserIDThe value set with setUserID is kept until the cookie value changes. After a page reload, the cookie value is used again
Value processingLeading and trailing spaces and double quotes are removed, and the value is URL-decoded. Values longer than 200 characters are truncated
Unreadable cookiesHttpOnly cookies, cookies for a different path or domain
  • In mobile app WebView integration, if the mobile agent passes a user ID, that value takes precedence. If the mobile agent does not pass a user ID, the cookie is read only on page open and on screen transitions.

  • If you specify a value that cannot be used as a cookie name, such as one containing ; or =, the agent prints a warning in the browser console and ignores the option.

  • The cookie value is not stored separately in the agent cookie.