newrelic.setCurrentRouteName(string NAME)
Gives SPA routes more accurate names than default names. Monitors specific routes rather than by default grouping.

Requirements

Requires New Relic Browser agent version nr-998 or higher.

Access to this feature depends on your subscription level. New Relic's single page app (SPA) monitoring is only available with New Relic Browser Pro.

Description

Currently this method applies only to SPA BrowserInteraction events.

This method names the current route. This can be useful to:

  • Give routes more accurate names than they would have by default.
  • Monitor a route that might otherwise be grouped with other routes by default.

The setCurrentRouteName is different from setName, which sets a name for a browser interaction, not a route. Using this API creates two new custom attributes that track the previous route and the target route:

  • previousRouteName
  • targetRouteName

When using this API, the browserInteractionName attribute will take the targetRouteName value. If setName is used to set the browser interaction name, that will take precedence.

The newrelic.setCurrentRouteName API determines the name attributes for BrowserInteraction events, so this API must be called every time there is a route change. This will ensure that BrowserInteraction events have the correct attributes.

To exit out of this route change requirement and return to the default naming strategy, call newrelic.setCurrentRouteName(null).

Parameters

Parameter Description

NAME

string

Required. Current route name for the page.

Route names passed to setCurrentRouteName can be any string, but they should represent a routing pattern rather than a specific resource. For example, use /users/:id rather than /users/123.

Example(s)

router.onChange(function (route) {
  newrelic.setCurrentRouteName(route.name)
})