newrelic.interaction().onEnd(function CALLBACK)
Adds custom attributes for SPA interactions to the end of an event.


Requires New Relic Browser agent version nr-963 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.


Similar to the SPA getContext method, this method:

  • Takes a callback that is invoked once the interaction has finished.
  • Passes the same object passed to callbacks given to getContext.

This allows you to alter the event at the end of the function; for example, to add custom attributes to the event.


Parameter Description



Required. A function that accepts the interaction context object as its only argument. You can invoke methods to modify the interaction, such as:

However, methods that have asynchronous side effects, such as this onEnd call, will not have an effect. Other calls with asynchronous side effects include:

Return value(s)

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


// router.js
router.addRoute('/dashboard', () => {
    const interaction = newrelic.interaction().onEnd(ctx => {
            ctx.totalChartLoadTime / ctx.chartLoadCount

// chart-loader.js
function loadChart (chart) {
    const start =
    chart.load().then(() => {
        const loadTime = - start
        interaction.getContext(ctx => {
             ctx.totalChartLoadTime = (ctx.totalChartLoadTime || 0) + loadTime
             ctx.chartLoadCount += (ctx.chartLoadCount || 0) + 1