Skip to content

Commit 915f7e8

Browse files
authored
Update modifying_data_and_context.md
1 parent 1d0b335 commit 915f7e8

File tree

1 file changed

+116
-82
lines changed

1 file changed

+116
-82
lines changed

content/en/real_user_monitoring/browser/modifying_data_and_context.md

Lines changed: 116 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ window.DD_RUM &&
326326
{{% /tab %}}
327327
{{< /tabs >}}
328328
329-
## Identify user sessions
329+
## User session
330330
331331
Adding user information to your RUM sessions can help you:
332332
* Follow the journey of a given user
@@ -345,7 +345,11 @@ The following attributes are optional but Datadog recommends providing at least
345345
346346
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.
347347
348-
To identify user sessions, use the `setUser` API:
348+
When making changes to the user session object, all RUM events collected after the change contain the updated information.
349+
350+
### Identify user session
351+
352+
`datadogRum.setUser(<USER_CONFIG_OBJECT>)`
349353
350354
{{< tabs >}}
351355
{{% tab "NPM" %}}
@@ -388,28 +392,111 @@ window.DD_RUM && window.DD_RUM.setUser({
388392
{{% /tab %}}
389393
{{< /tabs >}}
390394
391-
### Remove the user identification
395+
### Access user session
396+
397+
`datadogRum.getUser()`
398+
399+
{{< tabs >}}
400+
{{% tab "NPM" %}}
401+
```
402+
datadogRum.getUser()
403+
```
404+
405+
{{% /tab %}}
406+
{{% tab "CDN async" %}}
407+
```
408+
DD_RUM.onReady(function() {
409+
DD_RUM.getUser()
410+
})
411+
```
412+
{{% /tab %}}
413+
{{% tab "CDN sync" %}}
414+
415+
```
416+
window.DD_RUM && window.DD_RUM.getUser()
417+
```
418+
419+
{{% /tab %}}
420+
{{< /tabs >}}
421+
422+
### Add/Override user session property
423+
424+
`datadogRum.setUserProperty('<USER_KEY>', <USER_VALUE>)`
425+
426+
{{< tabs >}}
427+
{{% tab "NPM" %}}
428+
```
429+
datadogRum.setUserProperty('name', 'John Doe')
430+
```
431+
432+
{{% /tab %}}
433+
{{% tab "CDN async" %}}
434+
```
435+
DD_RUM.onReady(function() {
436+
DD_RUM.setUserProperty('name', 'John Doe')
437+
})
438+
```
439+
{{% /tab %}}
440+
{{% tab "CDN sync" %}}
441+
442+
```
443+
window.DD_RUM && window.DD_RUM.setUserProperty('name', 'John Doe')
444+
```
445+
446+
{{% /tab %}}
447+
{{< /tabs >}}
448+
449+
### Remove user session property
450+
451+
`datadogRum.removeUserProperty('<USER_KEY>')`
452+
453+
{{< tabs >}}
454+
{{% tab "NPM" %}}
455+
```
456+
datadogRum.removeUserProperty('name')
457+
```
458+
459+
{{% /tab %}}
460+
{{% tab "CDN async" %}}
461+
```
462+
DD_RUM.onReady(function() {
463+
DD_RUM.removeUserProperty('name')
464+
})
465+
```
466+
{{% /tab %}}
467+
{{% tab "CDN sync" %}}
468+
469+
```
470+
window.DD_RUM && window.DD_RUM.removeUserProperty('name')
471+
```
472+
473+
{{% /tab %}}
474+
{{< /tabs >}}
475+
476+
### Clear user session property
477+
478+
`datadogRum.clearUser()`
392479
393-
Clear a previously set user with the `removeUser` API. All RUM events collected afterwards do not contain user information.
480+
<div class="alert alert-info">The RUM Browser SDK v4.17.0 introduced `clearUser` and deprecated `removeUser`</div>
394481
395482
{{< tabs >}}
396483
{{% tab "NPM" %}}
397484
```
398-
datadogRum.removeUser()
485+
datadogRum.clearUser()
399486
```
400487
401488
{{% /tab %}}
402489
{{% tab "CDN async" %}}
403490
```
404491
DD_RUM.onReady(function() {
405-
DD_RUM.removeUser()
492+
DD_RUM.clearUser()
406493
})
407494
```
408495
{{% /tab %}}
409496
{{% tab "CDN sync" %}}
410497
411498
```
412-
window.DD_RUM && window.DD_RUM.removeUser()
499+
window.DD_RUM && window.DD_RUM.clearUser()
413500
```
414501
415502
{{% /tab %}}
@@ -474,20 +561,22 @@ For a sampled out session, all page views and associated telemetry for that sess
474561
475562
## Global context
476563
477-
### Add global context
564+
### Add global context property
478565
479-
Once RUM is initialized, add extra context to all RUM events collected from your application with the `addRumGlobalContext(key: string, value: any)` API:
566+
After RUM is initialized, add extra context to all RUM events collected from your application with the `setGlobalContextProperty(key: string, value: any)` API:
567+
568+
<div class="alert alert-info">The RUM Browser SDK v4.17.0 introduced `setGlobalContextProperty` and deprecated `addRumGlobalContext`</div>
480569
481570
{{< tabs >}}
482571
{{% tab "NPM" %}}
483572
484573
```
485574
import { datadogRum } from '@datadog/browser-rum';
486575

487-
datadogRum.addRumGlobalContext('<CONTEXT_KEY>', <CONTEXT_VALUE>);
576+
datadogRum.setGlobalContextProperty('<CONTEXT_KEY>', <CONTEXT_VALUE>);
488577

489578
// Code example
490-
datadogRum.addRumGlobalContext('activity', {
579+
datadogRum.setGlobalContextProperty('activity', {
491580
hasPaid: true,
492581
amount: 23.42
493582
});
@@ -497,12 +586,12 @@ datadogRum.addRumGlobalContext('activity', {
497586
{{% tab "CDN async" %}}
498587
```
499588
DD_RUM.onReady(function() {
500-
DD_RUM.addRumGlobalContext('<CONTEXT_KEY>', '<CONTEXT_VALUE>');
589+
DD_RUM.setGlobalContextProperty('<CONTEXT_KEY>', '<CONTEXT_VALUE>');
501590
})
502591

503592
// Code example
504593
DD_RUM.onReady(function() {
505-
DD_RUM.addRumGlobalContext('activity', {
594+
DD_RUM.setGlobalContextProperty('activity', {
506595
hasPaid: true,
507596
amount: 23.42
508597
});
@@ -512,10 +601,10 @@ DD_RUM.onReady(function() {
512601
{{% tab "CDN sync" %}}
513602
514603
```
515-
window.DD_RUM && window.DD_RUM.addRumGlobalContext('<CONTEXT_KEY>', '<CONTEXT_VALUE>');
604+
window.DD_RUM && window.DD_RUM.setGlobalContextProperty('<CONTEXT_KEY>', '<CONTEXT_VALUE>');
516605

517606
// Code example
518-
window.DD_RUM && window.DD_RUM.addRumGlobalContext('activity', {
607+
window.DD_RUM && window.DD_RUM.setGlobalContextProperty('activity', {
519608
hasPaid: true,
520609
amount: 23.42
521610
});
@@ -526,86 +615,31 @@ window.DD_RUM && window.DD_RUM.addRumGlobalContext('activity', {
526615
527616
Follow the [Datadog naming convention][16] for a better correlation of your data across the product.
528617
529-
### Replace global context
530-
531-
Once RUM is initialized, replace the default context for all your RUM events with the `setRumGlobalContext(context: Context)` API:
532-
533-
{{< tabs >}}
534-
{{% tab "NPM" %}}
535-
536-
```
537-
import { datadogRum } from '@datadog/browser-rum';
538-
539-
datadogRum.setRumGlobalContext({ '<CONTEXT_KEY>': '<CONTEXT_VALUE>' });
618+
### Remove global context property
540619
541-
// Code example
542-
datadogRum.setRumGlobalContext({
543-
codeVersion: 34,
544-
});
545-
```
620+
You can remove a previously defined global context property.
546621
547-
{{% /tab %}}
548-
{{% tab "CDN async" %}}
549-
```
550-
DD_RUM.onReady(function() {
551-
DD_RUM.setRumGlobalContext({ '<CONTEXT_KEY>': '<CONTEXT_VALUE>' });
552-
})
622+
<div class="alert alert-info">The RUM Browser SDK v4.17.0 introduced `removeGlobalContextProperty` and deprecated `removeRumGlobalContext`</div>
553623
554-
// Code example
555-
DD_RUM.onReady(function() {
556-
DD_RUM.setRumGlobalContext({
557-
codeVersion: 34,
558-
})
559-
})
560-
```
561-
{{% /tab %}}
562-
{{% tab "CDN sync" %}}
624+
Follow the [Datadog naming convention][16] for a better correlation of your data across the product.
563625
564-
```
565-
window.DD_RUM &&
566-
DD_RUM.setRumGlobalContext({ '<CONTEXT_KEY>': '<CONTEXT_VALUE>' });
626+
### Replace global context
567627
568-
// Code example
569-
window.DD_RUM &&
570-
DD_RUM.setRumGlobalContext({
571-
codeVersion: 34,
572-
});
573-
```
628+
Replace the default context for all your RUM events with the `setGlobalContext(context: Context)` API:
574629
575-
{{% /tab %}}
576-
{{< /tabs >}}
630+
<div class="alert alert-info">The RUM Browser SDK v4.17.0 introduced `setGlobalContext` and deprecated `setRumGlobalContext`</div>
577631
578632
Follow the [Datadog naming convention][16] for a better correlation of your data across the product.
579633
580-
### Read global context
581-
582-
Once RUM is initialized, read the global context with the `getRumGlobalContext()` API:
583-
584-
{{< tabs >}}
585-
{{% tab "NPM" %}}
634+
### Clear global context
586635
587-
```
588-
import { datadogRum } from '@datadog/browser-rum';
636+
You can clear the global context by using `clearGlobalContext`.
589637
590-
const context = datadogRum.getRumGlobalContext();
591-
```
592-
593-
{{% /tab %}}
594-
{{% tab "CDN async" %}}
595-
```
596-
DD_RUM.onReady(function() {
597-
var context = DD_RUM.getRumGlobalContext();
598-
});
599-
```
600-
{{% /tab %}}
601-
{{% tab "CDN sync" %}}
638+
### Read global context
602639
603-
```
604-
var context = window.DD_RUM && DD_RUM.getRumGlobalContext();
605-
```
640+
Once RUM is initialized, read the global context with the `getGlobalContext()` API:
606641
607-
{{% /tab %}}
608-
{{< /tabs >}}
642+
<div class="alert alert-info">The RUM Browser SDK v4.17.0 introduced `getGlobalContext` and deprecated `getRumGlobalContext`</div>
609643
610644
## Further Reading
611645

0 commit comments

Comments
 (0)