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¶
Field Design Recommendations¶
- Use stable, clearly named keys, for example
tenant_id,release_channel. - Avoid high-cardinality values such as timestamps or random numbers as general analysis dimensions.
- Do not write sensitive information such as passwords, tokens, or ID numbers.
- 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.