SPA: newrelic.interaction().getContext

newrelic.interaction().getContext(function CALLBACK)
Stores values across the current SPA interaction asynchronously in New Relic Browser.

Requirements

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.

Description

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.

Parameters

Parameter Description

CALLBACK

function

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 newrelic.interaction().

Example(s)

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

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