Skip to content

Global Context

Global Context is attached to all RUM events generated after it is set. It is suitable for recording stable business dimensions such as tenant, release channel, and experiment group.

API Reference

API Purpose Return Value
setGlobalContextProperty(key, value) Add or override a single field None
setGlobalContext(context) Replace the entire Global Context None
getGlobalContext() Get a copy of the current Global Context Object
removeGlobalContextProperty(key) Remove a single field None
clearGlobalContext() Clear all Global Context None
setGlobalContext() replaces the entire Context

If you only need to update one field, use setGlobalContextProperty() to avoid overwriting fields already set by other modules.

NPM Example

import { datafluxRum } from "@cloudcare/browser-rum"

datafluxRum.setGlobalContextProperty("tenant_id", "tenant-42")
datafluxRum.setGlobalContext({
  tenant_id: "tenant-42",
  release_channel: "stable"
})

const context = datafluxRum.getGlobalContext()
console.log(context)

datafluxRum.removeGlobalContextProperty("release_channel")
datafluxRum.clearGlobalContext()

CDN Example

if (window.DATAFLUX_RUM) {
  window.DATAFLUX_RUM.setGlobalContextProperty("tenant_id", "tenant-42")
  const context = window.DATAFLUX_RUM.getGlobalContext()
  console.log(context)
}
window.DATAFLUX_RUM.onReady(function () {
  window.DATAFLUX_RUM.setGlobalContextProperty("tenant_id", "tenant-42")
  const context = window.DATAFLUX_RUM.getGlobalContext()
  console.log(context)
})

Field Design Recommendations

  1. Use stable, clearly named keys, for example tenant_id, release_channel.
  2. Avoid high-cardinality values such as timestamps or random numbers as general analysis dimensions.
  3. Do not write sensitive information such as passwords, tokens, or ID numbers.
  4. Context only affects events generated after it is set; it does not modify already reported data.

Verification

After setting a field, trigger a View, Action, or API request. Confirm that the event contains tenant_id in the corresponding Explorer. If old events do not have this field, check whether the Context was set before the event occurred.

Feedback

Is this page helpful?