• Log inStart now

Guide to using the browser and SPA APIs

The browser and Single Page Application (SPA) APIs allow you to customize and extend your browser monitoring. To begin using the APIs, ensure the browser JavaScript snippet is present on every page you want to monitor. This document presents use cases for each browser and SPA API method.

For an overview of the browser agent and SPA APIs and their methods, see Browser Agent and SPA API.

Traces and events

To monitor traces and events, use these methods:

If you want to...

Use this

Track an action that New Relic doesn't automatically track

Use newrelic.addPageAction()

Add an object to an in-progress session trace

Use newrelic.addToTrace()

Record a time point when your page is finished according to custom criteria

Use newrelic.finished()

Add an attribute name and value to subsequent events on the page

Use newrelic.setCustomAttribute()

Group page views by setting a page name

Use newrelic.setPageViewName()

Report errors

To report errors in your application, use these methods:

If you want to...

Do this

Tag errors with your app's version information

Use newrelic.addRelease()

Log a caught or handled error, without disrupting your app's operation

Use newrelic.noticeError()

Selectively ignore a known error

Use newrelic.setErrorHandler()

Track single page apps (SPA API)

To track single page applications, use these SPA API methods:

If you want to...

Do this

Set the actionText, or text of the HTML element clicked, of a SPA interaction

Use newrelic.interaction().actionText()

Trace sub-components of a SPA interaction separately

Use newrelic.interaction().createTracer()

End a SPA interaction

Use newrelic.interaction().end()

Aggregate data associated with the current interaction

Use newrelic.interaction().getContext()

Ignore an interaction

Use newrelic.interaction().ignore()

Return a new API object bound to the current interaction

Use newrelic.interaction()

Adjust attributes, such as name and ignored attributes, before the interaction is recorded

Use newrelic.interaction().onEnd()

Ensure a browser interaction will be saved when it ends

Use newrelic.interaction().save()

Add a custom attribute to the current interaction

Use newrelic.interaction().setAttribute()

Give SPA routes more accurate names than default names

Use newrelic.interaction().setCurrentRouteName

Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.