SPA: onEnd

onEnd(function $callback)
Adds custom attributes for SPA interactions to the end of an event.


Agent version nr-963 or higher.

SPA calls require 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 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

For more help

Recommendations for learning more: