• /
  • EnglishEspañolFrançais日本語한국어Português
  • Log inStart now

interaction (SPA API)

Syntax

newrelic.interaction([JSON object $options])

Returns a new handle object that is bound to the current SPA interaction, or a new interaction if one does not exist.

Requirements

Description

The SPA monitoring interaction() call returns a new handle that is bound to the current interaction.

  • New interaction: If this function is called and no interaction is open or in-progress, then a new custom interaction is created.
    • A custom interaction will still follow the default heuristic and close automatically on the next complete soft navigation, unless waitForEnd is specified.
  • New object: If this function is called while an interaction is ongoing, a new handle referencing the current interaction is created.
    • Multiple handles can point to the same interaction. Each .interaction call creates a new handle.
    • The handle will point to the open interaction, whether it began from an user event like a click or from a previous api-triggered .interaction call.
    • This function cannot replace its own effect or that of an user event. That is, it cannot overwrite any existing open interaction with a new api-driven interaction.

Parameters

Parameter

Description

$options

JSON object

Optional: Specifies options that affect the behavior of the interaction.

  • waitForEnd - Default is false. To forcibly keep the interaction open until the .end method is called on its handle, set it to true. After an interaction is earmarked with this, it cannot be undone.

Return values

This method returns an native JS object that points to a potential BrowserInteraction event. Each time this method is called for the same BrowserInteraction while it has not yet ended, a new object is created, but it still references the same interaction.

Examples

SPA API methods must be used on newrelic.interaction(). You can assign the returned value or handle to another variable for later use. For example:

let myInteraction = newrelic.interaction();
...
myInteraction.save();

While the named handle can be saved and used from outside an interaction, note that SPA methods will have no effect after the interaction has ended.

Interaction duration can also be customized using the following method:

// Say an interaction is already open from a user click.
const userInteraction = newrelic.interaction({ waitForEnd: true }); // grabs the current interaction in-progress & keep it open
// URL changes & DOM is modified. Because of those condition being met, interaction will be saved but is kept open.
fetch('myurl.com/endpoint').then(() => userInteraction.end()) // associate this request to the interaction before completing this BrowserInteraction
const myCustomIxn = newrelic.interaction({ waitForEnd: true }) // create a new api-triggered interaction
// This interaction will be kept open indefinitely until `.end` is called, and no new interaction will start, custom or otherwise. AjaxRequest will continue to buffer under this interaction until it is closed.
Copyright © 2025 New Relic Inc.

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