newrelic.interaction().setAttribute(string KEY, any VALUE)
Adds a custom SPA attribute only to the current interaction in New Relic Browser.

Requirements

Requires New Relic Browser agent version nr-963 or higher.

Access to this feature depends on your subscription level. New Relic's single page app (SPA) monitoring is only available with New Relic Browser Pro.

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 newrelic.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 newrelic.setCustomAttribute(...) and with custom attributes set by a server-side agent.

Order of precedence Custom attributes
Highest level BrowserInteraction attributes set with the SPA API: These overwrite attributes set in the other two ways.
Next level Attributes set by newrelic.setCustomAttribute(...): These overwrite server-side custom attributes.
Lowest level Custom attributes set server-side.

Parameters

Parameter Description

KEY

string

Required. Used as the attribute name on the BrowserInteraction event.

VALUE

any

Required. Used as the attribute value on the BrowserInteraction event. This can be a string, number, boolean, or object. If it is an object, New Relic serializes it to a JSON string.

Return value(s)

This method returns the same API object created by newrelic.interaction().

Example(s)

router.addRoute('/profile', () => {
    const user = getCurrentUser()
    newrelic.interaction()
        .setAttribute('username', user.username)
        .setAttribute('userId', user.id)
    renderProfile(user)
})