@amplitude/plugin-session-replay-browser 1.0.2 → 1.1.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 +5 -0
- package/lib/cjs/constants.d.ts +0 -1
- package/lib/cjs/constants.d.ts.map +1 -1
- package/lib/cjs/constants.js +0 -3
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/session-replay.d.ts.map +1 -1
- package/lib/cjs/session-replay.js +29 -16
- package/lib/cjs/session-replay.js.map +1 -1
- package/lib/cjs/typings/session-replay.d.ts +1 -0
- package/lib/cjs/typings/session-replay.d.ts.map +1 -1
- package/lib/cjs/typings/session-replay.js.map +1 -1
- package/lib/esm/constants.d.ts +0 -1
- package/lib/esm/constants.d.ts.map +1 -1
- package/lib/esm/constants.js +0 -1
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/session-replay.d.ts.map +1 -1
- package/lib/esm/session-replay.js +29 -16
- package/lib/esm/session-replay.js.map +1 -1
- package/lib/esm/typings/session-replay.d.ts +1 -0
- package/lib/esm/typings/session-replay.d.ts.map +1 -1
- package/lib/esm/typings/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/constants.d.ts +0 -1
- package/lib/scripts/constants.d.ts.map +1 -1
- package/lib/scripts/session-replay.d.ts.map +1 -1
- package/lib/scripts/typings/session-replay.d.ts +1 -0
- package/lib/scripts/typings/session-replay.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -85,3 +85,8 @@ const sessionReplayTracking = sessionReplayPlugin({
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
```
|
|
88
|
+
|
|
89
|
+
## Debugging
|
|
90
|
+
|
|
91
|
+
### Using debugMode when developing locally
|
|
92
|
+
Since the Session Replay plugin only records and tags events when the page is in focus, this can sometimes be problematic when developing locally with the browser console open. If you are having issues with the replays not showing up (while your quota usage going up). Try turning setting `debugMode:true` to see if that helps with the issue.
|
package/lib/cjs/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":""}
|
package/lib/cjs/constants.js
CHANGED
package/lib/cjs/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAoChE,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;IAQpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa;IAiDnD,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"}
|
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
2
2
|
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
|
-
var constants_1 = require("./constants");
|
|
6
5
|
var ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';
|
|
7
6
|
var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
8
7
|
function SessionReplayEnrichmentPlugin() {
|
|
@@ -12,6 +11,7 @@ var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
|
12
11
|
SessionReplayEnrichmentPlugin.prototype.setup = function (_config, _client) {
|
|
13
12
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
14
13
|
return tslib_1.__generator(this, function (_a) {
|
|
14
|
+
this.config = _config;
|
|
15
15
|
return [2 /*return*/];
|
|
16
16
|
});
|
|
17
17
|
});
|
|
@@ -20,11 +20,18 @@ var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
|
20
20
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
21
21
|
var sessionRecordingProperties;
|
|
22
22
|
return tslib_1.__generator(this, function (_a) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// On event, synchronize the session id to the what's on the browserConfig (source of truth)
|
|
24
|
+
// Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored
|
|
25
|
+
// in SR.
|
|
26
|
+
if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {
|
|
27
|
+
sessionReplay.setSessionId(this.config.sessionId);
|
|
28
|
+
}
|
|
29
|
+
// Treating config.sessionId as source of truth, if the event's session id doesn't match, the
|
|
30
|
+
// event is not of the current session (offline/late events). In that case, don't tag the events
|
|
31
|
+
if (this.config.sessionId && this.config.sessionId === event.session_id) {
|
|
32
|
+
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
33
|
+
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
|
|
25
34
|
}
|
|
26
|
-
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
27
|
-
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
|
|
28
35
|
return [2 /*return*/, Promise.resolve(event)];
|
|
29
36
|
});
|
|
30
37
|
});
|
|
@@ -36,6 +43,10 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
36
43
|
this.name = '@amplitude/plugin-session-replay-browser';
|
|
37
44
|
this.type = 'destination';
|
|
38
45
|
this.options = tslib_1.__assign({}, options);
|
|
46
|
+
// The user did not explicitly configure forceSessionTracking to false, default to true.
|
|
47
|
+
if (this.options.forceSessionTracking !== false) {
|
|
48
|
+
this.options.forceSessionTracking = true;
|
|
49
|
+
}
|
|
39
50
|
}
|
|
40
51
|
SessionReplayPlugin.prototype.setup = function (config, client) {
|
|
41
52
|
var _a;
|
|
@@ -50,18 +61,20 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
50
61
|
config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');
|
|
51
62
|
this.client = client;
|
|
52
63
|
this.config = config;
|
|
53
|
-
if (
|
|
54
|
-
if (config.defaultTracking ===
|
|
55
|
-
config.defaultTracking
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
if (this.options.forceSessionTracking) {
|
|
65
|
+
if (typeof config.defaultTracking === 'boolean') {
|
|
66
|
+
if (config.defaultTracking === false) {
|
|
67
|
+
config.defaultTracking = {
|
|
68
|
+
pageViews: false,
|
|
69
|
+
formInteractions: false,
|
|
70
|
+
fileDownloads: false,
|
|
71
|
+
sessions: true,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
config.defaultTracking = tslib_1.__assign(tslib_1.__assign({}, config.defaultTracking), { sessions: true });
|
|
61
77
|
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
config.defaultTracking = tslib_1.__assign(tslib_1.__assign({}, config.defaultTracking), { sessions: true });
|
|
65
78
|
}
|
|
66
79
|
return [4 /*yield*/, sessionReplay.init(config.apiKey, {
|
|
67
80
|
instanceName: this.config.instanceName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAQA,uFAAmE;
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAQA,uFAAmE;AAEnE,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,SAAI,GAAG,sBAAsB,CAAC;QAC9B,SAAI,GAAG,YAAqB,CAAC;IA6B/B,CAAC;IAvBO,6CAAK,GAAX,UAAY,OAAsB,EAAE,OAAsB;;;gBACxD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;;;;KACvB;IAEK,+CAAO,GAAb,UAAc,KAAY;;;;gBACxB,4FAA4F;gBAC5F,kHAAkH;gBAClH,SAAS;gBACT,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,KAAK,aAAa,CAAC,YAAY,EAAE,EAAE;oBACnF,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;iBACnD;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,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,AAlGD,IAkGC;AAlGY,kDAAmB;AAoGzB,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 { 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 // 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\n async setup(_config: BrowserConfig, _client: BrowserClient) {\n this.config = _config;\n }\n\n async execute(event: Event) {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {\n sessionReplay.setSessionId(this.config.sessionId);\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (this.config.sessionId && this.config.sessionId === event.session_id) {\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 // The user did not explicitly configure forceSessionTracking to false, default to true.\n if (this.options.forceSessionTracking !== false) {\n this.options.forceSessionTracking = true;\n }\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 (this.options.forceSessionTracking) {\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\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 debugMode: this.options.debugMode,\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"","sourcesContent":["export interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\nexport interface SessionReplayOptions {\n sampleRate?: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"","sourcesContent":["export interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\nexport interface SessionReplayOptions {\n sampleRate?: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n forceSessionTracking?: boolean;\n}\n"]}
|
package/lib/esm/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":""}
|
package/lib/esm/constants.js
CHANGED
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAoChE,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;IAQpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa;IAiDnD,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,6 +1,5 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
2
|
import * as sessionReplay from '@amplitude/session-replay-browser';
|
|
3
|
-
import { DEFAULT_SESSION_START_EVENT } from './constants';
|
|
4
3
|
var ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';
|
|
5
4
|
var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
6
5
|
function SessionReplayEnrichmentPlugin() {
|
|
@@ -10,6 +9,7 @@ var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
|
10
9
|
SessionReplayEnrichmentPlugin.prototype.setup = function (_config, _client) {
|
|
11
10
|
return __awaiter(this, void 0, void 0, function () {
|
|
12
11
|
return __generator(this, function (_a) {
|
|
12
|
+
this.config = _config;
|
|
13
13
|
return [2 /*return*/];
|
|
14
14
|
});
|
|
15
15
|
});
|
|
@@ -18,11 +18,18 @@ var SessionReplayEnrichmentPlugin = /** @class */ (function () {
|
|
|
18
18
|
return __awaiter(this, void 0, void 0, function () {
|
|
19
19
|
var sessionRecordingProperties;
|
|
20
20
|
return __generator(this, function (_a) {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// On event, synchronize the session id to the what's on the browserConfig (source of truth)
|
|
22
|
+
// Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored
|
|
23
|
+
// in SR.
|
|
24
|
+
if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {
|
|
25
|
+
sessionReplay.setSessionId(this.config.sessionId);
|
|
26
|
+
}
|
|
27
|
+
// Treating config.sessionId as source of truth, if the event's session id doesn't match, the
|
|
28
|
+
// event is not of the current session (offline/late events). In that case, don't tag the events
|
|
29
|
+
if (this.config.sessionId && this.config.sessionId === event.session_id) {
|
|
30
|
+
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
31
|
+
event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
|
|
23
32
|
}
|
|
24
|
-
sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
|
|
25
|
-
event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
|
|
26
33
|
return [2 /*return*/, Promise.resolve(event)];
|
|
27
34
|
});
|
|
28
35
|
});
|
|
@@ -34,6 +41,10 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
34
41
|
this.name = '@amplitude/plugin-session-replay-browser';
|
|
35
42
|
this.type = 'destination';
|
|
36
43
|
this.options = __assign({}, options);
|
|
44
|
+
// The user did not explicitly configure forceSessionTracking to false, default to true.
|
|
45
|
+
if (this.options.forceSessionTracking !== false) {
|
|
46
|
+
this.options.forceSessionTracking = true;
|
|
47
|
+
}
|
|
37
48
|
}
|
|
38
49
|
SessionReplayPlugin.prototype.setup = function (config, client) {
|
|
39
50
|
var _a;
|
|
@@ -48,18 +59,20 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
48
59
|
config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');
|
|
49
60
|
this.client = client;
|
|
50
61
|
this.config = config;
|
|
51
|
-
if (
|
|
52
|
-
if (config.defaultTracking ===
|
|
53
|
-
config.defaultTracking
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
if (this.options.forceSessionTracking) {
|
|
63
|
+
if (typeof config.defaultTracking === 'boolean') {
|
|
64
|
+
if (config.defaultTracking === false) {
|
|
65
|
+
config.defaultTracking = {
|
|
66
|
+
pageViews: false,
|
|
67
|
+
formInteractions: false,
|
|
68
|
+
fileDownloads: false,
|
|
69
|
+
sessions: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
config.defaultTracking = __assign(__assign({}, config.defaultTracking), { sessions: true });
|
|
59
75
|
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
config.defaultTracking = __assign(__assign({}, config.defaultTracking), { sessions: true });
|
|
63
76
|
}
|
|
64
77
|
return [4 /*yield*/, sessionReplay.init(config.apiKey, {
|
|
65
78
|
instanceName: this.config.instanceName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AAEnE,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,S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analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\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 // 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\n async setup(_config: BrowserConfig, _client: BrowserClient) {\n this.config = _config;\n }\n\n async execute(event: Event) {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {\n sessionReplay.setSessionId(this.config.sessionId);\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (this.config.sessionId && this.config.sessionId === event.session_id) {\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 // The user did not explicitly configure forceSessionTracking to false, default to true.\n if (this.options.forceSessionTracking !== false) {\n this.options.forceSessionTracking = true;\n }\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 (this.options.forceSessionTracking) {\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\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 debugMode: this.options.debugMode,\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"","sourcesContent":["export interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\nexport interface SessionReplayOptions {\n sampleRate?: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"","sourcesContent":["export interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\nexport interface SessionReplayOptions {\n sampleRate?: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n forceSessionTracking?: boolean;\n}\n"]}
|