Syntax
newrelic.interaction().setAttribute(string $key, any $value)
Adds a custom SPA attribute only to the current interaction in browser.
Requirements
Browser Pro+SPA agent (v963 or higher)
If you're using npm to install the browser agent, you must enable the
spa
feature when instantiating theBrowserAgent
class. In thefeatures
array, add the following:import { Spa } from '@newrelic/browser-agent/features/spa';const options = {info: { ... },loader_config: { ... },init: { ... },features: [Spa]}For more information, see the npm browser installation documentation.
Description
This method adds a custom attribute to an interaction. If saved, this attribute will be exposed as a new property on the resulting BrowserInteraction
event. Unlike attributes added with setCustomAttribute()
, an attribute added to an interaction will only apply to the current interaction, and it will not be added to PageAction
events.
New Relic merges these custom attributes with the custom attributes set by calling setCustomAttribute()
and with custom attributes set by a server-side agent.
Order of precedence | Custom attributes |
---|---|
Highest level |
|
Next level | Attributes set by |
Lowest level | Custom attributes set server-side. |
Errors for custom attributes will be included in events on the JS Errors page. To view or log errors for a custom attribute via API, use the browser agent API's noticeError
call.
Parameters
Parameter | Description |
---|---|
string | Required. Used as the attribute name on the |
any | Required. Used as the attribute value on the |
Return values
This method returns the same API object created by interaction()
.
Examples
router.addRoute('/profile', () => { const user = getCurrentUser(); newrelic.interaction() .setAttribute('username', user.username) .setAttribute('userId', user.id); renderProfile(user);});