Syntax
newrelic.interaction().onEnd(function $callback)
Change the values associated with a SPA interaction before the interaction is saved.
Requirements
Browser Pro+SPA agent (v963 or higher)
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
This call provides the same object as getContext()
. When this is called, you can make final adjustments to the interaction before it's recorded. For example, you could add additional attributes based on the context values.
Other methods for modifying the interaction include:
Parameters
Parameter | Description |
---|---|
function | Required. This function is called when the interaction ends. It is called with one parameter, which is the interaction context. |
Return values
This method returns the same API object created by interaction()
.
Examples
// router.jsrouter.addRoute('/dashboard', () => { const interaction = newrelic.interaction().onEnd(ctx => { interaction.setAttribute( 'averageChartLoadTime', ctx.totalChartLoadTime / ctx.chartLoadCount ); }); getCharts().forEach(loadChart);});
// chart-loader.jsfunction loadChart(chart) { const start = Date.now(); chart.load().then(() => { const loadTime = Date.now() - start; interaction.getContext(ctx => { ctx.totalChartLoadTime = (ctx.totalChartLoadTime || 0) + loadTime; ctx.chartLoadCount += (ctx.chartLoadCount || 0) + 1; }); })}