SPA: getContext

newrelic.interaction().getContext([function $callback])
Stores values across the current SPA interaction asynchronously in New Relic Browser.


Agent version nr-963 or higher.

SPA calls require New Relic Browser Pro.


This SPA method takes a callback that will be invoked asynchronously with the context object associated with the current interaction. Use to store values associated with the current interaction in New Relic Browser.

This object is shared across the entire interaction and can be used in multiple places. This allows for aggregating data over the course of the interaction.


Parameter Description



Optional. A function that accepts the interaction context object as its only argument.

Return value(s)

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


router.addRoute('/products/{productId}', params => {
    newrelic.interaction().getContext(ctx => ctx.productId = params.productId)

window.addEventListener('hashchange', (ev) => {
    const interaction = newrelic.interaction()
    interaction.getContext(ctx => {
        if (ctx.productId) {
            interaction.setAttribute('productId', ctx.productId)

For more help

Recommendations for learning more: