Setup
All Session Replay SDK versions can be found in the Maven Central Repository.
To set up Mobile Session Replay for Android:
Make sure you've set up and initialized the Datadog Android RUM SDK with views instrumentation enabled.
Declare the Datadog Session Replay as a dependency:
build.gradle.kts
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]")
Enable Session Replay in your app:
Application.kt
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)
To set up Mobile Session Replay for iOS:
Make sure you've set up and initialized the Datadog iOS RUM SDK with views instrumentation enabled.
Link the Datadog Session Replay library to your project based on your package manager:
Package manager Installation step CocoaPods Add pod 'DatadogSessionReplay'
to yourPodfile
.Swift Package Manager Add DatadogSessionReplay
library as a dependency to your app target.Carthage Add DatadogSessionReplay.xcframework
as a dependency to your app target.Enable Session Replay in your app:
AppDelegate.swift
import DatadogSessionReplay SessionReplay.enable( with: SessionReplay.Configuration( replaySampleRate: sampleRate, // Enable the experimental SwiftUI recording featureFlags: [.swiftui: true] ) )
All Session Replay SDK versions can be found in the Maven Central Repository.
To set up Mobile Session Replay for Kotlin Multiplatform:
Make sure you've setup and initialized the Datadog Kotlin Multiplatform RUM SDK with views instrumentation enabled.
Add the
DatadogSessionReplay
iOS library as a link-only dependency. For instructions, see the guide.Declare Datadog Session Replay as a dependency:
build.gradle.kts
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]") } } }
Enable Session Replay in your app:
Application.kt
// in common source set val sessionReplayConfig = SessionReplayConfiguration.Builder([sampleRate]) .build() SessionReplay.enable(sessionReplayConfig)
In case you need Material support on Android, call the
SessionReplayConfiguration.Builder.addExtensionSupport(MaterialExtensionSupport())
method, available in the Android source set.
To enable Session Replay, you must use at least version
2.0.4
of the Datadog
React Native SDK, and ensure that the Session Replay SDK version matches the React
Native SDK version you are using.
All Session Replay SDK versions can be found in the npmjs repository.
To set up Mobile Session Replay for React Native:
Make sure you've set up and initialized the Datadog React Native SDK with views instrumentation enabled.
Add the
@datadog/mobile-react-native-session-replay
dependency, and make sure it matches the@datadog/mobile-react-native
version, either through npm or yarn.npm install @datadog/mobile-react-native-session-replay
yarn add @datadog/mobile-react-native-session-replay
After the Datadog React Native SDK and Session Replay SDK dependencies are imported, you can enable the feature when configuring the SDK.
If you use the
DatadogProvider
component:App.tsx
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, 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;
If you use the
DdSdkReactNative.initialize
method:App.tsx
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()) .catch((error) => { /* handle error */ });
Enable Session Replay in your app, after initializing the Datadog SDK:
App.tsx
import { SessionReplay } from "@datadog/mobile-react-native-session-replay"; SessionReplay.enable();
Define the configuration for Session Replay:
App.tsx
SessionReplay.enable({ replaySampleRate: 100, // Session Replay will be available for all sessions already captured by the SDK });
During this step, you can also configure multiple privacy levels that apply to Session Replays.
(iOS only) Update your iOS pods.
cd ios && pod install
Rebuild your iOS and Android apps.
Web view instrumentation
You can record the entire user journey across both web and native views 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.
To instrument your consolidated web and native Session Replay views for Android:
- Ensure you are using version
2.8.0
or higher of the Android SDK. - Enable webview tracking for your mobile application.
- Enable Session Replay for your web application.
- Enable Session Replay for your mobile application (see setup instructions above).
To instrument your consolidated web and native Session Replay views for iOS:
- Ensure you are using version
2.13.0
or higher of the iOS SDK. - Enable webview tracking for your mobile application.
- Enable Session Replay for your web application.
- Enable Session Replay for your mobile application (see setup instructions above).
To instrument your consolidated web and native Session Replay views for Kotlin Multiplatform:
- Enable webview tracking for your mobile application.
- Enable Session Replay for your web application.
- Enable Session Replay for your mobile application (see setup instructions above).
To instrument your consolidated web and native Session Replay views for React Native:
- Enable webview tracking for your React Native application.
- Enable Session Replay for your web application.
- Enable Session Replay for your mobile application (see setup instructions above).
Note: This feature is not compatible with React Native's New Architecture for Android.
Additional configuration
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 RUM 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.
Application.kt
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
...
.build()
AppDelegate.swift
var sessionReplayConfig = SessionReplay.Configuration(
replaySampleRate: <SAMPLE_RATE>
)
Application.kt
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
...
.build()
App.tsx
import { SessionReplay } from "@datadog/mobile-react-native-session-replay";
SessionReplay.enable({
replaySampleRate: <SAMPLE_RATE>
});
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.
Application.kt
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
.startRecordingImmediately(false)
.build()
// Do something
SessionReplay.startRecording()
SessionReplay.stopRecording()
AppDelegate.swift
let sessionReplayConfig = SessionReplay.Configuration(
replaySampleRate: <SAMPLE_RATE>,
startRecordingImmediately: false
)
// Do something
SessionReplay.startRecording()
SessionReplay.stopRecording()
Application.kt
val sessionReplayConfig = SessionReplayConfiguration.Builder(<SAMPLE_RATE>)
.startRecordingImmediately(false)
.build()
// Do something
SessionReplay.startRecording()
SessionReplay.stopRecording()
App.tsx
import { SessionReplay } from "@datadog/mobile-react-native-session-replay";
SessionReplay.enable({
replaySampleRate: sampleRate,
startRecordingImmediately: false
});
// Do something
SessionReplay.startRecording();
SessionReplay.stopRecording();
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.
Application.kt
Datadog.setVerbosity(Log.DEBUG)
AppDelegate.swift
Datadog.verbosityLevel = .debug
If everything is fine, following logs should appear in the Xcode debug console in about 30 seconds after launching the app:
Xcode console
[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]
Application.kt
Datadog.setVerbosity(SdkLogVerbosity.DEBUG)
Set the verbosity to DEBUG
when you initialize the SDK:
App.tsx
import { SdkVerbosity } from "@datadog/mobile-react-native";
...
config.verbosity = SdkVerbosity.DEBUG;
Privacy options
See Privacy Options.
Further reading
Additional helpful documentation, links, and articles: