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. The Browser agent API relies on a newrelic object that is automatically defined by the Browser agent.

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.

In order to use this API on a page within your application, the Browser agent must be present.

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