@mixpanel/react-native-session-replay 0.1.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 (38) hide show
  1. package/LICENSE +20 -0
  2. package/MixpanelReactNativeSessionReplay.podspec +26 -0
  3. package/README.md +200 -0
  4. package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeMixpanelReactNativeSessionReplaySpec.java +54 -0
  5. package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +36 -0
  6. package/android/app/build/generated/source/codegen/jni/MixpanelReactNativeSessionReplaySpec-generated.cpp +56 -0
  7. package/android/app/build/generated/source/codegen/jni/MixpanelReactNativeSessionReplaySpec.h +31 -0
  8. package/android/app/build/generated/source/codegen/jni/react/renderer/components/MixpanelReactNativeSessionReplaySpec/MixpanelReactNativeSessionReplaySpecJSI-generated.cpp +54 -0
  9. package/android/app/build/generated/source/codegen/jni/react/renderer/components/MixpanelReactNativeSessionReplaySpec/MixpanelReactNativeSessionReplaySpecJSI.h +107 -0
  10. package/android/build.gradle +89 -0
  11. package/android/gradle.properties +5 -0
  12. package/android/src/main/AndroidManifest.xml +2 -0
  13. package/android/src/main/java/com/mixpanelreactnativesessionreplay/MixpanelReactNativeSessionReplayModule.kt +287 -0
  14. package/android/src/main/java/com/mixpanelreactnativesessionreplay/MixpanelReactNativeSessionReplayPackage.kt +38 -0
  15. package/android/src/main/java/com/mixpanelreactnativesessionreplay/MixpanelSessionReplayView.kt +26 -0
  16. package/android/src/main/java/com/mixpanelreactnativesessionreplay/MixpanelSessionReplayViewManager.kt +29 -0
  17. package/ios/MixpanelReactNativeSessionReplay.h +5 -0
  18. package/ios/MixpanelReactNativeSessionReplay.mm +87 -0
  19. package/ios/MixpanelSessionReplayViewManager.mm +36 -0
  20. package/ios/MixpanelSwiftSessionReplay.swift +93 -0
  21. package/lib/module/MixpanelSessionReplayView.js +5 -0
  22. package/lib/module/MixpanelSessionReplayView.js.map +1 -0
  23. package/lib/module/NativeMixpanelReactNativeSessionReplay.js +5 -0
  24. package/lib/module/NativeMixpanelReactNativeSessionReplay.js.map +1 -0
  25. package/lib/module/index.js +188 -0
  26. package/lib/module/index.js.map +1 -0
  27. package/lib/module/package.json +1 -0
  28. package/lib/typescript/package.json +1 -0
  29. package/lib/typescript/src/MixpanelSessionReplayView.d.ts +7 -0
  30. package/lib/typescript/src/MixpanelSessionReplayView.d.ts.map +1 -0
  31. package/lib/typescript/src/NativeMixpanelReactNativeSessionReplay.d.ts +11 -0
  32. package/lib/typescript/src/NativeMixpanelReactNativeSessionReplay.d.ts.map +1 -0
  33. package/lib/typescript/src/index.d.ts +117 -0
  34. package/lib/typescript/src/index.d.ts.map +1 -0
  35. package/package.json +171 -0
  36. package/src/MixpanelSessionReplayView.tsx +10 -0
  37. package/src/NativeMixpanelReactNativeSessionReplay.ts +19 -0
  38. package/src/index.tsx +220 -0
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ import { Platform } from 'react-native';
4
+ import MixpanelReactNativeSessionReplay from "./NativeMixpanelReactNativeSessionReplay.js";
5
+ export let MPSessionReplayMask = /*#__PURE__*/function (MPSessionReplayMask) {
6
+ MPSessionReplayMask["Text"] = "text";
7
+ MPSessionReplayMask["Web"] = "web";
8
+ MPSessionReplayMask["Map"] = "map";
9
+ MPSessionReplayMask["Image"] = "image";
10
+ return MPSessionReplayMask;
11
+ }({});
12
+ export class MPSessionReplayConfig {
13
+ /**
14
+ * Determines whether replay events will only be flushed to the server when the device has a WiFi connection.
15
+ *
16
+ * - When set to `true`, replay events will only be flushed when the device is connected to WiFi.
17
+ * If no WiFi is available, flushes are skipped and the events remain in memory — they will be lost if the app is terminated before WiFi becomes available.
18
+ * - When set to `false`, replay events will be flushed over any network connection, including cellular.
19
+ * - **Default:** `true`
20
+ */
21
+
22
+ /**
23
+ * Controls the sampling rate for automatically started recording session replays.
24
+ *
25
+ * This value (between 0.0 and 100.0) defines the percentage of sessions that will automatically start recording
26
+ * when a new session begins.
27
+ *
28
+ * - At `0.0`, no sessions will be auto-recorded.
29
+ * - At `100.0`, all sessions will be auto-recorded.
30
+ * - This setting is not used when invoking `startRecording()` manually.
31
+ * - **Default:** `100`
32
+ */
33
+
34
+ /**
35
+ * Returns the set of views that are automatically masked by the SDK.
36
+ *
37
+ * By default, image, text, web, and map (MKMapView only for iOS) views are masked.
38
+ * This default behavior can be overridden using this configuration.
39
+ */
40
+
41
+ /**
42
+ * Determines whether or not the SDK will automatically start recording session replays upon initialization.
43
+ *
44
+ * - When set to `true`, the SDK will automatically start recording session replays when the instance is initialized.
45
+ * The recording will be stopped and started automatically whenever the app goes to background and comes to foreground.
46
+ * For each new automatically started session, the SDK uses `recordingSessionsPercent` to determine whether recording
47
+ * should begin for that session.
48
+ * - When set to `false`, the SDK will not start recording until explicitly invoked by calling `startRecording()`.
49
+ */
50
+
51
+ /**
52
+ * Specifies the flush interval in seconds.
53
+ *
54
+ * Screenshots are collected and sent to Mixpanel in batches of 10.
55
+ * One batch is sent after each flush interval.
56
+ * You can adjust the flush interval to delay or expedite the sending of screenshots.
57
+ *
58
+ * - **Default:** `10` seconds
59
+ */
60
+
61
+ /**
62
+ * Enables debug-level logging for the SDK.
63
+ *
64
+ * - When set to `true`, the SDK will print verbose debug logs to the console to assist with development and troubleshooting.
65
+ * These logs may include internal events, configuration status, and lifecycle hooks relevant to session replay.
66
+ * - When set to `false`, logging is suppressed except for critical errors or warnings.
67
+ * - **Default:** `false`
68
+ */
69
+
70
+ constructor({
71
+ wifiOnly = true,
72
+ autoStartRecording = true,
73
+ recordingSessionsPercent = 100,
74
+ autoMaskedViews = [MPSessionReplayMask.Image, MPSessionReplayMask.Text, MPSessionReplayMask.Web, MPSessionReplayMask.Map],
75
+ flushInterval = 10,
76
+ enableLogging = false
77
+ } = {}) {
78
+ this.wifiOnly = wifiOnly;
79
+ this.autoStartRecording = autoStartRecording;
80
+ this.recordingSessionsPercent = recordingSessionsPercent;
81
+ this.autoMaskedViews = autoMaskedViews;
82
+ this.flushInterval = flushInterval;
83
+ this.enableLogging = enableLogging;
84
+ }
85
+ transformMaskValueForPlatform(value) {
86
+ if (Platform.OS === 'android') {
87
+ // Android expects capitalized values: Text, Image, Web, Map
88
+ return value.charAt(0).toUpperCase() + value.slice(1);
89
+ }
90
+ // iOS expects lowercase values: text, image, web, map
91
+ return value;
92
+ }
93
+ toJSON() {
94
+ // Transform autoMaskedViews for platform-specific requirements
95
+ const transformedAutoMaskedViews = this.autoMaskedViews.filter(mask => !(Platform.OS === 'android' && mask === MPSessionReplayMask.Map)).map(mask => this.transformMaskValueForPlatform(mask));
96
+ const config = {
97
+ wifiOnly: this.wifiOnly,
98
+ recordingSessionsPercent: this.recordingSessionsPercent,
99
+ autoMaskedViews: transformedAutoMaskedViews,
100
+ autoStartRecording: this.autoStartRecording,
101
+ flushInterval: this.flushInterval,
102
+ enableLogging: this.enableLogging
103
+ };
104
+ if (Platform.OS === 'ios' || Platform.OS === 'android') {
105
+ // console.log(Platform.OS, JSON.stringify(config));
106
+ return JSON.stringify(config);
107
+ } else {
108
+ return '';
109
+ }
110
+ }
111
+ }
112
+ export { MixpanelSessionReplayView } from "./MixpanelSessionReplayView.js";
113
+
114
+ /**
115
+ * Initializes the Mixpanel Session Replay system with the provided configuration.
116
+ *
117
+ * It checks remote configuration to determine if session recording is enabled, and only then initializes the SDK.
118
+ * If the SDK is initialized previously, then it will be deinitialized first.
119
+ *
120
+ * @param token - The Mixpanel project token used to identify the project.
121
+ * @param distinctId - A unique identifier for the current user.
122
+ * @param config - The configuration object used to customize session replay behavior.
123
+ * @throws An error if the token or distinctId is missing or invalid, or if the configuration is invalid,
124
+ * or if the initialization fails.
125
+ */
126
+ export async function initialize(token, distinctId, config) {
127
+ if (!token || typeof token !== 'string') {
128
+ throw new Error('Mixpanel token is required and must be a string');
129
+ }
130
+ if (!distinctId || typeof distinctId !== 'string') {
131
+ throw new Error('distinctId is required and must be a string');
132
+ }
133
+ if (config.recordingSessionsPercent !== undefined && (config.recordingSessionsPercent < 0 || config.recordingSessionsPercent > 100)) {
134
+ throw new Error('recordingSessionsPercent must be between 0 and 100');
135
+ }
136
+ const json = config.toJSON();
137
+ return MixpanelReactNativeSessionReplay.initialize(token, distinctId, json);
138
+ }
139
+
140
+ /**
141
+ * Manually starts session replay recording.
142
+ *
143
+ * If recording is already active, calling this method has no effect.
144
+ * The recording will continue until you manually stop it or until the app goes to the background, whichever happens first.
145
+ *
146
+ * @param recordingSessionsPercent - A value from 0 to 100 representing the likelihood that the current session will be recorded.
147
+ * This controls sampling of sessions. The `recordingSessionsPercent` value from the config is ignored when calling this method.
148
+ * @default 100 (record all sessions)
149
+ */
150
+ export async function startRecording(recordingSessionsPercent = 100) {
151
+ return MixpanelReactNativeSessionReplay.startRecording(recordingSessionsPercent);
152
+ }
153
+
154
+ /**
155
+ * Stops the session recording and performs cleanup tasks.
156
+ *
157
+ * This method stops recording, clears relevant session state, and uploads pending events.
158
+ */
159
+ export async function stopRecording() {
160
+ return MixpanelReactNativeSessionReplay.stopRecording();
161
+ }
162
+
163
+ /**
164
+ * Tells you if the recording is in-progress.
165
+ *
166
+ * @returns A promise that resolves to `true` if recording is active, `false` otherwise.
167
+ */
168
+ export async function isRecording() {
169
+ return MixpanelReactNativeSessionReplay.isRecording();
170
+ }
171
+
172
+ /**
173
+ * Sets the distinct ID for session replays.
174
+ *
175
+ * You can use this method to update the distinctId after the Session Replay SDK initialization.
176
+ * It is recommended to call Identify from the Mixpanel main SDK first and then call identify from the Session Replay SDK.
177
+ * This ensures that users are properly merged.
178
+ *
179
+ * @param distinctId - The distinct ID of the user.
180
+ * @throws An error if the distinctId is missing or invalid.
181
+ */
182
+ export async function identify(distinctId) {
183
+ if (!distinctId || typeof distinctId !== 'string') {
184
+ throw new Error('distinctId is required and must be a string');
185
+ }
186
+ return MixpanelReactNativeSessionReplay.identify(distinctId);
187
+ }
188
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Platform","MixpanelReactNativeSessionReplay","MPSessionReplayMask","MPSessionReplayConfig","constructor","wifiOnly","autoStartRecording","recordingSessionsPercent","autoMaskedViews","Image","Text","Web","Map","flushInterval","enableLogging","transformMaskValueForPlatform","value","OS","charAt","toUpperCase","slice","toJSON","transformedAutoMaskedViews","filter","mask","map","config","JSON","stringify","MixpanelSessionReplayView","initialize","token","distinctId","Error","undefined","json","startRecording","stopRecording","isRecording","identify"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,OAAOC,gCAAgC,MAAM,6CAA0C;AAEvF,WAAYC,mBAAmB,0BAAnBA,mBAAmB;EAAnBA,mBAAmB;EAAnBA,mBAAmB;EAAnBA,mBAAmB;EAAnBA,mBAAmB;EAAA,OAAnBA,mBAAmB;AAAA;AAO/B,OAAO,MAAMC,qBAAqB,CAAC;EACjC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;EAGEC,WAAWA,CAAC;IACVC,QAAQ,GAAG,IAAI;IACfC,kBAAkB,GAAG,IAAI;IACzBC,wBAAwB,GAAG,GAAG;IAC9BC,eAAe,GAAG,CAChBN,mBAAmB,CAACO,KAAK,EACzBP,mBAAmB,CAACQ,IAAI,EACxBR,mBAAmB,CAACS,GAAG,EACvBT,mBAAmB,CAACU,GAAG,CACxB;IACDC,aAAa,GAAG,EAAE;IAClBC,aAAa,GAAG;EACc,CAAC,GAAG,CAAC,CAAC,EAAE;IACtC,IAAI,CAACT,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,kBAAkB,GAAGA,kBAAkB;IAC5C,IAAI,CAACC,wBAAwB,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;EAEA,OAAOhC,gCAAgC,CAACsC,QAAQ,CAACP,UAAU,CAAC;AAC9D","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,7 @@
1
+ import { type ViewProps } from 'react-native';
2
+ interface MixpanelSessionReplayViewProps extends ViewProps {
3
+ sensitive?: boolean;
4
+ }
5
+ export declare const MixpanelSessionReplayView: import("react-native").HostComponent<MixpanelSessionReplayViewProps>;
6
+ export {};
7
+ //# sourceMappingURL=MixpanelSessionReplayView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MixpanelSessionReplayView.d.ts","sourceRoot":"","sources":["../../../src/MixpanelSessionReplayView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAEtE,UAAU,8BAA+B,SAAQ,SAAS;IACxD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,yBAAyB,sEAGnC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ initialize(token: string, distinctId: string, configJSON: string): Promise<void>;
4
+ startRecording(recordingSessionsPercent: number): Promise<void>;
5
+ stopRecording(): Promise<void>;
6
+ isRecording(): Promise<boolean>;
7
+ identify(distinctId: string): Promise<void>;
8
+ }
9
+ declare const _default: Spec;
10
+ export default _default;
11
+ //# sourceMappingURL=NativeMixpanelReactNativeSessionReplay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeMixpanelReactNativeSessionReplay.d.ts","sourceRoot":"","sources":["../../../src/NativeMixpanelReactNativeSessionReplay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,UAAU,CACR,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,wBAAwB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/B,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;;AAED,wBAEE"}
@@ -0,0 +1,117 @@
1
+ export declare enum MPSessionReplayMask {
2
+ Text = "text",
3
+ Web = "web",
4
+ Map = "map",
5
+ Image = "image"
6
+ }
7
+ export declare class MPSessionReplayConfig {
8
+ /**
9
+ * Determines whether replay events will only be flushed to the server when the device has a WiFi connection.
10
+ *
11
+ * - When set to `true`, replay events will only be flushed when the device is connected to WiFi.
12
+ * If no WiFi is available, flushes are skipped and the events remain in memory — they will be lost if the app is terminated before WiFi becomes available.
13
+ * - When set to `false`, replay events will be flushed over any network connection, including cellular.
14
+ * - **Default:** `true`
15
+ */
16
+ wifiOnly: boolean;
17
+ /**
18
+ * Controls the sampling rate for automatically started recording session replays.
19
+ *
20
+ * This value (between 0.0 and 100.0) defines the percentage of sessions that will automatically start recording
21
+ * when a new session begins.
22
+ *
23
+ * - At `0.0`, no sessions will be auto-recorded.
24
+ * - At `100.0`, all sessions will be auto-recorded.
25
+ * - This setting is not used when invoking `startRecording()` manually.
26
+ * - **Default:** `100`
27
+ */
28
+ recordingSessionsPercent: number;
29
+ /**
30
+ * Returns the set of views that are automatically masked by the SDK.
31
+ *
32
+ * By default, image, text, web, and map (MKMapView only for iOS) views are masked.
33
+ * This default behavior can be overridden using this configuration.
34
+ */
35
+ autoMaskedViews: MPSessionReplayMask[];
36
+ /**
37
+ * Determines whether or not the SDK will automatically start recording session replays upon initialization.
38
+ *
39
+ * - When set to `true`, the SDK will automatically start recording session replays when the instance is initialized.
40
+ * The recording will be stopped and started automatically whenever the app goes to background and comes to foreground.
41
+ * For each new automatically started session, the SDK uses `recordingSessionsPercent` to determine whether recording
42
+ * should begin for that session.
43
+ * - When set to `false`, the SDK will not start recording until explicitly invoked by calling `startRecording()`.
44
+ */
45
+ autoStartRecording: boolean;
46
+ /**
47
+ * Specifies the flush interval in seconds.
48
+ *
49
+ * Screenshots are collected and sent to Mixpanel in batches of 10.
50
+ * One batch is sent after each flush interval.
51
+ * You can adjust the flush interval to delay or expedite the sending of screenshots.
52
+ *
53
+ * - **Default:** `10` seconds
54
+ */
55
+ flushInterval: number;
56
+ /**
57
+ * Enables debug-level logging for the SDK.
58
+ *
59
+ * - When set to `true`, the SDK will print verbose debug logs to the console to assist with development and troubleshooting.
60
+ * These logs may include internal events, configuration status, and lifecycle hooks relevant to session replay.
61
+ * - When set to `false`, logging is suppressed except for critical errors or warnings.
62
+ * - **Default:** `false`
63
+ */
64
+ enableLogging: boolean;
65
+ constructor({ wifiOnly, autoStartRecording, recordingSessionsPercent, autoMaskedViews, flushInterval, enableLogging, }?: Partial<MPSessionReplayConfig>);
66
+ private transformMaskValueForPlatform;
67
+ toJSON(): string;
68
+ }
69
+ export { MixpanelSessionReplayView } from './MixpanelSessionReplayView';
70
+ /**
71
+ * Initializes the Mixpanel Session Replay system with the provided configuration.
72
+ *
73
+ * It checks remote configuration to determine if session recording is enabled, and only then initializes the SDK.
74
+ * If the SDK is initialized previously, then it will be deinitialized first.
75
+ *
76
+ * @param token - The Mixpanel project token used to identify the project.
77
+ * @param distinctId - A unique identifier for the current user.
78
+ * @param config - The configuration object used to customize session replay behavior.
79
+ * @throws An error if the token or distinctId is missing or invalid, or if the configuration is invalid,
80
+ * or if the initialization fails.
81
+ */
82
+ export declare function initialize(token: string, distinctId: string, config: MPSessionReplayConfig): Promise<void>;
83
+ /**
84
+ * Manually starts session replay recording.
85
+ *
86
+ * If recording is already active, calling this method has no effect.
87
+ * The recording will continue until you manually stop it or until the app goes to the background, whichever happens first.
88
+ *
89
+ * @param recordingSessionsPercent - A value from 0 to 100 representing the likelihood that the current session will be recorded.
90
+ * This controls sampling of sessions. The `recordingSessionsPercent` value from the config is ignored when calling this method.
91
+ * @default 100 (record all sessions)
92
+ */
93
+ export declare function startRecording(recordingSessionsPercent?: number): Promise<void>;
94
+ /**
95
+ * Stops the session recording and performs cleanup tasks.
96
+ *
97
+ * This method stops recording, clears relevant session state, and uploads pending events.
98
+ */
99
+ export declare function stopRecording(): Promise<void>;
100
+ /**
101
+ * Tells you if the recording is in-progress.
102
+ *
103
+ * @returns A promise that resolves to `true` if recording is active, `false` otherwise.
104
+ */
105
+ export declare function isRecording(): Promise<boolean>;
106
+ /**
107
+ * Sets the distinct ID for session replays.
108
+ *
109
+ * You can use this method to update the distinctId after the Session Replay SDK initialization.
110
+ * It is recommended to call Identify from the Mixpanel main SDK first and then call identify from the Session Replay SDK.
111
+ * This ensures that users are properly merged.
112
+ *
113
+ * @param distinctId - The distinct ID of the user.
114
+ * @throws An error if the distinctId is missing or invalid.
115
+ */
116
+ export declare function identify(distinctId: string): Promise<void>;
117
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAGA,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,KAAK,UAAU;CAChB;AAED,qBAAa,qBAAqB;IAChC;;;;;;;OAOG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;OAUG;IACH,wBAAwB,EAAE,MAAM,CAAC;IAEjC;;;;;OAKG;IACH,eAAe,EAAE,mBAAmB,EAAE,CAAC;IAEvC;;;;;;;;OAQG;IACH,kBAAkB,EAAE,OAAO,CAAC;IAE5B;;;;;;;;OAQG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;;;OAOG;IACH,aAAa,EAAE,OAAO,CAAC;gBAEX,EACV,QAAe,EACf,kBAAyB,EACzB,wBAA8B,EAC9B,eAKC,EACD,aAAkB,EAClB,aAAqB,GACtB,GAAE,OAAO,CAAC,qBAAqB,CAAM;IAStC,OAAO,CAAC,6BAA6B;IASrC,MAAM,IAAI,MAAM;CAyBjB;AAED,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAClC,wBAAwB,GAAE,MAAY,GACrC,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAEnD;AAED;;;;GAIG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAEpD;AAED;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhE"}
package/package.json ADDED
@@ -0,0 +1,171 @@
1
+ {
2
+ "name": "@mixpanel/react-native-session-replay",
3
+ "version": "0.1.2",
4
+ "description": "Official React Native turbo module for Mixpanel Session Replay",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "react-native.config.js",
22
+ "MixpanelReactNativeSessionReplay.podspec",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace mixpanel-react-native-session-replay-example",
36
+ "test": "jest",
37
+ "typecheck": "tsc",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
40
+ "prepare": "bob build",
41
+ "release": "release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android",
47
+ "mixpanel",
48
+ "session-replay",
49
+ "analytics",
50
+ "user-behavior",
51
+ "mobile-analytics",
52
+ "turbo-module"
53
+ ],
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/mixpanel/mixpanel-react-native-session-replay.git"
57
+ },
58
+ "author": "Mixpanel <dev@mixpanel.com> (https://github.com/mixpanel)",
59
+ "license": "MIT",
60
+ "bugs": {
61
+ "url": "https://github.com/mixpanel/mixpanel-react-native-session-replay/issues"
62
+ },
63
+ "homepage": "https://github.com/mixpanel/mixpanel-react-native-session-replay#readme",
64
+ "publishConfig": {
65
+ "access": "public",
66
+ "registry": "https://registry.npmjs.org/"
67
+ },
68
+ "devDependencies": {
69
+ "@commitlint/config-conventional": "^19.6.0",
70
+ "@eslint/compat": "^1.2.7",
71
+ "@eslint/eslintrc": "^3.3.0",
72
+ "@eslint/js": "^9.22.0",
73
+ "@evilmartians/lefthook": "^1.5.0",
74
+ "@react-native-community/cli": "15.0.0-alpha.2",
75
+ "@react-native/babel-preset": "0.79.2",
76
+ "@react-native/eslint-config": "^0.78.0",
77
+ "@release-it/conventional-changelog": "^9.0.2",
78
+ "@types/jest": "^29.5.5",
79
+ "@types/react": "^19.0.0",
80
+ "commitlint": "^19.6.1",
81
+ "del-cli": "^5.1.0",
82
+ "eslint": "^9.22.0",
83
+ "eslint-config-prettier": "^10.1.1",
84
+ "eslint-plugin-prettier": "^5.2.3",
85
+ "jest": "^29.7.0",
86
+ "prettier": "^3.0.3",
87
+ "react": "19.0.0",
88
+ "react-native": "0.79.2",
89
+ "react-native-builder-bob": "^0.40.13",
90
+ "release-it": "^17.10.0",
91
+ "turbo": "^1.10.7",
92
+ "typescript": "^5.8.3"
93
+ },
94
+ "peerDependencies": {
95
+ "react": "*",
96
+ "react-native": "*"
97
+ },
98
+ "workspaces": [
99
+ "example"
100
+ ],
101
+ "packageManager": "yarn@3.6.1",
102
+ "jest": {
103
+ "preset": "react-native",
104
+ "modulePathIgnorePatterns": [
105
+ "<rootDir>/example/node_modules",
106
+ "<rootDir>/lib/"
107
+ ]
108
+ },
109
+ "commitlint": {
110
+ "extends": [
111
+ "@commitlint/config-conventional"
112
+ ]
113
+ },
114
+ "release-it": {
115
+ "git": {
116
+ "commitMessage": "chore: release ${version}",
117
+ "tagName": "v${version}"
118
+ },
119
+ "npm": {
120
+ "publish": true
121
+ },
122
+ "github": {
123
+ "release": true
124
+ },
125
+ "plugins": {
126
+ "@release-it/conventional-changelog": {
127
+ "preset": {
128
+ "name": "angular"
129
+ }
130
+ }
131
+ }
132
+ },
133
+ "prettier": {
134
+ "quoteProps": "consistent",
135
+ "singleQuote": true,
136
+ "tabWidth": 2,
137
+ "trailingComma": "es5",
138
+ "useTabs": false
139
+ },
140
+ "react-native-builder-bob": {
141
+ "source": "src",
142
+ "output": "lib",
143
+ "targets": [
144
+ [
145
+ "module",
146
+ {
147
+ "esm": true
148
+ }
149
+ ],
150
+ [
151
+ "typescript",
152
+ {
153
+ "project": "tsconfig.build.json"
154
+ }
155
+ ]
156
+ ]
157
+ },
158
+ "codegenConfig": {
159
+ "name": "MixpanelReactNativeSessionReplaySpec",
160
+ "type": "modules",
161
+ "jsSrcsDir": "src",
162
+ "android": {
163
+ "javaPackageName": "com.mixpanelreactnativesessionreplay"
164
+ }
165
+ },
166
+ "create-react-native-library": {
167
+ "languages": "kotlin-objc",
168
+ "type": "turbo-module",
169
+ "version": "0.52.0"
170
+ }
171
+ }
@@ -0,0 +1,10 @@
1
+ import { requireNativeComponent, type ViewProps } from 'react-native';
2
+
3
+ interface MixpanelSessionReplayViewProps extends ViewProps {
4
+ sensitive?: boolean;
5
+ }
6
+
7
+ export const MixpanelSessionReplayView =
8
+ requireNativeComponent<MixpanelSessionReplayViewProps>(
9
+ 'MixpanelSessionReplayView'
10
+ );
@@ -0,0 +1,19 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ initialize(
6
+ token: string,
7
+ distinctId: string,
8
+ configJSON: string
9
+ ): Promise<void>;
10
+ startRecording(recordingSessionsPercent: number): Promise<void>;
11
+ stopRecording(): Promise<void>;
12
+ // Functionality not available in Android SDK ATM. It returns true always.
13
+ isRecording(): Promise<boolean>;
14
+ identify(distinctId: string): Promise<void>;
15
+ }
16
+
17
+ export default TurboModuleRegistry.getEnforcing<Spec>(
18
+ 'MixpanelReactNativeSessionReplay'
19
+ );