---
title: React Native Advanced Configuration
description: Learn about advanced configuration options for your React Native setup.
breadcrumbs: >-
  Docs > RUM & Session Replay > Application Monitoring > React Native Monitoring
  > React Native Advanced Configuration
---

# React Native Advanced Configuration

If you have not set up the SDK yet, follow the [in-app setup instructions](https://app.datadoghq.com/rum/application/create) or see the [React Native RUM setup documentation](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/react_native.md).

## Jest testing{% #jest-testing %}

Testing apps using `'@datadog/mobile-react-native'` might require completing extra steps, since Native Modules do not exist in testing environments.

Datadog provides mocks for the `'@datadog/mobile-react-native'` package. To use them with [Jest](https://jestjs.io/), add the following in your Jest setup file:

```
jest.mock('@datadog/mobile-react-native', () => {
  return require('@datadog/mobile-react-native/jest')
});
```

Interaction, error, and resource automated tracking is disabled in your tests if you initialize the SDK with the `DatadogProvider` component.

All SDK methods are mocked by `jest.fn()`, so you can assert that a Datadog SDK method was called:

```
import { DdLogs } from '@datadog/mobile-react-native';

describe('App', () => {
    it('calls DdLogs.debug on mount', () => {
        renderer.create(<App />);
        expect(DdLogs.debug).toHaveBeenCalledWith('app started');
    });
});
```

If you use a test runner other than Jest, you need to create the mocks for your test runner.

## Initialization parameters{% #initialization-parameters %}

You can specify the following parameters in your configuration when initializing the SDK:

### Core configuration{% #core-configuration %}

{% dl %}

{% dt %}
`clientToken`
{% /dt %}

{% dd %}
Required**Type**: StringA [Datadog client token](https://docs.datadoghq.com/account_management/api-app-keys.md#client-tokens).
{% /dd %}

{% dt %}
`env`
{% /dt %}

{% dd %}
Required**Type**: StringThe application's environment, for example: prod, pre-prod, and staging. Follows the [tag syntax requirements](https://docs.datadoghq.com/getting_started/tagging.md#define-tags).
{% /dd %}

{% dt %}
`rumConfiguration`
{% /dt %}

{% dd %}
Optional**Type**: `RumConfiguration`The Datadog RUM configuration. RUM is **disabled by default**. See RUM configuration.
{% /dd %}

{% dt %}
`logsConfiguration`
{% /dt %}

{% dd %}
Optional**Default**: `undefined`**Type**: `LogsConfiguration`The Datadog Logs configuration. Logs is **disabled by default**: use an empty configuration `{}` to enable. See Logs configuration.
{% /dd %}

{% dt %}
`traceConfiguration`
{% /dt %}

{% dd %}
Optional**Type**: `TraceConfiguration`The Datadog Trace configuration. Trace is **disabled by default**: use an empty configuration `{}` to enable. See Trace configuration.
{% /dd %}

{% dt %}
`site`
{% /dt %}

{% dd %}
Optional**Type**: String**Default**: `US1`[The Datadog site parameter of your organization](https://docs.datadoghq.com/getting_started/site.md).
{% /dd %}

{% dt %}
`service`
{% /dt %}

{% dd %}
Optional**Type**: StringThe service name for your application. Follows the [tag syntax requirements](https://docs.datadoghq.com/getting_started/tagging.md#define-tags).
{% /dd %}

{% dt %}
`verbosity`
{% /dt %}

{% dd %}
Optional**Type**: SdkVerbosity**Default**: `undefined`Verbosity for internal SDK logging. Set to `SdkVerbosity.DEBUG` to debug your SDK implementation.
{% /dd %}

{% dt %}
`version`
{% /dt %}

{% dd %}
Optional**Type**: StringThe application's version. For example: 1.2.3, 6c44da20, and 2020.02.13. Follows the [tag syntax requirements](https://docs.datadoghq.com/getting_started/tagging.md#define-tags).
{% /dd %}

{% dt %}
`versionSuffix`
{% /dt %}

{% dd %}
Optional**Type**: StringAdd a suffix to the reported version of the app. Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`. Other special characters are converted to underscores. A dash (`-`) is automatically added between the version and the suffix. Follows the [tag syntax requirements](https://docs.datadoghq.com/getting_started/tagging.md#define-tags).
{% /dd %}

{% dt %}
`proxyConfig`
{% /dt %}

{% dd %}
Optional**Type**: ProxyConfigurationOptional [proxy configuration](https://docs.datadoghq.com/real_user_monitoring/guide/proxy-mobile-rum-data.md).
{% /dd %}

{% dt %}
`uploadFrequency`
{% /dt %}

{% dd %}
Optional**Type**: UploadFrequency**Default**: `UploadFrequency.AVERAGE`Sets the preferred frequency for uploading batches of data.
{% /dd %}

{% dt %}
`batchSize`
{% /dt %}

{% dd %}
Optional**Type**: BatchSize**Default**: `BatchSize.MEDIUM`Defines the Datadog SDK policy when batching data together before uploading it to Datadog servers. Smaller batches mean smaller but more network requests, whereas larger batches mean fewer but larger network requests.
{% /dd %}

{% /dl %}

### RUM configuration{% #rum-configuration %}

{% dl %}

{% dt %}
`applicationId`
{% /dt %}

{% dd %}
**Required****Type**: StringThe RUM application ID.
{% /dd %}

{% dt %}
`trackInteractions`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Enables automatic collection of user actions.
{% /dd %}

{% dt %}
`trackResources`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Enables collection of resource events.
{% /dd %}

{% dt %}
`trackErrors`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Enables collection of React Native crashes.
{% /dd %}

{% dt %}
`trackFrustrations`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `true`Enables [automatic collection of user frustrations](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/frustration_signals.md). Only error taps are supported. Implies `trackInteractions: true`.
{% /dd %}

{% dt %}
`sessionSampleRate`
{% /dt %}

{% dd %}
Optional**Type**: Number**Default**: `100`The percentage of sessions to track: `100` for all, `0` for none. Only tracked sessions send RUM events.
{% /dd %}

{% dt %}
`resourceTraceSampleRate`
{% /dt %}

{% dd %}
Optional**Type**: Number**Default**: `100`The percentage of requests to trace: `100` for all, `0` for none. For more information, see [Connect RUM and Traces](https://docs.datadoghq.com/real_user_monitoring/correlate_with_other_telemetry/apm.md?tab=reactnativerum).
{% /dd %}

{% dt %}
`nativeCrashReportEnabled`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Enables crash reporting for native platforms (iOS, Android).
{% /dd %}

{% dt %}
`nativeLongTaskThresholdMs`
{% /dt %}

{% dd %}
Optional**Type**: Number | false**Default**: `200`The threshold for native long tasks reporting in milliseconds. Setting it to `0` or `false` disables native long task reporting. Values below `100` are raised to `100`. Values above `5000` are lowered to `5000`.
{% /dd %}

{% dt %}
`nativeViewTracking`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Enables native views tracking. Set to `true` if you use a custom navigation system relying on native views.
{% /dd %}

{% dt %}
`nativeInteractionTracking`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Enables native interaction tracking. Set to `true` if you want to track interactions on native screens.
{% /dd %}

{% dt %}
`firstPartyHosts`
{% /dt %}

{% dd %}
Optional**Type**: List**Default**: `[]`List of your backends hosts to enable tracing with. For more information, see [Connect RUM and Traces](https://docs.datadoghq.com/real_user_monitoring/correlate_with_other_telemetry/apm.md?tab=reactnativerum).
{% /dd %}

{% dt %}
`telemetrySampleRate`
{% /dt %}

{% dd %}
Optional**Type**: Number**Default**: `20`Telemetry data (such as errors and debug logs) about SDK execution is sent to Datadog to detect and solve potential issues. Set this option to `0` to opt out from telemetry collection.
{% /dd %}

{% dt %}
`longTaskThresholdMs`
{% /dt %}

{% dd %}
Optional**Type**: Number | false**Default**: `0`The threshold for JavaScript long tasks reporting in milliseconds. Setting it to `0` or `false` disables JavaScript long task reporting. Values below `100` are raised to `100`. Values above `5000` are lowered to `5000`.
{% /dd %}

{% dt %}
`vitalsUpdateFrequency`
{% /dt %}

{% dd %}
Optional**Type**: VitalsUpdateFrequency**Default**: `VitalsUpdateFrequency.AVERAGE`Sets the preferred frequency for collecting mobile vitals.
{% /dd %}

{% dt %}
`trackBackgroundEvents`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Enables tracking of RUM event when no RUM View is active. By default, background events are not tracked. Enabling this feature might increase the number of sessions tracked and impact your billing.
{% /dd %}

{% dt %}
`useAccessibilityLabel`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `true`Determines whether the accessibility labels are used to name RUM actions (default is true).
{% /dd %}

{% dt %}
`trackNonFatalAnrs`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `true` on Android 29 and below, `false` on Android 30+.Enables tracking of non-fatal ANRs on Android. By default, the reporting of non-fatal ANRs on Android 30+ is disabled because it would create too much noise over fatal ANRs. On Android 29 and below, however, the reporting of non-fatal ANRs is enabled by default, as fatal ANRs cannot be reported on those versions.
{% /dd %}

{% dt %}
`trackWatchdogTerminations`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `false`Determines whether the SDK should track application termination by the watchdog on iOS.
{% /dd %}

{% dt %}
`trackMemoryWarnings`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `true`Enables tracking of memory warnings as RUM events on iOS. When enabled, the SDK automatically records a RUM event each time the app receives a memory warning from the operating system.
{% /dd %}

{% dt %}
`appHangThreshold`
{% /dt %}

{% dd %}
Optional**Type**: Number**Default**: `undefined`The app hang threshold in seconds for non-fatal app hangs on iOS. App hangs are an iOS-specific type of error that happens when the application is unresponsive for too long. By default, app hangs reporting is disabled, but you can enable it and set your own threshold to monitor app hangs that last more than a specified duration by using this parameter. Set the `appHangThreshold` parameter to the minimal duration you want app hangs to be reported. For example, enter 0.25 to report hangs lasting at least 250 ms. See [Configure the app hang threshold](https://docs.datadoghq.com/real_user_monitoring/error_tracking/mobile/ios.md?tab=cocoapods#configure-the-app-hang-threshold) for more guidance on what to set this value to.
{% /dd %}

{% dt %}
`initialResourceThreshold`
{% /dt %}

{% dd %}
Optional**Type**: Number**Default**: `0.1` (seconds)The amount of time after a view starts where a Resource should be considered when calculating Time to Network-Settled (TNS). TNS is calculated using all resources that start within the specified threshold, in seconds.
{% /dd %}

{% dt %}
`errorEventMapper`
{% /dt %}

{% dd %}
Optional**Type**: `ErrorEventMapper`**Default**: `null`Custom function to modify the attributes of a RUM Error event before it is sent to Datadog.
{% /dd %}

{% dt %}
`actionEventMapper`
{% /dt %}

{% dd %}
Optional**Type**: `ActionEventMapper`**Default**: `null`Custom function to modify the attributes of a RUM Action event before it is sent to Datadog.
{% /dd %}

{% dt %}
`resourceEventMapper`
{% /dt %}

{% dd %}
Optional**Type**: `ResourceEventMapper`**Default**: `null`Custom function to modify the attributes of a RUM Resource event before it is sent to Datadog.
{% /dd %}

{% dt %}
`customEndpoint`
{% /dt %}

{% dd %}
Optional**Type**: String**Default**: `undefined`Sets a target custom server for RUM.
{% /dd %}

{% /dl %}

### Logs configuration{% #logs-configuration %}

{% dl %}

{% dt %}
`bundleLogsWithRum`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `true`Enables RUM correlation with logs (default is true).
{% /dd %}

{% dt %}
`bundleLogsWithTraces`
{% /dt %}

{% dd %}
Optional**Type**: Boolean**Default**: `true`Enables trace correlation with logs.
{% /dd %}

{% dt %}
`logEventMapper`
{% /dt %}

{% dd %}
Optional**Type**: `LogEventMapper`**Default**: `null`Custom function to modify the attributes of a Log event before it is sent to Datadog.
{% /dd %}

{% dt %}
`customEndpoint`
{% /dt %}

{% dd %}
Optional**Type**: String**Default**: `undefined`Sets a target custom server for Logs.
{% /dd %}

{% /dl %}

### Trace configuration{% #trace-configuration %}

{% dl %}

{% dt %}
`customEndpoint`
{% /dt %}

{% dd %}
Optional**Type**: String**Default**: `undefined`Sets a target custom server for Traces.
{% /dd %}

{% /dl %}

## Manual instrumentation{% #manual-instrumentation %}

If automatic instrumentation doesn't suit your needs, you can manually create RUM Events and Logs:

### Send logs{% #send-logs %}

When you instrument your code to send logs, it can include debug, info, warn, or error details:

```
DdLogs.debug('Lorem ipsum dolor sit amet…', {});
DdLogs.info('Lorem ipsum dolor sit amet…', {});
DdLogs.warn('Lorem ipsum dolor sit amet…', {});
DdLogs.error('Lorem ipsum dolor sit amet…', {});
```

### Manually track RUM views{% #manually-track-rum-views %}

To manually track RUM Views, provide a `view key`, `view name`, and `action name` at initialization. Depending on your needs, you can choose one of the following strategies:

```
DdRum.startView('<view-key>', 'View Name', {}, Date.now());
//…
DdRum.stopView('<view-key>', { custom: 42 }, Date.now());
```

### Manually track RUM actions{% #manually-track-rum-actions %}

You can manually track RUM actions:

```
DdRum.addAction(RumActionType.TAP, 'action name', {}, Date.now());
```

To track a continuous action:

```
DdRum.startAction(RumActionType.TAP, 'action name', {}, Date.now());
//...
DdRum.stopAction({}, Date.now());
```

### Manually track RUM errors{% #manually-track-rum-errors %}

You can manually track RUM errors:

```
DdRum.addError('<message>', ErrorSource.SOURCE, '<stacktrace>', {}, Date.now());
```

### Manually track RUM resources{% #manually-track-rum-resources %}

You can manually track RUM resources:

```
DdRum.startResource('<res-key>', 'GET', 'http://www.example.com/api/v1/test', {}, Date.now());
//...
DdRum.stopResource('<res-key>', 200, 'xhr', (size = 1337), {}, Date.now());
```

### Notify the SDK that your view finished loading{% #notify-the-sdk-that-your-view-finished-loading %}

You can notify the SDK that your view has finished loading by calling the `addViewLoadingTime` method on `DdRum`. Call this method when your view is fully loaded and ready to be displayed to the user:

```
DdRum.addViewLoadingTime(true);
```

Use the `overwrite` parameter to replace the previously calculated loading time for the current view.

After the loading time is sent, it is accessible as `@view.loading_time` and is visible in the RUM UI.

**Note**: This API is experimental.

### Add custom timings{% #add-custom-timings %}

You can add custom timings:

```
DdRum.addTiming('<timing-name>');
```

### Manually send spans{% #manually-send-spans %}

You can send spans manually:

```
const spanId = await DdTrace.startSpan('foo', { custom: 42 }, Date.now());
//...
DdTrace.finishSpan(spanId, { custom: 21 }, Date.now());
```

## Track custom global attributes{% #track-custom-global-attributes %}

You can attach user information to all RUM events to get more detailed information from your RUM sessions.

### Track user sessions{% #track-user-sessions %}

Adding user information to your RUM sessions makes it possible to:

- Follow the journey of a given user
- Know which users are the most impacted by errors
- Monitor performance for your most important users

{% image
   source="https://docs.dd-static.net/images/real_user_monitoring/browser/advanced_configuration/user-api.73b0cac9af174bfd4322133367d6e968.png?auto=format"
   alt="User API in RUM UI" /%}

| Attribute       | Type   | Description                                                                                                                              |
| --------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `usr.id`        | String | (Required) Unique user identifier.                                                                                                       |
| `usr.name`      | String | (Optional) User friendly name, displayed by default in the RUM UI.                                                                       |
| `usr.email`     | String | (Optional) User email, displayed in the RUM UI if the user name is not present.                                                          |
| `usr.extraInfo` | Object | (Optional) Include custom attributes such as subscription type, any user specific information that enhance user context in RUM sessions. |

To identify user sessions, use the `setUserInfo` API, for example:

```
DdSdkReactNative.setUserInfo({
    id: '1337',
    name: 'John Smith',
    email: 'john@example.com',
    extraInfo: {
        type: 'premium'
    }
});
```

If you want to add or update user information, you can use the following code to modify the existing user's details.

```
DdSdkReactNative.addUserExtraInfo({
    hasPaid: 'true'
});
```

If you want to clear the user information (for example, when the user signs out), you can do so by calling the `clearUserInfo` API:

```
DdSdkReactNative.clearUserInfo();
```

### Global attributes{% #global-attributes %}

You can keep global attributes to track information about a specific session, such as A/B testing configuration, ad campaign origin, or cart status. These attributes are attached to all future Logs, Spans, and RUM events.

**Add multiple global attributes**

Use `addAttributes` to add or update several attributes at once.

```
DdSdkReactNative.addAttributes({
    profile_mode: 'wall',
    chat_enabled: true,
    campaign_origin: 'example_ad_network'
});
```

**Add a single global attribute**

Use `addAttribute` when you want to add or update a single attribute.

```
DdSdkReactNative.addAttribute('profile_mode', 'wall');
DdSdkReactNative.addAttribute('chat_enabled', true);
```

If the attribute already exists, its value is overwritten.

**Remove a single global attribute**

Use `removeAttribute` to remove a specific attribute from the global context.

```
DdSdkReactNative.removeAttribute('campaign_origin');
```

After removal, the attribute is no longer attached to future Logs, Spans, or RUM events.

**Remove multiple global attributes**

Use `removeAttributes` to remove several attributes at once.

```
DdSdkReactNative.removeAttributes([
    'profile_mode',
    'chat_enabled'
]);
```

This is useful when cleaning up session-specific data, such as when a user logs out or exits a feature flow.

## Track view navigation{% #track-view-navigation %}

Because React Native offers a wide range of libraries to create screen navigation, only manual view tracking is supported by default. To see RUM or Error tracking sessions populate in Datadog, you need to implement view tracking.

You can manually start and stop a view using the following `startView()` and `stopView` methods.

```
import {
    DdRum
} from '@datadog/mobile-react-native';

// Start a view with a unique view identifier, a custom view name, and an object to attach additional attributes to the view
DdRum.startView(
    '<view-key>', // <view-key> has to be unique, for example it can be ViewName-unique-id
    'View Name',
    { 'custom.foo': 'something' },
    Date.now()
);
// Stops a previously started view with the same unique view identifier, and an object to attach additional attributes to the view
DdRum.stopView('<view-key>', { 'custom.bar': 42 }, Date.now());
```

Use one of Datadog's integrations to automatically track views for the following libraries:

- If you use the [`react-native-navigation`](https://github.com/wix/react-native-navigation) library, then add the `@datadog/mobile-react-native-navigation` package and follow the [setup instructions](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/react_native/integrated_libraries.md).
- If you use the [`react-navigation`](https://github.com/react-navigation/react-navigation) library, then add the `@datadog/mobile-react-navigation` package and follow the [setup instructions](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/react_native/integrated_libraries.md).

If you experience any issues setting up View tracking with `@datadog/mobile-react-navigation` you can see this Datadog [example application](https://github.com/DataDog/dd-sdk-reactnative-examples/tree/main/rum-react-navigation) as a reference.

## Clear all data{% #clear-all-data %}

Use `clearAllData` to clear all data that has not been sent to Datadog.

```
DdSdkReactNative.clearAllData();
```

## Modify or drop RUM events{% #modify-or-drop-rum-events %}

To modify attributes of a RUM event before it is sent to Datadog, or to drop an event entirely, use the Event Mappers API when configuring the RUM React Native SDK:

```
import {
    SdkVerbosity,
    DatadogProvider,
    DatadogProviderConfiguration,
    RumConfiguration,
    LogsConfiguration,
    TraceConfiguration
} from '@datadog/mobile-react-native';

const config = new DatadogProviderConfiguration(
    '<CLIENT_TOKEN>',
    '<ENVIRONMENT_NAME>',
    {
        rumConfiguration: {
            applicationId: '<APPLICATION_ID>',
            trackInteractions: true, // Track user interactions (such as a tap on buttons).
            trackResources: true, // Track XHR resources
            trackErrors: true, // Track errors
            // RUM Event Mappers
            errorEventMapper: (event) => event,
            resourceEventMapper: (event) => event,
            actionEventMapper: (event) => event
        },

        // Log Event Mappers
        logsConfiguration: {
            logEventMapper: (event) => event
        },

        traceConfiguration: {}
    }
)
```

Each mapper is a function with a signature of `(T) -> T?`, where `T` is a concrete RUM event type. This allows changing portions of the event before it is sent, or dropping the event entirely.

For example, to redact sensitive information from a RUM error `message`, implement a custom `redacted` function and use it in `errorEventMapper`:

```
config.rumConfiguration.errorEventMapper = (event) => {
    event.message = redacted(event.message);
    return event;
};
```

Returning `null` from the error, resource, or action mapper drops the event entirely; the event is not sent to Datadog.

Depending on the event type, only some specific properties can be modified:

| Event Type               | Attribute key                   | Description                        |
| ------------------------ | ------------------------------- | ---------------------------------- |
| LogEvent                 | `logEvent.message`              | Message of the log.                |
| `logEvent.context`       | Custom attributes of the log.   |
| ActionEvent              | `actionEvent.context`           | Custom attributes of the action.   |
| ErrorEvent               | `errorEvent.message`            | Error message.                     |
| `errorEvent.source`      | Source of the error.            |
| `errorEvent.stacktrace`  | Stacktrace of the error.        |
| `errorEvent.context`     | Custom attributes of the error. |
| `errorEvent.timestampMs` | Timestamp of the error.         |
| ResourceEvent            | `resourceEvent.context`         | Custom attributes of the resource. |

Events include additional context:

| Event Type                                       | Context attribute key                                                   | Description                                                                                                                                                                                                      |
| ------------------------------------------------ | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| LogEvent                                         | `logEvent.additionalInformation.userInfo`                               | Contains the global user info set by `DdSdkReactNative.setUserInfo`.                                                                                                                                             |
| `logEvent.additionalInformation.attributes`      | Contains the global attributes set by `DdSdkReactNative.addAttributes`. |
| ActionEvent                                      | `actionEvent.actionContext`                                             | [GestureResponderEvent](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/683ec4a2b420ff6bd3873a7338416ad3ec0b6595/types/react-native-side-menu/index.d.ts#L2) corresponding to the action or `undefined`. |
| `actionEvent.additionalInformation.userInfo`     | Contains the global user info set by `DdSdkReactNative.setUserInfo`.    |
| `actionEvent.additionalInformation.attributes`   | Contains the global attributes set by `DdSdkReactNative.addAttributes`. |
| ErrorEvent                                       | `errorEvent.additionalInformation.userInfo`                             | Contains the global user info set by `DdSdkReactNative.setUserInfo`.                                                                                                                                             |
| `errorEvent.additionalInformation.attributes`    | Contains the global attributes set by `DdSdkReactNative.addAttributes`. |
| ResourceEvent                                    | `resourceEvent.resourceContext`                                         | [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) corresponding to the resource or `undefined`.                                                                                  |
| `resourceEvent.additionalInformation.userInfo`   | Contains the global user info set by `DdSdkReactNative.setUserInfo`.    |
| `resourceEvent.additionalInformation.attributes` | Contains the global attributes set by `DdSdkReactNative.addAttributes`. |

## Retrieve the RUM session ID{% #retrieve-the-rum-session-id %}

Retrieving the RUM session ID can be helpful for troubleshooting. For example, you can attach the session ID to support requests, emails, or bug reports so that your support team can later find the user session in Datadog.

You can access the RUM session ID at runtime with:

```
import { DdRum } from '@datadog/mobile-react-native';

const rumSessionId = await DdRum.getCurrentSessionId();
```

## Resource timings{% #resource-timings %}

Resource tracking provides the following timings:

- `First Byte`: The time between the scheduled request and the first byte of the response. This includes time for the request preparation on the native level, network latency, and the time it took the server to prepare the response.
- `Download`: The time it took to receive a response.

## Initializing asynchronously{% #initializing-asynchronously %}

If your app includes a lot of animations when it starts, running code during these animations might delay them on some devices. To delay the Datadog React Native SDK for RUM to run after all current animations are started, set the `initializationMode` to `InitializationMode.ASYNC` in your configuration:

```
import {
    DatadogProvider,
    DatadogProviderConfiguration,
    InitializationMode,
    RumConfiguration
} from '@datadog/mobile-react-native';

const datadogConfiguration = new DatadogProviderConfiguration(
    '<CLIENT_TOKEN>',
    '<ENVIRONMENT_NAME>',
    initializationMode: InitializationMode.ASYNC,
    rumConfiguration: {
        applicationId: '<APPLICATION_ID>'
    }
);

export default function App() {
    return (
        <DatadogProvider configuration={datadogConfiguration}>
            <Navigation />
        </DatadogProvider>
    );
}
```

This uses React Native's [InteractionManager.runAfterInteractions](https://reactnative.dev/docs/interactionmanager#runafterinteractions) to delay the animations.

All interactions with the RUM SDK (view tracking, actions, resources tracing, and so on) are still recorded and kept in a queue with a limit of 100 events.

Logs are not recorded and calling a `DdLogs` method before the actual initialization might break logging.

If you experience any issue setting up the asynchronous initialization of Datadog, see the [example application](https://github.com/DataDog/dd-sdk-reactnative-examples/tree/main/rum-react-navigation-async).

## Delaying the initialization{% #delaying-the-initialization %}

There may be situations where you want to wait before initializing the SDK. For example, when you want to use a different configuration based on the user role or to fetch the configuration from one of your servers.

In that case, you can auto-instrument your app from the start (automatically collect user interactions, XHR resources, and errors) and record up to 100 RUM and span events before initializing the SDK.

```
import {
    DatadogProvider,
    DatadogProviderConfiguration,
    PropagatorType
} from '@datadog/mobile-react-native';

const datadogAutoInstrumentation = {
    rumConfiguration: {
        resourceTraceSampleRate: 100,
        trackErrors: true,
        trackInteractions: true,
        trackResources: true,
        firstPartyHosts: [
            {
                match: 'example.com',
                propagatorTypes: [
                    PropagatorType.DATADOG,
                    PropagatorType.TRACECONTEXT
                ]
            }
        ],
    }
};

const initializeApp = async () => {
    const configuration = await fetchDatadogConfiguration(); // Fetches the configuration from one of your servers
    await DatadogProvider.initialize(configuration);
};

export default function App() {
    useEffect(() => initializeApp(), []);

    return (
        <DatadogProvider configuration={datadogAutoInstrumentation}>
            <Navigation />
        </DatadogProvider>
    );
}
```

Where your configuration has the following keys:

```
import { ProxyConfiguration, SdkVerbosity, TrackingConsent } from '@datadog/mobile-react-native';

const configuration = {
    clientToken: '<CLIENT_TOKEN>',
    env: '<ENVIRONMENT_NAME>',
    service: 'com.myapp', // Optional: set the reported service name. Default = package name / bundleIdentifier of your Android / iOS app respectively
    version: '1.0.0', // Optional: see overriding the reported version in the documentation. Default = VersionName / Version of your Android / iOS app respectively
    versionSuffix: 'codepush.v3', // Optional: see overriding the reported version in the documentation. Default = undefined
    trackingConsent: TrackingConsent.GRANTED, // Optional: disable collection if user has not granted consent for tracking. Default = TrackingConsent.GRANTED
    verbosity: SdkVerbosity.WARN, // Optional: let the SDK print internal logs (above or equal to the provided level). Default = undefined (no logs)
    proxyConfiguration: new ProxyConfiguration() // Optional: send requests through a proxy. Default = undefined,
    site: 'US1', // Optional: specify Datadog site. Default = 'US1'
    rumConfiguration: {
        applicationId: '<RUM_APPLICATION_ID>',
        sessionSampleRate: 80, // Optional: sample RUM sessions (here, 80% of session will be sent to Datadog). Default = 100%
        nativeViewTracking: true, // Optional: enables tracking of native views. Default = false
        nativeCrashReportEnabled: true, // Optional: enable native crash reports. Default = false
    }
};
```

## Hybrid app monitoring{% #hybrid-app-monitoring %}

See [Monitor hybrid React Native applications](https://docs.datadoghq.com/real_user_monitoring/guide/monitor-hybrid-react-native-applications.md).

## Further reading{% #further-reading %}

- [Source code for dd-sdk-reactnative](https://github.com/DataDog/dd-sdk-reactnative)
- [Learn about React Native monitoring](https://docs.datadoghq.com/real_user_monitoring/reactnative.md)
- [Monitor hybrid React Native applications](https://docs.datadoghq.com/real_user_monitoring/guide/monitor-hybrid-react-native-applications.md)

{% image
   source="https://docs.dd-static.net/images/real_user_monitoring/browser/advanced_configuration/user-api.73b0cac9af174bfd4322133367d6e968.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/real_user_monitoring/browser/advanced_configuration/user-api.73b0cac9af174bfd4322133367d6e968.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="" /%}
