@amplitude/plugin-session-replay-browser 0.9.0 → 0.10.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 +1 -1
- package/lib/cjs/session-replay.d.ts +8 -6
- package/lib/cjs/session-replay.d.ts.map +1 -1
- package/lib/cjs/session-replay.js +71 -10
- package/lib/cjs/session-replay.js.map +1 -1
- package/lib/esm/session-replay.d.ts +8 -6
- package/lib/esm/session-replay.d.ts.map +1 -1
- package/lib/esm/session-replay.js +71 -10
- package/lib/esm/session-replay.js.map +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/session-replay.d.ts +8 -6
- package/lib/scripts/session-replay.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ yarn add @amplitude/plugin-session-replay-browser
|
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
25
|
|
|
26
|
-
This plugin works on top of Amplitude Browser SDK and adds session replay features to built-in features. To use this plugin, you need to install `@amplitude/analytics-browser` version `v1.
|
|
26
|
+
This plugin works on top of Amplitude Browser SDK and adds session replay features to built-in features. To use this plugin, you need to install `@amplitude/analytics-browser` version `v1.9.1` or later.
|
|
27
27
|
|
|
28
28
|
This plugin requires that default tracking for sessions is enabled. If default tracking for sessions is not enabled in the config, the plugin will automatically enable it.
|
|
29
29
|
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { BrowserConfig,
|
|
1
|
+
import { BrowserClient, BrowserConfig, DestinationPlugin, Event, Result } from '@amplitude/analytics-types';
|
|
2
2
|
import { SessionReplayOptions } from './typings/session-replay';
|
|
3
|
-
export declare class SessionReplayPlugin implements
|
|
3
|
+
export declare class SessionReplayPlugin implements DestinationPlugin {
|
|
4
4
|
name: string;
|
|
5
|
-
type: "
|
|
5
|
+
type: "destination";
|
|
6
|
+
client: BrowserClient;
|
|
6
7
|
config: BrowserConfig;
|
|
7
8
|
options: SessionReplayOptions;
|
|
8
9
|
constructor(options?: SessionReplayOptions);
|
|
9
|
-
setup(config: BrowserConfig): Promise<void>;
|
|
10
|
-
execute(event: Event): Promise<
|
|
10
|
+
setup(config: BrowserConfig, client?: BrowserClient): Promise<void>;
|
|
11
|
+
execute(event: Event): Promise<Result>;
|
|
12
|
+
flush(): Promise<void>;
|
|
11
13
|
teardown(): Promise<void>;
|
|
12
14
|
getSessionReplayProperties(): {
|
|
13
15
|
[key: string]: string | boolean | null;
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
export declare const sessionReplayPlugin: (options?: SessionReplayOptions) =>
|
|
18
|
+
export declare const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin;
|
|
17
19
|
//# sourceMappingURL=session-replay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AA0BhE,qBAAa,mBAAoB,YAAW,iBAAiB;IAC3D,IAAI,SAA8C;IAClD,IAAI,gBAA0B;IAI9B,MAAM,EAAE,aAAa,CAAC;IAItB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;gBAElB,OAAO,CAAC,EAAE,oBAAoB;IAIpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa;IA8CnD,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAQtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,iBAIrE,CAAC"}
|
|
@@ -3,19 +3,52 @@ exports.sessionReplayPlugin = exports.SessionReplayPlugin = void 0;
|
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var sessionReplay = tslib_1.__importStar(require("@amplitude/session-replay-browser"));
|
|
5
5
|
var constants_1 = require("./constants");
|
|
6
|
+
var ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';
|
|
7
|
+
var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
8
|
+
function SessionReplayEnrichmentPlugin() {
|
|
9
|
+
this.name = ENRICHMENT_PLUGIN_NAME;
|
|
10
|
+
this.type = 'enrichment';
|
|
11
|
+
}
|
|
12
|
+
SessionReplayEnrichmentPlugin.prototype.setup = function (_config, _client) {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
14
|
+
return tslib_1.__generator(this, function (_a) {
|
|
15
|
+
return [2 /*return*/];
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
SessionReplayEnrichmentPlugin.prototype.execute = function (event) {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
21
|
+
var sessionRecordingProperties;
|
|
22
|
+
return tslib_1.__generator(this, function (_a) {
|
|
23
|
+
if (event.event_type === constants_1.DEFAULT_SESSION_START_EVENT && event.session_id) {
|
|
24
|
+
sessionReplay.setSessionId(event.session_id);
|
|
25
|
+
}
|
|
26
|
+
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
27
|
+
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
|
|
28
|
+
return [2 /*return*/, Promise.resolve(event)];
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return SessionReplayEnrichmentPlugin;
|
|
33
|
+
}());
|
|
6
34
|
var SessionReplayPlugin = /** @class */ (function () {
|
|
7
35
|
function SessionReplayPlugin(options) {
|
|
8
36
|
this.name = '@amplitude/plugin-session-replay-browser';
|
|
9
|
-
this.type = '
|
|
37
|
+
this.type = 'destination';
|
|
10
38
|
this.options = tslib_1.__assign({}, options);
|
|
11
39
|
}
|
|
12
|
-
SessionReplayPlugin.prototype.setup = function (config) {
|
|
40
|
+
SessionReplayPlugin.prototype.setup = function (config, client) {
|
|
13
41
|
var _a;
|
|
14
42
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
15
43
|
return tslib_1.__generator(this, function (_b) {
|
|
16
44
|
switch (_b.label) {
|
|
17
45
|
case 0:
|
|
46
|
+
if (!client) {
|
|
47
|
+
config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');
|
|
48
|
+
return [2 /*return*/];
|
|
49
|
+
}
|
|
18
50
|
config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');
|
|
51
|
+
this.client = client;
|
|
19
52
|
this.config = config;
|
|
20
53
|
if (typeof config.defaultTracking === 'boolean') {
|
|
21
54
|
if (config.defaultTracking === false) {
|
|
@@ -45,6 +78,11 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
45
78
|
},
|
|
46
79
|
}).promise];
|
|
47
80
|
case 1:
|
|
81
|
+
_b.sent();
|
|
82
|
+
// add enrichment plugin to add session replay properties to events
|
|
83
|
+
return [4 /*yield*/, client.add(new SessionReplayEnrichmentPlugin()).promise];
|
|
84
|
+
case 2:
|
|
85
|
+
// add enrichment plugin to add session replay properties to events
|
|
48
86
|
_b.sent();
|
|
49
87
|
return [2 /*return*/];
|
|
50
88
|
}
|
|
@@ -53,22 +91,45 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
53
91
|
};
|
|
54
92
|
SessionReplayPlugin.prototype.execute = function (event) {
|
|
55
93
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var sessionRecordingProperties;
|
|
57
94
|
return tslib_1.__generator(this, function (_a) {
|
|
58
|
-
|
|
59
|
-
|
|
95
|
+
return [2 /*return*/, Promise.resolve({
|
|
96
|
+
event: event,
|
|
97
|
+
code: 200,
|
|
98
|
+
message: 'success',
|
|
99
|
+
})];
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
SessionReplayPlugin.prototype.flush = function () {
|
|
104
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
105
|
+
return tslib_1.__generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0: return [4 /*yield*/, sessionReplay.flush(false)];
|
|
108
|
+
case 1:
|
|
109
|
+
_a.sent();
|
|
110
|
+
return [2 /*return*/];
|
|
60
111
|
}
|
|
61
|
-
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
62
|
-
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
|
|
63
|
-
return [2 /*return*/, Promise.resolve(event)];
|
|
64
112
|
});
|
|
65
113
|
});
|
|
66
114
|
};
|
|
67
115
|
SessionReplayPlugin.prototype.teardown = function () {
|
|
68
116
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
69
117
|
return tslib_1.__generator(this, function (_a) {
|
|
70
|
-
|
|
71
|
-
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, this.client.remove(ENRICHMENT_PLUGIN_NAME).promise];
|
|
120
|
+
case 1:
|
|
121
|
+
_a.sent();
|
|
122
|
+
sessionReplay.shutdown();
|
|
123
|
+
// the following are initialized in setup() which will always be called first
|
|
124
|
+
// here we reset them to null to prevent memory leaks
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
this.config = null;
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
this.client = null;
|
|
131
|
+
return [2 /*return*/];
|
|
132
|
+
}
|
|
72
133
|
});
|
|
73
134
|
});
|
|
74
135
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAQA,uFAAmE;AACnE,yCAA0D;AAE1D,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,SAAI,GAAG,sBAAsB,CAAC;QAC9B,SAAI,GAAG,YAAqB,CAAC;IAmB/B,CAAC;IAjBO,6CAAK,GAAX,UAAY,OAAsB,EAAE,OAAsB;;;;;;KAEzD;IAEK,+CAAO,GAAb,UAAc,KAAY;;;;gBACxB,IAAI,KAAK,CAAC,UAAU,KAAK,uCAA2B,IAAI,KAAK,CAAC,UAAU,EAAE;oBACxE,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;iBAC9C;gBAEK,0BAA0B,GAAG,aAAa,CAAC,0BAA0B,EAAE,CAAC;gBAC9E,KAAK,CAAC,gBAAgB,yCACjB,KAAK,CAAC,gBAAgB,GACtB,0BAA0B,CAC9B,CAAC;gBAEF,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;KAC/B;IACH,oCAAC;AAAD,CAAC,AArBD,IAqBC;AAED;IAaE,6BAAY,OAA8B;QAZ1C,SAAI,GAAG,0CAA0C,CAAC;QAClD,SAAI,GAAG,aAAsB,CAAC;QAY5B,IAAI,CAAC,OAAO,wBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,mCAAK,GAAX,UAAY,MAAqB,EAAE,MAAsB;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,aAAa;iCACzD;6BACF,CAAC,CAAC,OAAO,EAAA;;wBAbV,SAaU,CAAC;wBAEX,mEAAmE;wBACnE,qBAAM,MAAM,CAAC,GAAG,CAAC,IAAI,6BAA6B,EAAE,CAAC,CAAC,OAAO,EAAA;;wBAD7D,mEAAmE;wBACnE,SAA6D,CAAC;;;;;KAC/D;IAEK,qCAAO,GAAb,UAAc,KAAY;;;gBACxB,sBAAO,OAAO,CAAC,OAAO,CAAC;wBACrB,KAAK,OAAA;wBACL,IAAI,EAAE,GAAG;wBACT,OAAO,EAAE,SAAS;qBACnB,CAAC,EAAC;;;KACJ;IAEK,mCAAK,GAAX;;;;4BACE,qBAAM,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,EAAA;;wBAAhC,SAAgC,CAAC;;;;;KAClC;IAEK,sCAAQ,GAAd;;;;4BACE,qBAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,OAAO,EAAA;;wBAAxD,SAAwD,CAAC;wBACzD,aAAa,CAAC,QAAQ,EAAE,CAAC;wBACzB,6EAA6E;wBAC7E,qDAAqD;wBACrD,6DAA6D;wBAC7D,aAAa;wBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;wBACnB,6DAA6D;wBAC7D,aAAa;wBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;;;;;KACpB;IAED,wDAA0B,GAA1B;QACE,OAAO,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACpD,CAAC;IACH,0BAAC;AAAD,CAAC,AA3FD,IA2FC;AA3FY,kDAAmB;AA6FzB,IAAM,mBAAmB,GAA0D,UACxF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import {\n BrowserClient,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { DEFAULT_SESSION_START_EVENT } from './constants';\nimport { SessionReplayOptions } from './typings/session-replay';\nconst ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';\n\nclass SessionReplayEnrichmentPlugin implements EnrichmentPlugin {\n name = ENRICHMENT_PLUGIN_NAME;\n type = 'enrichment' as const;\n\n async setup(_config: BrowserConfig, _client: BrowserClient) {\n // do nothing\n }\n\n async execute(event: Event) {\n if (event.event_type === DEFAULT_SESSION_START_EVENT && event.session_id) {\n sessionReplay.setSessionId(event.session_id);\n }\n\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n\n return Promise.resolve(event);\n }\n}\n\nexport class SessionReplayPlugin implements DestinationPlugin {\n name = '@amplitude/plugin-session-replay-browser';\n type = 'destination' as const;\n // this.client is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n client: BrowserClient;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n }\n\n async setup(config: BrowserConfig, client?: BrowserClient) {\n if (!client) {\n config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');\n return;\n }\n\n config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');\n\n this.client = client;\n this.config = config;\n\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n },\n }).promise;\n\n // add enrichment plugin to add session replay properties to events\n await client.add(new SessionReplayEnrichmentPlugin()).promise;\n }\n\n async execute(event: Event): Promise<Result> {\n return Promise.resolve({\n event,\n code: 200,\n message: 'success',\n });\n }\n\n async flush(): Promise<void> {\n await sessionReplay.flush(false);\n }\n\n async teardown(): Promise<void> {\n await this.client.remove(ENRICHMENT_PLUGIN_NAME).promise;\n sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.client = null;\n }\n\n getSessionReplayProperties() {\n return sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { BrowserConfig,
|
|
1
|
+
import { BrowserClient, BrowserConfig, DestinationPlugin, Event, Result } from '@amplitude/analytics-types';
|
|
2
2
|
import { SessionReplayOptions } from './typings/session-replay';
|
|
3
|
-
export declare class SessionReplayPlugin implements
|
|
3
|
+
export declare class SessionReplayPlugin implements DestinationPlugin {
|
|
4
4
|
name: string;
|
|
5
|
-
type: "
|
|
5
|
+
type: "destination";
|
|
6
|
+
client: BrowserClient;
|
|
6
7
|
config: BrowserConfig;
|
|
7
8
|
options: SessionReplayOptions;
|
|
8
9
|
constructor(options?: SessionReplayOptions);
|
|
9
|
-
setup(config: BrowserConfig): Promise<void>;
|
|
10
|
-
execute(event: Event): Promise<
|
|
10
|
+
setup(config: BrowserConfig, client?: BrowserClient): Promise<void>;
|
|
11
|
+
execute(event: Event): Promise<Result>;
|
|
12
|
+
flush(): Promise<void>;
|
|
11
13
|
teardown(): Promise<void>;
|
|
12
14
|
getSessionReplayProperties(): {
|
|
13
15
|
[key: string]: string | boolean | null;
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
export declare const sessionReplayPlugin: (options?: SessionReplayOptions) =>
|
|
18
|
+
export declare const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin;
|
|
17
19
|
//# sourceMappingURL=session-replay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AA0BhE,qBAAa,mBAAoB,YAAW,iBAAiB;IAC3D,IAAI,SAA8C;IAClD,IAAI,gBAA0B;IAI9B,MAAM,EAAE,aAAa,CAAC;IAItB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;gBAElB,OAAO,CAAC,EAAE,oBAAoB;IAIpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa;IA8CnD,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAQtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,iBAIrE,CAAC"}
|
|
@@ -1,19 +1,52 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
2
|
import * as sessionReplay from '@amplitude/session-replay-browser';
|
|
3
3
|
import { DEFAULT_SESSION_START_EVENT } from './constants';
|
|
4
|
+
var ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';
|
|
5
|
+
var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
6
|
+
function SessionReplayEnrichmentPlugin() {
|
|
7
|
+
this.name = ENRICHMENT_PLUGIN_NAME;
|
|
8
|
+
this.type = 'enrichment';
|
|
9
|
+
}
|
|
10
|
+
SessionReplayEnrichmentPlugin.prototype.setup = function (_config, _client) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
12
|
+
return __generator(this, function (_a) {
|
|
13
|
+
return [2 /*return*/];
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
SessionReplayEnrichmentPlugin.prototype.execute = function (event) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
19
|
+
var sessionRecordingProperties;
|
|
20
|
+
return __generator(this, function (_a) {
|
|
21
|
+
if (event.event_type === DEFAULT_SESSION_START_EVENT && event.session_id) {
|
|
22
|
+
sessionReplay.setSessionId(event.session_id);
|
|
23
|
+
}
|
|
24
|
+
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
25
|
+
event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
|
|
26
|
+
return [2 /*return*/, Promise.resolve(event)];
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
return SessionReplayEnrichmentPlugin;
|
|
31
|
+
}());
|
|
4
32
|
var SessionReplayPlugin = /** @class */ (function () {
|
|
5
33
|
function SessionReplayPlugin(options) {
|
|
6
34
|
this.name = '@amplitude/plugin-session-replay-browser';
|
|
7
|
-
this.type = '
|
|
35
|
+
this.type = 'destination';
|
|
8
36
|
this.options = __assign({}, options);
|
|
9
37
|
}
|
|
10
|
-
SessionReplayPlugin.prototype.setup = function (config) {
|
|
38
|
+
SessionReplayPlugin.prototype.setup = function (config, client) {
|
|
11
39
|
var _a;
|
|
12
40
|
return __awaiter(this, void 0, void 0, function () {
|
|
13
41
|
return __generator(this, function (_b) {
|
|
14
42
|
switch (_b.label) {
|
|
15
43
|
case 0:
|
|
44
|
+
if (!client) {
|
|
45
|
+
config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');
|
|
46
|
+
return [2 /*return*/];
|
|
47
|
+
}
|
|
16
48
|
config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');
|
|
49
|
+
this.client = client;
|
|
17
50
|
this.config = config;
|
|
18
51
|
if (typeof config.defaultTracking === 'boolean') {
|
|
19
52
|
if (config.defaultTracking === false) {
|
|
@@ -43,6 +76,11 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
43
76
|
},
|
|
44
77
|
}).promise];
|
|
45
78
|
case 1:
|
|
79
|
+
_b.sent();
|
|
80
|
+
// add enrichment plugin to add session replay properties to events
|
|
81
|
+
return [4 /*yield*/, client.add(new SessionReplayEnrichmentPlugin()).promise];
|
|
82
|
+
case 2:
|
|
83
|
+
// add enrichment plugin to add session replay properties to events
|
|
46
84
|
_b.sent();
|
|
47
85
|
return [2 /*return*/];
|
|
48
86
|
}
|
|
@@ -51,22 +89,45 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
51
89
|
};
|
|
52
90
|
SessionReplayPlugin.prototype.execute = function (event) {
|
|
53
91
|
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
-
var sessionRecordingProperties;
|
|
55
92
|
return __generator(this, function (_a) {
|
|
56
|
-
|
|
57
|
-
|
|
93
|
+
return [2 /*return*/, Promise.resolve({
|
|
94
|
+
event: event,
|
|
95
|
+
code: 200,
|
|
96
|
+
message: 'success',
|
|
97
|
+
})];
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
SessionReplayPlugin.prototype.flush = function () {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0: return [4 /*yield*/, sessionReplay.flush(false)];
|
|
106
|
+
case 1:
|
|
107
|
+
_a.sent();
|
|
108
|
+
return [2 /*return*/];
|
|
58
109
|
}
|
|
59
|
-
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
60
|
-
event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
|
|
61
|
-
return [2 /*return*/, Promise.resolve(event)];
|
|
62
110
|
});
|
|
63
111
|
});
|
|
64
112
|
};
|
|
65
113
|
SessionReplayPlugin.prototype.teardown = function () {
|
|
66
114
|
return __awaiter(this, void 0, void 0, function () {
|
|
67
115
|
return __generator(this, function (_a) {
|
|
68
|
-
|
|
69
|
-
|
|
116
|
+
switch (_a.label) {
|
|
117
|
+
case 0: return [4 /*yield*/, this.client.remove(ENRICHMENT_PLUGIN_NAME).promise];
|
|
118
|
+
case 1:
|
|
119
|
+
_a.sent();
|
|
120
|
+
sessionReplay.shutdown();
|
|
121
|
+
// the following are initialized in setup() which will always be called first
|
|
122
|
+
// here we reset them to null to prevent memory leaks
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
this.config = null;
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
this.client = null;
|
|
129
|
+
return [2 /*return*/];
|
|
130
|
+
}
|
|
70
131
|
});
|
|
71
132
|
});
|
|
72
133
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":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AE,GAAG;wBACT,OAAO,EAAE,SAAS;qBACnB,CAAC,EAAC;;;KACJ;IAEK,mCAAK,GAAX;;;;4BACE,qBAAM,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,EAAA;;wBAAhC,SAAgC,CAAC;;;;;KAClC;IAEK,sCAAQ,GAAd;;;;4BACE,qBAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,OAAO,EAAA;;wBAAxD,SAAwD,CAAC;wBACzD,aAAa,CAAC,QAAQ,EAAE,CAAC;wBACzB,6EAA6E;wBAC7E,qDAAqD;wBACrD,6DAA6D;wBAC7D,aAAa;wBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;wBACnB,6DAA6D;wBAC7D,aAAa;wBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;;;;;KACpB;IAED,wDAA0B,GAA1B;QACE,OAAO,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACpD,CAAC;IACH,0BAAC;AAAD,CAAC,AA3FD,IA2FC;;AAED,MAAM,CAAC,IAAM,mBAAmB,GAA0D,UACxF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import {\n BrowserClient,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { DEFAULT_SESSION_START_EVENT } from './constants';\nimport { SessionReplayOptions } from './typings/session-replay';\nconst ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';\n\nclass SessionReplayEnrichmentPlugin implements EnrichmentPlugin {\n name = ENRICHMENT_PLUGIN_NAME;\n type = 'enrichment' as const;\n\n async setup(_config: BrowserConfig, _client: BrowserClient) {\n // do nothing\n }\n\n async execute(event: Event) {\n if (event.event_type === DEFAULT_SESSION_START_EVENT && event.session_id) {\n sessionReplay.setSessionId(event.session_id);\n }\n\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n\n return Promise.resolve(event);\n }\n}\n\nexport class SessionReplayPlugin implements DestinationPlugin {\n name = '@amplitude/plugin-session-replay-browser';\n type = 'destination' as const;\n // this.client is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n client: BrowserClient;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n }\n\n async setup(config: BrowserConfig, client?: BrowserClient) {\n if (!client) {\n config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');\n return;\n }\n\n config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');\n\n this.client = client;\n this.config = config;\n\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n },\n }).promise;\n\n // add enrichment plugin to add session replay properties to events\n await client.add(new SessionReplayEnrichmentPlugin()).promise;\n }\n\n async execute(event: Event): Promise<Result> {\n return Promise.resolve({\n event,\n code: 200,\n message: 'success',\n });\n }\n\n async flush(): Promise<void> {\n await sessionReplay.flush(false);\n }\n\n async teardown(): Promise<void> {\n await this.client.remove(ENRICHMENT_PLUGIN_NAME).promise;\n sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.client = null;\n }\n\n getSessionReplayProperties() {\n return sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
|