---
title: setName (SPA API)
source: https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setname
---

## Syntax

```js
newrelic.interaction().setName(string $name[, string $trigger])
```

Sets the name and trigger of a SPA's browser interaction that is not a route change or URL change.

## Requirements

-   Browser Pro+SPA agent (v963 or higher)
-   If you're installing the browser agent via npm and building a custom agent with selected features, you must enable the `spa` feature when creating the `Agent` instance. In the `features` array, add the following:

    ```js
    import { Spa } from '@newrelic/browser-agent/features/spa';

    const options = {
      info: { ... },
      loader_config: { ... },
      init: { ... },
      features: [
        Spa
      ]
    }
    ```

    For more information, see the [npm browser installation documentation](https://www.npmjs.com/package/@newrelic/browser-agent#new-relic-browser-agent).

## Description

This SPA monitoring method sets the name and trigger of a browser interaction. The name will be exposed as the [`browserInteractionName`](https://docs.newrelic.com/docs/insights/explore-data/attributes/browser-default-attributes-insights#interaction-name) attribute in the `BrowserInteraction` event. It will also be used for grouping in the UI.

By default, `browserInteractionName` is named after an associated URL or route. Use `setName()` when you want to record an interaction that is not a route change or URL change.

The [`setCurrentRouteName()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-agent-apis/browser-spa-api-newrelicsetcurrentroutename) method also names the current route. When you use both:

-   `setName()` takes precedence for naming the interaction.
-   The `previousRouteName` and `targetRouteName` attributes are still set with values passed to `setCurrentRouteName()`.

Using these methods together allows many options for filtering and grouping in the UI. For example, you can:

-   Filter down to interactions of a certain type, such as `LikeButtonClick`.
-   Then, group by `targetRouteName` to see what routes have the most `LikeButtonClick` interactions.

> #### 💡 TIP
>
> This API call applies to data in [SPA page views](https://docs.newrelic.com/docs/browser/single-page-app-monitoring/get-started/introduction-single-page-app-monitoring) in browser and the [`BrowserInteraction`](https://docs.newrelic.com/docs/insights/insights-data-sources/default-data/browser-default-events-attributes-insights#browserinteraction-attributes) event type. To set a custom name for standard page views and the **PageView** event type, see [`setPageViewName`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-agent-spa-api/set-pageview-name). Using both calls together is recommended.

## Parameters

| Parameter           | Description                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$name` _string_    | Required. If null, the name will be set using the [`targetGroupedUrl` attribute](https://docs.newrelic.com/docs/insights/explore-data/attributes/browser-default-attributes-insights#target-groupedurl). If not null, this will set the [`browserInteractionName`](https://docs.newrelic.com/docs/insights/explore-data/attributes/browser-default-attributes-insights#interaction-name) attribute in the `BrowserInteraction` event. |
| `$trigger` _string_ | Optional. If not null, this will set the [`TRIGGER`](https://docs.newrelic.com/docs/insights/explore-data/attributes/browser-default-attributes-insights#trigger) attribute on the `BrowserInteraction` event.                                                                                                                                                                                                                        |

## Return values

This method returns the same API object created by `interaction()`.

## Examples

```js
document.getElementById('subscribe').addEventListener('submit', () => {
  newrelic.interaction().setName('createSubscription');
  createSubscription();
});
```
