@amplitude/plugin-session-replay-react-native 0.2.8 → 0.3.0
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 -0
- package/android/build.gradle +1 -2
- package/android/src/main/java/com/amplitude/pluginsessionreplayreactnative/PluginSessionReplayReactNativeModule.kt +19 -2
- package/ios/PluginSessionReplayReactNative.mm +5 -1
- package/ios/PluginSessionReplayReactNative.swift +18 -4
- package/lib/commonjs/session-replay-config.js +3 -1
- package/lib/commonjs/session-replay-config.js.map +1 -1
- package/lib/commonjs/session-replay.js +25 -2
- package/lib/commonjs/session-replay.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/session-replay-config.js +3 -1
- package/lib/module/session-replay-config.js.map +1 -1
- package/lib/module/session-replay.js +25 -2
- package/lib/module/session-replay.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/session-replay-config.d.ts +3 -0
- package/lib/typescript/session-replay-config.d.ts.map +1 -1
- package/lib/typescript/session-replay.d.ts +3 -0
- package/lib/typescript/session-replay.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/session-replay-config.tsx +4 -0
- package/src/session-replay.ts +27 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ import { SessionReplayPlugin } from '@amplitude/plugin-session-replay-react-nati
|
|
|
19
19
|
const config: SessionReplayConfig = {
|
|
20
20
|
enableRemoteConfig: true, // default true
|
|
21
21
|
sampleRate: 1, // default 0
|
|
22
|
+
logLevel: LogLevel.Warn, // default LogLevel.Warn
|
|
22
23
|
};
|
|
23
24
|
await init('YOUR_API_KEY').promise;
|
|
24
25
|
await add(new SessionReplayPlugin(config)).promise;
|
package/android/build.gradle
CHANGED
|
@@ -90,7 +90,7 @@ repositories {
|
|
|
90
90
|
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
91
91
|
|
|
92
92
|
dependencies {
|
|
93
|
-
implementation("com.amplitude:session-replay-android:[0.
|
|
93
|
+
implementation("com.amplitude:session-replay-android:[0.19.0, 1.0.0]")
|
|
94
94
|
|
|
95
95
|
// For < 0.71, this will be from the local maven repo
|
|
96
96
|
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
@@ -98,4 +98,3 @@ dependencies {
|
|
|
98
98
|
implementation "com.facebook.react:react-native:+"
|
|
99
99
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
100
100
|
}
|
|
101
|
-
|
|
@@ -19,8 +19,15 @@ class PluginSessionReplayReactNativeModule(private val reactContext: ReactApplic
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
@ReactMethod
|
|
22
|
-
fun setup(apiKey: String, deviceId: String?, sessionId: Double, sampleRate: Double, enableRemoteConfig: Boolean) {
|
|
23
|
-
LogcatLogger.logger.logMode =
|
|
22
|
+
fun setup(apiKey: String, deviceId: String?, sessionId: Double, sampleRate: Double, enableRemoteConfig: Boolean, logLevel: Int) {
|
|
23
|
+
LogcatLogger.logger.logMode = when (logLevel) {
|
|
24
|
+
0 -> Logger.LogMode.OFF
|
|
25
|
+
1 -> Logger.LogMode.ERROR
|
|
26
|
+
2 -> Logger.LogMode.WARN
|
|
27
|
+
3 -> Logger.LogMode.INFO
|
|
28
|
+
4 -> Logger.LogMode.DEBUG
|
|
29
|
+
else -> Logger.LogMode.WARN
|
|
30
|
+
}
|
|
24
31
|
sessionReplay = SessionReplay(
|
|
25
32
|
apiKey,
|
|
26
33
|
reactContext.applicationContext,
|
|
@@ -61,6 +68,16 @@ class PluginSessionReplayReactNativeModule(private val reactContext: ReactApplic
|
|
|
61
68
|
}
|
|
62
69
|
promise.resolve(map)
|
|
63
70
|
}
|
|
71
|
+
|
|
72
|
+
@ReactMethod
|
|
73
|
+
fun start() {
|
|
74
|
+
sessionReplay.start()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@ReactMethod
|
|
78
|
+
fun stop() {
|
|
79
|
+
sessionReplay.stop()
|
|
80
|
+
}
|
|
64
81
|
|
|
65
82
|
@ReactMethod
|
|
66
83
|
fun flush() {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
@interface RCT_EXTERN_MODULE(PluginSessionReplayReactNative, NSObject)
|
|
4
4
|
|
|
5
|
-
RCT_EXTERN_METHOD(setup:(NSString)apiKey deviceId:(NSString)deviceId sessionId:(nonnull NSNumber)sessionId sampleRate:(float)sampleRate enableRemoteConfig:(BOOL)enableRemoteConfig resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
5
|
+
RCT_EXTERN_METHOD(setup:(NSString)apiKey deviceId:(NSString)deviceId sessionId:(nonnull NSNumber)sessionId sampleRate:(float)sampleRate enableRemoteConfig:(BOOL)enableRemoteConfig logLevel:(int)logLevel resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
6
6
|
|
|
7
7
|
RCT_EXTERN_METHOD(setSessionId:(nonnull NSNumber)sessionId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
8
8
|
|
|
@@ -10,6 +10,10 @@ RCT_EXTERN_METHOD(getSessionId:(RCTPromiseResolveBlock)resolve reject:(RCTPromis
|
|
|
10
10
|
|
|
11
11
|
RCT_EXTERN_METHOD(getSessionReplayProperties:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
12
12
|
|
|
13
|
+
RCT_EXTERN_METHOD(start:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
14
|
+
|
|
15
|
+
RCT_EXTERN_METHOD(stop:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
16
|
+
|
|
13
17
|
RCT_EXTERN_METHOD(flush:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
14
18
|
|
|
15
19
|
RCT_EXTERN_METHOD(teardown:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
@@ -6,14 +6,14 @@ class PluginSessionReplayReactNative: NSObject {
|
|
|
6
6
|
|
|
7
7
|
var sessionReplay: SessionReplay!
|
|
8
8
|
|
|
9
|
-
@objc(setup:deviceId:sessionId:sampleRate:enableRemoteConfig:resolve:reject:)
|
|
10
|
-
func setup(_ apiKey: String, deviceId: String, sessionId: NSNumber, sampleRate: Float, enableRemoteConfig: Bool, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
11
|
-
print("setup: API Key: \(apiKey) Device Id: \(deviceId) Session Id: \(sessionId) Sample Rate: \(sampleRate) Enable Remote Config: \(enableRemoteConfig)")
|
|
9
|
+
@objc(setup:deviceId:sessionId:sampleRate:enableRemoteConfig:logLevel:resolve:reject:)
|
|
10
|
+
func setup(_ apiKey: String, deviceId: String, sessionId: NSNumber, sampleRate: Float, enableRemoteConfig: Bool, logLevel: Int, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
11
|
+
print("setup: API Key: \(apiKey) Device Id: \(deviceId) Session Id: \(sessionId) Sample Rate: \(sampleRate) Enable Remote Config: \(enableRemoteConfig) Log Level: \(logLevel)")
|
|
12
12
|
sessionReplay = SessionReplay(apiKey:apiKey,
|
|
13
13
|
deviceId: deviceId,
|
|
14
14
|
sessionId: sessionId.int64Value,
|
|
15
15
|
sampleRate: sampleRate,
|
|
16
|
-
logger:ConsoleLogger(logLevel:
|
|
16
|
+
logger:ConsoleLogger(logLevel: logLevel),
|
|
17
17
|
enableRemoteConfig: enableRemoteConfig)
|
|
18
18
|
sessionReplay.start()
|
|
19
19
|
resolve(nil)
|
|
@@ -38,6 +38,20 @@ class PluginSessionReplayReactNative: NSObject {
|
|
|
38
38
|
resolve(sessionReplay.additionalEventProperties)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
@objc(start:reject:)
|
|
42
|
+
func start(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
43
|
+
print("start")
|
|
44
|
+
sessionReplay.start()
|
|
45
|
+
resolve(nil)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@objc(stop:reject:)
|
|
49
|
+
func stop(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
50
|
+
print("stop")
|
|
51
|
+
sessionReplay.stop()
|
|
52
|
+
resolve(nil)
|
|
53
|
+
}
|
|
54
|
+
|
|
41
55
|
@objc(flush:reject:)
|
|
42
56
|
func flush(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
43
57
|
print("flush")
|
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getDefaultConfig = void 0;
|
|
7
|
+
var _analyticsTypes = require("@amplitude/analytics-types");
|
|
7
8
|
const getDefaultConfig = () => {
|
|
8
9
|
return {
|
|
9
10
|
sampleRate: 0,
|
|
10
|
-
enableRemoteConfig: true
|
|
11
|
+
enableRemoteConfig: true,
|
|
12
|
+
logLevel: _analyticsTypes.LogLevel.Warn
|
|
11
13
|
};
|
|
12
14
|
};
|
|
13
15
|
exports.getDefaultConfig = getDefaultConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getDefaultConfig","sampleRate","enableRemoteConfig"],"sourceRoot":"../../src","sources":["session-replay-config.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"names":["getDefaultConfig","sampleRate","enableRemoteConfig","logLevel","LogLevel","Warn"],"sourceRoot":"../../src","sources":["session-replay-config.tsx"],"mappings":";;;;;;AAAA;AAQO,MAAMA,gBAAgB,GAAG,MAAM;EAClC,OAAO;IACHC,UAAU,EAAE,CAAC;IACbC,kBAAkB,EAAE,IAAI;IACxBC,QAAQ,EAAEC,wBAAQ,CAACC;EACvB,CAAC;AACL,CAAC;AAAA"}
|
|
@@ -7,6 +7,7 @@ exports.SessionReplayPlugin = void 0;
|
|
|
7
7
|
var _nativeModule = require("./native-module");
|
|
8
8
|
var _version = require("./version");
|
|
9
9
|
var _sessionReplayConfig = require("./session-replay-config");
|
|
10
|
+
var _analyticsTypes = require("@amplitude/analytics-types");
|
|
10
11
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
12
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
13
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
@@ -20,6 +21,7 @@ class SessionReplayPlugin {
|
|
|
20
21
|
_defineProperty(this, "name", '@amplitude/plugin-session-replay-react-native');
|
|
21
22
|
_defineProperty(this, "type", 'enrichment');
|
|
22
23
|
_defineProperty(this, "config", void 0);
|
|
24
|
+
_defineProperty(this, "isInitialized", false);
|
|
23
25
|
_defineProperty(this, "sessionReplayConfig", void 0);
|
|
24
26
|
this.sessionReplayConfig = {
|
|
25
27
|
...(0, _sessionReplayConfig.getDefaultConfig)(),
|
|
@@ -30,9 +32,14 @@ class SessionReplayPlugin {
|
|
|
30
32
|
async setup(config, _) {
|
|
31
33
|
this.config = config;
|
|
32
34
|
console.log(`Installing @amplitude/plugin-session-replay-react-native, version ${_version.VERSION}.`);
|
|
33
|
-
await _nativeModule.PluginSessionReplayReactNative.setup(config.apiKey, config.deviceId, config.sessionId, this.sessionReplayConfig.sampleRate ?? 1, this.sessionReplayConfig.enableRemoteConfig ?? true);
|
|
35
|
+
await _nativeModule.PluginSessionReplayReactNative.setup(config.apiKey, config.deviceId, config.sessionId, this.sessionReplayConfig.sampleRate ?? 1, this.sessionReplayConfig.enableRemoteConfig ?? true, this.sessionReplayConfig.logLevel ?? _analyticsTypes.LogLevel.Warn);
|
|
36
|
+
this.isInitialized = true;
|
|
34
37
|
}
|
|
35
38
|
async execute(event) {
|
|
39
|
+
if (!this.isInitialized) {
|
|
40
|
+
return Promise.resolve(event);
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
// On event, synchronize the session id to the what's on the browserConfig (source of truth)
|
|
37
44
|
// Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored
|
|
38
45
|
// in SR.
|
|
@@ -50,15 +57,31 @@ class SessionReplayPlugin {
|
|
|
50
57
|
}
|
|
51
58
|
return Promise.resolve(event);
|
|
52
59
|
}
|
|
60
|
+
async start() {
|
|
61
|
+
if (this.isInitialized) {
|
|
62
|
+
await _nativeModule.PluginSessionReplayReactNative.start();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async stop() {
|
|
66
|
+
if (this.isInitialized) {
|
|
67
|
+
await _nativeModule.PluginSessionReplayReactNative.stop();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
53
70
|
async teardown() {
|
|
54
|
-
|
|
71
|
+
if (this.isInitialized) {
|
|
72
|
+
await _nativeModule.PluginSessionReplayReactNative.teardown();
|
|
73
|
+
}
|
|
55
74
|
// the following are initialized in setup() which will always be called first
|
|
56
75
|
// here we reset them to null to prevent memory leaks
|
|
57
76
|
|
|
58
77
|
// @ts-ignore
|
|
59
78
|
this.config = null;
|
|
79
|
+
this.isInitialized = false;
|
|
60
80
|
}
|
|
61
81
|
async getSessionReplayProperties() {
|
|
82
|
+
if (!this.isInitialized) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
62
85
|
return _nativeModule.PluginSessionReplayReactNative.getSessionReplayProperties();
|
|
63
86
|
}
|
|
64
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SessionReplayPlugin","constructor","config","sessionReplayConfig","getDefaultConfig","console","log","setup","_","VERSION","PluginSessionReplayReactNative","apiKey","deviceId","sessionId","sampleRate","enableRemoteConfig","execute","event","getSessionId","setSessionId","session_id","sessionRecordingProperties","getSessionReplayProperties","event_properties","
|
|
1
|
+
{"version":3,"names":["SessionReplayPlugin","constructor","config","sessionReplayConfig","getDefaultConfig","console","log","setup","_","VERSION","PluginSessionReplayReactNative","apiKey","deviceId","sessionId","sampleRate","enableRemoteConfig","logLevel","LogLevel","Warn","isInitialized","execute","event","Promise","resolve","getSessionId","setSessionId","session_id","sessionRecordingProperties","getSessionReplayProperties","event_properties","start","stop","teardown"],"sourceRoot":"../../src","sources":["session-replay.ts"],"mappings":";;;;;;AAOA;AACA;AACA;AACA;AAAsD;AAAA;AAAA;AAE/C,MAAMA,mBAAmB,CAAmE;EAGjG;;EAEA;;EAMAC,WAAW,GAAmC;IAAA,IAAlCC,MAA2B,uEAAG,CAAC,CAAC;IAAA,8BAVrC,+CAA+C;IAAA,8BAC/C,YAAY;IAAA;IAAA,uCAKH,KAAK;IAAA;IAKnB,IAAI,CAACC,mBAAmB,GAAG;MACzB,GAAG,IAAAC,qCAAgB,GAAE;MACrB,GAAGF;IACL,CAAC;IACDG,OAAO,CAACC,GAAG,CAAC,gDAAgD,EAAE,IAAI,CAACH,mBAAmB,CAAC;EACzF;EAEA,MAAMI,KAAK,CAACL,MAAyB,EAAEM,CAAoB,EAAiB;IAC1E,IAAI,CAACN,MAAM,GAAGA,MAAM;IACpBG,OAAO,CAACC,GAAG,CAAE,qEAAoEG,gBAAQ,GAAE,CAAC;IAC5F,MAAMC,4CAA8B,CAACH,KAAK,CACxCL,MAAM,CAACS,MAAM,EACbT,MAAM,CAACU,QAAQ,EACfV,MAAM,CAACW,SAAS,EAChB,IAAI,CAACV,mBAAmB,CAACW,UAAU,IAAI,CAAC,EACxC,IAAI,CAACX,mBAAmB,CAACY,kBAAkB,IAAI,IAAI,EACnD,IAAI,CAACZ,mBAAmB,CAACa,QAAQ,IAAIC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AAMS,0BAA0B,GAAG;IACjC,IAAI,CAAC,IAAI,CAACT,aAAa,EAAE;MACvB,OAAO,CAAC,CAAC;IACX;IACA,OAAOT,4CAA8B,CAACkB,0BAA0B,EAAE;EACpE;AACF;AAAC"}
|
package/lib/commonjs/version.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { LogLevel } from "@amplitude/analytics-types";
|
|
1
2
|
export const getDefaultConfig = () => {
|
|
2
3
|
return {
|
|
3
4
|
sampleRate: 0,
|
|
4
|
-
enableRemoteConfig: true
|
|
5
|
+
enableRemoteConfig: true,
|
|
6
|
+
logLevel: LogLevel.Warn
|
|
5
7
|
};
|
|
6
8
|
};
|
|
7
9
|
//# sourceMappingURL=session-replay-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getDefaultConfig","sampleRate","enableRemoteConfig"],"sourceRoot":"../../src","sources":["session-replay-config.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"names":["LogLevel","getDefaultConfig","sampleRate","enableRemoteConfig","logLevel","Warn"],"sourceRoot":"../../src","sources":["session-replay-config.tsx"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,4BAA4B;AAQrD,OAAO,MAAMC,gBAAgB,GAAG,MAAM;EAClC,OAAO;IACHC,UAAU,EAAE,CAAC;IACbC,kBAAkB,EAAE,IAAI;IACxBC,QAAQ,EAAEJ,QAAQ,CAACK;EACvB,CAAC;AACL,CAAC"}
|
|
@@ -10,6 +10,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
10
10
|
import { PluginSessionReplayReactNative } from './native-module';
|
|
11
11
|
import { VERSION } from './version';
|
|
12
12
|
import { getDefaultConfig } from './session-replay-config';
|
|
13
|
+
import { LogLevel } from '@amplitude/analytics-types';
|
|
13
14
|
export class SessionReplayPlugin {
|
|
14
15
|
// this.config is defined in setup() which will always be called first
|
|
15
16
|
|
|
@@ -20,6 +21,7 @@ export class SessionReplayPlugin {
|
|
|
20
21
|
_defineProperty(this, "name", '@amplitude/plugin-session-replay-react-native');
|
|
21
22
|
_defineProperty(this, "type", 'enrichment');
|
|
22
23
|
_defineProperty(this, "config", void 0);
|
|
24
|
+
_defineProperty(this, "isInitialized", false);
|
|
23
25
|
_defineProperty(this, "sessionReplayConfig", void 0);
|
|
24
26
|
this.sessionReplayConfig = {
|
|
25
27
|
...getDefaultConfig(),
|
|
@@ -30,9 +32,14 @@ export class SessionReplayPlugin {
|
|
|
30
32
|
async setup(config, _) {
|
|
31
33
|
this.config = config;
|
|
32
34
|
console.log(`Installing @amplitude/plugin-session-replay-react-native, version ${VERSION}.`);
|
|
33
|
-
await PluginSessionReplayReactNative.setup(config.apiKey, config.deviceId, config.sessionId, this.sessionReplayConfig.sampleRate ?? 1, this.sessionReplayConfig.enableRemoteConfig ?? true);
|
|
35
|
+
await PluginSessionReplayReactNative.setup(config.apiKey, config.deviceId, config.sessionId, this.sessionReplayConfig.sampleRate ?? 1, this.sessionReplayConfig.enableRemoteConfig ?? true, this.sessionReplayConfig.logLevel ?? LogLevel.Warn);
|
|
36
|
+
this.isInitialized = true;
|
|
34
37
|
}
|
|
35
38
|
async execute(event) {
|
|
39
|
+
if (!this.isInitialized) {
|
|
40
|
+
return Promise.resolve(event);
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
// On event, synchronize the session id to the what's on the browserConfig (source of truth)
|
|
37
44
|
// Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored
|
|
38
45
|
// in SR.
|
|
@@ -50,15 +57,31 @@ export class SessionReplayPlugin {
|
|
|
50
57
|
}
|
|
51
58
|
return Promise.resolve(event);
|
|
52
59
|
}
|
|
60
|
+
async start() {
|
|
61
|
+
if (this.isInitialized) {
|
|
62
|
+
await PluginSessionReplayReactNative.start();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async stop() {
|
|
66
|
+
if (this.isInitialized) {
|
|
67
|
+
await PluginSessionReplayReactNative.stop();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
53
70
|
async teardown() {
|
|
54
|
-
|
|
71
|
+
if (this.isInitialized) {
|
|
72
|
+
await PluginSessionReplayReactNative.teardown();
|
|
73
|
+
}
|
|
55
74
|
// the following are initialized in setup() which will always be called first
|
|
56
75
|
// here we reset them to null to prevent memory leaks
|
|
57
76
|
|
|
58
77
|
// @ts-ignore
|
|
59
78
|
this.config = null;
|
|
79
|
+
this.isInitialized = false;
|
|
60
80
|
}
|
|
61
81
|
async getSessionReplayProperties() {
|
|
82
|
+
if (!this.isInitialized) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
62
85
|
return PluginSessionReplayReactNative.getSessionReplayProperties();
|
|
63
86
|
}
|
|
64
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PluginSessionReplayReactNative","VERSION","getDefaultConfig","SessionReplayPlugin","constructor","config","sessionReplayConfig","console","log","setup","_","apiKey","deviceId","sessionId","sampleRate","enableRemoteConfig","execute","event","getSessionId","setSessionId","session_id","sessionRecordingProperties","getSessionReplayProperties","event_properties","
|
|
1
|
+
{"version":3,"names":["PluginSessionReplayReactNative","VERSION","getDefaultConfig","LogLevel","SessionReplayPlugin","constructor","config","sessionReplayConfig","console","log","setup","_","apiKey","deviceId","sessionId","sampleRate","enableRemoteConfig","logLevel","Warn","isInitialized","execute","event","Promise","resolve","getSessionId","setSessionId","session_id","sessionRecordingProperties","getSessionReplayProperties","event_properties","start","stop","teardown"],"sourceRoot":"../../src","sources":["session-replay.ts"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;;AAGA,SAASA,8BAA8B,QAAQ,iBAAiB;AAChE,SAASC,OAAO,QAAQ,WAAW;AACnC,SAA8BC,gBAAgB,QAAQ,yBAAyB;AAC/E,SAASC,QAAQ,QAAQ,4BAA4B;AAErD,OAAO,MAAMC,mBAAmB,CAAmE;EAGjG;;EAEA;;EAMAC,WAAW,GAAmC;IAAA,IAAlCC,MAA2B,uEAAG,CAAC,CAAC;IAAA,8B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G,MAAM3B,8BAA8B,CAAC4B,0BAA0B,EAAE;MACpGP,KAAK,CAACQ,gBAAgB,GAAG;QACvB,GAAGR,KAAK,CAACQ,gBAAgB;QACzB,GAAGF;MACL,CAAC;IACH;IACA,OAAOL,OAAO,CAACC,OAAO,CAACF,KAAK,CAAC;EAC/B;EAEA,MAAMS,KAAK,GAAkB;IAC3B,IAAI,IAAI,CAACX,aAAa,EAAE;MACtB,MAAMnB,8BAA8B,CAAC8B,KAAK,EAAE;IAC9C;EACF;EAEA,MAAMC,IAAI,GAAkB;IAC1B,IAAI,IAAI,CAACZ,aAAa,EAAE;MACtB,MAAMnB,8BAA8B,CAAC+B,IAAI,EAAE;IAC7C;EACF;EAEA,MAAMC,QAAQ,GAAkB;IAC9B,IAAI,IAAI,CAACb,aAAa,EAAE;MACtB,MAAMnB,8BAA8B,CAACgC,QAAQ,EAAE;IACjD;IACA;IACA;;IAEA;IACA,IAAI,CAAC1B,MAAM,GAAG,IAAI;IAClB,IAAI,CAACa,aAAa,GAAG,KAAK;EAC5B;EAEA,MAAMS,0BAA0B,GAAG;IACjC,IAAI,CAAC,IAAI,CAACT,aAAa,EAAE;MACvB,OAAO,CAAC,CAAC;IACX;IACA,OAAOnB,8BAA8B,CAAC4B,0BAA0B,EAAE;EACpE;AACF"}
|
package/lib/module/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.3.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { LogLevel } from "@amplitude/analytics-types";
|
|
1
2
|
export interface SessionReplayConfig {
|
|
2
3
|
sampleRate?: number;
|
|
3
4
|
enableRemoteConfig?: boolean;
|
|
5
|
+
logLevel?: LogLevel;
|
|
4
6
|
}
|
|
5
7
|
export declare const getDefaultConfig: () => {
|
|
6
8
|
sampleRate: number;
|
|
7
9
|
enableRemoteConfig: boolean;
|
|
10
|
+
logLevel: LogLevel;
|
|
8
11
|
};
|
|
9
12
|
//# sourceMappingURL=session-replay-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay-config.d.ts","sourceRoot":"","sources":["../../src/session-replay-config.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay-config.d.ts","sourceRoot":"","sources":["../../src/session-replay-config.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,MAAM,WAAW,mBAAmB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACvB;AAED,eAAO,MAAM,gBAAgB;;;;CAM5B,CAAA"}
|
|
@@ -4,10 +4,13 @@ export declare class SessionReplayPlugin implements EnrichmentPlugin<ReactNative
|
|
|
4
4
|
name: string;
|
|
5
5
|
type: "enrichment";
|
|
6
6
|
config: ReactNativeConfig;
|
|
7
|
+
isInitialized: boolean;
|
|
7
8
|
sessionReplayConfig: SessionReplayConfig;
|
|
8
9
|
constructor(config?: SessionReplayConfig);
|
|
9
10
|
setup(config: ReactNativeConfig, _: ReactNativeClient): Promise<void>;
|
|
10
11
|
execute(event: Event): Promise<Event | null>;
|
|
12
|
+
start(): Promise<void>;
|
|
13
|
+
stop(): Promise<void>;
|
|
11
14
|
teardown(): Promise<void>;
|
|
12
15
|
getSessionReplayProperties(): Promise<any>;
|
|
13
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAIhH,OAAO,EAAE,mBAAmB,EAAoB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAIhH,OAAO,EAAE,mBAAmB,EAAoB,MAAM,yBAAyB,CAAC;AAGhF,qBAAa,mBAAoB,YAAW,gBAAgB,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAChG,IAAI,SAAmD;IACvD,IAAI,eAAyB;IAI7B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,aAAa,UAAS;IAEtB,mBAAmB,EAAE,mBAAmB,CAAC;gBAE7B,MAAM,GAAE,mBAAwB;IAQtC,KAAK,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAcrE,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAuB5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAYzB,0BAA0B;CAMjC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.3.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/plugin-session-replay-react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Amplitude Session Replay plugin for React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
]
|
|
93
93
|
]
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "96fc8d5545967d6c02e4b07e6c0fb26c1a6abf66"
|
|
96
96
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { LogLevel } from "@amplitude/analytics-types";
|
|
2
|
+
|
|
1
3
|
export interface SessionReplayConfig {
|
|
2
4
|
sampleRate?: number;
|
|
3
5
|
enableRemoteConfig?: boolean;
|
|
6
|
+
logLevel?: LogLevel;
|
|
4
7
|
}
|
|
5
8
|
|
|
6
9
|
export const getDefaultConfig = () => {
|
|
7
10
|
return {
|
|
8
11
|
sampleRate: 0,
|
|
9
12
|
enableRemoteConfig: true,
|
|
13
|
+
logLevel: LogLevel.Warn,
|
|
10
14
|
};
|
|
11
15
|
}
|
package/src/session-replay.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { EnrichmentPlugin, Event, ReactNativeClient, ReactNativeConfig } fr
|
|
|
8
8
|
import { PluginSessionReplayReactNative } from './native-module';
|
|
9
9
|
import { VERSION } from './version';
|
|
10
10
|
import { SessionReplayConfig, getDefaultConfig } from './session-replay-config';
|
|
11
|
+
import { LogLevel } from '@amplitude/analytics-types';
|
|
11
12
|
|
|
12
13
|
export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient, ReactNativeConfig> {
|
|
13
14
|
name = '@amplitude/plugin-session-replay-react-native';
|
|
@@ -16,6 +17,7 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient,
|
|
|
16
17
|
|
|
17
18
|
// @ts-ignore
|
|
18
19
|
config: ReactNativeConfig;
|
|
20
|
+
isInitialized = false;
|
|
19
21
|
|
|
20
22
|
sessionReplayConfig: SessionReplayConfig;
|
|
21
23
|
|
|
@@ -36,10 +38,16 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient,
|
|
|
36
38
|
config.sessionId,
|
|
37
39
|
this.sessionReplayConfig.sampleRate ?? 1,
|
|
38
40
|
this.sessionReplayConfig.enableRemoteConfig ?? true,
|
|
41
|
+
this.sessionReplayConfig.logLevel ?? LogLevel.Warn,
|
|
39
42
|
);
|
|
43
|
+
this.isInitialized = true;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
async execute(event: Event): Promise<Event | null> {
|
|
47
|
+
if (!this.isInitialized) {
|
|
48
|
+
return Promise.resolve(event);
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
// On event, synchronize the session id to the what's on the browserConfig (source of truth)
|
|
44
52
|
// Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored
|
|
45
53
|
// in SR.
|
|
@@ -58,16 +66,34 @@ export class SessionReplayPlugin implements EnrichmentPlugin<ReactNativeClient,
|
|
|
58
66
|
return Promise.resolve(event);
|
|
59
67
|
}
|
|
60
68
|
|
|
69
|
+
async start(): Promise<void> {
|
|
70
|
+
if (this.isInitialized) {
|
|
71
|
+
await PluginSessionReplayReactNative.start();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async stop(): Promise<void> {
|
|
76
|
+
if (this.isInitialized) {
|
|
77
|
+
await PluginSessionReplayReactNative.stop();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
61
81
|
async teardown(): Promise<void> {
|
|
62
|
-
|
|
82
|
+
if (this.isInitialized) {
|
|
83
|
+
await PluginSessionReplayReactNative.teardown();
|
|
84
|
+
}
|
|
63
85
|
// the following are initialized in setup() which will always be called first
|
|
64
86
|
// here we reset them to null to prevent memory leaks
|
|
65
87
|
|
|
66
88
|
// @ts-ignore
|
|
67
89
|
this.config = null;
|
|
90
|
+
this.isInitialized = false;
|
|
68
91
|
}
|
|
69
92
|
|
|
70
93
|
async getSessionReplayProperties() {
|
|
94
|
+
if (!this.isInitialized) {
|
|
95
|
+
return {};
|
|
96
|
+
}
|
|
71
97
|
return PluginSessionReplayReactNative.getSessionReplayProperties();
|
|
72
98
|
}
|
|
73
99
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.3.0';
|