---
title: Using browser APIs
source: https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/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](https://docs.newrelic.com/docs/browser/new-relic-browser/installation/install-new-relic-browser-agent).

Below are use cases for each browser API method.

## Traces and events [#api-traces]

To monitor traces and events, use these methods:

| If you want to...                                                                                                                                                           | Use this API                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| Track an action that New Relic doesn't automatically track                                                                                                                  | [`newrelic.addPageAction()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addpageaction)                 |
| Add an object to an in-progress [session trace](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-pro-features/session-traces-exploring-webpages-life-cycle) | [`newrelic.addToTrace()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addtotrace)                       |
| Record a time point when your page is finished according to custom criteria                                                                                                 | [`newrelic.finished()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/finished)                           |
| Add an attribute name and value to subsequent events on the page                                                                                                            | [`newrelic.setCustomAttribute()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute)       |
| Add application version information to subsequent events on the page                                                                                                        | [`newrelic.setApplicationVersion()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setApplicationVersion) |
| Group page views by setting a page name                                                                                                                                     | [`newrelic.setPageViewName()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setpageviewname)             |
| Add user id information to subsequent events on the page                                                                                                                    | [`newrelic.setUserId()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setuserid)                         |
| Capture a single browser log event                                                                                                                                          | [`newrelic.log()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/log)                                     |
| Automatically capture messages passing through your existing logger methods as log events                                                                                   | [`newrelic.wrapLogger()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/wrapLogger)                       |

## Report errors [#api-errors]

To report errors in your application, use these methods:

| If you want to...                                                         | Use this API                                                                                                          |
| ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| Tag errors with your app's version information                            | [`newrelic.addRelease()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addrelease)           |
| Capture a caught or handled error without disrupting your app's operation | [`newrelic.noticeError()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/noticeerror)         |
| Selectively ignore a known error                                          | [`newrelic.setErrorHandler()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/seterrorhandler) |

## Track single page apps (SPA only) [#spa-api]

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

| If you want to...                                                                                                                                                                                                                                               | Use this API                                                                                                                               |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| Set the [`actionText`](/attribute-dictionary/?event=BrowserInteraction&attribute=actionText) (the text of the HTML element clicked) of a SPA [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction). | [`newrelic.interaction().actionText()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/actiontext)                  |
| Trace sub-components of a SPA [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction) separately                                                                                                      | [`newrelic.interaction().createTracer()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/createtracer) (deprecated) |
| End a SPA [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction)                                                                                                                                     | [`newrelic.interaction().end()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/end)                                |
| Aggregate data associated with the current [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction)                                                                                                    | [`newrelic.interaction().getContext()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/getcontext)                  |
| Ignore an [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction)                                                                                                                                     | [`newrelic.interaction().ignore()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/ignore)                          |
| Return a new API object bound to the current [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction)                                                                                                  | [`newrelic.interaction()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/interaction)                              |
| Adjust attributes, such as name and ignored attributes, before the [interaction](/attribute-dictionary/?event=BrowserInteraction) is recorded                                                                                                                   | [`newrelic.interaction().onEnd()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/onend)                            |
| Ensure a browser [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction) will be saved when it ends                                                                                                   | [`newrelic.interaction().save()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/save)                              |
| Add a custom attribute to the current [interaction](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary/#interaction)                                                                                                         | [`newrelic.interaction().setAttribute()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setattribute)              |
| Give SPA routes more accurate names than default names                                                                                                                                                                                                          | [`newrelic.interaction().setCurrentRouteName`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcurrentroutename)  |

## Control agent data collection behaviors [#agent-control-api]

To control agent harvesting behaviors, use these API methods:

| If you want to...                                           | Use this API                                                                                                    |
| ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Prevent feature(s) from harvesting until manually triggered | [`newrelic.start()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/start)               |
| Manually start session replay collection                    | [`newrelic.recordReplay()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/recordReplay) |
| Manually pause session replay collection                    | [`newrelic.pauseReplay()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/pauseReplay)   |
