Skip to content
82 changes: 82 additions & 0 deletions docs/platforms/apple/guides/ios/session-replay/customredact.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: Using Custom Masking for Session Replay
sidebar_order: 5501
notSupported:
description: "Learn how to mask parts of your app's data in Session Replay."
---

<Alert>

If you choose to use custom masking in your Session Replays, you may accidentally expose sensitive customer data. Be sure to double-check what you choose to expose.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because for that they must disable the default masking, right?
Worth calling that out?

@lizokm might have ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an extra reminder, so the user understands the severity of it.


</Alert>

By default, our Session Replay SDK masks all text content, images, and user input. This helps ensure that no sensitive data will be exposed. You can also manually choose which parts of your app's data you want to mask by using the different options listed below.


## Mask by View Class

You can choose which type of view you want to mask or ignore by using the `maskedViewClasses` or `unmaskedViewClasses` options.

Let's say you have a custom view that you want to mask and a `UILabel` subclass (which normally would be masked) that you doesn't want to mask. You can set the options like this:

```swift
options.experimental.sessionReplay.maskedViewClasses = [MyCustomView.self]
options.experimental.sessionReplay.unmaskedViewClasses = [MyCustomLabel.self]
```

## Mask by View Instance

You can also choose to mask or unmask a specific view instance by using the [replay API](/api/replays/) or view extensions like this:

```swift
SentrySDK.replay.maskView(view: view)
SentrySDK.replay.unmaskView(view: label)
```
or

```swift
view.sentryReplayMask()
label.sentryReplayUnmask()
```

## SwiftUI

Because of the way SwiftUI is transformed into UIKit, it will often be over-masked. A modifier like `background` uses the same element as an `Image`.
In order to control the SwiftUI masking process, you need to use the `sentryReplayUnmask` and/or `sentryReplayMask` modifiers.

In this example we want to show the message, but not the user name.
```swift
@Binding var user: String

var body: some View {
VStack {
Text("Hello")
.sentryReplayUnmask()
Text("\(user)")
}
}
```

In this example, we need to unmask the VStack because its background element will be masked by default.
To hide the username, we need to mask it.

```swift
@Binding var user: String

var body: some View {
VStack {
Text("Hello")
Text("\(user)")
.sentrtReplayMask()
}
.background(.blue)
.sentryReplayUnmask()
}
```

<Alert>

Before publising an App with Session Replay enabled, make sure to test it thoroughly to ensure that no sensitive data is exposed.

</Alert>
4 changes: 3 additions & 1 deletion docs/platforms/apple/guides/ios/session-replay/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Sampling begins as soon as a session starts. `sessionSampleRate` is evaluated fi

## Privacy

The SDK is recording and aggressively redacting all text and images. We plan to add fine controls for redacting, but in this version, we just allow either on or off. The default is on. Please don’t turn it off if you have sensitive data in your app. Before the Beta is complete, we'll give you the controls you need.
The SDK aggressively records the app and masks all text and images.
Please don't turn it off if you have sensitive data in your app.
If you want to manually mask parts of your app's data, read our guide on [custom masking](/platforms/apple/guides/ios/session-replay/customredact).

<Note>

Expand Down