@amplitude/session-replay-react-native 0.1.0-beta.3 → 0.1.0-beta.5
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.
- package/README.md +1 -17
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeModule.kt +99 -48
- package/android/src/oldarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +2 -1
- package/ios/AMPNativeSessionReplay.mm +4 -2
- package/ios/NativeSessionReplay.swift +41 -37
- package/lib/commonjs/index.js +15 -9
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native-module.js.map +1 -1
- package/lib/commonjs/plugin-session-replay.js +23 -32
- package/lib/commonjs/plugin-session-replay.js.map +1 -1
- package/lib/commonjs/session-replay-config.js +0 -1
- package/lib/commonjs/session-replay-config.js.map +1 -1
- package/lib/commonjs/session-replay.js +40 -40
- package/lib/commonjs/session-replay.js.map +1 -1
- package/lib/commonjs/specs/NativeAmpSessionReplay.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/native-module.js.map +1 -1
- package/lib/module/plugin-session-replay.js +24 -33
- package/lib/module/plugin-session-replay.js.map +1 -1
- package/lib/module/session-replay-config.js +0 -1
- package/lib/module/session-replay-config.js.map +1 -1
- package/lib/module/session-replay.js +38 -39
- package/lib/module/session-replay.js.map +1 -1
- package/lib/module/specs/NativeAmpSessionReplay.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/index.d.ts +2 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/native-module.d.ts +9 -12
- package/lib/typescript/native-module.d.ts.map +1 -1
- package/lib/typescript/plugin-session-replay.d.ts +9 -14
- package/lib/typescript/plugin-session-replay.d.ts.map +1 -1
- package/lib/typescript/session-replay-config.d.ts +0 -5
- package/lib/typescript/session-replay-config.d.ts.map +1 -1
- package/lib/typescript/session-replay.d.ts +18 -28
- package/lib/typescript/session-replay.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAmpSessionReplay.d.ts +2 -1
- package/lib/typescript/specs/NativeAmpSessionReplay.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.tsx +3 -4
- package/src/native-module.ts +11 -14
- package/src/plugin-session-replay.ts +24 -33
- package/src/session-replay-config.ts +0 -7
- package/src/session-replay.ts +38 -42
- package/src/specs/NativeAmpSessionReplay.ts +2 -1
- package/src/version.ts +1 -1
|
@@ -1 +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;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf
|
|
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;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;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;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;;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;;;;;;;;GAQG;AACH,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;AAEjF,eAAO,MAAM,gBAAgB,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAexF,CAAC;AACF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SessionReplayConfig } from './session-replay-config';
|
|
2
2
|
import { createSessionReplayLogger } from './logger';
|
|
3
3
|
/**
|
|
4
|
-
* Configure the SDK
|
|
4
|
+
* Configure the SDK. Call `start()` explicitly to begin collecting replays.
|
|
5
5
|
* This function must be called before any other session replay operations.
|
|
6
6
|
*
|
|
7
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
|
-
*
|
|
8
|
+
* @returns Promise that resolves when initialization is complete. Native setup
|
|
9
|
+
* failures are logged and do not reject the promise.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -61,29 +61,6 @@ export declare function setDeviceId(deviceId: string | null): Promise<void>;
|
|
|
61
61
|
* ```
|
|
62
62
|
*/
|
|
63
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
64
|
/**
|
|
88
65
|
* Flush any pending session replay data to the server.
|
|
89
66
|
* Forces immediate upload of recorded session data that may be buffered locally.
|
|
@@ -100,13 +77,12 @@ export declare function flush(): Promise<void>;
|
|
|
100
77
|
/**
|
|
101
78
|
* Start session replay recording.
|
|
102
79
|
* Begins capturing user interactions and screen content for replay.
|
|
103
|
-
* If autoStart is enabled in the configuration, this is called automatically during initialization.
|
|
104
80
|
*
|
|
105
81
|
* @returns Promise that resolves when recording starts
|
|
106
82
|
*
|
|
107
83
|
* @example
|
|
108
84
|
* ```typescript
|
|
109
|
-
* //
|
|
85
|
+
* // Recording starts only after this explicit call.
|
|
110
86
|
* await start();
|
|
111
87
|
* ```
|
|
112
88
|
*/
|
|
@@ -124,5 +100,19 @@ export declare function start(): Promise<void>;
|
|
|
124
100
|
* ```
|
|
125
101
|
*/
|
|
126
102
|
export declare function stop(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Update whether session replay collection is disabled for the current user.
|
|
105
|
+
*
|
|
106
|
+
* @param optOut - Whether to opt out of session replay collection
|
|
107
|
+
* @returns Promise that resolves when the opt-out state is updated
|
|
108
|
+
*/
|
|
109
|
+
export declare function setOptOut(optOut: boolean): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Shut down the native SDK and clear all JavaScript lifecycle state.
|
|
112
|
+
* Call `init()` again before using any other session replay operation.
|
|
113
|
+
*
|
|
114
|
+
* @returns Promise that resolves when teardown is complete
|
|
115
|
+
*/
|
|
116
|
+
export declare function teardown(): Promise<void>;
|
|
127
117
|
export declare function privateInit(config: SessionReplayConfig, newLogger: ReturnType<typeof createSessionReplayLogger>): Promise<void>;
|
|
128
118
|
//# sourceMappingURL=session-replay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,mBAAmB,EAA+B,MAAM,yBAAyB,CAAC;AAC7G,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,mBAAmB,EAA+B,MAAM,yBAAyB,CAAC;AAC7G,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AA4BrD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBrE;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;;;;;;;;;;;GAWG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAM1C;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAM9D;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAQ9C;AAmBD,wBAAsB,WAAW,CAC/B,MAAM,EAAE,mBAAmB,EAC3B,SAAS,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC,CAGf"}
|
|
@@ -4,11 +4,12 @@ export interface Spec extends TurboModule {
|
|
|
4
4
|
setup(config: UnsafeObject): Promise<void>;
|
|
5
5
|
setSessionId(sessionId: number): Promise<void>;
|
|
6
6
|
setDeviceId(deviceId: string | null): Promise<void>;
|
|
7
|
+
setOptOut(optOut: boolean): Promise<void>;
|
|
7
8
|
getSessionId(): Promise<number>;
|
|
8
|
-
getSessionReplayProperties(): Promise<UnsafeObject>;
|
|
9
9
|
start(): Promise<void>;
|
|
10
10
|
stop(): Promise<void>;
|
|
11
11
|
flush(): Promise<void>;
|
|
12
|
+
teardown(): Promise<void>;
|
|
12
13
|
}
|
|
13
14
|
declare const _default: Spec | null;
|
|
14
15
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeAmpSessionReplay.d.ts","sourceRoot":"","sources":["../../../src/specs/NativeAmpSessionReplay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAQ9E,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,
|
|
1
|
+
{"version":3,"file":"NativeAmpSessionReplay.d.ts","sourceRoot":"","sources":["../../../src/specs/NativeAmpSessionReplay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAQ9E,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;;AAOD,wBAAuE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0-beta.
|
|
1
|
+
export declare const VERSION = "0.1.0-beta.5";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -2,15 +2,14 @@ export {
|
|
|
2
2
|
init,
|
|
3
3
|
setSessionId,
|
|
4
4
|
getSessionId,
|
|
5
|
-
getSessionReplayProperties,
|
|
6
5
|
flush,
|
|
7
6
|
start,
|
|
8
7
|
stop,
|
|
9
8
|
setDeviceId,
|
|
9
|
+
setOptOut,
|
|
10
|
+
teardown,
|
|
10
11
|
} from './session-replay';
|
|
11
12
|
export { type SessionReplayConfig, type MaskLevel, type PrivacyConfig } from './session-replay-config';
|
|
12
|
-
|
|
13
|
-
export { SessionReplayPlugin } from './plugin-session-replay';
|
|
14
|
-
export type { SessionReplayPluginConfig } from './plugin-session-replay-config';
|
|
13
|
+
export { LogLevel } from './session-replay-config';
|
|
15
14
|
|
|
16
15
|
export { AmpMaskView, type AmpMaskViewProps } from './amp-mask-view';
|
package/src/native-module.ts
CHANGED
|
@@ -30,8 +30,6 @@ export const NativeSessionReplay = (SessionReplaySpec ??
|
|
|
30
30
|
export interface NativeSessionReplayConfig {
|
|
31
31
|
/** Your Amplitude API key for authentication and data routing */
|
|
32
32
|
apiKey: string;
|
|
33
|
-
/** Whether to automatically start recording when the module is initialized */
|
|
34
|
-
autoStart: boolean;
|
|
35
33
|
/** Device identifier that matches the device ID sent with Amplitude events */
|
|
36
34
|
deviceId: string | null;
|
|
37
35
|
/** Whether to enable remote configuration for dynamic settings updates */
|
|
@@ -50,10 +48,6 @@ export interface NativeSessionReplayConfig {
|
|
|
50
48
|
sessionId: number;
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
export interface NativeSessionReplayProperties {
|
|
54
|
-
[key: string]: string | number | boolean;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
51
|
/**
|
|
58
52
|
* Interface defining the native session replay module specification.
|
|
59
53
|
* This interface provides the contract for communication between JavaScript and
|
|
@@ -76,14 +70,6 @@ export interface NativeSessionReplaySpec {
|
|
|
76
70
|
*/
|
|
77
71
|
getSessionId(): Promise<number>;
|
|
78
72
|
|
|
79
|
-
/**
|
|
80
|
-
* Retrieves session replay properties that should be attached to Amplitude events.
|
|
81
|
-
* These properties help correlate events with session recordings.
|
|
82
|
-
* @returns Promise resolving to an object containing session replay metadata
|
|
83
|
-
* @note OLD ARCH: ideally we want to cache that on JS side to avoid bridge overhead
|
|
84
|
-
*/
|
|
85
|
-
getSessionReplayProperties(): Promise<NativeSessionReplayProperties>;
|
|
86
|
-
|
|
87
73
|
/**
|
|
88
74
|
* Updates the device identifier used for session replay tracking.
|
|
89
75
|
* @param deviceId - The device identifier string, or null to clear the device ID
|
|
@@ -98,6 +84,12 @@ export interface NativeSessionReplaySpec {
|
|
|
98
84
|
*/
|
|
99
85
|
setSessionId(sessionId: number): Promise<void>;
|
|
100
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Updates whether session replay collection is disabled for the current user.
|
|
89
|
+
* @param optOut - Whether to opt out of session replay collection
|
|
90
|
+
*/
|
|
91
|
+
setOptOut(optOut: boolean): Promise<void>;
|
|
92
|
+
|
|
101
93
|
/**
|
|
102
94
|
* Initializes the native session replay module with the provided configuration.
|
|
103
95
|
* This method must be called before any other session replay operations.
|
|
@@ -116,4 +108,9 @@ export interface NativeSessionReplaySpec {
|
|
|
116
108
|
* Ends the current recording session and processes any captured data.
|
|
117
109
|
*/
|
|
118
110
|
stop(): Promise<void>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Shuts down the native session replay instance and releases its resources.
|
|
114
|
+
*/
|
|
115
|
+
teardown(): Promise<void>;
|
|
119
116
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from '@amplitude/analytics-types';
|
|
7
7
|
|
|
8
8
|
import { SessionReplayPluginConfig, getDefaultSessionReplayPluginConfig } from './plugin-session-replay-config';
|
|
9
|
-
import { getSessionId,
|
|
9
|
+
import { getSessionId, privateInit, setOptOut, setSessionId, start, stop, teardown } from './session-replay';
|
|
10
10
|
import { createSessionReplayLogger } from './logger';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -72,11 +72,14 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient,
|
|
|
72
72
|
sampleRate: this.sessionReplayConfig.sampleRate,
|
|
73
73
|
enableRemoteConfig: this.sessionReplayConfig.enableRemoteConfig,
|
|
74
74
|
logLevel: this.sessionReplayConfig.logLevel,
|
|
75
|
-
|
|
75
|
+
optOut: config.optOut,
|
|
76
76
|
},
|
|
77
77
|
this.logger,
|
|
78
78
|
);
|
|
79
79
|
this.isInitialized = true;
|
|
80
|
+
if (this.sessionReplayConfig.autoStart) {
|
|
81
|
+
await start();
|
|
82
|
+
}
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
async execute(event: Event): Promise<Event | null> {
|
|
@@ -90,15 +93,6 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient,
|
|
|
90
93
|
if (this.config?.sessionId && this.config.sessionId !== (await getSessionId())) {
|
|
91
94
|
await setSessionId(this.config.sessionId);
|
|
92
95
|
}
|
|
93
|
-
// Treating config.sessionId as source of truth, if the event's session id doesn't match, the
|
|
94
|
-
// event is not of the current session (offline/late events). In that case, don't tag the events
|
|
95
|
-
if (this.config?.sessionId && this.config.sessionId === event.session_id) {
|
|
96
|
-
const sessionRecordingProperties = await getSessionReplayProperties();
|
|
97
|
-
event.event_properties = {
|
|
98
|
-
...event.event_properties,
|
|
99
|
-
...sessionRecordingProperties,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
96
|
return Promise.resolve(event);
|
|
103
97
|
}
|
|
104
98
|
|
|
@@ -126,34 +120,31 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient,
|
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
|
|
129
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Update whether session replay collection is disabled for the current user.
|
|
125
|
+
*
|
|
126
|
+
* @param optOut - Whether to opt out of session replay collection
|
|
127
|
+
* @returns Promise that resolves when the opt-out state is updated
|
|
128
|
+
*/
|
|
129
|
+
async setOptOut(optOut: boolean): Promise<void> {
|
|
130
130
|
if (this.isInitialized) {
|
|
131
|
-
await
|
|
131
|
+
await setOptOut(optOut);
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
this.config = null;
|
|
135
|
-
this.isInitialized = false;
|
|
136
133
|
}
|
|
137
134
|
|
|
138
135
|
/**
|
|
139
|
-
*
|
|
140
|
-
* When you send events to Amplitude, call this method to get the most up-to-date session replay properties for the event.
|
|
141
|
-
*
|
|
142
|
-
* @returns Promise that resolves to an object containing session replay metadata
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* const sessionReplayProperties = await plugin.getSessionReplayProperties();
|
|
147
|
-
* analytics.track('Button Clicked', {
|
|
148
|
-
* buttonName: 'submit',
|
|
149
|
-
* ...sessionReplayProperties
|
|
150
|
-
* });
|
|
151
|
-
* ```
|
|
136
|
+
* Amplitude SDK hook. `client.setOptOut()` fans this out through the plugin timeline.
|
|
152
137
|
*/
|
|
153
|
-
async
|
|
154
|
-
|
|
155
|
-
|
|
138
|
+
async onOptOutChanged(optOut: boolean): Promise<void> {
|
|
139
|
+
await this.setOptOut(optOut);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async teardown(): Promise<void> {
|
|
143
|
+
if (this.isInitialized) {
|
|
144
|
+
await teardown();
|
|
156
145
|
}
|
|
157
|
-
|
|
146
|
+
|
|
147
|
+
this.config = null;
|
|
148
|
+
this.isInitialized = false;
|
|
158
149
|
}
|
|
159
150
|
}
|
|
@@ -27,12 +27,6 @@ export interface SessionReplayConfig {
|
|
|
27
27
|
*/
|
|
28
28
|
apiKey: string;
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* Whether to automatically start recording when the SDK is initialized
|
|
32
|
-
* @default true
|
|
33
|
-
*/
|
|
34
|
-
autoStart?: boolean;
|
|
35
|
-
|
|
36
30
|
/**
|
|
37
31
|
* Device identifier that matches the device ID sent with Amplitude events
|
|
38
32
|
* Must match the Device ID passed as event properties to Amplitude
|
|
@@ -107,7 +101,6 @@ export type SessionReplayConfigInternal = Omit<SessionReplayConfig, 'maskLevel'>
|
|
|
107
101
|
|
|
108
102
|
export const getDefaultConfig: () => Required<Omit<SessionReplayConfigInternal, 'apiKey'>> = () => {
|
|
109
103
|
return {
|
|
110
|
-
autoStart: true,
|
|
111
104
|
deviceId: null,
|
|
112
105
|
enableRemoteConfig: true,
|
|
113
106
|
logLevel: LogLevel.Warn,
|
package/src/session-replay.ts
CHANGED
|
@@ -27,17 +27,16 @@ function normalizeConfig(config: SessionReplayConfig): SessionReplayConfigIntern
|
|
|
27
27
|
return rest;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
let fullConfig: ResolvedSessionReplayConfig | null = null;
|
|
31
30
|
let isInitialized = false;
|
|
32
31
|
let logger = createSessionReplayLogger();
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
|
-
* Configure the SDK
|
|
34
|
+
* Configure the SDK. Call `start()` explicitly to begin collecting replays.
|
|
36
35
|
* This function must be called before any other session replay operations.
|
|
37
36
|
*
|
|
38
37
|
* @param config - Configuration object containing API key, device ID, session ID, and other options
|
|
39
|
-
* @returns Promise that resolves when initialization is complete
|
|
40
|
-
*
|
|
38
|
+
* @returns Promise that resolves when initialization is complete. Native setup
|
|
39
|
+
* failures are logged and do not reject the promise.
|
|
41
40
|
*
|
|
42
41
|
* @example
|
|
43
42
|
* ```typescript
|
|
@@ -59,16 +58,16 @@ export async function init(config: SessionReplayConfig): Promise<void> {
|
|
|
59
58
|
// the default object wholesale. That's fine while `PrivacyConfig` only
|
|
60
59
|
// carries `maskLevel`, but if it ever grows more fields a deeper merge will
|
|
61
60
|
// be needed so partial user configs don't drop defaults.
|
|
62
|
-
|
|
61
|
+
const resolvedConfig: ResolvedSessionReplayConfig = {
|
|
63
62
|
...getDefaultConfig(),
|
|
64
63
|
...normalizeConfig(config),
|
|
65
64
|
};
|
|
66
65
|
|
|
67
|
-
logger.setLogLevel(
|
|
68
|
-
logger.log(`initializing @amplitude/session-replay-react-native version: ${VERSION} with config: `,
|
|
66
|
+
logger.setLogLevel(resolvedConfig.logLevel);
|
|
67
|
+
logger.log(`initializing @amplitude/session-replay-react-native version: ${VERSION} with config: `, resolvedConfig);
|
|
69
68
|
|
|
70
69
|
try {
|
|
71
|
-
await NativeSessionReplay.setup(nativeConfig(
|
|
70
|
+
await NativeSessionReplay.setup(nativeConfig(resolvedConfig));
|
|
72
71
|
logger.log('SessionReplay initialized');
|
|
73
72
|
isInitialized = true;
|
|
74
73
|
} catch (error) {
|
|
@@ -139,38 +138,6 @@ export async function getSessionId(): Promise<number | null> {
|
|
|
139
138
|
return await NativeSessionReplay.getSessionId();
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
/**
|
|
143
|
-
* Interface for session replay properties that should be attached to Amplitude events.
|
|
144
|
-
* These properties help correlate events with session recordings.
|
|
145
|
-
*/
|
|
146
|
-
export interface SessionReplayProperties {
|
|
147
|
-
[key: string]: string | boolean | null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* When you send events to Amplitude, call this function to get the most up-to-date session replay properties for the event.
|
|
152
|
-
* Collect Session Replay properties to send with other event properties.
|
|
153
|
-
*
|
|
154
|
-
* @returns Promise that resolves to an object containing session replay metadata
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* const sessionReplayProperties = await getSessionReplayProperties();
|
|
159
|
-
* analytics.track('Button Clicked', {
|
|
160
|
-
* buttonName: 'submit',
|
|
161
|
-
* ...sessionReplayProperties // Merge session replay properties
|
|
162
|
-
* });
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export async function getSessionReplayProperties(): Promise<SessionReplayProperties> {
|
|
166
|
-
if (!isInitialized) {
|
|
167
|
-
logger.warn('SessionReplay is not initialized');
|
|
168
|
-
return {};
|
|
169
|
-
}
|
|
170
|
-
const properties = await NativeSessionReplay.getSessionReplayProperties();
|
|
171
|
-
return properties as SessionReplayProperties;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
141
|
/**
|
|
175
142
|
* Flush any pending session replay data to the server.
|
|
176
143
|
* Forces immediate upload of recorded session data that may be buffered locally.
|
|
@@ -194,13 +161,12 @@ export async function flush(): Promise<void> {
|
|
|
194
161
|
/**
|
|
195
162
|
* Start session replay recording.
|
|
196
163
|
* Begins capturing user interactions and screen content for replay.
|
|
197
|
-
* If autoStart is enabled in the configuration, this is called automatically during initialization.
|
|
198
164
|
*
|
|
199
165
|
* @returns Promise that resolves when recording starts
|
|
200
166
|
*
|
|
201
167
|
* @example
|
|
202
168
|
* ```typescript
|
|
203
|
-
* //
|
|
169
|
+
* // Recording starts only after this explicit call.
|
|
204
170
|
* await start();
|
|
205
171
|
* ```
|
|
206
172
|
*/
|
|
@@ -232,6 +198,36 @@ export async function stop(): Promise<void> {
|
|
|
232
198
|
await NativeSessionReplay.stop();
|
|
233
199
|
}
|
|
234
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Update whether session replay collection is disabled for the current user.
|
|
203
|
+
*
|
|
204
|
+
* @param optOut - Whether to opt out of session replay collection
|
|
205
|
+
* @returns Promise that resolves when the opt-out state is updated
|
|
206
|
+
*/
|
|
207
|
+
export async function setOptOut(optOut: boolean): Promise<void> {
|
|
208
|
+
if (!isInitialized) {
|
|
209
|
+
logger.warn('SessionReplay is not initialized');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
await NativeSessionReplay.setOptOut(optOut);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Shut down the native SDK and clear all JavaScript lifecycle state.
|
|
217
|
+
* Call `init()` again before using any other session replay operation.
|
|
218
|
+
*
|
|
219
|
+
* @returns Promise that resolves when teardown is complete
|
|
220
|
+
*/
|
|
221
|
+
export async function teardown(): Promise<void> {
|
|
222
|
+
if (!isInitialized) {
|
|
223
|
+
logger.warn('SessionReplay is not initialized');
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
await NativeSessionReplay.teardown();
|
|
227
|
+
isInitialized = false;
|
|
228
|
+
logger = createSessionReplayLogger();
|
|
229
|
+
}
|
|
230
|
+
|
|
235
231
|
function nativeConfig(config: ResolvedSessionReplayConfig): NativeSessionReplayConfig {
|
|
236
232
|
// Resolve the effective mask level here — the single source of truth for the
|
|
237
233
|
// default. `normalizeConfig()` already folded the deprecated top-level
|
|
@@ -14,11 +14,12 @@ export interface Spec extends TurboModule {
|
|
|
14
14
|
setup(config: UnsafeObject): Promise<void>;
|
|
15
15
|
setSessionId(sessionId: number): Promise<void>;
|
|
16
16
|
setDeviceId(deviceId: string | null): Promise<void>;
|
|
17
|
+
setOptOut(optOut: boolean): Promise<void>;
|
|
17
18
|
getSessionId(): Promise<number>;
|
|
18
|
-
getSessionReplayProperties(): Promise<UnsafeObject>;
|
|
19
19
|
start(): Promise<void>;
|
|
20
20
|
stop(): Promise<void>;
|
|
21
21
|
flush(): Promise<void>;
|
|
22
|
+
teardown(): Promise<void>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
// Use non-enforcing `get` (returns null when the native module isn't linked)
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.0-beta.
|
|
1
|
+
export const VERSION = '0.1.0-beta.5';
|