title | type | shortDescription | tags | metaDescription | redirects | freshnessValidatedDate | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getContext (SPA API) |
apiDoc |
Stores values for the current SPA interaction asynchronously in Browser. |
|
SPA API call to store values across the current SPA interaction asynchronously in browser monitoring. |
|
never |
newrelic.interaction().getContext(function $callback)
Stores values for the current SPA interaction asynchronously in browser.
-
Browser Pro+SPA agent (v963 or higher)
-
If you're using npm to install the browser agent, you must enable the
spa
feature when instantiating theBrowserAgent
class. In thefeatures
array, add the following:import { Spa } from '@newrelic/browser-agent/features/spa'; const options = { info: { ... }, loader_config: { ... }, init: { ... }, features: [ Spa ] }
For more information, see the npm browser installation documentation.
This API method takes a callback that will be invoked asynchronously with the context object associated with the current interaction. Use this for aggregating data associated with the current interaction. These values can be used in other parts of your code.
This context is also provided by the onEnd
call.
<th>
Description
</th>
</tr>
Parameter |
---|
`$callback`
|
This method returns the same API object created by interaction()
.
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);
}
});
});