@amplitude/session-replay-react-native 0.0.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/AmplitudeSessionReplayReactNative.podspec +45 -0
  2. package/LICENSE +20 -0
  3. package/README.md +101 -0
  4. package/android/build.gradle +101 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeModule.kt +182 -0
  9. package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +17 -0
  10. package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeViewManager.kt +22 -0
  11. package/ios/AMPNativeSessionReplay.mm +21 -0
  12. package/ios/NativeSessionReplay-Bridging-Header.h +2 -0
  13. package/ios/NativeSessionReplay.swift +150 -0
  14. package/ios/RCTAmpMaskViewManager.m +29 -0
  15. package/lib/commonjs/amp-mask-view.js +9 -0
  16. package/lib/commonjs/amp-mask-view.js.map +1 -0
  17. package/lib/commonjs/index.js +76 -0
  18. package/lib/commonjs/index.js.map +1 -0
  19. package/lib/commonjs/logger.js +42 -0
  20. package/lib/commonjs/logger.js.map +1 -0
  21. package/lib/commonjs/native-module.js +31 -0
  22. package/lib/commonjs/native-module.js.map +1 -0
  23. package/lib/commonjs/plugin-session-replay-config.js +21 -0
  24. package/lib/commonjs/plugin-session-replay-config.js.map +1 -0
  25. package/lib/commonjs/plugin-session-replay.js +150 -0
  26. package/lib/commonjs/plugin-session-replay.js.map +1 -0
  27. package/lib/commonjs/session-replay-config.js +49 -0
  28. package/lib/commonjs/session-replay-config.js.map +1 -0
  29. package/lib/commonjs/session-replay.js +226 -0
  30. package/lib/commonjs/session-replay.js.map +1 -0
  31. package/lib/commonjs/version.js +9 -0
  32. package/lib/commonjs/version.js.map +1 -0
  33. package/lib/module/amp-mask-view.js +3 -0
  34. package/lib/module/amp-mask-view.js.map +1 -0
  35. package/lib/module/index.js +5 -0
  36. package/lib/module/index.js.map +1 -0
  37. package/lib/module/logger.js +35 -0
  38. package/lib/module/logger.js.map +1 -0
  39. package/lib/module/native-module.js +25 -0
  40. package/lib/module/native-module.js.map +1 -0
  41. package/lib/module/plugin-session-replay-config.js +15 -0
  42. package/lib/module/plugin-session-replay-config.js.map +1 -0
  43. package/lib/module/plugin-session-replay.js +144 -0
  44. package/lib/module/plugin-session-replay.js.map +1 -0
  45. package/lib/module/session-replay-config.js +40 -0
  46. package/lib/module/session-replay-config.js.map +1 -0
  47. package/lib/module/session-replay.js +212 -0
  48. package/lib/module/session-replay.js.map +1 -0
  49. package/lib/module/version.js +3 -0
  50. package/lib/module/version.js.map +1 -0
  51. package/lib/typescript/amp-mask-view.d.ts +7 -0
  52. package/lib/typescript/amp-mask-view.d.ts.map +1 -0
  53. package/lib/typescript/index.d.ts +6 -0
  54. package/lib/typescript/index.d.ts.map +1 -0
  55. package/lib/typescript/logger.d.ts +9 -0
  56. package/lib/typescript/logger.d.ts.map +1 -0
  57. package/lib/typescript/native-module.d.ts +87 -0
  58. package/lib/typescript/native-module.d.ts.map +1 -0
  59. package/lib/typescript/plugin-session-replay-config.d.ts +29 -0
  60. package/lib/typescript/plugin-session-replay-config.d.ts.map +1 -0
  61. package/lib/typescript/plugin-session-replay.d.ts +77 -0
  62. package/lib/typescript/plugin-session-replay.d.ts.map +1 -0
  63. package/lib/typescript/session-replay-config.d.ts +80 -0
  64. package/lib/typescript/session-replay-config.d.ts.map +1 -0
  65. package/lib/typescript/session-replay.d.ts +128 -0
  66. package/lib/typescript/session-replay.d.ts.map +1 -0
  67. package/lib/typescript/version.d.ts +2 -0
  68. package/lib/typescript/version.d.ts.map +1 -0
  69. package/package.json +96 -0
  70. package/src/amp-mask-view.tsx +7 -0
  71. package/src/index.tsx +16 -0
  72. package/src/logger.ts +41 -0
  73. package/src/native-module.ts +113 -0
  74. package/src/plugin-session-replay-config.ts +40 -0
  75. package/src/plugin-session-replay.ts +159 -0
  76. package/src/session-replay-config.ts +103 -0
  77. package/src/session-replay.ts +223 -0
  78. package/src/version.ts +2 -0
@@ -0,0 +1,87 @@
1
+ export declare const NativeSessionReplay: NativeSessionReplaySpec;
2
+ /**
3
+ * Configuration interface for setting up the native iOS and Android session replay modules.
4
+ * This interface defines all the parameters required to initialize the native session replay functionality.
5
+ */
6
+ export interface NativeSessionReplayConfig {
7
+ /** Your Amplitude API key for authentication and data routing */
8
+ apiKey: string;
9
+ /** Whether to automatically start recording when the module is initialized */
10
+ autoStart: boolean;
11
+ /** Device identifier that matches the device ID sent with Amplitude events */
12
+ deviceId: string | null;
13
+ /** Whether to enable remote configuration for dynamic settings updates */
14
+ enableRemoteConfig: boolean;
15
+ /** Log level for native module logging (0=None, 1=Error, 2=Warn, 3=Log, 4=Debug) */
16
+ logLevel: 0 | 1 | 2 | 3 | 4;
17
+ /** Level of masking applied to sensitive content in recordings */
18
+ maskLevel: 'light' | 'medium' | 'conservative';
19
+ /** Whether the user has opted out of session replay recording */
20
+ optOut: boolean;
21
+ /** Sample rate for session replay (0.0 to 1.0) determining recording frequency */
22
+ sampleRate: number;
23
+ /** Amplitude server zone for data routing ('US' or 'EU') */
24
+ serverZone: 'US' | 'EU';
25
+ /** Current session identifier for correlating events with recordings */
26
+ sessionId: number;
27
+ }
28
+ export interface NativeSessionReplayProperties {
29
+ [key: string]: string | number | boolean;
30
+ }
31
+ /**
32
+ * Interface defining the native session replay module specification.
33
+ * This interface provides the contract for communication between JavaScript and
34
+ * the native iOS/Android session replay modules through React Native's bridge.
35
+ *
36
+ * All methods are asynchronous and return Promises to handle the bridge communication
37
+ * between JavaScript and native code.
38
+ */
39
+ export interface NativeSessionReplaySpec {
40
+ /**
41
+ * Flushes any pending session replay data to the server.
42
+ * Forces immediate upload of recorded session data that may be buffered locally.
43
+ */
44
+ flush(): Promise<void>;
45
+ /**
46
+ * Retrieves the current session identifier from the native module.
47
+ * @returns Promise resolving to the current session ID number
48
+ * @note OLD ARCH: ideally we want to cache that on JS side to avoid bridge overhead
49
+ */
50
+ getSessionId(): Promise<number>;
51
+ /**
52
+ * Retrieves session replay properties that should be attached to Amplitude events.
53
+ * These properties help correlate events with session recordings.
54
+ * @returns Promise resolving to an object containing session replay metadata
55
+ * @note OLD ARCH: ideally we want to cache that on JS side to avoid bridge overhead
56
+ */
57
+ getSessionReplayProperties(): Promise<NativeSessionReplayProperties>;
58
+ /**
59
+ * Updates the device identifier used for session replay tracking.
60
+ * @param deviceId - The device identifier string, or null to clear the device ID
61
+ * @note OLD ARCH: combine those into one method to avoid bridge overhead
62
+ */
63
+ setDeviceId(deviceId: string | null): Promise<void>;
64
+ /**
65
+ * Updates the session identifier used for session replay tracking.
66
+ * @param sessionId - The session identifier number
67
+ * @note OLD ARCH: combine those into one method to avoid bridge overhead
68
+ */
69
+ setSessionId(sessionId: number): Promise<void>;
70
+ /**
71
+ * Initializes the native session replay module with the provided configuration.
72
+ * This method must be called before any other session replay operations.
73
+ * @param config - Configuration object containing all necessary parameters for setup
74
+ */
75
+ setup(config: NativeSessionReplayConfig): Promise<void>;
76
+ /**
77
+ * Starts session replay recording.
78
+ * Begins capturing user interactions and screen content for replay.
79
+ */
80
+ start(): Promise<void>;
81
+ /**
82
+ * Stops session replay recording.
83
+ * Ends the current recording session and processes any captured data.
84
+ */
85
+ stop(): Promise<void>;
86
+ }
87
+ //# sourceMappingURL=native-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-module.d.ts","sourceRoot":"","sources":["../../src/native-module.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,mBAAmB,yBASC,CAAC;AAElC;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,SAAS,EAAE,OAAO,CAAC;IACnB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,0EAA0E;IAC1E,kBAAkB,EAAE,OAAO,CAAC;IAC5B,oFAAoF;IACpF,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,kEAAkE;IAClE,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC;IAC/C,iEAAiE;IACjE,MAAM,EAAE,OAAO,CAAC;IAChB,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,6BAA6B;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;OAIG;IACH,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhC;;;;;OAKG;IACH,0BAA0B,IAAI,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAErE;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
@@ -0,0 +1,29 @@
1
+ import { LogLevel } from '@amplitude/analytics-types';
2
+ /**
3
+ * Configuration for Session Replay React Native Plugin
4
+ */
5
+ export interface SessionReplayPluginConfig {
6
+ /**
7
+ * Sample rate for session replay (0.0 to 1.0)
8
+ * Determines what percentage of sessions will be recorded
9
+ * @default 0
10
+ */
11
+ sampleRate?: number;
12
+ /**
13
+ * Whether to enable remote configuration
14
+ * @default true
15
+ */
16
+ enableRemoteConfig?: boolean;
17
+ /**
18
+ * Log level for the SDK
19
+ * @default LogLevel.Warn
20
+ */
21
+ logLevel?: LogLevel;
22
+ /**
23
+ * Whether to automatically start recording when the plugin is added
24
+ * @default true
25
+ */
26
+ autoStart?: boolean;
27
+ }
28
+ export declare const getDefaultSessionReplayPluginConfig: () => Required<SessionReplayPluginConfig>;
29
+ //# sourceMappingURL=plugin-session-replay-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-session-replay-config.d.ts","sourceRoot":"","sources":["../../src/plugin-session-replay-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,mCAAmC,EAAE,MAAM,QAAQ,CAAC,yBAAyB,CAOzF,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { type EnrichmentPlugin, type Event, type ReactNativeClient, type ReactNativeConfig } from '@amplitude/analytics-types';
2
+ import { SessionReplayPluginConfig } from './plugin-session-replay-config';
3
+ /**
4
+ * Session Replay Plugin for React Native Amplitude SDK.
5
+ * This plugin automatically handles session replay recording and event correlation.
6
+ *
7
+ * The plugin automatically handles:
8
+ * - Device ID and Session ID management
9
+ * - Session ID changes
10
+ * - Event property collection and tracking
11
+ */
12
+ export declare class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient, ReactNativeConfig> {
13
+ name: string;
14
+ type: "enrichment";
15
+ private config;
16
+ private isInitialized;
17
+ private sessionReplayConfig;
18
+ private logger;
19
+ /**
20
+ * Create a new Session Replay Plugin instance.
21
+ *
22
+ * @param config - Configuration options for the session replay plugin
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const sessionReplayPlugin = new SessionReplayPlugin({
27
+ * sampleRate: 0.1,
28
+ * enableRemoteConfig: true,
29
+ * logLevel: LogLevel.Warn,
30
+ * autoStart: true
31
+ * });
32
+ * ```
33
+ */
34
+ constructor(config?: SessionReplayPluginConfig);
35
+ /**
36
+ * Set up the Session Replay Plugin with the Amplitude configuration.
37
+ * This method is called automatically by the Amplitude SDK during initialization.
38
+ *
39
+ * @param config - The React Native configuration from the Amplitude SDK
40
+ * @param _ - The React Native client instance (unused)
41
+ * @returns Promise that resolves when setup is complete
42
+ */
43
+ setup(config: ReactNativeConfig, _: ReactNativeClient): Promise<void>;
44
+ execute(event: Event): Promise<Event | null>;
45
+ /**
46
+ * Start session replay recording.
47
+ * Begins capturing user interactions and screen content for replay.
48
+ *
49
+ * @returns Promise that resolves when recording starts
50
+ */
51
+ start(): Promise<void>;
52
+ /**
53
+ * Stop session replay recording.
54
+ * Ends the current recording session and processes any captured data.
55
+ *
56
+ * @returns Promise that resolves when recording stops
57
+ */
58
+ stop(): Promise<void>;
59
+ teardown(): Promise<void>;
60
+ /**
61
+ * Get session replay properties for manual event correlation.
62
+ * When you send events to Amplitude, call this method to get the most up-to-date session replay properties for the event.
63
+ *
64
+ * @returns Promise that resolves to an object containing session replay metadata
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const sessionReplayProperties = await plugin.getSessionReplayProperties();
69
+ * analytics.track('Button Clicked', {
70
+ * buttonName: 'submit',
71
+ * ...sessionReplayProperties
72
+ * });
73
+ * ```
74
+ */
75
+ getSessionReplayProperties(): Promise<import("./session-replay").SessionReplayProperties>;
76
+ }
77
+ //# sourceMappingURL=plugin-session-replay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-session-replay.d.ts","sourceRoot":"","sources":["../../src/plugin-session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,KAAK,EACV,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,yBAAyB,EAAuC,MAAM,gCAAgC,CAAC;AAIhH;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,YAAW,gBAAgB,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAChG,IAAI,SAAmD;IACvD,IAAI,eAAyB;IAE7B,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,mBAAmB,CAAsC;IACjE,OAAO,CAAC,MAAM,CAA+B;IAE7C;;;;;;;;;;;;;;OAcG;gBACS,MAAM,GAAE,yBAA8B;IAUlD;;;;;;;OAOG;IACG,KAAK,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBrE,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAuBlD;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B;;;;;;;;;;;;;;OAcG;IACG,0BAA0B;CAMjC"}
@@ -0,0 +1,80 @@
1
+ import { LogLevel } from '@amplitude/analytics-types';
2
+ /**
3
+ * Masking levels for sensitive content in session replay
4
+ */
5
+ export declare enum MaskLevel {
6
+ /**
7
+ * Light masking - minimal content is masked
8
+ */
9
+ Light = "light",
10
+ /**
11
+ * Medium masking - balanced approach to content masking
12
+ */
13
+ Medium = "medium",
14
+ /**
15
+ * Conservative masking - maximum content masking for privacy
16
+ */
17
+ Conservative = "conservative"
18
+ }
19
+ /**
20
+ * Configuration for Session Replay React Native SDK
21
+ */
22
+ export interface SessionReplayConfig {
23
+ /**
24
+ * Your Amplitude API key
25
+ * @required
26
+ */
27
+ apiKey: string;
28
+ /**
29
+ * Whether to automatically start recording when the SDK is initialized
30
+ * @default true
31
+ */
32
+ autoStart?: boolean;
33
+ /**
34
+ * Device identifier that matches the device ID sent with Amplitude events
35
+ * Must match the Device ID passed as event properties to Amplitude
36
+ * @default null
37
+ */
38
+ deviceId?: string | null;
39
+ /**
40
+ * Whether to enable remote configuration
41
+ * @default true
42
+ */
43
+ enableRemoteConfig?: boolean;
44
+ /**
45
+ * Log level for the SDK
46
+ * @default LogLevel.Warn
47
+ */
48
+ logLevel?: LogLevel;
49
+ /**
50
+ * Level of masking applied to sensitive content
51
+ * @default MaskLevel.Medium
52
+ */
53
+ maskLevel?: MaskLevel;
54
+ /**
55
+ * Whether to opt out of session replay collection
56
+ * @default false
57
+ */
58
+ optOut?: boolean;
59
+ /**
60
+ * Sample rate for session replay (0.0 to 1.0)
61
+ * Determines what percentage of sessions will be recorded
62
+ * @default 0
63
+ */
64
+ sampleRate?: number;
65
+ /**
66
+ * Server zone for data processing
67
+ * @default 'US'
68
+ * @review: Verify EU server zone compliance and data residency requirements
69
+ */
70
+ serverZone?: 'EU' | 'US';
71
+ /**
72
+ * Session identifier that matches the session ID sent with Amplitude events
73
+ * Must match the Session ID passed as event properties to Amplitude
74
+ * @default -1
75
+ */
76
+ sessionId?: number;
77
+ }
78
+ export declare const getDefaultConfig: () => Required<Omit<SessionReplayConfig, 'apiKey'>>;
79
+ export { LogLevel };
80
+ //# sourceMappingURL=session-replay-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-replay-config.d.ts","sourceRoot":"","sources":["../../src/session-replay-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD;;GAEG;AACH,oBAAY,SAAS;IACnB;;OAEG;IACH,KAAK,UAAU;IACf;;OAEG;IACH,MAAM,WAAW;IACjB;;OAEG;IACH,YAAY,iBAAiB;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAEzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAYhF,CAAC;AACF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,128 @@
1
+ import { SessionReplayConfig } from './session-replay-config';
2
+ import { createSessionReplayLogger } from './logger';
3
+ /**
4
+ * Configure the SDK and begin collecting replays.
5
+ * This function must be called before any other session replay operations.
6
+ *
7
+ * @param config - Configuration object containing API key, device ID, session ID, and other options
8
+ * @returns Promise that resolves when initialization is complete
9
+ * @throws Error if initialization fails
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * await init({
14
+ * apiKey: 'YOUR_API_KEY',
15
+ * deviceId: 'user-device-id',
16
+ * sessionId: Date.now(),
17
+ * sampleRate: 0.1
18
+ * });
19
+ * ```
20
+ */
21
+ export declare function init(config: SessionReplayConfig): Promise<void>;
22
+ /**
23
+ * Call whenever the session ID changes.
24
+ * The Session ID you pass to the SDK must match the Session ID sent as event properties to Amplitude.
25
+ *
26
+ * @param sessionId - The new session identifier number
27
+ * @returns Promise that resolves when the session ID is updated
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * await setSessionId(Date.now());
32
+ * ```
33
+ */
34
+ export declare function setSessionId(sessionId: number): Promise<void>;
35
+ /**
36
+ * Update the device ID used for session replay tracking.
37
+ * The Device ID you pass to the SDK must match the Device ID sent as event properties to Amplitude.
38
+ *
39
+ * @param deviceId - The device identifier string, or null to clear the device ID
40
+ * @returns Promise that resolves when the device ID is updated
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * await setDeviceId('user-device-id');
45
+ * // or clear device ID
46
+ * await setDeviceId(null);
47
+ * ```
48
+ */
49
+ export declare function setDeviceId(deviceId: string | null): Promise<void>;
50
+ /**
51
+ * Get the current session identifier from the session replay SDK.
52
+ *
53
+ * @returns Promise that resolves to the current session ID number, or null if not initialized
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const sessionId = await getSessionId();
58
+ * if (sessionId !== null) {
59
+ * console.log('Current session ID:', sessionId);
60
+ * }
61
+ * ```
62
+ */
63
+ export declare function getSessionId(): Promise<number | null>;
64
+ /**
65
+ * Interface for session replay properties that should be attached to Amplitude events.
66
+ * These properties help correlate events with session recordings.
67
+ */
68
+ export interface SessionReplayProperties {
69
+ [key: string]: string | boolean | null;
70
+ }
71
+ /**
72
+ * When you send events to Amplitude, call this function to get the most up-to-date session replay properties for the event.
73
+ * Collect Session Replay properties to send with other event properties.
74
+ *
75
+ * @returns Promise that resolves to an object containing session replay metadata
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const sessionReplayProperties = await getSessionReplayProperties();
80
+ * analytics.track('Button Clicked', {
81
+ * buttonName: 'submit',
82
+ * ...sessionReplayProperties // Merge session replay properties
83
+ * });
84
+ * ```
85
+ */
86
+ export declare function getSessionReplayProperties(): Promise<SessionReplayProperties>;
87
+ /**
88
+ * Flush any pending session replay data to the server.
89
+ * Forces immediate upload of recorded session data that may be buffered locally.
90
+ *
91
+ * @returns Promise that resolves when the flush operation is complete
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // Flush data before app termination
96
+ * await flush();
97
+ * ```
98
+ */
99
+ export declare function flush(): Promise<void>;
100
+ /**
101
+ * Start session replay recording.
102
+ * Begins capturing user interactions and screen content for replay.
103
+ * If autoStart is enabled in the configuration, this is called automatically during initialization.
104
+ *
105
+ * @returns Promise that resolves when recording starts
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Start recording manually if autoStart is false
110
+ * await start();
111
+ * ```
112
+ */
113
+ export declare function start(): Promise<void>;
114
+ /**
115
+ * Stop session replay recording.
116
+ * Ends the current recording session and processes any captured data.
117
+ *
118
+ * @returns Promise that resolves when recording stops
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // Stop recording when user logs out or app goes to background
123
+ * await stop();
124
+ * ```
125
+ */
126
+ export declare function stop(): Promise<void>;
127
+ export declare function privateInit(config: SessionReplayConfig, newLogger: ReturnType<typeof createSessionReplayLogger>): Promise<void>;
128
+ //# sourceMappingURL=session-replay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAOrD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAMxE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAM3D;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;CACxC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAOnF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAM1C;AAUD,wBAAsB,WAAW,CAC/B,MAAM,EAAE,mBAAmB,EAC3B,SAAS,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -0,0 +1,2 @@
1
+ export declare const VERSION = "0.0.1-beta.2";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@amplitude/session-replay-react-native",
3
+ "version": "0.0.1-beta.2",
4
+ "description": "Amplitude Session Replay for React Native",
5
+ "keywords": [
6
+ "analytics",
7
+ "amplitude",
8
+ "react-native",
9
+ "ios",
10
+ "android",
11
+ "session-replay"
12
+ ],
13
+ "author": "Amplitude Inc",
14
+ "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
15
+ "license": "MIT",
16
+ "main": "lib/commonjs/index",
17
+ "module": "lib/module/index",
18
+ "types": "lib/typescript/index.d.ts",
19
+ "react-native": "src/index",
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "tag": "latest"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
27
+ },
28
+ "scripts": {
29
+ "build": "bob build",
30
+ "clean": "rimraf node_modules lib coverage",
31
+ "fix": "yarn fix:eslint & yarn fix:prettier",
32
+ "fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
33
+ "fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
34
+ "lint": "yarn lint:prettier && yarn lint:eslint",
35
+ "lint:eslint": "eslint '{src,test}/**/*.ts'",
36
+ "lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
37
+ "test": "jest",
38
+ "typecheck": "tsc -p ./tsconfig.json",
39
+ "version": "yarn version-file && yarn build",
40
+ "version-file": "node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts",
41
+ "typescript": "tsc --noEmit",
42
+ "example": "yarn workspace @amplitude/plugin-session-replay-react-native-example",
43
+ "pods": "cd example && pod-install --quiet"
44
+ },
45
+ "source": "src/index",
46
+ "files": [
47
+ "src",
48
+ "lib",
49
+ "android",
50
+ "ios",
51
+ "cpp",
52
+ "*.podspec",
53
+ "!ios/build",
54
+ "!android/build",
55
+ "!android/gradle",
56
+ "!android/gradlew",
57
+ "!android/gradlew.bat",
58
+ "!android/local.properties",
59
+ "!test",
60
+ "!**/__tests__",
61
+ "!**/__fixtures__",
62
+ "!**/__mocks__",
63
+ "!**/.*"
64
+ ],
65
+ "bugs": {
66
+ "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
67
+ },
68
+ "dependencies": {
69
+ "@amplitude/analytics-types": "^1.3.4"
70
+ },
71
+ "devDependencies": {
72
+ "@types/react": "^18.0.26",
73
+ "react": "18.2.0",
74
+ "react-native": "0.73.0",
75
+ "react-native-builder-bob": "^0.20.3"
76
+ },
77
+ "peerDependencies": {
78
+ "react": "*",
79
+ "react-native": "*"
80
+ },
81
+ "react-native-builder-bob": {
82
+ "source": "src",
83
+ "output": "lib",
84
+ "targets": [
85
+ "commonjs",
86
+ "module",
87
+ [
88
+ "typescript",
89
+ {
90
+ "project": "tsconfig.build.json"
91
+ }
92
+ ]
93
+ ]
94
+ },
95
+ "private": false
96
+ }
@@ -0,0 +1,7 @@
1
+ import { requireNativeComponent, type ViewProps } from 'react-native';
2
+
3
+ interface AmpMaskViewProps extends ViewProps {
4
+ mask: 'amp-mask' | 'amp-unmask' | 'amp-block';
5
+ }
6
+
7
+ export const AmpMaskView = requireNativeComponent<AmpMaskViewProps>('AMPMaskComponentView');
package/src/index.tsx ADDED
@@ -0,0 +1,16 @@
1
+ export {
2
+ init,
3
+ setSessionId,
4
+ getSessionId,
5
+ getSessionReplayProperties,
6
+ flush,
7
+ start,
8
+ stop,
9
+ setDeviceId,
10
+ } from './session-replay';
11
+ export { type SessionReplayConfig, MaskLevel } from './session-replay-config';
12
+
13
+ export { SessionReplayPlugin } from './plugin-session-replay';
14
+ export type { SessionReplayPluginConfig } from './plugin-session-replay-config';
15
+
16
+ export { AmpMaskView } from './amp-mask-view';
package/src/logger.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { LogLevel } from '@amplitude/analytics-types';
2
+
3
+ const PREFIX = 'Amplitude Session Replay ';
4
+
5
+ export const createSessionReplayLogger = () => {
6
+ let logLevel: LogLevel = LogLevel.Warn;
7
+
8
+ return {
9
+ setLogLevel: function setLogLevel(level: LogLevel): void {
10
+ logLevel = level;
11
+ },
12
+
13
+ log: function log(...args: unknown[]): void {
14
+ if (logLevel < LogLevel.Verbose) {
15
+ return;
16
+ }
17
+ console.log(`${PREFIX}[Log]:`, ...args);
18
+ },
19
+
20
+ warn: function warn(...args: unknown[]): void {
21
+ if (logLevel < LogLevel.Warn) {
22
+ return;
23
+ }
24
+ console.warn(`${PREFIX}[Warn]:`, ...args);
25
+ },
26
+
27
+ error: function error(...args: unknown[]): void {
28
+ if (logLevel < LogLevel.Error) {
29
+ return;
30
+ }
31
+ console.error(`${PREFIX}[Error]:`, ...args);
32
+ },
33
+
34
+ debug: function debug(...args: unknown[]): void {
35
+ if (logLevel < LogLevel.Debug) {
36
+ return;
37
+ }
38
+ console.log(`${PREFIX}[Debug]:`, ...args);
39
+ },
40
+ };
41
+ };