Overview

The privacy plugin generates an allowlist of safe, static strings at build time. When the mask-unless-allowlisted privacy level is enabled, the RUM Browser SDK uses this allowlist to unmask these static strings automatically. Dynamic text, such as user input or customer data fetched from an API, remains masked by default. The allowlist gives mask-unless-allowlisted similar privacy benefits to the mask privacy level, while retaining UI text that makes action names and Session Replay more useful.

How the privacy plugin works

  1. During the build, the plugin extracts static strings from compiled application artifacts, including bundles and source maps, to generate an allowlist. Only string literals appear in the allowlist; runtime values are never included.
  2. At runtime, the RUM Browser SDK checks candidate text against the allowlist before using it in action names or Session Replay. It keeps matching text readable and replaces unknown text with a fixed masking placeholder.

For example, a static Order value label can remain readable in an action name such as Click on Order value. A customer-specific value calculated at runtime, such as $142.75, stays masked unless it’s in the allowlist.

Element-level privacy overrides (for example, data-dd-privacy="mask") still take precedence over the build-time allowlist.

Prerequisites

  • RUM Browser SDK v7 or later.
  • The Datadog build plugin installed and registered with your bundler. See Build Plugins for installation instructions.

Action tracking does not take privacy levels into account when the enablePrivacyForActionName: false SDK configuration option is set. Remove this option to allow the privacy plugin to affect action names. See Tracking User Actions.

Configuration

Configure the Browser SDK

Set defaultPrivacyLevel to mask-unless-allowlisted to apply build-time allowlisting across the application. The mask-unless-allowlisted privacy level requires RUM Browser SDK v7 or later.

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

datadogRum.init({
  applicationId: '<DATADOG_APPLICATION_ID>',
  clientToken: '<DATADOG_CLIENT_TOKEN>',
  site: '<DATADOG_SITE>',
  defaultPrivacyLevel: 'mask-unless-allowlisted',
});

To apply mask-unless-allowlisted to part of the application, set data-dd-privacy="mask-unless-allowlisted" on the relevant HTML element. See Session Replay privacy options for more about element-level privacy overrides.

Configure the build plugin

Enable the privacy plugin by adding a rum.privacy object to your build plugin options. Use include and exclude to control which source files the plugin processes when generating the allowlist:

ParameterTypeRequiredDefaultDescription
rum.privacy.includeArray of RegExp or StringNoJS/TS files (.js, .ts, .jsx, .tsx, .mjs, .cjs, and variants)File patterns to process when generating the allowlist.
rum.privacy.excludeArray of RegExp or StringNonode_modules, .preval. filesFile patterns to skip.

Examples

Enable the privacy plugin with default settings (processes JS/TS files and excludes node_modules and .preval. files):

const { datadogWebpackPlugin } = require('@datadog/webpack-plugin');

module.exports = {
  plugins: [
    datadogWebpackPlugin({
      rum: {
        privacy: {},
      },
    }),
  ],
};

To customize which files the plugin processes, set include and exclude patterns:

const { datadogWebpackPlugin } = require('@datadog/webpack-plugin');

module.exports = {
  plugins: [
    datadogWebpackPlugin({
      rum: {
        privacy: {
          include: [/\.jsx?$/, /\.tsx?$/],
          exclude: [/\/node_modules\//, /\/test\//],
        },
      },
    }),
  ],
};
These examples use webpack. The configuration object is identical across all supported bundlers. See Build Plugins for installation instructions.

Further reading