Syntax
newrelic.setUserId(value: string|null)
Adds a user-defined identifier string to subsequent events on the page.
Requirements
Browser Lite, Pro, or Pro+SPA agent (v1.230.0 or higher)
If you're using npm to install the browser agent, you must enable at least one feature when instantiating the
BrowserAgent
class. For example, add the following in thefeatures
array:import { Metrics } from '@newrelic/browser-agent/features/metrics'const options = {info: { ... },loader_config: { ... },init: { ... },features: [Metrics]}For more information, see the npm browser installation documentation.
Description
Upon executing this function with a valid value, the browser agent records the value as the enduser.id
attribute with all events until the attribute is manually unset. The identifier will be stored in the browser, so that subsequent page visits of the same origin attach it on events within a session span. Note that this functionality may fluctuate depending on end-user browser privacy settings. If this function is called with a value = null
, any existing user ID will be deleted from both the current page's events and the storage.
The ID will be attached to JavaScriptError events in particular for Errors Inbox usage. If you are using SPA monitoring with a compatible agent version, user ID will also be included in newrelic.interaction
events.
Parameters
Parameter | Description |
---|---|
string OR null | Required. A string identifier for the end-user, useful for tying all browser events to specific users. The Passing a |
Examples
Marking an end user's "start of session"
newrelic.setUserId('user-1234-v1.0')
Stopping events from attributing to current user
newrelic.setUserId(null)