> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Datadog RUM

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs">
  <Danger>
    **This integration is not available on LaunchDarkly's European Union (EU) instance**

    To learn more, read <a href="/docs/home/infrastructure/eu">LaunchDarkly in the European Union (EU)</a>.
  </Danger>
</View>

<Note>
  **The Datadog RUM integration is available to customers on select plans**

  The Datadog RUM integration is only available to customers on select plans. To learn more, [read about our pricing](https://launchdarkly.com/pricing/). To upgrade your plan, [contact Sales](https://launchdarkly.com/contact-sales/).
</Note>

This topic explains how to send LaunchDarkly feature flag evaluation data to Datadog Real User Monitoring (RUM) and how to use that data once it arrives.

Datadog is an observability service for cloud-scale applications. It monitors servers, databases, tools, and services through a Software as a Service (SaaS) data analytics platform. Datadog's RUM product monitors the performance and behavior of your front-end applications. Datadog's LaunchDarkly RUM integration lets you send feature flag evaluation data from the LaunchDarkly JavaScript SDK to Datadog as event properties. When you send this data to RUM, you can correlate feature releases with user experience, error rates, and Core Web Vitals.

## Prerequisites

You need the following things to complete this procedure:

* The [LaunchDarkly JavaScript SDK](/docs/sdk/client-side/javascript) installed and initialized in your application
* Datadog RUM Browser SDK version 4.25.0 or higher, with [RUM browser monitoring](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser.md#setup) set up
* Your LaunchDarkly client-side ID

<Accordion title="Finding your SDK credentials">
  You can find your server-side SDK keys, mobile keys, and client-side ID on the **SDK keys** page under **Settings**.
</Accordion>

## Set up feature flag data collection

To send feature flag evaluation data from LaunchDarkly to Datadog, configure both SDKs: the Datadog RUM SDK to accept feature flag data, and the LaunchDarkly JavaScript SDK to report evaluations to Datadog as they happen.

### Enable feature flags in the Datadog RUM SDK

First, configure the Datadog RUM SDK to collect feature flag data. Add the `enableExperimentalFeatures` initialization parameter with the value `["feature_flags"]`:

<CodeGroup>
  ```js title="Datadog RUM SDK initialization" expandable lines wrap theme={null}
  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',
    enableExperimentalFeatures: ["feature_flags"],
    sessionSampleRate: 100,
    sessionReplaySampleRate: 20,
    trackUserInteractions: true,
    trackResources: true,
    trackLongTasks: true,
  });
  ```
</CodeGroup>

### Report flag evaluations from the LaunchDarkly SDK

Next, initialize the LaunchDarkly JavaScript SDK with an `inspectors` configuration option. Inspectors let the SDK notify other systems, like Datadog, each time it evaluates a flag.

Add a `flag-used` inspector that calls Datadog's `addFeatureFlagEvaluation` method for every flag evaluation. Here is an example:

<CodeGroup>
  ```js title="LaunchDarkly SDK initialization with Datadog inspector" expandable lines wrap theme={null}
  import * as LDClient from 'launchdarkly-js-client-sdk';
  import { datadogRum } from '@datadog/browser-rum';

  const context = {
    kind: 'user',
    key: 'example-user-key',
    name: 'Sandy',
    email: 'sandy@testcorp.com'
  };

  const client = LDClient.initialize('enter-your-client-side-id-here', context, {
    inspectors: [
      {
        type: 'flag-used',
        name: 'dd-inspector',
        method: (key, detail) => {
          datadogRum.addFeatureFlagEvaluation(key, detail.value);
        },
      },
    ],
  });
  ```
</CodeGroup>

Every time your application evaluates a flag through this client, the inspector sends the flag's key and evaluated value to Datadog as a feature flag evaluation.

<Warning>
  **Feature flag names have character restrictions in Datadog**

  Datadog does not support these characters in feature flag names: `.`, `:`, `+`, `-`, `=`, `&&`, `||`, `>`, `<`, `!`, `(`, `)`, `{`, `}`, `[`, `]`, `^`, `"`, `~`, `*`, `?`, `\`. If your flag keys contain any of these characters, replace them before you send the evaluation to Datadog. Here is an example: `datadogRum.addFeatureFlagEvaluation(key.replaceAll(':', '_'), value)`.
</Warning>

<Note>
  **This integration supports the Browser SDK only**

  Datadog's LaunchDarkly RUM integration works with the LaunchDarkly JavaScript SDK. It does not support the LaunchDarkly iOS, Android, Flutter, or React Native SDKs.
</Note>

## Review your feature flag data

After you configure both SDKs, Datadog associates flag evaluations with the RUM sessions, views, and errors where they occur.

### Use the Feature Flag Tracking tab

Open the **Feature Flag Tracking** tab within RUM to see a list of your feature flags along with summary statistics for each one.

Each flag has one of three statuses:

* **Active**: The flag evaluated more than one variant over the past two weeks.
* **Inactive**: The flag only evaluated its control variant over the past two weeks.
* **Out to 100%**: The flag only evaluated one of its non-control variants over the past two weeks.

Click a flag in the list to open its feature flag analysis page, which has the following tabs:

* The **Users** tab shows summary statistics about the users who encountered each variant of the flag.
* The **Issues** tab shows errors that occurred in sessions where the flag evaluated. Use this tab to check whether an error is related to a specific variant.
* The **Performance** tab shows Core Web Vitals and loading time for each variant, so you can determine whether a variant affects your application's performance.

### Query flag data in the RUM Explorer

To build custom views of your flag data, use the [RUM Explorer](https://app.datadoghq.com/rum/explorer) with the `@feature_flags.{flag_name}` attribute. Search your Sessions, Views, or Errors, and scope your queries to sessions where a specific flag evaluated.

For example, if you want to measure how a new checkout flow affects conversion rate, group a conversion rate graph by `@feature_flags.{flag_name}` to compare each variant.

## Further reading

* To learn more about setting up feature flag tracking for other SDK platforms, read Datadog's [Setup Feature Flag Tracking](https://docs.datadoghq.com/real_user_monitoring/feature_flag_tracking/setup/#launchdarkly-integration) documentation.
* For an example of remotely configuring your RUM initialization settings using LaunchDarkly flags, read Datadog's guide [Remotely configure RUM using LaunchDarkly](https://docs.datadoghq.com/real_user_monitoring/guide/remotely-configure-rum-using-launchdarkly/).
* To learn more about SDK hooks and inspectors, read [Inspectors](/docs/sdk/features/inspectors) in the JavaScript SDK reference guide.
