newrelic.setCustomAttribute(string $name, string OR number $value)
Requirements
Agent version nr-593 or higher.
Description
The Browser API call adds a user-defined attribute name and value to subsequent events on the page. Make this call before the window load event fires (when that data is transmitted) in order for the attributes to be included in the PageView
event. Once an attribute is set, New Relic One records it with all PageAction
events until the page is reloaded or the attribute is manually unset.
If you are using SPA monitoring with a compatible agent version, attributes set with this call will also be included in newrelic.interaction
events. However, attributes set using the SPA API will take precedence over these attributes.
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 API's noticeError
call.
Parameters
Parameter | Description |
---|---|
string |
Required. Name of the attribute. Appears as column in the Avoid using reserved NRQL words when you name the attribute/value. |
string OR integer |
Required. Value of the attribute. Appears as the value in the named attribute column in the Avoid using reserved NRQL words when you name the attribute/value. |
Example(s)
Get JavaScript/jQuery for HTML elements
This example uses JavasScript/jQuery to get the values of the following HTML elements on the Drupal-generated pages for New Relic's Docs site:
<link rel="shortlink" href="/node/1111" />
<h1>Using NRQL</h1>
New Relic reports them as custom attributes. This is useful to query PageView and PageAction events in New Relic One.
var node_id = ''; node_id= jQuery("link[rel='shortlink']").attr("href"); var node_title = ''; node_title= jQuery('h1').text(); if (typeof newrelic == 'object') { newrelic.setCustomAttribute('nodeId', node_id); newrelic.setCustomAttribute('title', node_title); }