---
title: Mobile Session Replay Setup and Configuration
description: Setting up and configuring Mobile Session Replay.
breadcrumbs: >-
  Docs > Session Replay > Mobile Session Replay > Mobile Session Replay Setup
  and Configuration
---

# Mobile Session Replay Setup and Configuration

## Setup{% #setup %}

{% section displayed-if="SDK is Android" %}
This section only applies to users who meet the following criteria: SDK is Android

All Session Replay SDK versions can be found in the [Maven Central Repository](https://central.sonatype.com/artifact/com.datadoghq/dd-sdk-kotlin-multiplatform-session-replay/versions).

To set up Mobile Session Replay for Android:

### Step 1 - Set up the Android RUM SDK{% #step-1--set-up-the-android-rum-sdk %}

Make sure you've [set up and initialized the Datadog Android RUM SDK](https://docs.datadoghq.com/real_user_monitoring/android/?tab=kotlin) with views instrumentation enabled.

### Step 2 - Declare the Datadog Session Replay as a dependency{% #step-2--declare-the-datadog-session-replay-as-a-dependency %}

In the `build.gradle.kts` file:

```
implementation("com.datadoghq:dd-sdk-android-rum:[datadog_version]")
implementation("com.datadoghq:dd-sdk-android-session-replay:[datadog_version]")
// in case you need Material support
implementation("com.datadoghq:dd-sdk-android-session-replay-material:[datadog_version]")
// in case you need Jetpack Compose support
implementation("com.datadoghq:dd-sdk-android-session-replay-compose:[datadog_version]")
```

### Step 3 - Enable Session Replay{% #enable-android %}

In the `Application.kt` file:

```
val sessionReplayConfig = SessionReplayConfiguration.Builder([sampleRate])
  // in case you need Material extension support
  .addExtensionSupport(MaterialExtensionSupport())
  // in case you need Jetpack Compose support
  .addExtensionSupport(ComposeExtensionSupport())
  .build()

SessionReplay.enable(sessionReplayConfig)
```
{% /section %}

{% section displayed-if="SDK is iOS" %}
This section only applies to users who meet the following criteria: SDK is iOS

To set up Mobile Session Replay for iOS:

### Step 1 - Set up the iOS RUM SDK{% #step-1--set-up-the-ios-rum-sdk %}

Make sure you've [set up and initialized the Datadog iOS RUM SDK](https://docs.datadoghq.com/real_user_monitoring/ios/?tab=swift) with views instrumentation enabled.

### Step 2 - Declare the Datadog Session Replay as a dependency{% #step-2--declare-the-datadog-session-replay-as-a-dependency-2 %}

{% tab title="Swift Package Manager" %}
Add `DatadogSessionReplay` library as a dependency to your app target.
{% /tab %}

{% tab title="CocoaPods" %}
Add `pod 'DatadogSessionReplay` to your `Podfile`.
{% /tab %}

{% tab title="Carthage" %}
Add `DatadogSessionReplay.xcframework` as a dependency to your app target.
{% /tab %}

### Step 3 - Enable Session Replay{% #enable-ios %}

In the `AppDelegate.swift` file:

```
import DatadogSessionReplay

SessionReplay.enable(
  with: SessionReplay.Configuration(
    replaySampleRate: sampleRate,
    // Enable the experimental SwiftUI recording
    featureFlags: [.swiftui: true]
  )
)
```
{% /section %}

{% section displayed-if="SDK is Kotlin Multiplatform" %}
This section only applies to users who meet the following criteria: SDK is Kotlin Multiplatform

All Session Replay SDK versions can be found in the [Maven Central Repository](https://central.sonatype.com/artifact/com.datadoghq/dd-sdk-android-session-replay/versions).

To set up Mobile Session Replay for Kotlin Multiplatform:

### Step 1 - Set up the Kotlin Multiplatform RUM SDK{% #step-1--set-up-the-kotlin-multiplatform-rum-sdk %}

Make sure you've [set up and initialized the Datadog Kotlin Multiplatform RUM SDK](https://docs.datadoghq.com/real_user_monitoring/kotlin_multiplatform/) with views instrumentation enabled.

### Step 2 - Add the `DatadogSessionReplay` iOS library as a link-only dependency{% #step-2--add-the- %}

For instructions, see the [guide](https://docs.datadoghq.com/real_user_monitoring/kotlin_multiplatform/#add-native-dependencies-for-ios).

### Step 3 - Declare Datadog Session Replay as a dependency{% #step-3--declare-datadog-session-replay-as-a-dependency %}

In the `build.gradle.kts` file:

```
kotlin {
  sourceSets {
    commonMain.dependencies {
      implementation("com.datadoghq:dd-sdk-kotlin-multiplatform-rum:[datadog_version]")
      implementation("com.datadoghq:dd-sdk-kotlin-multiplatform-session-replay:[datadog_version]")
    }

    // in case you need Material support on Android
    androidMain.dependencies {
      implementation("com.datadoghq:dd-sdk-android-session-replay-material:[datadog_version]")
    }
  }
}
```

### Step 4 - Enable Session Replay{% #step-4--enable-session-replay %}

In the `Application.kt` file:

```
// in common source set
val sessionReplayConfig = SessionReplayConfiguration.Builder([sampleRate])
  .build()
SessionReplay.enable(sessionReplayConfig)
```

### Step 5 - Set up Material support on Android (Optional){% #step-5--set-up-material-support-on-android--optional %}

If your app uses Material on Android, add:

```
SessionReplayConfiguration.Builder.addExtensionSupport(MaterialExtensionSupport())
```
{% /section %}

{% section displayed-if="SDK is React Native" %}
This section only applies to users who meet the following criteria: SDK is React Native

{% alert level="warning" %}
To enable Session Replay, you must use at least version `2.0.4` of the Datadog [React Native SDK](https://github.com/DataDog/dd-sdk-reactnative), and ensure that the Session Replay SDK version matches the React Native SDK version you are using.
{% /alert %}

All Session Replay SDK versions can be found in the [npmjs repository](https://www.npmjs.com/package/@datadog/mobile-react-native-session-replay?activeTab=versions).

To set up Mobile Session Replay for React Native:

### Step 1 - Set up the React Native SDK{% #step-1--set-up-the-react-native-sdk %}

Make sure you've [set up and initialized the Datadog React Native SDK](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/react_native/setup) with views instrumentation enabled.

### Step 2 - Declare the React Native Session Replay as a dependency{% #step-2--declare-the-react-native-session-replay-as-a-dependency %}

Add the `@datadog/mobile-react-native-session-replay` dependency, and make sure it matches the `@datadog/mobile-react-native` version, either through [npm](https://www.npmjs.com/package/@datadog/mobile-react-native-session-replay?activeTab=versions) or [yarn](https://yarnpkg.com/package?q=datadog%20react%20native%20ses&name=%40datadog%2Fmobile-react-native-session-replay).

{% tab title="npm" %}

```
npm install @datadog/mobile-react-native-session-replay
```

{% /tab %}

{% tab title="yarn" %}

```
yarn add @datadog/mobile-react-native-session-replay
```

{% /tab %}

### Step 3 - Enable Session Replay{% #enable-react-native %}

After the Datadog React Native SDK and Session Replay SDK dependencies are imported, you can enable the feature when configuring the SDK.

{% tab title="DatadogProvider" %}
If you use the `DatadogProvider` component:

In the `App.tsx` file:

```
import { DatadogProvider, DatadogProviderConfiguration } from "@datadog/mobile-react-native";
import {
  ImagePrivacyLevel,
  SessionReplay,
  TextAndInputPrivacyLevel,
  TouchPrivacyLevel,
} from "@datadog/mobile-react-native-session-replay";

const configuration = new DatadogProviderConfiguration(/* ... */)

// Add this function as onInitialization prop to DatadogProvider
const onSDKInitialized = async () => {
  await SessionReplay.enable({
    replaySampleRate: 100, // Session Replay will be available for all sessions already captured by the SDK
    textAndInputPrivacyLevel: TextAndInputPrivacyLevel.MASK_SENSITIVE_INPUTS,
    imagePrivacyLevel: ImagePrivacyLevel.MASK_NONE,
    touchPrivacyLevel: TouchPrivacyLevel.SHOW,
  });
};

const App = () => {
  const navigationRef = React.useRef(null);
  return (
    <DatadogProvider configuration={configuration} onInitialization={onSDKInitialized}>
      {/* App */}
    </DatadogProvider>
  );
};

export default App;
```

{% /tab %}

{% tab title="DdSdkReactNative.initialize" %}
If you use the `DdSdkReactNative.initialize` method:

In the `App.tsx` file:

```
import { DdSdkReactNative, DdSdkReactNativeConfiguration } from "@datadog/mobile-react-native";
import { SessionReplay } from "@datadog/mobile-react-native-session-replay";

const configuration = new DdSdkReactNativeConfiguration(/* ... */)

DdSdkReactNative.initialize(configuration)
  .then(() => SessionReplay.enable({
    replaySampleRate: 100, // Session Replay will be available for all sessions already captured by the SDK
    textAndInputPrivacyLevel: TextAndInputPrivacyLevel.MASK_SENSITIVE_INPUTS,
    imagePrivacyLevel: ImagePrivacyLevel.MASK_NONE,
    touchPrivacyLevel: TouchPrivacyLevel.SHOW,
  }))
  .catch((error) => { /* handle error */ });
```

{% /tab %}

During this step, you can also configure multiple [privacy levels](https://docs.datadoghq.com/session_replay/mobile/privacy_options/?tab=reactnative) that apply to Session Replays.

### Step 4 - (iOS only) Update your iOS pods.{% #step-4---ios-only-update-your-ios-pods %}

```
cd ios && pod install
```

### Step 5 - Rebuild your app{% #step-5--rebuild-your-app %}

Rebuild your iOS and Android apps
{% /section %}

{% section displayed-if="SDK is Flutter" %}
This section only applies to users who meet the following criteria: SDK is Flutter

{% alert level="info" %}
Datadog Session Replay for Flutter is currently in Preview.
{% /alert %}

All Session Replay SDK versions can be found in [Pub](https://pub.dev/packages/datadog_session_replay).

To set up Datadog Session Replay for Flutter:

### Step 1 - Set up the Flutter plugin{% #step-1--set-up-the-flutter-plugin %}

Make sure you have [set up and initialized the Datadog Flutter Plugin](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/flutter/setup?tab=rum).

### Step 2 - Add the package to your `pubspec.yaml`{% #step-2--add-the-package-to-your- %}

In the `pubspec.yaml` file:

```
packages:
  # other packages
  datadog_session_replay: ^x.x.x
```

### Step 3 - Enable Session Replay in your `DatadogConfiguration`{% #step-3--enable-session-replay-in-your- %}

```
import 'package:datadog_session_replay/datadog_session_replay.dart';

// ....
final configuration = DatadogConfiguration(
    // Normal Datadog configuration
    clientToken: 'client-token',
    // RUM is required to use Datadog Session Replay
    rumConfiguration: RumConfiguration(
        applicationId: '<application-id'>
    ),
)..enableSessionReplay(
    DatadogSessionReplayConfiguration(
        // Setup default text, image, and touch privacy
        textAndInputPrivacyLevel: TextAndInputPrivacyLevel.maskSensitiveInputs,
        touchPrivacyLevel: TouchPrivacyLevel.show,
        // Setup session replay sample rate.
        replaySampleRate: 100.0,
    ),
);
```

### Step 4 - Add a SessionReplayCapture to the root of your Widget tree{% #step-4--add-a-sessionreplaycapture-to-the-root-of-your-widget-tree %}

Add a SessionReplayCapture widget to the root of your Widget tree, above your MaterialApp or similar application widget.

```
class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // Note a key is required for SessionReplayCapture
  final captureKey = GlobalKey();

  // Other App Configuration

  @override
  Widget build(BuildContext context) {
    return SessionReplayCapture(
      key: captureKey,
      rum: DatadogSdk.instance.rum!,
      sessionReplay: DatadogSessionReplay.instance!,
      child: MaterialApp.router(color: color, routerConfig: router),
    );
  }
}
```
{% /section %}

## Web view instrumentation{% #web-view-instrumentation %}

You can record the entire user journey across both [web and native views](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/ios/web_view_tracking) on iOS or Android and watch it in a single Session Replay.

The Session Replay is recorded through the Browser SDK, then the Mobile SDK handles the batching and uploading of the webview recording.

{% section displayed-if="SDK is Android" %}
This section only applies to users who meet the following criteria: SDK is Android

To instrument your consolidated web and native Session Replay views for Android:

1. Ensure you are using version [`2.8.0`](https://github.com/DataDog/dd-sdk-android/releases/tag/2.8.0) or higher of the Android SDK.
1. Enable [webview tracking](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/android/web_view_tracking/?tab=android#instrument-your-web-views) for your mobile application.
1. Enable [Session Replay](https://docs.datadoghq.com/session_replay/browser/#setup) for your web application.
1. Enable Session Replay for your mobile application (see setup instructions above).
{% /section %}

{% section displayed-if="SDK is iOS" %}
This section only applies to users who meet the following criteria: SDK is iOS

To instrument your consolidated web and native Session Replay views for iOS:

1. Ensure you are using version [`2.13.0`](https://github.com/DataDog/dd-sdk-ios/releases/tag/2.13.0) or higher of the iOS SDK.
1. Enable [webview tracking](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/ios/web_view_tracking/?tab=ios#instrument-your-web-views) for your mobile application.
1. Enable [Session Replay](https://docs.datadoghq.com/session_replay/browser/#setup) for your web application.
1. Enable Session Replay for your mobile application (see setup instructions above).
{% /section %}

{% section displayed-if="SDK is Kotlin Multiplatform" %}
This section only applies to users who meet the following criteria: SDK is Kotlin Multiplatform

To instrument your consolidated web and native Session Replay views for Kotlin Multiplatform:

1. Enable [webview tracking](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/kotlin_multiplatform/web_view_tracking/?tab=kotlinmultiplatform#instrument-your-web-views) for your mobile application.
1. Enable [Session Replay](https://docs.datadoghq.com/session_replay/browser/#setup) for your web application.
1. Enable Session Replay for your mobile application (see setup instructions above).
{% /section %}

{% section displayed-if="SDK is React Native" %}
This section only applies to users who meet the following criteria: SDK is React Native

To instrument your consolidated web and native Session Replay views for React Native:

1. Enable [webview tracking](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/web_view_tracking/?tab=reactnative#instrument-your-web-views) for your React Native application.
1. Enable [Session Replay](https://docs.datadoghq.com/session_replay/browser/#setup) for your web application.
1. Enable Session Replay for your mobile application (see setup instructions above).

**Note**: This feature is not compatible with React Native's [New Architecture](https://reactnative.dev/architecture/landing-page) for Android.
{% /section %}

{% section displayed-if="SDK is Flutter" %}
This section only applies to users who meet the following criteria: SDK is Flutter

Datadog Session Replay for Flutter does not currently support Web view capture.
{% /section %}

## Additional configuration{% #additional-configuration %}

### Set the sample rate for recorded sessions to appear{% #set-the-sample-rate-for-recorded-sessions-to-appear %}

The sample rate is an optional parameter in the Session Replay configuration. It must be a number between 0.0 and 100.0, where 0 indicates that no replays are recorded and 100 means that all sessions include a replay. If the sample rate is not specified in the configuration, the default value of 100 is applied.

This sample rate is applied in addition to the RUM sample rate. For example, if RUM uses a sample rate of 80% and Session Replay uses a sample rate of 20%, it means that out of all user sessions, 80% are included in RUM, and within those sessions, only 20% have replays.

{% section displayed-if="SDK is Android" %}
This section only applies to users who meet the following criteria: SDK is Android

In the `Application.kt` file:

```
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
  ...
  .build()
```
{% /section %}

{% section displayed-if="SDK is iOS" %}
This section only applies to users who meet the following criteria: SDK is iOS

In the `AppDelegate.swift` file:

```
var sessionReplayConfig = SessionReplay.Configuration(
  replaySampleRate: <SAMPLE_RATE>
)
```
{% /section %}

{% section displayed-if="SDK is Kotlin Multiplatform" %}
This section only applies to users who meet the following criteria: SDK is Kotlin Multiplatform

In the `Application.kt` file:

```
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
  ...
  .build()
```
{% /section %}

{% section displayed-if="SDK is React Native" %}
This section only applies to users who meet the following criteria: SDK is React Native

In the `App.tsx` file:

```
import { SessionReplay } from "@datadog/mobile-react-native-session-replay";

SessionReplay.enable({
  replaySampleRate: <SAMPLE_RATE>
});
```
{% /section %}

{% section displayed-if="SDK is Android" %}
This section only applies to users who meet the following criteria: SDK is Android

```
final configuration = DatadogConfiguration(
  // ...
)..enableSessionReplay(
  DatadogSessionReplayConfiguration(
    replaySampleRate: <SAMPLE_RATE>
  )
);
```
{% /section %}

### Start or stop the recording manually{% #start-or-stop-the-recording-manually %}

By default, Session Replay starts recording automatically. However, if you prefer to manually start recording at a specific point in your application, you can use the optional `startRecordingImmediately` parameter as shown below, and later call `SessionReplay.startRecording()`. You can also use `SessionReplay.stopRecording()` to stop the recording anytime.

{% section displayed-if="SDK is Android" %}
This section only applies to users who meet the following criteria: SDK is Android

In the `Application.kt` file:

```
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
  .startRecordingImmediately(false)
  .build()
// Do something
SessionReplay.startRecording()
SessionReplay.stopRecording()
```
{% /section %}

{% section displayed-if="SDK is iOS" %}
This section only applies to users who meet the following criteria: SDK is iOS

In the `AppDelegate.swift` file:

```
let sessionReplayConfig = SessionReplay.Configuration(
  replaySampleRate: <SAMPLE_RATE>,
  startRecordingImmediately: false
)

// Do something
SessionReplay.startRecording()
SessionReplay.stopRecording()
```
{% /section %}

{% section displayed-if="SDK is Kotlin Multiplatform" %}
This section only applies to users who meet the following criteria: SDK is Kotlin Multiplatform

In the `Application.kt` file:

```
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
  .startRecordingImmediately(false)
  .build()

// Do something
SessionReplay.startRecording()
SessionReplay.stopRecording()
```
{% /section %}

{% section displayed-if="SDK is React Native" %}
This section only applies to users who meet the following criteria: SDK is React Native

In the `App.tsx` file:

```
import { SessionReplay } from "@datadog/mobile-react-native-session-replay";

SessionReplay.enable({
  replaySampleRate: sampleRate,
  startRecordingImmediately: false
});
// Do something
SessionReplay.startRecording();
SessionReplay.stopRecording();
```
{% /section %}

{% section displayed-if="SDK is Flutter" %}
This section only applies to users who meet the following criteria: SDK is Flutter

Datadog Session Replay for Flutter does not currently support manual recording.
{% /section %}

### Validate whether Session Replay data is being sent{% #validate-whether-session-replay-data-is-being-sent %}

To validate whether Session Replay data is being sent from the app, you can enable debug option in Datadog SDK.

{% section displayed-if="SDK is Android" %}
This section only applies to users who meet the following criteria: SDK is Android

In the `Application.kt` file:

```
Datadog.setVerbosity(Log.DEBUG)
```
{% /section %}

{% section displayed-if="SDK is iOS" %}
This section only applies to users who meet the following criteria: SDK is iOS

In the `AppDelegate.swift` file:

```
Datadog.verbosityLevel = .debug
```

If everything is fine, following logs should appear in the Xcode debug console in about 30 seconds after launching the app:

In the `Xcode console` file:

```
[DATADOG SDK] 🐶 → 10:21:29.812 ⏳ (session-replay) Uploading batch...
[DATADOG SDK] 🐶 → 10:21:30.442    → (session-replay) accepted, won't be retransmitted: [response code: 202 (accepted), request ID: BD445EA-...-8AFCD3F3D16]
```
{% /section %}

{% section displayed-if="SDK is Kotlin Multiplatform" %}
This section only applies to users who meet the following criteria: SDK is Kotlin Multiplatform

In the `Application.kt` file:

```
Datadog.setVerbosity(SdkLogVerbosity.DEBUG)
```
{% /section %}

{% section displayed-if="SDK is React Native" %}
This section only applies to users who meet the following criteria: SDK is React Native

Set the verbosity to `DEBUG` when you initialize the SDK:

In the `App.tsx` file:

```
import { SdkVerbosity } from "@datadog/mobile-react-native";

...

config.verbosity = SdkVerbosity.DEBUG;
```
{% /section %}

{% section displayed-if="SDK is Flutter" %}
This section only applies to users who meet the following criteria: SDK is Flutter

Set the SDKs verbosity to `CoreLoggerLevel.debug` before you initialize the SDK:

```
DatadogSdk.instance.sdkVerbosity = CoreLoggerLevel.debug;
```
{% /section %}

### Privacy options{% #privacy-options %}

See [Privacy Options](https://docs.datadoghq.com/session_replay/mobile/privacy_options).

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

- [Mobile Session Replay](https://docs.datadoghq.com/session_replay/mobile/)
- [How Mobile Session Replay Impacts App Performance](https://docs.datadoghq.com/session_replay/mobile/app_performance)
- [Mobile Session Replay Privacy Options](https://docs.datadoghq.com/session_replay/mobile/privacy_options)
- [Troubleshoot Mobile Session Replay](https://docs.datadoghq.com/session_replay/mobile/troubleshooting)
- [Session Replay](https://docs.datadoghq.com/session_replay/)
- [Web View Tracking](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/android/web_view_tracking)
