@dynatrace/react-native-session-replay
v0.351.1
Published
Session Replay for Dynatrace React Native Plugin
Readme
Dynatrace Session Replay for React Native
Session Replay records what users see in your React Native app, so you can replay their sessions in Dynatrace. It is an add-on to @dynatrace/react-native-plugin. Full documentation: Configure Session Replay for React Native.
Preview. Session Replay for React Native is available as a preview. Register for the preview program to use it. It is not available for RUM Classic or Dynatrace Managed; the preview is available with the latest Dynatrace and DPS licensing. In
0.xversions, any minor version can contain breaking changes. npm's default^0.x.yrange only takes patch updates, so move to a new minor version by hand.
Requirements
- Dynatrace version 1.303 or newer, registered for the Session Replay for React Native preview program
@dynatrace/react-native-plugin2.349.1 or newer, set up and working in your app- React Native 0.67 or newer, React 16.11 or newer
- Android API level 23 or newer, iOS 15 or newer
Installation
- Turn on Session Replay for your app in Dynatrace: Experience Vitals > Overview > Mobile > your frontend > Settings > Enablement and cost control.
- Add the package. On iOS, also run CocoaPods:
npm install @dynatrace/react-native-session-replay
cd ios && pod installThe native agent versions come from the installed @dynatrace/react-native-plugin, so both packages always use the same agent.
Usage
Session Replay starts with the native agent and records when the native configuration enables it (Session Replay turned on for your app in Dynatrace, and the user's privacy settings allow it).
Installing the package is enough. The Dynatrace Babel plugin loads it for your app when it is installed, so navigation and list reloads (FlatList, SectionList) are captured without any import or setup code.
The plugin decides this while Metro transforms React Native, and Metro caches the result. After you install or remove this package, restart Metro with --reset-cache (for example npx react-native start --reset-cache). The package must also be reachable from react-native (in a monorepo, hoisted next to it); otherwise it is not loaded automatically and you need the explicit import below.
Older
@dynatrace/react-native-pluginversions do not load the package for you. Addimport '@dynatrace/react-native-session-replay';to your entry file (for exampleindex.js) so it loads at startup. You need an explicit import anyway when you useSessionReplay.setMaskingConfiguration(),DTMaskorDTWithMask, as shown below.
SessionReplay.configure() is no longer needed. Existing calls keep working but have no effect, so you can delete them.
configure({ enabled: false })no longer opts out. It used to stop the JS-driven captures (navigation, list reloads) and JS events, though never native recording. It is now ignored. To stop recording, use the privacy options (screenRecordOptedIninDynatrace.applyUserPrivacyOptions), or leave Session Replay off in the native configuration.
Masking
There are three masking levels:
- Safest: all editable text fields, images, labels, WebViews and switches are masked.
- Safe: all editable text fields and WebViews are masked.
- Custom: starts like Safest, then you choose which view types are masked.
Until you set a level, the native agent's masking defaults apply. Set it with SessionReplay.setMaskingConfiguration(). You can call it at any time, including at startup: it is applied as soon as the native agent is up.
import { SessionReplay, MaskingConfiguration, MaskableView } from '@dynatrace/react-native-session-replay';
SessionReplay.setMaskingConfiguration(MaskingConfiguration.Safest());
// Mask only TextInput fields
SessionReplay.setMaskingConfiguration(
MaskingConfiguration.Custom()
.removeAllMaskedViews()
.addMaskedViews([MaskableView.TextInput])
);MaskableView covers TextInput, Text, Image, WebView and Switch. TextInput components with secureTextEntry are always masked.
To mask one component regardless of the level, wrap it in DTMask, or create a masked version with DTWithMask:
import { Text, TextInput } from 'react-native';
import { DTMask, DTWithMask } from '@dynatrace/react-native-session-replay';
<DTMask>
<Text>Sensitive data</Text>
</DTMask>;
const MaskedTextInput = DTWithMask(TextInput);Custom events
Navigation and list reloads (FlatList, SectionList) are captured automatically. To capture another moment, track a custom event:
SessionReplay.trackCustomEvent('User logged in');Logs
Session Replay logs are part of the @dynatrace/react-native-plugin logs. To turn on debug logs, set react: { debug: true } in dynatrace.config.js.
Changelog
0.351.1
SessionReplay.configure()is deprecated and has no effect. Session Replay is enabled by the native configuration alone, and no JavaScript setup is needed.- Behavior change:
SessionReplay.configure({ enabled: false })is now ignored and no longer stops the JS-driven captures. Use the privacy options (screenRecordOptedIn) to stop recording. - The Dynatrace Babel plugin loads the package when it is installed, so no import is needed (requires a
@dynatrace/react-native-pluginrelease that includes this change). Restart Metro with--reset-cacheafter installing or removing the package. - The startup log line now says the package is
loadedinstead ofenabled; whether replay records is decided by the native agent. SessionReplay.setMaskingConfiguration()is no longer ignored beforeconfigure(); it is applied once the native agent is up.
0.349.1
- First public preview release
