@amplitude/segment-session-replay-plugin-react-native 0.0.1-beta.2 → 0.1.0-beta.1
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 +24 -9
- package/package.json +18 -19
- package/src/index.ts +4 -1
- package/src/segment-session-replay-plugin.ts +33 -11
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -49,25 +49,40 @@ await segmentClient.add(createSegmentSessionReplayPlugin(sessionReplayConfig));
|
|
|
49
49
|
|
|
50
50
|
### Plugin Configuration
|
|
51
51
|
|
|
52
|
-
The plugin accepts a `
|
|
52
|
+
The plugin accepts a `SegmentSessionReplayPluginConfig` object: every option from the
|
|
53
|
+
`SessionReplayConfig` of `@amplitude/session-replay-react-native`, plus:
|
|
54
|
+
|
|
55
|
+
| Option | Default | Description |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| `autoStart` | `true` | Start recording as soon as the plugin is added to the Segment client. |
|
|
58
|
+
|
|
59
|
+
Set `autoStart: false` to control when recording begins, then call `start()` from
|
|
60
|
+
`@amplitude/session-replay-react-native` yourself:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { start } from '@amplitude/session-replay-react-native';
|
|
64
|
+
|
|
65
|
+
await segmentClient.add(createSegmentSessionReplayPlugin({ ...sessionReplayConfig, autoStart: false }));
|
|
66
|
+
|
|
67
|
+
// later, once you're ready to record
|
|
68
|
+
await start();
|
|
69
|
+
```
|
|
53
70
|
|
|
54
71
|
### Automatic Integration
|
|
55
72
|
|
|
56
73
|
The plugin automatically:
|
|
57
74
|
|
|
58
75
|
1. **Initializes Session Replay**: Sets up Amplitude Session Replay with your configuration
|
|
59
|
-
2. **
|
|
60
|
-
3. **
|
|
76
|
+
2. **Starts Recording**: Begins recording once configured, unless `autoStart` is `false`
|
|
77
|
+
3. **Syncs Session Data**: Updates session ID and device ID for each Segment event
|
|
61
78
|
4. **Manages Lifecycle**: Handles start/stop operations for session replay
|
|
62
79
|
|
|
63
80
|
### Event Processing
|
|
64
81
|
|
|
65
|
-
|
|
66
|
-
- `TrackEvent`: Adds session replay properties to track events
|
|
67
|
-
- `ScreenEvent`: Adds session replay properties to screen events
|
|
68
|
-
|
|
69
|
-
For these events, the plugin:
|
|
82
|
+
For every event, the plugin:
|
|
70
83
|
- Extracts session ID from event properties or Amplitude integration data
|
|
71
84
|
- Extracts device ID from event context or anonymous ID
|
|
72
|
-
-
|
|
85
|
+
- Forwards both to Session Replay so the recording is attributed correctly
|
|
86
|
+
|
|
87
|
+
Events are passed through unmodified; the plugin does not add properties to them.
|
|
73
88
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/segment-session-replay-plugin-react-native",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"description": "Amplitude Segment Session Replay Plugin for React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -26,20 +26,6 @@
|
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
|
|
28
28
|
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"build": "bob build",
|
|
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
|
-
},
|
|
43
29
|
"files": [
|
|
44
30
|
"src",
|
|
45
31
|
"!test",
|
|
@@ -52,9 +38,9 @@
|
|
|
52
38
|
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
53
39
|
},
|
|
54
40
|
"devDependencies": {
|
|
55
|
-
"@amplitude/session-replay-react-native": ">=0.0.1-beta.2 <1.0.0",
|
|
56
41
|
"@segment/analytics-react-native": "2.15.0",
|
|
57
|
-
"react-native-builder-bob": "^0.20.3"
|
|
42
|
+
"react-native-builder-bob": "^0.20.3",
|
|
43
|
+
"@amplitude/session-replay-react-native": "1.0.1"
|
|
58
44
|
},
|
|
59
45
|
"peerDependencies": {
|
|
60
46
|
"@amplitude/session-replay-react-native": "*",
|
|
@@ -74,5 +60,18 @@
|
|
|
74
60
|
]
|
|
75
61
|
]
|
|
76
62
|
},
|
|
77
|
-
"
|
|
78
|
-
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "bob build",
|
|
65
|
+
"fix": "pnpm fix:eslint & pnpm fix:prettier",
|
|
66
|
+
"fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
|
|
67
|
+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
|
|
68
|
+
"lint": "pnpm lint:prettier && pnpm lint:eslint",
|
|
69
|
+
"lint:eslint": "eslint '{src,test}/**/*.ts'",
|
|
70
|
+
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
|
|
71
|
+
"test": "jest",
|
|
72
|
+
"typecheck": "tsc -p ./tsconfig.json",
|
|
73
|
+
"version": "pnpm version-file && pnpm build",
|
|
74
|
+
"version-file": "node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts",
|
|
75
|
+
"typescript": "tsc --noEmit"
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,15 +2,31 @@ import { Plugin, PluginType, type SegmentEvent, EventType, SegmentClient } from
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
type SessionReplayConfig,
|
|
5
|
-
getSessionReplayProperties,
|
|
6
5
|
init,
|
|
7
6
|
setDeviceId,
|
|
7
|
+
setOptOut,
|
|
8
8
|
setSessionId,
|
|
9
9
|
start,
|
|
10
10
|
stop,
|
|
11
|
+
teardown,
|
|
11
12
|
} from '@amplitude/session-replay-react-native';
|
|
12
13
|
import { VERSION } from './version';
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for the Segment Session Replay plugin.
|
|
17
|
+
*
|
|
18
|
+
* Extends the standalone `SessionReplayConfig` with plugin-owned options. The
|
|
19
|
+
* standalone SDK requires an explicit `start()`, so `autoStart` lives here to
|
|
20
|
+
* keep "add the plugin and record" working without the caller wiring it up.
|
|
21
|
+
*/
|
|
22
|
+
export interface SegmentSessionReplayPluginConfig extends SessionReplayConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Whether to automatically start recording when the plugin is configured
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
autoStart?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
function getSessionId(event: SegmentEvent): number {
|
|
15
31
|
const amplitudeSessionId =
|
|
16
32
|
(event.integrations?.['Actions Amplitude'] as { session_id: number })?.['session_id'] ?? null;
|
|
@@ -35,24 +51,29 @@ export class SegmentSessionReplayPlugin extends Plugin {
|
|
|
35
51
|
version: string = VERSION;
|
|
36
52
|
type: PluginType = PluginType.enrichment;
|
|
37
53
|
|
|
38
|
-
private sessionReplayConfig:
|
|
54
|
+
private sessionReplayConfig: SegmentSessionReplayPluginConfig;
|
|
39
55
|
|
|
40
56
|
// @review: This is to ensure the plugin is initialized before the first event is processed.
|
|
41
57
|
// because `configure` is not asynchronous
|
|
42
58
|
private initPromise: Promise<void> | null = null;
|
|
43
59
|
|
|
44
|
-
constructor(config:
|
|
60
|
+
constructor(config: SegmentSessionReplayPluginConfig) {
|
|
45
61
|
super();
|
|
46
62
|
this.sessionReplayConfig = config;
|
|
47
63
|
}
|
|
48
64
|
|
|
49
65
|
async configure(analytics: SegmentClient): Promise<void> {
|
|
50
66
|
super.configure(analytics);
|
|
67
|
+
const { autoStart = true, ...sessionReplayConfig } = this.sessionReplayConfig;
|
|
51
68
|
this.initPromise = init({
|
|
52
69
|
deviceId: analytics.userInfo.get().anonymousId,
|
|
53
|
-
...
|
|
70
|
+
...sessionReplayConfig,
|
|
54
71
|
});
|
|
55
72
|
await this.initPromise;
|
|
73
|
+
|
|
74
|
+
if (autoStart) {
|
|
75
|
+
await start();
|
|
76
|
+
}
|
|
56
77
|
}
|
|
57
78
|
|
|
58
79
|
async execute(event: SegmentEvent): Promise<SegmentEvent> {
|
|
@@ -64,17 +85,13 @@ export class SegmentSessionReplayPlugin extends Plugin {
|
|
|
64
85
|
await setSessionId(sessionId);
|
|
65
86
|
await setDeviceId(deviceId);
|
|
66
87
|
|
|
67
|
-
if (event.type === EventType.TrackEvent || event.type === EventType.ScreenEvent) {
|
|
68
|
-
const properties = await getSessionReplayProperties();
|
|
69
|
-
event.properties = { ...event.properties, ...properties };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
88
|
return event;
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
async shutdown(): Promise<void> {
|
|
76
92
|
await this.initPromise;
|
|
77
|
-
await
|
|
93
|
+
await teardown();
|
|
94
|
+
this.initPromise = null;
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
async start(): Promise<void> {
|
|
@@ -86,8 +103,13 @@ export class SegmentSessionReplayPlugin extends Plugin {
|
|
|
86
103
|
await this.initPromise;
|
|
87
104
|
await stop();
|
|
88
105
|
}
|
|
106
|
+
|
|
107
|
+
async setOptOut(optOut: boolean): Promise<void> {
|
|
108
|
+
await this.initPromise;
|
|
109
|
+
await setOptOut(optOut);
|
|
110
|
+
}
|
|
89
111
|
}
|
|
90
112
|
|
|
91
|
-
export function createSegmentSessionReplayPlugin(config:
|
|
113
|
+
export function createSegmentSessionReplayPlugin(config: SegmentSessionReplayPluginConfig): Plugin {
|
|
92
114
|
return new SegmentSessionReplayPlugin(config);
|
|
93
115
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.0
|
|
1
|
+
export const VERSION = '0.1.0-beta.1';
|