Browser Agent and SPA API

New Relic Browser includes an agent API you can use to report additional data and events to New Relic Browser and New Relic Insights. To use the API, follow these guidelines:

  • The API relies on a newrelic object that is automatically defined by the Browser JavaScript snippet described in the install documentation.
  • The Browser JavaScript must be present on each page in which you want to use the API.
  • The app's instrumentation level setting does not affect the availability of API functions.

In addition, if you are using Browser's single-page application (SPA) monitoring, you can use the SPA API to add custom monitoring of specific browser interactions. This is useful for monitoring interactions that aren't recorded automatically by New Relic because they don't result in route changes, such as a dynamically-updated widget. The SPA API also allows you to turn off default monitoring for interactions that you do not consider important enough to monitor.

addPageAction
Reports a Browser PageAction event to Insights along with a name and attributes.
addRelease
Adds a unique name and ID to identify releases with multiple JavaScript bundles on the same page.
addToTrace
Adds a JavaScript object with a custom name, start time, etc. to an in-progress session trace.
finished
Records an additional time point as "finished" in a session trace, and sends the event to Insights.
noticeError
Identifies a browser error without disrupting your app's operations.
setCustomAttribute
Adds a user-defined attribute name and value to subsequent events on the page.
setErrorHandler
Allows selective ignoring of known errors that the Browser agent captures.
setPageViewName
Groups page views to help URL structure or to capture the URL's routing information.
SPA: createTracer
Times sub-components of a SPA interaction separately, including wait time and JS execution time.
SPA: end
Ends the New Relic SPA interaction at the current time.
SPA: getContext
Stores values across the current SPA interaction asynchronously in New Relic Browser.
SPA: ignore
Overrides other SPA save() calls; ignores an interaction so it is not be saved or sent to New Relic.
SPA: interaction
Returns a new API object that is bound to the current SPA interaction.
SPA: onEnd
Adds custom attributes for SPA interactions to the end of an event.
SPA: save
Ensures a SPA browser interaction will be saved when it ends.
SPA: setAttribute
Adds a custom SPA attribute only to the current interaction in New Relic Browser.
SPA: setCurrentRouteName
Gives SPA routes more accurate names than default names. Monitors specific routes rather than by default grouping.
SPA: setName
Sets the name and trigger of a SPA's browser interaction that is not a route change or URL change.