-
Notifications
You must be signed in to change notification settings - Fork 61
feat(plugin-session-replay-react-native): pass maskLevel through to native SessionReplay #1771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
62a74f3
84adcd0
8f74c51
7b4ed3c
584ab86
6c93e5f
00bc47d
22e0544
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| export { SessionReplayPlugin } from './session-replay'; | ||
| export { type SessionReplayConfig, MaskLevel, PrivacyConfig } from './session-replay-config'; | ||
|
|
||
| export { AmpMaskView } from './app-mask-view'; | ||
|
|
||
| export { SessionReplayConfig } from './session-replay-config'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,78 @@ | ||
| import { LogLevel } from '@amplitude/analytics-types'; | ||
|
|
||
| /** | ||
| * Masking levels for sensitive content in session replay | ||
| */ | ||
| export enum MaskLevel { | ||
| /** | ||
| * Light masking - minimal content is masked | ||
| */ | ||
| Light = 'light', | ||
| /** | ||
| * Medium masking - balanced approach to content masking | ||
| */ | ||
| Medium = 'medium', | ||
| /** | ||
| * Conservative masking - maximum content masking for privacy | ||
| */ | ||
| Conservative = 'conservative', | ||
| } | ||
|
|
||
| export interface PrivacyConfig { | ||
| maskLevel?: MaskLevel; | ||
| } | ||
|
|
||
| /** | ||
| * Configuration for the Session Replay React Native plugin. | ||
| * | ||
| * Unlike the standalone `@amplitude/session-replay-react-native` SDK, the | ||
| * plugin auto-sources `apiKey`, `deviceId`, `sessionId`, and `serverZone` | ||
| * from the analytics client's `ReactNativeConfig` at `setup()` time, so | ||
| * those fields are intentionally absent from the public plugin config. | ||
| * The plugin also never shipped a deprecated top-level `maskLevel`, so no | ||
| * input-boundary normalization (and no `SessionReplayConfigInternal` alias) | ||
| * is needed here. | ||
| */ | ||
| export interface SessionReplayConfig { | ||
| sampleRate?: number; | ||
| /** | ||
| * Whether to automatically start recording when the plugin is added | ||
| * @default true | ||
| */ | ||
| autoStart?: boolean; | ||
|
|
||
| /** | ||
| * Whether to enable remote configuration | ||
| * @default true | ||
| */ | ||
| enableRemoteConfig?: boolean; | ||
|
|
||
| /** | ||
| * Log level for the SDK | ||
| * @default LogLevel.Warn | ||
| */ | ||
| logLevel?: LogLevel; | ||
| autoStart?: boolean; | ||
|
|
||
| /** | ||
| * Privacy configuration for session replay | ||
| * @default { maskLevel: MaskLevel.Medium } | ||
| */ | ||
| privacyConfig?: PrivacyConfig; | ||
|
|
||
| /** | ||
| * Sample rate for session replay (0.0 to 1.0) | ||
| * Determines what percentage of sessions will be recorded | ||
| * @default 0 | ||
| */ | ||
| sampleRate?: number; | ||
| } | ||
|
|
||
| export const getDefaultConfig: () => SessionReplayConfig = () => { | ||
| export const getDefaultConfig: () => Required<SessionReplayConfig> = () => { | ||
| return { | ||
| sampleRate: 0, | ||
| autoStart: true, | ||
| enableRemoteConfig: true, | ||
| logLevel: LogLevel.Warn, | ||
| autoStart: true, | ||
| privacyConfig: { maskLevel: MaskLevel.Medium }, | ||
| sampleRate: 0, | ||
| }; | ||
| }; | ||
| export { LogLevel }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,8 @@ import type { EnrichmentPlugin, Event, ReactNativeClient, ReactNativeConfig } fr | |
| import { PluginSessionReplayReactNative } from './native-module'; | ||
| import { VERSION } from './version'; | ||
| import { SessionReplayConfig, getDefaultConfig } from './session-replay-config'; | ||
| import { LogLevel } from '@amplitude/analytics-types'; | ||
|
|
||
| type ResolvedSessionReplayConfig = Required<SessionReplayConfig>; | ||
|
|
||
| export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient, ReactNativeConfig> { | ||
| name = '@amplitude/plugin-session-replay-react-native'; | ||
|
|
@@ -19,7 +20,7 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient, | |
| config: ReactNativeConfig; | ||
| isInitialized = false; | ||
|
|
||
| sessionReplayConfig: SessionReplayConfig; | ||
| sessionReplayConfig: ResolvedSessionReplayConfig; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shallow merge lets
|
||
|
|
||
| constructor(config: SessionReplayConfig = {}) { | ||
| this.sessionReplayConfig = { | ||
|
|
@@ -32,15 +33,24 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient, | |
| async setup(config: ReactNativeConfig, _: ReactNativeClient): Promise<void> { | ||
| this.config = config; | ||
| console.log(`Installing @amplitude/plugin-session-replay-react-native, version ${VERSION}.`); | ||
| // `apiKey`, `deviceId`, `sessionId`, and `serverZone` are sourced from the | ||
| // analytics client's `ReactNativeConfig` because the plugin runs inside an | ||
| // initialized Amplitude SDK and inherits identity from it. | ||
| // `privacyConfig.maskLevel` is guaranteed to be set by the merge in the | ||
| // constructor: `getDefaultConfig()` supplies `{ maskLevel: Medium }` and a | ||
| // user-supplied `privacyConfig` always carries a `maskLevel`. | ||
| const { privacyConfig } = this.sessionReplayConfig; | ||
| await PluginSessionReplayReactNative.setup( | ||
| config.apiKey, | ||
| config.deviceId, | ||
| config.sessionId, | ||
| config.serverZone, | ||
| this.sessionReplayConfig.sampleRate ?? 1, | ||
| this.sessionReplayConfig.enableRemoteConfig ?? true, | ||
| this.sessionReplayConfig.logLevel ?? LogLevel.Warn, | ||
| this.sessionReplayConfig.autoStart ?? true, | ||
| this.sessionReplayConfig.sampleRate, | ||
| this.sessionReplayConfig.enableRemoteConfig, | ||
| this.sessionReplayConfig.logLevel, | ||
| this.sessionReplayConfig.autoStart, | ||
| // TODO(SDKRN-15): Migrate native bridge to accept the full privacyConfig object instead of a flat maskLevel string. | ||
| privacyConfig.maskLevel, | ||
| ); | ||
| this.isInitialized = true; | ||
| } | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you also need to apply those changes to session-replay-react-native package?