SPA: onEnd

onEnd(function $callback)
Change the values associated with a SPA interaction before the interaction is saved .


Agent version nr-963 or higher.


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:


Parameter Description



Required. This function is called when the interaction ends. It is called with one parameter, which is the interaction context.

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

If you need more help, check out these support and learning resources: