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
Browser Pro+SPA agent (v963 or higher)
The
$options
parameter requires v1.285.0+If you're using npm to install the browser agent, you must enable the
spa
feature when instantiating theBrowserAgent
class. In thefeatures
array, add the following: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.
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.
- A custom interaction will still follow the default heuristic and close automatically on the next complete soft navigation, unless
- 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.
- Multiple handles can point to the same interaction. Each
Parameters
Parameter | Description |
---|---|
JSON object | Optional: Specifies options that affect the behavior of the interaction.
|
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.