Socket
Socket
Sign inDemoInstall

@datadog/browser-rum

Package Overview
Dependencies
Maintainers
1
Versions
251
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/browser-rum

## Overview


Version published
Weekly downloads
1.4M
decreased by-3.03%
Maintainers
1
Weekly downloads
 
Created

Package description

What is @datadog/browser-rum?

The @datadog/browser-rum package is a Real User Monitoring (RUM) solution provided by Datadog. It allows developers to collect and analyze performance and user behavior data from their web applications in real-time. This data can be used to identify and troubleshoot issues, improve user experience, and monitor application performance.

What are @datadog/browser-rum's main functionalities?

Real User Monitoring

Initializes the RUM SDK to start collecting data from the user's browser, including session replay recording.

import { datadogRum } from '@datadog/browser-rum';

datadogRum.init({
  applicationId: 'YOUR_APPLICATION_ID',
  clientToken: 'YOUR_CLIENT_TOKEN',
  site: 'datadoghq.com',
  service:'your-service-name',
  // Specify a version number to identify the deployed version of your application in Datadog
  version: '1.0.0',
  sampleRate: 100,
  trackInteractions: true,
});

datadogRum.startSessionReplayRecording();

Custom User Actions

Records custom user actions, such as button clicks, with additional context.

datadogRum.addAction('button_click', { buttonId: 'my-button' });

Logging Errors

Logs errors manually with additional context to help with debugging.

datadogRum.addError(new Error('Something went wrong'), {
  context: {
    productId: 123
  }
});

User Tracking

Sets user information to track user-specific data and associate it with the collected RUM data.

datadogRum.setUser({
  id: '1234',
  name: 'John Doe',
  email: 'john.doe@example.com',
  // User-defined attributes
  plan_type: 'premium',
});

Other packages similar to @datadog/browser-rum

Changelog

Source

v1.24.1

  • 🐛 [RUMF-742] fix cookie creation domain when trackSessionAcrossSubdomains: true (#573)
  • ✨ [RUMF-727] introduce v2 format (experimental) (#570)

Readme

Source

RUM Browser Monitoring

Overview

Datadog Real User Monitoring (RUM) enables you to visualize and analyze the real-time performance and user journeys of your application's individual users.

Setup

Datadog

To set up Datadog RUM browser monitoring:

  1. In Datadog, navigate to the Real User Monitoring page and click the New Application button.
  2. Enter a name for your application and click Generate Client Token. This generates a clientToken and an applicationId for your application.
  3. Setup the Datadog RUM SDK NPM or the generated code snippet.
  4. Deploy the changes to your application. Once your deployment is live, Datadog collects events from user browsers.
  5. Visualize the data collected using Datadog dashboards.

Note: Your application shows up on the application list page as "pending" until Datadog starts receiving data.

NPM

Add @datadog/browser-rum to your package.json file, then initialize it with:

import { datadogRum } from '@datadog/browser-rum'

datadogRum.init({
  applicationId: '<DATADOG_APPLICATION_ID>',
  clientToken: '<DATADOG_CLIENT_TOKEN>',
  site: '<DATADOG_SITE>',
  //  service: 'my-web-application',
  //  env: 'production',
  //  version: '1.0.0',
  sampleRate: 100,
  trackInteractions: true,
})

Note: The trackInteractions parameter enables the automatic collection of user clicks in your application. Sensitive and private data contained on your pages may be included to identify the elements interacted with.

Bundle

Add the generated code snippet to the head tag (in front of any other script tags) of every HTML page you want to monitor in your application. Including the script tag higher and synchronized ensures Datadog RUM can collect all performance data and errors.

<script src="https://www.datadoghq-browser-agent.com/datadog-rum.js" type="text/javascript"></script>
<script>
  window.DD_RUM &&
    window.DD_RUM.init({
      clientToken: '<CLIENT_TOKEN>',
      applicationId: '<APPLICATION_ID>',
      site: '<DATADOG_SITE>',
      //  service: 'my-web-application',
      //  env: 'production',
      //  version: '1.0.0',
      sampleRate: 100,
      trackInteractions: true,
    })
</script>

Notes:

  • The trackInteractions parameter enables the automatic collection of user clicks in your application. Sensitive and private data contained on your pages may be included to identify the elements interacted with.
  • The window.DD_RUM check is used to prevent issues if a loading failure occurs with the RUM SDK.

TypeScript

Types are compatible with TypeScript >= 3.0. For earlier versions, import JS sources and use global variables to avoid any compilation issues:

import '@datadog/browser-rum/bundle/datadog-rum'

window.DD_RUM.init({
  applicationId: 'XXX',
  clientToken: 'XXX',
  site: 'datadoghq.com',
  resourceSampleRate: 100,
  sampleRate: 100,
})

Configuration

Initialization parameters

The following parameters are available:

ParameterTypeRequiredDefaultDescription
applicationIdStringYesThe RUM application ID.
clientTokenStringYesA Datadog client token.
siteStringYesdatadoghq.comThe Datadog site of your organization. US: datadoghq.com, EU: datadoghq.eu
serviceStringNoThe service name for your application.
envStringNoThe application’s environment, for example: prod, pre-prod, staging, etc.
versionStringNoThe application’s version, for example: 1.2.3, 6c44da20, 2020.02.13, etc.
trackInteractionsBooleanNofalseEnables automatic collection of users actions.
resourceSampleRateNumberNo100The percentage of tracked sessions with resources collection: 100 for all, 0 for none.
sampleRateNumberNo100The percentage of sessions to track: 100 for all, 0 for none. Only tracked sessions send rum events.
silentMultipleInitBooleanNofalseInitialization fails silently if Datadog's RUM is already initialized on the page.
proxyHostStringNoOptional proxy host (ex: www.proxy.com), see the full proxy setup guide for more information.
allowedTracingOriginsListNoA list of request origins used to inject tracing headers.

Options that must have matching configuration when also using logs SDK:

ParameterTypeRequiredDefaultDescription
trackSessionAcrossSubdomainsBooleanNofalsePreserve the session across subdomains for the same site.
useSecureSessionCookieBooleanNofalseUse a secure session cookie. This disables RUM events sent on insecure (non-HTTPS) connections.
useCrossSiteSessionCookieBooleanNofalseUse a secure cross-site session cookie. This allows the logs SDK to run when the site is loaded from another one (iframe). Implies useSecureSessionCookie.
Example

Init must be called to start the tracking:

init(configuration: {
    applicationId: string,
    clientToken: string,
    site?: string,
    resourceSampleRate?: number
    sampleRate?: number,
    silentMultipleInit?: boolean,
    trackInteractions?: boolean,
    service?: string,
    env?: string,
    version?: string,
    allowedTracingOrigins?: Array<String|Regexp>,
    trackSessionAcrossSubdomains?: boolean,
    useSecureSessionCookie?: boolean,
    useCrossSiteSessionCookie?: boolean,
})

Name click actions

The RUM library uses various strategies to automatically name click actions. If you want more control, define a data-dd-action-name attribute on clickable elements (or any of their parents) to name the action, for example:

<a class="btn btn-default" href="#" role="button" data-dd-action-name="Login button">Login</a>
<div class="alert alert-danger" role="alert" data-dd-action-name="Dismiss alert">
  <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
  <span class="sr-only">Error:</span>
  Enter a valid email address
</div>

FAQs

Package last updated on 20 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc