From 915f7e8a755d0019e3e3833a3d8ed1ae87642764 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 23 Aug 2022 12:27:07 +0100 Subject: [PATCH] Update modifying_data_and_context.md --- .../browser/modifying_data_and_context.md | 198 ++++++++++-------- 1 file changed, 116 insertions(+), 82 deletions(-) diff --git a/content/en/real_user_monitoring/browser/modifying_data_and_context.md b/content/en/real_user_monitoring/browser/modifying_data_and_context.md index cc96a47dcc6ed..669e2c2a43e34 100644 --- a/content/en/real_user_monitoring/browser/modifying_data_and_context.md +++ b/content/en/real_user_monitoring/browser/modifying_data_and_context.md @@ -326,7 +326,7 @@ window.DD_RUM && {{% /tab %}} {{< /tabs >}} -## Identify user sessions +## User session Adding user information to your RUM sessions can help you: * Follow the journey of a given user @@ -345,7 +345,11 @@ The following attributes are optional but Datadog recommends providing at least Increase your filtering capabilities by adding extra attributes on top of the recommended ones. For instance, add information about the user plan, or which user group they belong to. -To identify user sessions, use the `setUser` API: +When making changes to the user session object, all RUM events collected after the change contain the updated information. + +### Identify user session + +`datadogRum.setUser()` {{< tabs >}} {{% tab "NPM" %}} @@ -388,28 +392,111 @@ window.DD_RUM && window.DD_RUM.setUser({ {{% /tab %}} {{< /tabs >}} -### Remove the user identification +### Access user session + +`datadogRum.getUser()` + +{{< tabs >}} +{{% tab "NPM" %}} +``` +datadogRum.getUser() +``` + +{{% /tab %}} +{{% tab "CDN async" %}} +``` +DD_RUM.onReady(function() { + DD_RUM.getUser() +}) +``` +{{% /tab %}} +{{% tab "CDN sync" %}} + +``` +window.DD_RUM && window.DD_RUM.getUser() +``` + +{{% /tab %}} +{{< /tabs >}} + +### Add/Override user session property + +`datadogRum.setUserProperty('', )` + +{{< tabs >}} +{{% tab "NPM" %}} +``` +datadogRum.setUserProperty('name', 'John Doe') +``` + +{{% /tab %}} +{{% tab "CDN async" %}} +``` +DD_RUM.onReady(function() { + DD_RUM.setUserProperty('name', 'John Doe') +}) +``` +{{% /tab %}} +{{% tab "CDN sync" %}} + +``` +window.DD_RUM && window.DD_RUM.setUserProperty('name', 'John Doe') +``` + +{{% /tab %}} +{{< /tabs >}} + +### Remove user session property + +`datadogRum.removeUserProperty('')` + +{{< tabs >}} +{{% tab "NPM" %}} +``` +datadogRum.removeUserProperty('name') +``` + +{{% /tab %}} +{{% tab "CDN async" %}} +``` +DD_RUM.onReady(function() { + DD_RUM.removeUserProperty('name') +}) +``` +{{% /tab %}} +{{% tab "CDN sync" %}} + +``` +window.DD_RUM && window.DD_RUM.removeUserProperty('name') +``` + +{{% /tab %}} +{{< /tabs >}} + +### Clear user session property + +`datadogRum.clearUser()` -Clear a previously set user with the `removeUser` API. All RUM events collected afterwards do not contain user information. +
The RUM Browser SDK v4.17.0 introduced `clearUser` and deprecated `removeUser`
{{< tabs >}} {{% tab "NPM" %}} ``` -datadogRum.removeUser() +datadogRum.clearUser() ``` {{% /tab %}} {{% tab "CDN async" %}} ``` DD_RUM.onReady(function() { - DD_RUM.removeUser() + DD_RUM.clearUser() }) ``` {{% /tab %}} {{% tab "CDN sync" %}} ``` -window.DD_RUM && window.DD_RUM.removeUser() +window.DD_RUM && window.DD_RUM.clearUser() ``` {{% /tab %}} @@ -474,9 +561,11 @@ For a sampled out session, all page views and associated telemetry for that sess ## Global context -### Add global context +### Add global context property -Once RUM is initialized, add extra context to all RUM events collected from your application with the `addRumGlobalContext(key: string, value: any)` API: +After RUM is initialized, add extra context to all RUM events collected from your application with the `setGlobalContextProperty(key: string, value: any)` API: + +
The RUM Browser SDK v4.17.0 introduced `setGlobalContextProperty` and deprecated `addRumGlobalContext`
{{< tabs >}} {{% tab "NPM" %}} @@ -484,10 +573,10 @@ Once RUM is initialized, add extra context to all RUM events collected from your ``` import { datadogRum } from '@datadog/browser-rum'; -datadogRum.addRumGlobalContext('', ); +datadogRum.setGlobalContextProperty('', ); // Code example -datadogRum.addRumGlobalContext('activity', { +datadogRum.setGlobalContextProperty('activity', { hasPaid: true, amount: 23.42 }); @@ -497,12 +586,12 @@ datadogRum.addRumGlobalContext('activity', { {{% tab "CDN async" %}} ``` DD_RUM.onReady(function() { - DD_RUM.addRumGlobalContext('', ''); + DD_RUM.setGlobalContextProperty('', ''); }) // Code example DD_RUM.onReady(function() { - DD_RUM.addRumGlobalContext('activity', { + DD_RUM.setGlobalContextProperty('activity', { hasPaid: true, amount: 23.42 }); @@ -512,10 +601,10 @@ DD_RUM.onReady(function() { {{% tab "CDN sync" %}} ``` -window.DD_RUM && window.DD_RUM.addRumGlobalContext('', ''); +window.DD_RUM && window.DD_RUM.setGlobalContextProperty('', ''); // Code example -window.DD_RUM && window.DD_RUM.addRumGlobalContext('activity', { +window.DD_RUM && window.DD_RUM.setGlobalContextProperty('activity', { hasPaid: true, amount: 23.42 }); @@ -526,86 +615,31 @@ window.DD_RUM && window.DD_RUM.addRumGlobalContext('activity', { Follow the [Datadog naming convention][16] for a better correlation of your data across the product. -### Replace global context - -Once RUM is initialized, replace the default context for all your RUM events with the `setRumGlobalContext(context: Context)` API: - -{{< tabs >}} -{{% tab "NPM" %}} - -``` -import { datadogRum } from '@datadog/browser-rum'; - -datadogRum.setRumGlobalContext({ '': '' }); +### Remove global context property -// Code example -datadogRum.setRumGlobalContext({ - codeVersion: 34, -}); -``` +You can remove a previously defined global context property. -{{% /tab %}} -{{% tab "CDN async" %}} -``` -DD_RUM.onReady(function() { - DD_RUM.setRumGlobalContext({ '': '' }); -}) +
The RUM Browser SDK v4.17.0 introduced `removeGlobalContextProperty` and deprecated `removeRumGlobalContext`
-// Code example -DD_RUM.onReady(function() { - DD_RUM.setRumGlobalContext({ - codeVersion: 34, - }) -}) -``` -{{% /tab %}} -{{% tab "CDN sync" %}} +Follow the [Datadog naming convention][16] for a better correlation of your data across the product. -``` -window.DD_RUM && - DD_RUM.setRumGlobalContext({ '': '' }); +### Replace global context -// Code example -window.DD_RUM && - DD_RUM.setRumGlobalContext({ - codeVersion: 34, - }); -``` +Replace the default context for all your RUM events with the `setGlobalContext(context: Context)` API: -{{% /tab %}} -{{< /tabs >}} +
The RUM Browser SDK v4.17.0 introduced `setGlobalContext` and deprecated `setRumGlobalContext`
Follow the [Datadog naming convention][16] for a better correlation of your data across the product. -### Read global context - -Once RUM is initialized, read the global context with the `getRumGlobalContext()` API: - -{{< tabs >}} -{{% tab "NPM" %}} +### Clear global context -``` -import { datadogRum } from '@datadog/browser-rum'; +You can clear the global context by using `clearGlobalContext`. -const context = datadogRum.getRumGlobalContext(); -``` - -{{% /tab %}} -{{% tab "CDN async" %}} -``` -DD_RUM.onReady(function() { - var context = DD_RUM.getRumGlobalContext(); -}); -``` -{{% /tab %}} -{{% tab "CDN sync" %}} +### Read global context -``` -var context = window.DD_RUM && DD_RUM.getRumGlobalContext(); -``` +Once RUM is initialized, read the global context with the `getGlobalContext()` API: -{{% /tab %}} -{{< /tabs >}} +
The RUM Browser SDK v4.17.0 introduced `getGlobalContext` and deprecated `getRumGlobalContext`
## Further Reading