Privacy for React Native
Learn how to mask sensitive data that may appear in your app in Session Replay.
The masking options below only apply when using the default PixelCopy strategy on Android. If you set the strategy to Canvas, those options will be ignored and all sensitive content (texts, inputs, images) will be always masked.
Before enabling Session Replay in production, verify your masking configuration to ensure no sensitive data is captured. Our default settings aggressively mask potentially sensitive data, but if you modify these settings or update UI frameworks or system SDKs, you must thoroughly test your application. If you find any masking issues or sensitive data that should be masked but isn't, please create a GitHub issue and avoid deploying to production with Session Replay enabled until the issue is resolved.
The Session Replay SDK masks all text content, images, webviews, and user input by default. This helps ensure that no sensitive data is exposed. You can also manually choose which parts of your app to mask by using the options listed below.
If your app doesn't contain any sensitive date, you can disable the default masking behavior with:
Sentry.mobileReplayIntegration({
maskAllText: false,
maskAllImages: false,
maskAllVectors: false,
}),
Sentry.mobileReplayIntegration({
maskAllText: false,
maskAllImages: false,
maskAllVectors: false,
}),
Make sure your Sentry React Native SDK version is 5.36.0, 6.3.0 and up
You can choose which views you want to mask or unmask by using the Mask or Unmask components.
import * as Sentry from "@sentry/react-native";
const Example = () => {
return (
<View>
<Sentry.Unmask>
<Text>This will be unmasked</Text>
</Sentry.Unmask>
<Sentry.Mask>
<Text>This will be masked</Text>
</Sentry.Mask>
</View>
);
};
import * as Sentry from "@sentry/react-native";
const Example = () => {
return (
<View>
<Sentry.Unmask>
<Text>This will be unmasked</Text>
</Sentry.Unmask>
<Sentry.Mask>
<Text>This will be masked</Text>
</Sentry.Mask>
</View>
);
};
Make sure your Sentry React Native SDK version is 6.4.0-beta.1 and up to use the masking components
Supported in React Native SDK v8.27.0 and later
When you can't wrap views with the Mask or Unmask components—for example, views rendered by a third-party library—you can mask or unmask them by their native view class name. Use maskedViewClasses to redact additional classes on top of the maskAllText/maskAllImages/maskAllVectors defaults, and unmaskedViewClasses to exempt classes from redaction. Both match views that are instances of the listed classes or their subclasses.
import * as Sentry from "@sentry/react-native";
Sentry.init({
dsn: "___PUBLIC_DSN___",
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
integrations: [
Sentry.mobileReplayIntegration({
maskAllText: true,
// Unmask text views so text is visible in the replay, even though
// `maskAllText` is enabled.
unmaskedViewClasses: [
"RCTTextView", // iOS (Legacy Architecture)
"RCTParagraphComponentView", // iOS (New Architecture)
"com.facebook.react.views.text.ReactTextView", // Android
],
// Mask a specific native view class in addition to the defaults.
maskedViewClasses: [
"MKMapView", // iOS
],
}),
],
});
import * as Sentry from "@sentry/react-native";
Sentry.init({
dsn: "___PUBLIC_DSN___",
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
integrations: [
Sentry.mobileReplayIntegration({
maskAllText: true,
// Unmask text views so text is visible in the replay, even though
// `maskAllText` is enabled.
unmaskedViewClasses: [
"RCTTextView", // iOS (Legacy Architecture)
"RCTParagraphComponentView", // iOS (New Architecture)
"com.facebook.react.views.text.ReactTextView", // Android
],
// Mask a specific native view class in addition to the defaults.
maskedViewClasses: [
"MKMapView", // iOS
],
}),
],
});
The class names are the native view class names, not the React component names, and they differ between iOS and Android. Class names for the other platform are harmless no-ops, so you can list both in the same array. Because matching is class-based, a name that isn't loaded at runtime is ignored.
Each class you want to mask or unmask must be listed explicitly (matching includes subclasses). For subtree-wide control — masking or unmasking a view and all of its children — use the Mask and Unmask components instead.
unmaskedViewClasses takes precedence over the maskAllText/maskAllImages/maskAllVectors defaults, so a view whose class is unmasked is shown in the replay even when the corresponding maskAll* option is enabled. An explicit Mask component still always wins—see Masking Priority.
When components are wrapped by Unmask, only direct children will be unmasked. You'll need to explicitly wrap any indirect children that you want to appear in the replay.
<Sentry.Unmask>
<Text>
This will be unmasked
<Text>This will be masked</Text>
</Text>
<Text>This will be unmasked</Text>
</Sentry.Unmask>;
<Sentry.Unmask>
<Text>
This will be unmasked
<Text>This will be masked</Text>
</Text>
<Text>This will be unmasked</Text>
</Sentry.Unmask>;
When components are wrapped by Mask, all children will be masked.
<Sentry.Mask>
<Text>
This will be masked
<Text>This will be masked</Text>
</Text>
<Text>This will be masked</Text>
</Sentry.Mask>;
<Sentry.Mask>
<Text>
This will be masked
<Text>This will be masked</Text>
</Text>
<Text>This will be masked</Text>
</Sentry.Mask>;
If a view is marked as masked, it will always be masked, even if it's a child of an unmasked view.
<Sentry.Mask>
<Text>This will be masked</Text>
<Sentry.Unmask>
<Text>This will be masked</Text>
</Sentry.Unmask>
</Sentry.Mask>;
<Sentry.Mask>
<Text>This will be masked</Text>
<Sentry.Unmask>
<Text>This will be masked</Text>
</Sentry.Unmask>
</Sentry.Mask>;
The Mask component can't be unmasked.
<Sentry.Unmask>
<Sentry.Mask>
<Text>This will be masked</Text>
</Sentry.Mask>
</Sentry.Unmask>;
<Sentry.Unmask>
<Sentry.Mask>
<Text>This will be masked</Text>
</Sentry.Mask>
</Sentry.Unmask>;
The Mask and Unmask components are native on iOS and Android and are compatible with both the New and the Legacy Architecture.
The masking components behave as standard React Native View components.
If you're experiencing issues with unmasking that are more than one level deep, check if the wrapped components are present in the native views hierarchy. If not, it means that your view was evaluated by React Native as Layout Only and flattened. Read more about flattening views in the React Native documentation.
Note that View Flattening may cause the Mask and Unmask components to not behave as expected accidentally exposing sensitive data. Make sure to test your app thoroughly to ensure that no sensitive data is exposed before publishing it.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").