Using browser APIs

The browser APIs allow you to customize and extend your browser monitoring. To begin using the APIs, ensure the browser agent is present on every page you want to monitor.

Below are use cases for each browser API method.

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 only)

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