@amplitude/plugin-session-replay-browser 0.5.0 → 0.5.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/lib/cjs/constants.d.ts.map +1 -1
- package/lib/cjs/constants.js +0 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/helpers.d.ts +2 -0
- package/lib/cjs/helpers.d.ts.map +1 -1
- package/lib/cjs/helpers.js +21 -1
- package/lib/cjs/helpers.js.map +1 -1
- package/lib/cjs/session-replay.d.ts.map +1 -1
- package/lib/cjs/session-replay.js +18 -47
- package/lib/cjs/session-replay.js.map +1 -1
- package/lib/cjs/typings/session-replay.d.ts +1 -4
- 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.map +1 -1
- package/lib/esm/constants.js +0 -1
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/helpers.d.ts +2 -0
- package/lib/esm/helpers.d.ts.map +1 -1
- package/lib/esm/helpers.js +18 -0
- package/lib/esm/helpers.js.map +1 -1
- package/lib/esm/session-replay.d.ts.map +1 -1
- package/lib/esm/session-replay.js +20 -49
- package/lib/esm/session-replay.js.map +1 -1
- package/lib/esm/typings/session-replay.d.ts +1 -4
- 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.map +1 -1
- package/lib/scripts/helpers.d.ts +2 -0
- package/lib/scripts/helpers.d.ts.map +1 -1
- package/lib/scripts/session-replay.d.ts.map +1 -1
- package/lib/scripts/typings/session-replay.d.ts +1 -4
- package/lib/scripts/typings/session-replay.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,eAAO,MAAM,6BAA6B,gBAAgB,CAAC;AAE3D,eAAO,MAAM,+BAA+B,QAAsD,CAAC;AACnG,eAAO,MAAM,2BAA2B,kBAAkB,CAAC;AAC3D,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AAEvD,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAC9C,eAAO,MAAM,yBAAyB,oDAAoD,CAAC;AAC3F,eAAO,MAAM,qBAAqB,gDAAgD,CAAC;AACnF,eAAO,MAAM,cAAc,QAAsC,CAAC;AAElE,eAAO,MAAM,4BAA4B,QAAgE,CAAC;AAC1G,eAAO,MAAM,YAAY,MAAM,CAAC;AAChC,eAAO,MAAM,YAAY,QAAY,CAAC;AACtC,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,eAAO,MAAM,6BAA6B,gBAAgB,CAAC;AAE3D,eAAO,MAAM,+BAA+B,QAAsD,CAAC;AACnG,eAAO,MAAM,2BAA2B,kBAAkB,CAAC;AAC3D,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AAEvD,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAC9C,eAAO,MAAM,yBAAyB,oDAAoD,CAAC;AAC3F,eAAO,MAAM,qBAAqB,gDAAgD,CAAC;AACnF,eAAO,MAAM,cAAc,QAAsC,CAAC;AAElE,eAAO,MAAM,4BAA4B,QAAgE,CAAC;AAC1G,eAAO,MAAM,YAAY,MAAM,CAAC;AAChC,eAAO,MAAM,YAAY,QAAY,CAAC;AACtC,eAAO,MAAM,mBAAmB,EAAE,eAGjC,CAAC;AACF,eAAO,MAAM,sBAAsB,QAA0B,CAAC"}
|
package/lib/cjs/constants.js
CHANGED
|
@@ -16,7 +16,6 @@ exports.MAX_EVENT_LIST_SIZE_IN_BYTES = 10 * 1000000 - PAYLOAD_ESTIMATED_SIZE_IN_
|
|
|
16
16
|
exports.MIN_INTERVAL = 500; // 500 ms
|
|
17
17
|
exports.MAX_INTERVAL = 10 * 1000; // 10 seconds
|
|
18
18
|
exports.defaultSessionStore = {
|
|
19
|
-
shouldRecord: true,
|
|
20
19
|
currentSequenceId: 0,
|
|
21
20
|
sessionSequences: {},
|
|
22
21
|
};
|
package/lib/cjs/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,4DAA6D;AAGhD,QAAA,6BAA6B,GAAG,aAAa,CAAC;AAE9C,QAAA,+BAA+B,GAAG,UAAG,qCAA6B,sBAAmB,CAAC;AACtF,QAAA,2BAA2B,GAAG,eAAe,CAAC;AAC9C,QAAA,yBAAyB,GAAG,aAAa,CAAC;AAE1C,QAAA,WAAW,GAAG,WAAW,CAAC;AAC1B,QAAA,eAAe,GAAG,UAAU,CAAC;AAC7B,QAAA,iBAAiB,GAAG,YAAY,CAAC;AACjC,QAAA,yBAAyB,GAAG,iDAAiD,CAAC;AAC9E,QAAA,qBAAqB,GAAG,6CAA6C,CAAC;AACtE,QAAA,cAAc,GAAG,UAAG,iCAAgB,mBAAgB,CAAC;AAClE,IAAM,8CAA8C,GAAG,GAAG,CAAC,CAAC,iEAAiE;AAChH,QAAA,4BAA4B,GAAG,EAAE,GAAG,OAAO,GAAG,8CAA8C,CAAC;AAC7F,QAAA,YAAY,GAAG,GAAG,CAAC,CAAC,SAAS;AAC7B,QAAA,YAAY,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AACvC,QAAA,mBAAmB,GAAoB;IAClD,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,4DAA6D;AAGhD,QAAA,6BAA6B,GAAG,aAAa,CAAC;AAE9C,QAAA,+BAA+B,GAAG,UAAG,qCAA6B,sBAAmB,CAAC;AACtF,QAAA,2BAA2B,GAAG,eAAe,CAAC;AAC9C,QAAA,yBAAyB,GAAG,aAAa,CAAC;AAE1C,QAAA,WAAW,GAAG,WAAW,CAAC;AAC1B,QAAA,eAAe,GAAG,UAAU,CAAC;AAC7B,QAAA,iBAAiB,GAAG,YAAY,CAAC;AACjC,QAAA,yBAAyB,GAAG,iDAAiD,CAAC;AAC9E,QAAA,qBAAqB,GAAG,6CAA6C,CAAC;AACtE,QAAA,cAAc,GAAG,UAAG,iCAAgB,mBAAgB,CAAC;AAClE,IAAM,8CAA8C,GAAG,GAAG,CAAC,CAAC,iEAAiE;AAChH,QAAA,4BAA4B,GAAG,EAAE,GAAG,OAAO,GAAG,8CAA8C,CAAC;AAC7F,QAAA,YAAY,GAAG,GAAG,CAAC,CAAC,SAAS;AAC7B,QAAA,YAAY,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AACvC,QAAA,mBAAmB,GAAoB;IAClD,iBAAiB,EAAE,CAAC;IACpB,gBAAgB,EAAE,EAAE;CACrB,CAAC;AACW,QAAA,sBAAsB,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS","sourcesContent":["import { AMPLITUDE_PREFIX } from '@amplitude/analytics-core';\nimport { IDBStoreSession } from './typings/session-replay';\n\nexport const DEFAULT_EVENT_PROPERTY_PREFIX = '[Amplitude]';\n\nexport const DEFAULT_SESSION_REPLAY_PROPERTY = `${DEFAULT_EVENT_PROPERTY_PREFIX} Session Recorded`;\nexport const DEFAULT_SESSION_START_EVENT = 'session_start';\nexport const DEFAULT_SESSION_END_EVENT = 'session_end';\n\nexport const BLOCK_CLASS = 'amp-block';\nexport const MASK_TEXT_CLASS = 'amp-mask';\nexport const UNMASK_TEXT_CLASS = 'amp-unmask';\nexport const SESSION_REPLAY_SERVER_URL = 'https://api-secure.amplitude.com/sessions/track';\nexport const SESSION_REPLAY_EU_URL = 'https://api.eu.amplitude.com/sessions/track';\nexport const STORAGE_PREFIX = `${AMPLITUDE_PREFIX}_replay_unsent`;\nconst PAYLOAD_ESTIMATED_SIZE_IN_BYTES_WITHOUT_EVENTS = 500; // derived by JSON stringifying an example payload without events\nexport const MAX_EVENT_LIST_SIZE_IN_BYTES = 10 * 1000000 - PAYLOAD_ESTIMATED_SIZE_IN_BYTES_WITHOUT_EVENTS;\nexport const MIN_INTERVAL = 500; // 500 ms\nexport const MAX_INTERVAL = 10 * 1000; // 10 seconds\nexport const defaultSessionStore: IDBStoreSession = {\n currentSequenceId: 0,\n sessionSequences: {},\n};\nexport const MAX_IDB_STORAGE_LENGTH = 1000 * 60 * 60 * 24 * 3; // 3 days\n"]}
|
package/lib/cjs/helpers.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare const maskInputFn: (text: string, element: HTMLElement) => string;
|
|
2
|
+
export declare const generateHashCode: (str: string) => number;
|
|
3
|
+
export declare const isSessionInSample: (sessionId: number, sampleRate: number) => boolean;
|
|
2
4
|
//# sourceMappingURL=helpers.d.ts.map
|
package/lib/cjs/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,SAAU,MAAM,WAAW,WAAW,WAK7D,CAAC"}
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,SAAU,MAAM,WAAW,WAAW,WAK7D,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAkB,MAAM,WASpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAAwB,MAAM,cAAc,MAAM,YAM/E,CAAC"}
|
package/lib/cjs/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.maskInputFn = void 0;
|
|
2
|
+
exports.isSessionInSample = exports.generateHashCode = exports.maskInputFn = void 0;
|
|
3
3
|
var constants_1 = require("./constants");
|
|
4
4
|
var maskInputFn = function (text, element) {
|
|
5
5
|
var _a;
|
|
@@ -9,4 +9,24 @@ var maskInputFn = function (text, element) {
|
|
|
9
9
|
return '*'.repeat(text.length);
|
|
10
10
|
};
|
|
11
11
|
exports.maskInputFn = maskInputFn;
|
|
12
|
+
var generateHashCode = function (str) {
|
|
13
|
+
var hash = 0;
|
|
14
|
+
if (str.length === 0)
|
|
15
|
+
return hash;
|
|
16
|
+
for (var i = 0; i < str.length; i++) {
|
|
17
|
+
var chr = str.charCodeAt(i);
|
|
18
|
+
hash = (hash << 5) - hash + chr;
|
|
19
|
+
hash |= 0;
|
|
20
|
+
}
|
|
21
|
+
return hash;
|
|
22
|
+
};
|
|
23
|
+
exports.generateHashCode = generateHashCode;
|
|
24
|
+
var isSessionInSample = function (sessionId, sampleRate) {
|
|
25
|
+
var hashNumber = (0, exports.generateHashCode)(sessionId.toString());
|
|
26
|
+
var absHash = Math.abs(hashNumber);
|
|
27
|
+
var absHashMultiply = absHash * 31;
|
|
28
|
+
var mod = absHashMultiply % 100;
|
|
29
|
+
return mod / 100 < sampleRate;
|
|
30
|
+
};
|
|
31
|
+
exports.isSessionInSample = isSessionInSample;
|
|
12
32
|
//# sourceMappingURL=helpers.js.map
|
package/lib/cjs/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;AAAA,yCAAgD;AAEzC,IAAM,WAAW,GAAG,UAAC,IAAY,EAAE,OAAoB;;IAC5D,IAAI,MAAA,OAAO,CAAC,SAAS,0CAAE,QAAQ,CAAC,6BAAiB,CAAC,EAAE;QAClD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB","sourcesContent":["import { UNMASK_TEXT_CLASS } from './constants';\n\nexport const maskInputFn = (text: string, element: HTMLElement) => {\n if (element.classList?.contains(UNMASK_TEXT_CLASS)) {\n return text;\n }\n return '*'.repeat(text.length);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;AAAA,yCAAgD;AAEzC,IAAM,WAAW,GAAG,UAAC,IAAY,EAAE,OAAoB;;IAC5D,IAAI,MAAA,OAAO,CAAC,SAAS,0CAAE,QAAQ,CAAC,6BAAiB,CAAC,EAAE;QAClD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB;AAEK,IAAM,gBAAgB,GAAG,UAAU,GAAW;IACnD,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,IAAM,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC;QAChC,IAAI,IAAI,CAAC,CAAC;KACX;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AATW,QAAA,gBAAgB,oBAS3B;AAEK,IAAM,iBAAiB,GAAG,UAAU,SAAiB,EAAE,UAAkB;IAC9E,IAAM,UAAU,GAAG,IAAA,wBAAgB,EAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1D,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACrC,IAAM,eAAe,GAAG,OAAO,GAAG,EAAE,CAAC;IACrC,IAAM,GAAG,GAAG,eAAe,GAAG,GAAG,CAAC;IAClC,OAAO,GAAG,GAAG,GAAG,GAAG,UAAU,CAAC;AAChC,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B","sourcesContent":["import { UNMASK_TEXT_CLASS } from './constants';\n\nexport const maskInputFn = (text: string, element: HTMLElement) => {\n if (element.classList?.contains(UNMASK_TEXT_CLASS)) {\n return text;\n }\n return '*'.repeat(text.length);\n};\n\nexport const generateHashCode = function (str: string) {\n let hash = 0;\n if (str.length === 0) return hash;\n for (let i = 0; i < str.length; i++) {\n const chr = str.charCodeAt(i);\n hash = (hash << 5) - hash + chr;\n hash |= 0;\n }\n return hash;\n};\n\nexport const isSessionInSample = function (sessionId: number, sampleRate: number) {\n const hashNumber = generateHashCode(sessionId.toString());\n const absHash = Math.abs(hashNumber);\n const absHashMultiply = absHash * 31;\n const mod = absHashMultiply % 100;\n return mod / 100 < sampleRate;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAsBA,OAAO,EAQL,mBAAmB,EACpB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAsBA,OAAO,EAQL,mBAAmB,EACpB,MAAM,0BAA0B,CAAC;AA8alC,eAAO,MAAM,mBAAmB,EAAE,mBAEjC,CAAC"}
|
|
@@ -25,7 +25,6 @@ var SessionReplay = /** @class */ (function () {
|
|
|
25
25
|
this.maxPersistedEventsSize = constants_1.MAX_EVENT_LIST_SIZE_IN_BYTES;
|
|
26
26
|
this.interval = constants_1.MIN_INTERVAL;
|
|
27
27
|
this.timeAtLastSend = null;
|
|
28
|
-
this.shouldRecord = true;
|
|
29
28
|
/**
|
|
30
29
|
* Determines whether to send the events list to the backend and start a new
|
|
31
30
|
* empty events list, based on the size of the list as well as the last time sent
|
|
@@ -93,18 +92,14 @@ var SessionReplay = /** @class */ (function () {
|
|
|
93
92
|
};
|
|
94
93
|
SessionReplay.prototype.execute = function (event) {
|
|
95
94
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
96
|
-
var GlobalScope;
|
|
95
|
+
var GlobalScope, shouldRecord;
|
|
97
96
|
var _a;
|
|
98
97
|
return tslib_1.__generator(this, function (_b) {
|
|
99
98
|
GlobalScope = (0, analytics_client_common_1.getGlobalScope)();
|
|
100
99
|
if (GlobalScope && GlobalScope.document && !GlobalScope.document.hasFocus()) {
|
|
101
100
|
return [2 /*return*/, Promise.resolve(event)];
|
|
102
101
|
}
|
|
103
|
-
if (this.shouldRecord) {
|
|
104
|
-
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), (_a = {}, _a[constants_1.DEFAULT_SESSION_REPLAY_PROPERTY] = true, _a));
|
|
105
|
-
}
|
|
106
102
|
if (event.event_type === constants_1.DEFAULT_SESSION_START_EVENT && !this.stopRecordingEvents) {
|
|
107
|
-
this.setShouldRecord();
|
|
108
103
|
this.recordEvents();
|
|
109
104
|
}
|
|
110
105
|
else if (event.event_type === constants_1.DEFAULT_SESSION_END_EVENT) {
|
|
@@ -120,6 +115,10 @@ var SessionReplay = /** @class */ (function () {
|
|
|
120
115
|
this.events = [];
|
|
121
116
|
this.currentSequenceId = 0;
|
|
122
117
|
}
|
|
118
|
+
shouldRecord = this.getShouldRecord();
|
|
119
|
+
if (shouldRecord) {
|
|
120
|
+
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), (_a = {}, _a[constants_1.DEFAULT_SESSION_REPLAY_PROPERTY] = true, _a));
|
|
121
|
+
}
|
|
123
122
|
return [2 /*return*/, Promise.resolve(event)];
|
|
124
123
|
});
|
|
125
124
|
});
|
|
@@ -158,7 +157,6 @@ var SessionReplay = /** @class */ (function () {
|
|
|
158
157
|
this.events = (lastSequence === null || lastSequence === void 0 ? void 0 : lastSequence.events) || [];
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
|
-
this.setShouldRecord(storedSequencesForSession);
|
|
162
160
|
if (shouldSendStoredEvents && storedReplaySessions) {
|
|
163
161
|
this.sendStoredEvents(storedReplaySessions);
|
|
164
162
|
}
|
|
@@ -168,20 +166,17 @@ var SessionReplay = /** @class */ (function () {
|
|
|
168
166
|
});
|
|
169
167
|
});
|
|
170
168
|
};
|
|
171
|
-
SessionReplay.prototype.
|
|
172
|
-
if (
|
|
173
|
-
|
|
169
|
+
SessionReplay.prototype.getShouldRecord = function () {
|
|
170
|
+
if (this.config.optOut) {
|
|
171
|
+
return false;
|
|
174
172
|
}
|
|
175
|
-
else if (this.config.
|
|
176
|
-
|
|
173
|
+
else if (!this.config.sessionId) {
|
|
174
|
+
return false;
|
|
177
175
|
}
|
|
178
176
|
else if (this.options && this.options.sampleRate) {
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
this.config.sessionId && void this.storeShouldRecordForSession(this.config.sessionId, this.shouldRecord);
|
|
182
|
-
if (!this.shouldRecord && this.config.sessionId) {
|
|
183
|
-
this.config.loggerProvider.log("Opting session ".concat(this.config.sessionId, " out of recording."));
|
|
177
|
+
return (0, helpers_1.isSessionInSample)(this.config.sessionId, this.options.sampleRate);
|
|
184
178
|
}
|
|
179
|
+
return true;
|
|
185
180
|
};
|
|
186
181
|
SessionReplay.prototype.sendStoredEvents = function (storedReplaySessions) {
|
|
187
182
|
for (var sessionId in storedReplaySessions) {
|
|
@@ -205,7 +200,9 @@ var SessionReplay = /** @class */ (function () {
|
|
|
205
200
|
};
|
|
206
201
|
SessionReplay.prototype.recordEvents = function () {
|
|
207
202
|
var _this = this;
|
|
208
|
-
|
|
203
|
+
var shouldRecord = this.getShouldRecord();
|
|
204
|
+
if (!shouldRecord && this.config.sessionId) {
|
|
205
|
+
this.config.loggerProvider.log("Opting session ".concat(this.config.sessionId, " out of recording."));
|
|
209
206
|
return;
|
|
210
207
|
}
|
|
211
208
|
this.stopRecordingEvents = (0, rrweb_1.record)({
|
|
@@ -442,35 +439,9 @@ var SessionReplay = /** @class */ (function () {
|
|
|
442
439
|
});
|
|
443
440
|
});
|
|
444
441
|
};
|
|
445
|
-
SessionReplay.prototype.storeShouldRecordForSession = function (sessionId, shouldRecord) {
|
|
446
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
447
|
-
var e_4;
|
|
448
|
-
return tslib_1.__generator(this, function (_a) {
|
|
449
|
-
switch (_a.label) {
|
|
450
|
-
case 0:
|
|
451
|
-
_a.trys.push([0, 2, , 3]);
|
|
452
|
-
return [4 /*yield*/, IDBKeyVal.update(this.storageKey, function (sessionMap) {
|
|
453
|
-
var _a;
|
|
454
|
-
if (sessionMap === void 0) { sessionMap = {}; }
|
|
455
|
-
var session = sessionMap[sessionId] || tslib_1.__assign({}, constants_1.defaultSessionStore);
|
|
456
|
-
session.shouldRecord = shouldRecord;
|
|
457
|
-
return tslib_1.__assign(tslib_1.__assign({}, sessionMap), (_a = {}, _a[sessionId] = session, _a));
|
|
458
|
-
})];
|
|
459
|
-
case 1:
|
|
460
|
-
_a.sent();
|
|
461
|
-
return [3 /*break*/, 3];
|
|
462
|
-
case 2:
|
|
463
|
-
e_4 = _a.sent();
|
|
464
|
-
this.config.loggerProvider.error("".concat(messages_1.STORAGE_FAILURE, ": ").concat(e_4));
|
|
465
|
-
return [3 /*break*/, 3];
|
|
466
|
-
case 3: return [2 /*return*/];
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
};
|
|
471
442
|
SessionReplay.prototype.cleanUpSessionEventsStore = function (sessionId, sequenceId) {
|
|
472
443
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
473
|
-
var
|
|
444
|
+
var e_4;
|
|
474
445
|
return tslib_1.__generator(this, function (_a) {
|
|
475
446
|
switch (_a.label) {
|
|
476
447
|
case 0:
|
|
@@ -505,8 +476,8 @@ var SessionReplay = /** @class */ (function () {
|
|
|
505
476
|
_a.sent();
|
|
506
477
|
return [3 /*break*/, 3];
|
|
507
478
|
case 2:
|
|
508
|
-
|
|
509
|
-
this.config.loggerProvider.error("".concat(messages_1.STORAGE_FAILURE, ": ").concat(
|
|
479
|
+
e_4 = _a.sent();
|
|
480
|
+
this.config.loggerProvider.error("".concat(messages_1.STORAGE_FAILURE, ": ").concat(e_4));
|
|
510
481
|
return [3 /*break*/, 3];
|
|
511
482
|
case 3: return [2 /*return*/];
|
|
512
483
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AACpE,4DAA0D;AAC1D,8DAAsF;AACtF,4DAAwC;AACxC,+BAAqC;AACrC,yCAcqB;AACrB,qCAAwC;AACxC,uCAAwH;AACxH,2DASkC;AAClC;IAoBE,uBAAY,OAA8B;QAA1C,iBAEC;QArBD,SAAI,GAAG,0CAA0C,CAAC;QAClD,SAAI,GAAG,YAAqB,CAAC;QAK7B,eAAU,GAAG,EAAE,CAAC;QAChB,iBAAY,GAAG,IAAI,CAAC;QACpB,WAAM,GAAW,EAAE,CAAC;QACpB,sBAAiB,GAAG,CAAC,CAAC;QACd,cAAS,GAAyC,IAAI,CAAC;QAC/D,UAAK,GAA2B,EAAE,CAAC;QACnC,wBAAmB,GAAqC,IAAI,CAAC;QAC7D,2BAAsB,GAAG,wCAA4B,CAAC;QACtD,aAAQ,GAAG,wBAAY,CAAC;QACx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AU,CAAC;4BACpB,CAAC,CAAC,EAAA;;wBA3BF,SA2BE,CAAC;;;;wBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,UAAG,0BAAe,eAAK,GAAW,CAAE,CAAC,CAAC;;;;;;KAE1E;IAED,uCAAe,GAAf,UAAgB,EAA4F;YAA1F,OAAO,aAAA,EAAE,GAAG,SAAA,EAAE,OAAO,aAAA;QACrC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3F,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACvC;aAAM,IAAI,OAAO,EAAE;YAClB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SACzC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AA/bD,IA+bC;AAEM,IAAM,mBAAmB,GAAwB,UAAC,OAA8B;IACrF,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["import { getGlobalScope } from '@amplitude/analytics-client-common';\nimport { BaseTransport } from '@amplitude/analytics-core';\nimport { BrowserConfig, Event, ServerZone, Status } from '@amplitude/analytics-types';\nimport * as IDBKeyVal from 'idb-keyval';\nimport { pack, record } from 'rrweb';\nimport {\n BLOCK_CLASS,\n DEFAULT_SESSION_END_EVENT,\n DEFAULT_SESSION_REPLAY_PROPERTY,\n DEFAULT_SESSION_START_EVENT,\n MASK_TEXT_CLASS,\n MAX_EVENT_LIST_SIZE_IN_BYTES,\n MAX_IDB_STORAGE_LENGTH,\n MAX_INTERVAL,\n MIN_INTERVAL,\n SESSION_REPLAY_SERVER_URL,\n STORAGE_PREFIX,\n defaultSessionStore,\n SESSION_REPLAY_EU_URL as SESSION_REPLAY_EU_SERVER_URL,\n} from './constants';\nimport { maskInputFn } from './helpers';\nimport { MAX_RETRIES_EXCEEDED_MESSAGE, STORAGE_FAILURE, UNEXPECTED_ERROR_MESSAGE, getSuccessMessage } from './messages';\nimport {\n Events,\n IDBStore,\n IDBStoreSession,\n RecordingStatus,\n SessionReplayContext,\n SessionReplayEnrichmentPlugin,\n SessionReplayOptions,\n SessionReplayPlugin,\n} from './typings/session-replay';\nclass SessionReplay implements SessionReplayEnrichmentPlugin {\n name = '@amplitude/plugin-session-replay-browser';\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 storageKey = '';\n retryTimeout = 1000;\n events: Events = [];\n currentSequenceId = 0;\n private scheduled: ReturnType<typeof setTimeout> | null = null;\n queue: SessionReplayContext[] = [];\n stopRecordingEvents: ReturnType<typeof record> | null = null;\n maxPersistedEventsSize = MAX_EVENT_LIST_SIZE_IN_BYTES;\n interval = MIN_INTERVAL;\n timeAtLastSend: number | null = null;\n options: SessionReplayOptions;\n shouldRecord = true;\n\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n }\n\n async setup(config: BrowserConfig) {\n config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');\n\n this.config = config;\n this.config.sessionId = config.sessionId;\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\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 const GlobalScope = getGlobalScope();\n if (GlobalScope && GlobalScope.window) {\n GlobalScope.window.addEventListener('blur', () => {\n this.stopRecordingEvents && this.stopRecordingEvents();\n this.stopRecordingEvents = null;\n });\n GlobalScope.window.addEventListener('focus', () => {\n void this.initialize();\n });\n }\n\n if (GlobalScope && GlobalScope.document && GlobalScope.document.hasFocus()) {\n await this.initialize(true);\n }\n }\n\n async execute(event: Event) {\n const GlobalScope = getGlobalScope();\n if (GlobalScope && GlobalScope.document && !GlobalScope.document.hasFocus()) {\n return Promise.resolve(event);\n }\n\n if (this.shouldRecord) {\n event.event_properties = {\n ...event.event_properties,\n [DEFAULT_SESSION_REPLAY_PROPERTY]: true,\n };\n }\n if (event.event_type === DEFAULT_SESSION_START_EVENT && !this.stopRecordingEvents) {\n this.setShouldRecord();\n this.recordEvents();\n } else if (event.event_type === DEFAULT_SESSION_END_EVENT) {\n if (event.session_id && this.events.length) {\n this.sendEventsList({\n events: this.events,\n sequenceId: this.currentSequenceId,\n sessionId: event.session_id,\n });\n }\n this.stopRecordingEvents && this.stopRecordingEvents();\n this.stopRecordingEvents = null;\n this.events = [];\n this.currentSequenceId = 0;\n }\n return Promise.resolve(event);\n }\n\n async initialize(shouldSendStoredEvents = false) {\n this.timeAtLastSend = Date.now(); // Initialize this so we have a point of comparison when events are recorded\n if (!this.config.sessionId) {\n return;\n }\n const storedReplaySessions = await this.getAllSessionEventsFromStore();\n // This resolves a timing issue when focus is fired multiple times in short succession,\n // we only want the rest of this function to run once. We can be sure that initialize has\n // already been called if this.stopRecordingEvents is defined\n if (this.stopRecordingEvents) {\n return;\n }\n const storedSequencesForSession = storedReplaySessions && storedReplaySessions[this.config.sessionId];\n if (storedReplaySessions && storedSequencesForSession && storedSequencesForSession.sessionSequences) {\n const storedSeqId = storedSequencesForSession.currentSequenceId;\n const lastSequence = storedSequencesForSession.sessionSequences[storedSeqId];\n if (lastSequence && lastSequence.status !== RecordingStatus.RECORDING) {\n this.currentSequenceId = storedSeqId + 1;\n this.events = [];\n } else {\n // Pick up recording where it was left off in another tab or window\n this.currentSequenceId = storedSeqId;\n this.events = lastSequence?.events || [];\n }\n }\n this.setShouldRecord(storedSequencesForSession);\n if (shouldSendStoredEvents && storedReplaySessions) {\n this.sendStoredEvents(storedReplaySessions);\n }\n\n this.recordEvents();\n }\n\n setShouldRecord(sessionStore?: IDBStoreSession) {\n if (sessionStore && typeof sessionStore.shouldRecord === 'boolean') {\n this.shouldRecord = sessionStore.shouldRecord;\n } else if (this.config.optOut) {\n this.shouldRecord = false;\n } else if (this.options && this.options.sampleRate) {\n this.shouldRecord = Math.random() < this.options.sampleRate;\n }\n\n this.config.sessionId && void this.storeShouldRecordForSession(this.config.sessionId, this.shouldRecord);\n if (!this.shouldRecord && this.config.sessionId) {\n this.config.loggerProvider.log(`Opting session ${this.config.sessionId} out of recording.`);\n }\n }\n\n sendStoredEvents(storedReplaySessions: IDBStore) {\n for (const sessionId in storedReplaySessions) {\n const storedSequences = storedReplaySessions[sessionId].sessionSequences;\n for (const storedSeqId in storedSequences) {\n const seq = storedSequences[storedSeqId];\n const numericSeqId = parseInt(storedSeqId, 10);\n const numericSessionId = parseInt(sessionId, 10);\n if (numericSessionId === this.config.sessionId && numericSeqId === this.currentSequenceId) {\n continue;\n }\n if (seq.events.length && seq.status === RecordingStatus.RECORDING) {\n this.sendEventsList({\n events: seq.events,\n sequenceId: numericSeqId,\n sessionId: numericSessionId,\n });\n }\n }\n }\n }\n\n recordEvents() {\n if (!this.shouldRecord) {\n return;\n }\n this.stopRecordingEvents = record({\n emit: (event) => {\n const GlobalScope = getGlobalScope();\n if (GlobalScope && GlobalScope.document && !GlobalScope.document.hasFocus()) {\n this.stopRecordingEvents && this.stopRecordingEvents();\n return;\n }\n const eventString = JSON.stringify(event);\n\n const shouldSplit = this.shouldSplitEventsList(eventString);\n if (shouldSplit) {\n this.sendEventsList({\n events: this.events,\n sequenceId: this.currentSequenceId,\n sessionId: this.config.sessionId as number,\n });\n this.events = [];\n this.currentSequenceId++;\n }\n this.events.push(eventString);\n void this.storeEventsForSession(this.events, this.currentSequenceId, this.config.sessionId as number);\n },\n packFn: pack,\n maskAllInputs: true,\n maskTextClass: MASK_TEXT_CLASS,\n blockClass: BLOCK_CLASS,\n maskInputFn,\n });\n }\n\n /**\n * Determines whether to send the events list to the backend and start a new\n * empty events list, based on the size of the list as well as the last time sent\n * @param nextEventString\n * @returns boolean\n */\n shouldSplitEventsList = (nextEventString: string): boolean => {\n const sizeOfNextEvent = new Blob([nextEventString]).size;\n const sizeOfEventsList = new Blob(this.events).size;\n if (sizeOfEventsList + sizeOfNextEvent >= this.maxPersistedEventsSize) {\n return true;\n }\n if (this.timeAtLastSend !== null && Date.now() - this.timeAtLastSend > this.interval && this.events.length) {\n this.interval = Math.min(MAX_INTERVAL, this.interval + MIN_INTERVAL);\n this.timeAtLastSend = Date.now();\n return true;\n }\n return false;\n };\n\n sendEventsList({ events, sequenceId, sessionId }: { events: string[]; sequenceId: number; sessionId: number }) {\n this.addToQueue({\n events,\n sequenceId,\n attempts: 0,\n timeout: 0,\n sessionId,\n });\n }\n\n addToQueue(...list: SessionReplayContext[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n this.completeRequest({\n context,\n err: `${MAX_RETRIES_EXCEEDED_MESSAGE}, batch sequence id, ${context.sequenceId}`,\n });\n return false;\n });\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(0);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = setTimeout(() => {\n void this.flush(true).then(() => {\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: SessionReplayContext[] = [];\n const later: SessionReplayContext[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n if (this.scheduled) {\n clearTimeout(this.scheduled);\n this.scheduled = null;\n }\n\n await Promise.all(list.map((context) => this.send(context, useRetry)));\n }\n\n getServerUrl() {\n if (this.config.serverZone === ServerZone.EU) {\n return SESSION_REPLAY_EU_SERVER_URL;\n }\n return SESSION_REPLAY_SERVER_URL;\n }\n\n async send(context: SessionReplayContext, useRetry = true) {\n const payload = {\n api_key: this.config.apiKey,\n device_id: this.config.deviceId,\n session_id: context.sessionId,\n start_timestamp: context.sessionId,\n events_batch: {\n version: 1,\n events: context.events,\n seq_number: context.sequenceId,\n },\n };\n try {\n const options: RequestInit = {\n headers: {\n 'Content-Type': 'application/json',\n Accept: '*/*',\n },\n body: JSON.stringify(payload),\n method: 'POST',\n };\n const server_url = this.getServerUrl();\n const res = await fetch(server_url, options);\n if (res === null) {\n this.completeRequest({ context, err: UNEXPECTED_ERROR_MESSAGE });\n return;\n }\n if (!useRetry) {\n let responseBody = '';\n try {\n responseBody = JSON.stringify(res.body, null, 2);\n } catch {\n // to avoid crash, but don't care about the error, add comment to avoid empty block lint error\n }\n this.completeRequest({ context, success: `${res.status}: ${responseBody}` });\n } else {\n this.handleReponse(res.status, context);\n }\n } catch (e) {\n this.completeRequest({ context, err: e as string });\n }\n }\n\n handleReponse(status: number, context: SessionReplayContext) {\n const parsedStatus = new BaseTransport().buildStatus(status);\n switch (parsedStatus) {\n case Status.Success:\n this.handleSuccessResponse(context);\n break;\n default:\n this.handleOtherResponse(context);\n }\n }\n\n handleSuccessResponse(context: SessionReplayContext) {\n this.completeRequest({ context, success: getSuccessMessage(context.sessionId) });\n }\n\n handleOtherResponse(context: SessionReplayContext) {\n this.addToQueue({\n ...context,\n timeout: context.attempts * this.retryTimeout,\n });\n }\n\n async getAllSessionEventsFromStore() {\n try {\n const storedReplaySessionContexts: IDBStore | undefined = await IDBKeyVal.get(this.storageKey);\n\n return storedReplaySessionContexts;\n } catch (e) {\n this.config.loggerProvider.error(`${STORAGE_FAILURE}: ${e as string}`);\n }\n return undefined;\n }\n\n async storeEventsForSession(events: Events, sequenceId: number, sessionId: number) {\n try {\n await IDBKeyVal.update(this.storageKey, (sessionMap: IDBStore = {}): IDBStore => {\n const session: IDBStoreSession = sessionMap[sessionId] || { ...defaultSessionStore };\n session.currentSequenceId = sequenceId;\n\n const currentSequence = (session.sessionSequences && session.sessionSequences[sequenceId]) || {};\n\n currentSequence.events = events;\n currentSequence.status = RecordingStatus.RECORDING;\n\n return {\n ...sessionMap,\n [sessionId]: {\n ...session,\n sessionSequences: {\n ...session.sessionSequences,\n [sequenceId]: currentSequence,\n },\n },\n };\n });\n } catch (e) {\n this.config.loggerProvider.error(`${STORAGE_FAILURE}: ${e as string}`);\n }\n }\n\n async storeShouldRecordForSession(sessionId: number, shouldRecord: boolean) {\n try {\n await IDBKeyVal.update(this.storageKey, (sessionMap: IDBStore = {}): IDBStore => {\n const session: IDBStoreSession = sessionMap[sessionId] || { ...defaultSessionStore };\n session.shouldRecord = shouldRecord;\n\n return {\n ...sessionMap,\n [sessionId]: session,\n };\n });\n } catch (e) {\n this.config.loggerProvider.error(`${STORAGE_FAILURE}: ${e as string}`);\n }\n }\n\n async cleanUpSessionEventsStore(sessionId: number, sequenceId: number) {\n try {\n await IDBKeyVal.update(this.storageKey, (sessionMap: IDBStore = {}): IDBStore => {\n const session: IDBStoreSession = sessionMap[sessionId];\n const sequenceToUpdate = session?.sessionSequences && session.sessionSequences[sequenceId];\n if (!sequenceToUpdate) {\n return sessionMap;\n }\n\n sequenceToUpdate.events = [];\n sequenceToUpdate.status = RecordingStatus.SENT;\n\n // Delete sent sequences for current session\n Object.entries(session.sessionSequences).forEach(([storedSeqId, sequence]) => {\n const numericStoredSeqId = parseInt(storedSeqId, 10);\n if (sequence.status === RecordingStatus.SENT && sequenceId !== numericStoredSeqId) {\n delete session.sessionSequences[numericStoredSeqId];\n }\n });\n\n // Delete any sessions that are older than 3 days\n Object.keys(sessionMap).forEach((sessionId: string) => {\n const numericSessionId = parseInt(sessionId, 10);\n if (Date.now() - numericSessionId >= MAX_IDB_STORAGE_LENGTH) {\n delete sessionMap[numericSessionId];\n }\n });\n\n return sessionMap;\n });\n } catch (e) {\n this.config.loggerProvider.error(`${STORAGE_FAILURE}: ${e as string}`);\n }\n }\n\n completeRequest({ context, err, success }: { context: SessionReplayContext; err?: string; success?: string }) {\n context.sessionId && this.cleanUpSessionEventsStore(context.sessionId, context.sequenceId);\n if (err) {\n this.config.loggerProvider.error(err);\n } else if (success) {\n this.config.loggerProvider.log(success);\n }\n }\n}\n\nexport const sessionReplayPlugin: SessionReplayPlugin = (options?: SessionReplayOptions) => {\n return new SessionReplay(options);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AACpE,4DAA0D;AAC1D,8DAAsF;AACtF,4DAAwC;AACxC,+BAAqC;AACrC,yCAcqB;AACrB,qCAA2D;AAC3D,uCAAwH;AACxH,2DASkC;AAClC;IAmBE,uBAAY,OAA8B;QAA1C,iBAEC;QApBD,SAAI,GAAG,0CAA0C,CAAC;QAClD,SAAI,GAAG,YAAqB,CAAC;QAK7B,eAAU,GAAG,EAAE,CAAC;QAChB,iBAAY,GAAG,IAAI,CAAC;QACpB,WAAM,GAAW,EAAE,CAAC;QACpB,sBAAiB,GAAG,CAAC,CAAC;QACd,cAAS,GAAyC,IAAI,CAAC;QAC/D,UAAK,GAA2B,EAAE,CAAC;QACnC,wBAAmB,GAAqC,IAAI,CAAC;QAC7D,2BAAsB,GAAG,wCAA4B,CAAC;QACtD,aAAQ,GAAG,wBAAY,CAAC;QACxB,mBAAc,GAAkB,IAAI,CAAC;QAiLrC;;;;;WAKG;QACH,0BAAqB,GAAG,UAAC,eAAuB;YAC9C,IAAM,eAAe,GAAG,IAAI,IAAI,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC;YACzD,IAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,KAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YACpD,IAAI,gBAAgB,GAAG,eAAe,IAAI,KAAI,CAAC,sBAAsB,EAAE;gBACrE,OAAO,IAAI,CAAC;aACb;YACD,IAAI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CAAsB,EAAE;wCAC3D,OAAO,UAAU,CAAC,gBAAgB,CAAC,CAAC;qCACrC;gCACH,CAAC,CAAC,CAAC;gCAEH,OAAO,UAAU,CAAC;4BACpB,CAAC,CAAC,EAAA;;wBA3BF,SA2BE,CAAC;;;;wBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,UAAG,0BAAe,eAAK,GAAW,CAAE,CAAC,CAAC;;;;;;KAE1E;IAED,uCAAe,GAAf,UAAgB,EAA4F;YAA1F,OAAO,aAAA,EAAE,GAAG,SAAA,EAAE,OAAO,aAAA;QACrC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3F,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACvC;aAAM,IAAI,OAAO,EAAE;YAClB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SACzC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AA3aD,IA2aC;AAEM,IAAM,mBAAmB,GAAwB,UAAC,OAA8B;IACrF,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["import { getGlobalScope } from '@amplitude/analytics-client-common';\nimport { BaseTransport } from '@amplitude/analytics-core';\nimport { BrowserConfig, Event, ServerZone, Status } from '@amplitude/analytics-types';\nimport * as IDBKeyVal from 'idb-keyval';\nimport { pack, record } from 'rrweb';\nimport {\n BLOCK_CLASS,\n DEFAULT_SESSION_END_EVENT,\n DEFAULT_SESSION_REPLAY_PROPERTY,\n DEFAULT_SESSION_START_EVENT,\n MASK_TEXT_CLASS,\n MAX_EVENT_LIST_SIZE_IN_BYTES,\n MAX_IDB_STORAGE_LENGTH,\n MAX_INTERVAL,\n MIN_INTERVAL,\n SESSION_REPLAY_EU_URL as SESSION_REPLAY_EU_SERVER_URL,\n SESSION_REPLAY_SERVER_URL,\n STORAGE_PREFIX,\n defaultSessionStore,\n} from './constants';\nimport { isSessionInSample, maskInputFn } from './helpers';\nimport { MAX_RETRIES_EXCEEDED_MESSAGE, STORAGE_FAILURE, UNEXPECTED_ERROR_MESSAGE, getSuccessMessage } from './messages';\nimport {\n Events,\n IDBStore,\n IDBStoreSession,\n RecordingStatus,\n SessionReplayContext,\n SessionReplayEnrichmentPlugin,\n SessionReplayOptions,\n SessionReplayPlugin,\n} from './typings/session-replay';\nclass SessionReplay implements SessionReplayEnrichmentPlugin {\n name = '@amplitude/plugin-session-replay-browser';\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 storageKey = '';\n retryTimeout = 1000;\n events: Events = [];\n currentSequenceId = 0;\n private scheduled: ReturnType<typeof setTimeout> | null = null;\n queue: SessionReplayContext[] = [];\n stopRecordingEvents: ReturnType<typeof record> | null = null;\n maxPersistedEventsSize = MAX_EVENT_LIST_SIZE_IN_BYTES;\n interval = MIN_INTERVAL;\n timeAtLastSend: number | null = null;\n options: SessionReplayOptions;\n\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n }\n\n async setup(config: BrowserConfig) {\n config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');\n\n this.config = config;\n this.config.sessionId = config.sessionId;\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\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 const GlobalScope = getGlobalScope();\n if (GlobalScope && GlobalScope.window) {\n GlobalScope.window.addEventListener('blur', () => {\n this.stopRecordingEvents && this.stopRecordingEvents();\n this.stopRecordingEvents = null;\n });\n GlobalScope.window.addEventListener('focus', () => {\n void this.initialize();\n });\n }\n\n if (GlobalScope && GlobalScope.document && GlobalScope.document.hasFocus()) {\n await this.initialize(true);\n }\n }\n\n async execute(event: Event) {\n const GlobalScope = getGlobalScope();\n if (GlobalScope && GlobalScope.document && !GlobalScope.document.hasFocus()) {\n return Promise.resolve(event);\n }\n if (event.event_type === DEFAULT_SESSION_START_EVENT && !this.stopRecordingEvents) {\n this.recordEvents();\n } else if (event.event_type === DEFAULT_SESSION_END_EVENT) {\n if (event.session_id && this.events.length) {\n this.sendEventsList({\n events: this.events,\n sequenceId: this.currentSequenceId,\n sessionId: event.session_id,\n });\n }\n this.stopRecordingEvents && this.stopRecordingEvents();\n this.stopRecordingEvents = null;\n this.events = [];\n this.currentSequenceId = 0;\n }\n\n const shouldRecord = this.getShouldRecord();\n if (shouldRecord) {\n event.event_properties = {\n ...event.event_properties,\n [DEFAULT_SESSION_REPLAY_PROPERTY]: true,\n };\n }\n\n return Promise.resolve(event);\n }\n\n async initialize(shouldSendStoredEvents = false) {\n this.timeAtLastSend = Date.now(); // Initialize this so we have a point of comparison when events are recorded\n if (!this.config.sessionId) {\n return;\n }\n const storedReplaySessions = await this.getAllSessionEventsFromStore();\n // This resolves a timing issue when focus is fired multiple times in short succession,\n // we only want the rest of this function to run once. We can be sure that initialize has\n // already been called if this.stopRecordingEvents is defined\n if (this.stopRecordingEvents) {\n return;\n }\n const storedSequencesForSession = storedReplaySessions && storedReplaySessions[this.config.sessionId];\n if (storedReplaySessions && storedSequencesForSession && storedSequencesForSession.sessionSequences) {\n const storedSeqId = storedSequencesForSession.currentSequenceId;\n const lastSequence = storedSequencesForSession.sessionSequences[storedSeqId];\n if (lastSequence && lastSequence.status !== RecordingStatus.RECORDING) {\n this.currentSequenceId = storedSeqId + 1;\n this.events = [];\n } else {\n // Pick up recording where it was left off in another tab or window\n this.currentSequenceId = storedSeqId;\n this.events = lastSequence?.events || [];\n }\n }\n if (shouldSendStoredEvents && storedReplaySessions) {\n this.sendStoredEvents(storedReplaySessions);\n }\n this.recordEvents();\n }\n\n getShouldRecord() {\n if (this.config.optOut) {\n return false;\n } else if (!this.config.sessionId) {\n return false;\n } else if (this.options && this.options.sampleRate) {\n return isSessionInSample(this.config.sessionId, this.options.sampleRate);\n }\n return true;\n }\n\n sendStoredEvents(storedReplaySessions: IDBStore) {\n for (const sessionId in storedReplaySessions) {\n const storedSequences = storedReplaySessions[sessionId].sessionSequences;\n for (const storedSeqId in storedSequences) {\n const seq = storedSequences[storedSeqId];\n const numericSeqId = parseInt(storedSeqId, 10);\n const numericSessionId = parseInt(sessionId, 10);\n if (numericSessionId === this.config.sessionId && numericSeqId === this.currentSequenceId) {\n continue;\n }\n if (seq.events.length && seq.status === RecordingStatus.RECORDING) {\n this.sendEventsList({\n events: seq.events,\n sequenceId: numericSeqId,\n sessionId: numericSessionId,\n });\n }\n }\n }\n }\n\n recordEvents() {\n const shouldRecord = this.getShouldRecord();\n if (!shouldRecord && this.config.sessionId) {\n this.config.loggerProvider.log(`Opting session ${this.config.sessionId} out of recording.`);\n return;\n }\n this.stopRecordingEvents = record({\n emit: (event) => {\n const GlobalScope = getGlobalScope();\n if (GlobalScope && GlobalScope.document && !GlobalScope.document.hasFocus()) {\n this.stopRecordingEvents && this.stopRecordingEvents();\n return;\n }\n const eventString = JSON.stringify(event);\n\n const shouldSplit = this.shouldSplitEventsList(eventString);\n if (shouldSplit) {\n this.sendEventsList({\n events: this.events,\n sequenceId: this.currentSequenceId,\n sessionId: this.config.sessionId as number,\n });\n this.events = [];\n this.currentSequenceId++;\n }\n this.events.push(eventString);\n void this.storeEventsForSession(this.events, this.currentSequenceId, this.config.sessionId as number);\n },\n packFn: pack,\n maskAllInputs: true,\n maskTextClass: MASK_TEXT_CLASS,\n blockClass: BLOCK_CLASS,\n maskInputFn,\n });\n }\n\n /**\n * Determines whether to send the events list to the backend and start a new\n * empty events list, based on the size of the list as well as the last time sent\n * @param nextEventString\n * @returns boolean\n */\n shouldSplitEventsList = (nextEventString: string): boolean => {\n const sizeOfNextEvent = new Blob([nextEventString]).size;\n const sizeOfEventsList = new Blob(this.events).size;\n if (sizeOfEventsList + sizeOfNextEvent >= this.maxPersistedEventsSize) {\n return true;\n }\n if (this.timeAtLastSend !== null && Date.now() - this.timeAtLastSend > this.interval && this.events.length) {\n this.interval = Math.min(MAX_INTERVAL, this.interval + MIN_INTERVAL);\n this.timeAtLastSend = Date.now();\n return true;\n }\n return false;\n };\n\n sendEventsList({ events, sequenceId, sessionId }: { events: string[]; sequenceId: number; sessionId: number }) {\n this.addToQueue({\n events,\n sequenceId,\n attempts: 0,\n timeout: 0,\n sessionId,\n });\n }\n\n addToQueue(...list: SessionReplayContext[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n this.completeRequest({\n context,\n err: `${MAX_RETRIES_EXCEEDED_MESSAGE}, batch sequence id, ${context.sequenceId}`,\n });\n return false;\n });\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(0);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = setTimeout(() => {\n void this.flush(true).then(() => {\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: SessionReplayContext[] = [];\n const later: SessionReplayContext[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n if (this.scheduled) {\n clearTimeout(this.scheduled);\n this.scheduled = null;\n }\n\n await Promise.all(list.map((context) => this.send(context, useRetry)));\n }\n\n getServerUrl() {\n if (this.config.serverZone === ServerZone.EU) {\n return SESSION_REPLAY_EU_SERVER_URL;\n }\n return SESSION_REPLAY_SERVER_URL;\n }\n\n async send(context: SessionReplayContext, useRetry = true) {\n const payload = {\n api_key: this.config.apiKey,\n device_id: this.config.deviceId,\n session_id: context.sessionId,\n start_timestamp: context.sessionId,\n events_batch: {\n version: 1,\n events: context.events,\n seq_number: context.sequenceId,\n },\n };\n try {\n const options: RequestInit = {\n headers: {\n 'Content-Type': 'application/json',\n Accept: '*/*',\n },\n body: JSON.stringify(payload),\n method: 'POST',\n };\n const server_url = this.getServerUrl();\n const res = await fetch(server_url, options);\n if (res === null) {\n this.completeRequest({ context, err: UNEXPECTED_ERROR_MESSAGE });\n return;\n }\n if (!useRetry) {\n let responseBody = '';\n try {\n responseBody = JSON.stringify(res.body, null, 2);\n } catch {\n // to avoid crash, but don't care about the error, add comment to avoid empty block lint error\n }\n this.completeRequest({ context, success: `${res.status}: ${responseBody}` });\n } else {\n this.handleReponse(res.status, context);\n }\n } catch (e) {\n this.completeRequest({ context, err: e as string });\n }\n }\n\n handleReponse(status: number, context: SessionReplayContext) {\n const parsedStatus = new BaseTransport().buildStatus(status);\n switch (parsedStatus) {\n case Status.Success:\n this.handleSuccessResponse(context);\n break;\n default:\n this.handleOtherResponse(context);\n }\n }\n\n handleSuccessResponse(context: SessionReplayContext) {\n this.completeRequest({ context, success: getSuccessMessage(context.sessionId) });\n }\n\n handleOtherResponse(context: SessionReplayContext) {\n this.addToQueue({\n ...context,\n timeout: context.attempts * this.retryTimeout,\n });\n }\n\n async getAllSessionEventsFromStore() {\n try {\n const storedReplaySessionContexts: IDBStore | undefined = await IDBKeyVal.get(this.storageKey);\n\n return storedReplaySessionContexts;\n } catch (e) {\n this.config.loggerProvider.error(`${STORAGE_FAILURE}: ${e as string}`);\n }\n return undefined;\n }\n\n async storeEventsForSession(events: Events, sequenceId: number, sessionId: number) {\n try {\n await IDBKeyVal.update(this.storageKey, (sessionMap: IDBStore = {}): IDBStore => {\n const session: IDBStoreSession = sessionMap[sessionId] || { ...defaultSessionStore };\n session.currentSequenceId = sequenceId;\n\n const currentSequence = (session.sessionSequences && session.sessionSequences[sequenceId]) || {};\n\n currentSequence.events = events;\n currentSequence.status = RecordingStatus.RECORDING;\n\n return {\n ...sessionMap,\n [sessionId]: {\n ...session,\n sessionSequences: {\n ...session.sessionSequences,\n [sequenceId]: currentSequence,\n },\n },\n };\n });\n } catch (e) {\n this.config.loggerProvider.error(`${STORAGE_FAILURE}: ${e as string}`);\n }\n }\n\n async cleanUpSessionEventsStore(sessionId: number, sequenceId: number) {\n try {\n await IDBKeyVal.update(this.storageKey, (sessionMap: IDBStore = {}): IDBStore => {\n const session: IDBStoreSession = sessionMap[sessionId];\n const sequenceToUpdate = session?.sessionSequences && session.sessionSequences[sequenceId];\n if (!sequenceToUpdate) {\n return sessionMap;\n }\n\n sequenceToUpdate.events = [];\n sequenceToUpdate.status = RecordingStatus.SENT;\n\n // Delete sent sequences for current session\n Object.entries(session.sessionSequences).forEach(([storedSeqId, sequence]) => {\n const numericStoredSeqId = parseInt(storedSeqId, 10);\n if (sequence.status === RecordingStatus.SENT && sequenceId !== numericStoredSeqId) {\n delete session.sessionSequences[numericStoredSeqId];\n }\n });\n\n // Delete any sessions that are older than 3 days\n Object.keys(sessionMap).forEach((sessionId: string) => {\n const numericSessionId = parseInt(sessionId, 10);\n if (Date.now() - numericSessionId >= MAX_IDB_STORAGE_LENGTH) {\n delete sessionMap[numericSessionId];\n }\n });\n\n return sessionMap;\n });\n } catch (e) {\n this.config.loggerProvider.error(`${STORAGE_FAILURE}: ${e as string}`);\n }\n }\n\n completeRequest({ context, err, success }: { context: SessionReplayContext; err?: string; success?: string }) {\n context.sessionId && this.cleanUpSessionEventsStore(context.sessionId, context.sequenceId);\n if (err) {\n this.config.loggerProvider.error(err);\n } else if (success) {\n this.config.loggerProvider.log(success);\n }\n }\n}\n\nexport const sessionReplayPlugin: SessionReplayPlugin = (options?: SessionReplayOptions) => {\n return new SessionReplay(options);\n};\n"]}
|
|
@@ -21,7 +21,6 @@ export interface IDBStoreSequence {
|
|
|
21
21
|
status: RecordingStatus;
|
|
22
22
|
}
|
|
23
23
|
export interface IDBStoreSession {
|
|
24
|
-
shouldRecord: boolean;
|
|
25
24
|
currentSequenceId: number;
|
|
26
25
|
sessionSequences: {
|
|
27
26
|
[sequenceId: number]: IDBStoreSequence;
|
|
@@ -38,13 +37,12 @@ export interface SessionReplayEnrichmentPlugin extends EnrichmentPlugin {
|
|
|
38
37
|
events: Events;
|
|
39
38
|
currentSequenceId: number;
|
|
40
39
|
interval: number;
|
|
41
|
-
shouldRecord: boolean;
|
|
42
40
|
queue: SessionReplayContext[];
|
|
43
41
|
timeAtLastSend: number | null;
|
|
44
42
|
stopRecordingEvents: ReturnType<typeof record> | null;
|
|
45
43
|
maxPersistedEventsSize: number;
|
|
46
44
|
initialize: (shouldSendStoredEvents?: boolean) => Promise<void>;
|
|
47
|
-
|
|
45
|
+
getShouldRecord: () => boolean;
|
|
48
46
|
recordEvents: () => void;
|
|
49
47
|
shouldSplitEventsList: (nextEventString: string) => boolean;
|
|
50
48
|
sendEventsList: ({ events, sequenceId, sessionId, }: {
|
|
@@ -64,7 +62,6 @@ export interface SessionReplayEnrichmentPlugin extends EnrichmentPlugin {
|
|
|
64
62
|
}): void;
|
|
65
63
|
getAllSessionEventsFromStore: () => Promise<IDBStore | undefined>;
|
|
66
64
|
storeEventsForSession: (events: Events, sequenceId: number, sessionId: number) => Promise<void>;
|
|
67
|
-
storeShouldRecordForSession: (sessionId: number, shouldRecord: boolean) => Promise<void>;
|
|
68
65
|
cleanUpSessionEventsStore: (sessionId: number, sequenceId: number) => Promise<void>;
|
|
69
66
|
}
|
|
70
67
|
export interface SessionReplayPlugin {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;AAE9B,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,oBAAY,eAAe;IACzB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;AAE9B,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,oBAAY,eAAe;IACzB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,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AAC,QAAQ,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,eAAe,CAAC,EACd,OAAO,EACP,GAAG,EACH,OAAO,EACP,YAAY,GACb,EAAE;QACD,OAAO,EAAE,oBAAoB,CAAC;QAC9B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KACpC,GAAG,IAAI,CAAC;IACT,4BAA4B,EAAE,MAAM,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IAClE,qBAAqB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChG,yBAAyB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrF;AAED,MAAM,WAAW,mBAAmB;IAClC,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,6BAA6B,CAAC;CACjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":";;AAiBA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,sCAAmB,CAAA;IACnB,gCAAa,CAAA;AACf,CAAC,EAJW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAI1B","sourcesContent":["import { BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types';\nimport { record } from 'rrweb';\n\nexport interface SessionReplayOptions {\n sampleRate?: number;\n}\n\nexport type Events = string[];\n\nexport interface SessionReplayContext {\n events: Events;\n sequenceId: number;\n attempts: number;\n timeout: number;\n sessionId: number;\n}\n\nexport enum RecordingStatus {\n RECORDING = 'recording',\n SENDING = 'sending',\n SENT = 'sent',\n}\n\nexport interface IDBStoreSequence {\n events: Events;\n status: RecordingStatus;\n}\n\nexport interface IDBStoreSession {\n
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../../src/typings/session-replay.ts"],"names":[],"mappings":";;AAiBA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,sCAAmB,CAAA;IACnB,gCAAa,CAAA;AACf,CAAC,EAJW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAI1B","sourcesContent":["import { BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types';\nimport { record } from 'rrweb';\n\nexport interface SessionReplayOptions {\n sampleRate?: number;\n}\n\nexport type Events = string[];\n\nexport interface SessionReplayContext {\n events: Events;\n sequenceId: number;\n attempts: number;\n timeout: number;\n sessionId: number;\n}\n\nexport enum RecordingStatus {\n RECORDING = 'recording',\n SENDING = 'sending',\n SENT = 'sent',\n}\n\nexport interface IDBStoreSequence {\n events: Events;\n status: RecordingStatus;\n}\n\nexport interface IDBStoreSession {\n currentSequenceId: number;\n sessionSequences: {\n [sequenceId: number]: IDBStoreSequence;\n };\n}\n\nexport interface IDBStore {\n [sessionId: number]: IDBStoreSession;\n}\nexport interface SessionReplayEnrichmentPlugin extends EnrichmentPlugin {\n setup: (config: BrowserConfig) => Promise<void>;\n config: BrowserConfig;\n storageKey: string;\n retryTimeout: number;\n events: Events;\n currentSequenceId: number;\n interval: number;\n queue: SessionReplayContext[];\n timeAtLastSend: number | null;\n stopRecordingEvents: ReturnType<typeof record> | null;\n maxPersistedEventsSize: number;\n initialize: (shouldSendStoredEvents?: boolean) => Promise<void>;\n getShouldRecord: () => boolean;\n recordEvents: () => void;\n shouldSplitEventsList: (nextEventString: string) => boolean;\n sendEventsList: ({\n events,\n sequenceId,\n sessionId,\n }: {\n events: string[];\n sequenceId: number;\n sessionId: number;\n }) => void;\n addToQueue: (...list: SessionReplayContext[]) => void;\n schedule: (timeout: number) => void;\n flush: (useRetry?: boolean) => Promise<void>;\n send: (context: SessionReplayContext, useRetry?: boolean) => Promise<void>;\n completeRequest({\n context,\n err,\n success,\n removeEvents,\n }: {\n context: SessionReplayContext;\n err?: string | undefined;\n success?: string | undefined;\n removeEvents?: boolean | undefined;\n }): void;\n getAllSessionEventsFromStore: () => Promise<IDBStore | undefined>;\n storeEventsForSession: (events: Events, sequenceId: number, sessionId: number) => Promise<void>;\n cleanUpSessionEventsStore: (sessionId: number, sequenceId: number) => Promise<void>;\n}\n\nexport interface SessionReplayPlugin {\n (options?: SessionReplayOptions): SessionReplayEnrichmentPlugin;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,eAAO,MAAM,6BAA6B,gBAAgB,CAAC;AAE3D,eAAO,MAAM,+BAA+B,QAAsD,CAAC;AACnG,eAAO,MAAM,2BAA2B,kBAAkB,CAAC;AAC3D,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AAEvD,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAC9C,eAAO,MAAM,yBAAyB,oDAAoD,CAAC;AAC3F,eAAO,MAAM,qBAAqB,gDAAgD,CAAC;AACnF,eAAO,MAAM,cAAc,QAAsC,CAAC;AAElE,eAAO,MAAM,4BAA4B,QAAgE,CAAC;AAC1G,eAAO,MAAM,YAAY,MAAM,CAAC;AAChC,eAAO,MAAM,YAAY,QAAY,CAAC;AACtC,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,eAAO,MAAM,6BAA6B,gBAAgB,CAAC;AAE3D,eAAO,MAAM,+BAA+B,QAAsD,CAAC;AACnG,eAAO,MAAM,2BAA2B,kBAAkB,CAAC;AAC3D,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AAEvD,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAC9C,eAAO,MAAM,yBAAyB,oDAAoD,CAAC;AAC3F,eAAO,MAAM,qBAAqB,gDAAgD,CAAC;AACnF,eAAO,MAAM,cAAc,QAAsC,CAAC;AAElE,eAAO,MAAM,4BAA4B,QAAgE,CAAC;AAC1G,eAAO,MAAM,YAAY,MAAM,CAAC;AAChC,eAAO,MAAM,YAAY,QAAY,CAAC;AACtC,eAAO,MAAM,mBAAmB,EAAE,eAGjC,CAAC;AACF,eAAO,MAAM,sBAAsB,QAA0B,CAAC"}
|
package/lib/esm/constants.js
CHANGED
|
@@ -14,7 +14,6 @@ export var MAX_EVENT_LIST_SIZE_IN_BYTES = 10 * 1000000 - PAYLOAD_ESTIMATED_SIZE_
|
|
|
14
14
|
export var MIN_INTERVAL = 500; // 500 ms
|
|
15
15
|
export var MAX_INTERVAL = 10 * 1000; // 10 seconds
|
|
16
16
|
export var defaultSessionStore = {
|
|
17
|
-
shouldRecord: true,
|
|
18
17
|
currentSequenceId: 0,
|
|
19
18
|
sessionSequences: {},
|
|
20
19
|
};
|
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,MAAM,CAAC,IAAM,6BA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MAAM,CAAC,IAAM,eAAe,GAAG,UAAU,CAAC;AAC1C,MAAM,CAAC,IAAM,iBAAiB,GAAG,YAAY,CAAC;AAC9C,MAAM,CAAC,IAAM,yBAAyB,GAAG,iDAAiD,CAAC;AAC3F,MAAM,CAAC,IAAM,qBAAqB,GAAG,6CAA6C,CAAC;AACnF,MAAM,CAAC,IAAM,cAAc,GAAG,UAAG,gBAAgB,mBAAgB,CAAC;AAClE,IAAM,8CAA8C,GAAG,GAAG,CAAC,CAAC,iEAAiE;AAC7H,MAAM,CAAC,IAAM,4BAA4B,GAAG,EAAE,GAAG,OAAO,GAAG,8CAA8C,CAAC;AAC1G,MAAM,CAAC,IAAM,YAAY,GAAG,GAAG,CAAC,CAAC,SAAS;AAC1C,MAAM,CAAC,IAAM,YAAY,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AACpD,MAAM,CAAC,IAAM,mBAAmB,GAAoB;IAClD,iBAAiB,EAAE,CAAC;IACpB,gBAAgB,EAAE,EAAE;CACrB,CAAC;AACF,MAAM,CAAC,IAAM,sBAAsB,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS","sourcesContent":["import { AMPLITUDE_PREFIX } from '@amplitude/analytics-core';\nimport { IDBStoreSession } from './typings/session-replay';\n\nexport const DEFAULT_EVENT_PROPERTY_PREFIX = '[Amplitude]';\n\nexport const DEFAULT_SESSION_REPLAY_PROPERTY = `${DEFAULT_EVENT_PROPERTY_PREFIX} Session Recorded`;\nexport const DEFAULT_SESSION_START_EVENT = 'session_start';\nexport const DEFAULT_SESSION_END_EVENT = 'session_end';\n\nexport const BLOCK_CLASS = 'amp-block';\nexport const MASK_TEXT_CLASS = 'amp-mask';\nexport const UNMASK_TEXT_CLASS = 'amp-unmask';\nexport const SESSION_REPLAY_SERVER_URL = 'https://api-secure.amplitude.com/sessions/track';\nexport const SESSION_REPLAY_EU_URL = 'https://api.eu.amplitude.com/sessions/track';\nexport const STORAGE_PREFIX = `${AMPLITUDE_PREFIX}_replay_unsent`;\nconst PAYLOAD_ESTIMATED_SIZE_IN_BYTES_WITHOUT_EVENTS = 500; // derived by JSON stringifying an example payload without events\nexport const MAX_EVENT_LIST_SIZE_IN_BYTES = 10 * 1000000 - PAYLOAD_ESTIMATED_SIZE_IN_BYTES_WITHOUT_EVENTS;\nexport const MIN_INTERVAL = 500; // 500 ms\nexport const MAX_INTERVAL = 10 * 1000; // 10 seconds\nexport const defaultSessionStore: IDBStoreSession = {\n currentSequenceId: 0,\n sessionSequences: {},\n};\nexport const MAX_IDB_STORAGE_LENGTH = 1000 * 60 * 60 * 24 * 3; // 3 days\n"]}
|
package/lib/esm/helpers.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare const maskInputFn: (text: string, element: HTMLElement) => string;
|
|
2
|
+
export declare const generateHashCode: (str: string) => number;
|
|
3
|
+
export declare const isSessionInSample: (sessionId: number, sampleRate: number) => boolean;
|
|
2
4
|
//# sourceMappingURL=helpers.d.ts.map
|
package/lib/esm/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,SAAU,MAAM,WAAW,WAAW,WAK7D,CAAC"}
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,SAAU,MAAM,WAAW,WAAW,WAK7D,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAkB,MAAM,WASpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAAwB,MAAM,cAAc,MAAM,YAM/E,CAAC"}
|
package/lib/esm/helpers.js
CHANGED
|
@@ -6,4 +6,22 @@ export var maskInputFn = function (text, element) {
|
|
|
6
6
|
}
|
|
7
7
|
return '*'.repeat(text.length);
|
|
8
8
|
};
|
|
9
|
+
export var generateHashCode = function (str) {
|
|
10
|
+
var hash = 0;
|
|
11
|
+
if (str.length === 0)
|
|
12
|
+
return hash;
|
|
13
|
+
for (var i = 0; i < str.length; i++) {
|
|
14
|
+
var chr = str.charCodeAt(i);
|
|
15
|
+
hash = (hash << 5) - hash + chr;
|
|
16
|
+
hash |= 0;
|
|
17
|
+
}
|
|
18
|
+
return hash;
|
|
19
|
+
};
|
|
20
|
+
export var isSessionInSample = function (sessionId, sampleRate) {
|
|
21
|
+
var hashNumber = generateHashCode(sessionId.toString());
|
|
22
|
+
var absHash = Math.abs(hashNumber);
|
|
23
|
+
var absHashMultiply = absHash * 31;
|
|
24
|
+
var mod = absHashMultiply % 100;
|
|
25
|
+
return mod / 100 < sampleRate;
|
|
26
|
+
};
|
|
9
27
|
//# sourceMappingURL=helpers.js.map
|
package/lib/esm/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,CAAC,IAAM,WAAW,GAAG,UAAC,IAAY,EAAE,OAAoB;;IAC5D,IAAI,MAAA,OAAO,CAAC,SAAS,0CAAE,QAAQ,CAAC,iBAAiB,CAAC,EAAE;QAClD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC","sourcesContent":["import { UNMASK_TEXT_CLASS } from './constants';\n\nexport const maskInputFn = (text: string, element: HTMLElement) => {\n if (element.classList?.contains(UNMASK_TEXT_CLASS)) {\n return text;\n }\n return '*'.repeat(text.length);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,CAAC,IAAM,WAAW,GAAG,UAAC,IAAY,EAAE,OAAoB;;IAC5D,IAAI,MAAA,OAAO,CAAC,SAAS,0CAAE,QAAQ,CAAC,iBAAiB,CAAC,EAAE;QAClD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAU,GAAW;IACnD,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,IAAM,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC;QAChC,IAAI,IAAI,CAAC,CAAC;KACX;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAU,SAAiB,EAAE,UAAkB;IAC9E,IAAM,UAAU,GAAG,gBAAgB,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1D,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACrC,IAAM,eAAe,GAAG,OAAO,GAAG,EAAE,CAAC;IACrC,IAAM,GAAG,GAAG,eAAe,GAAG,GAAG,CAAC;IAClC,OAAO,GAAG,GAAG,GAAG,GAAG,UAAU,CAAC;AAChC,CAAC,CAAC","sourcesContent":["import { UNMASK_TEXT_CLASS } from './constants';\n\nexport const maskInputFn = (text: string, element: HTMLElement) => {\n if (element.classList?.contains(UNMASK_TEXT_CLASS)) {\n return text;\n }\n return '*'.repeat(text.length);\n};\n\nexport const generateHashCode = function (str: string) {\n let hash = 0;\n if (str.length === 0) return hash;\n for (let i = 0; i < str.length; i++) {\n const chr = str.charCodeAt(i);\n hash = (hash << 5) - hash + chr;\n hash |= 0;\n }\n return hash;\n};\n\nexport const isSessionInSample = function (sessionId: number, sampleRate: number) {\n const hashNumber = generateHashCode(sessionId.toString());\n const absHash = Math.abs(hashNumber);\n const absHashMultiply = absHash * 31;\n const mod = absHashMultiply % 100;\n return mod / 100 < sampleRate;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAsBA,OAAO,EAQL,mBAAmB,EACpB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAsBA,OAAO,EAQL,mBAAmB,EACpB,MAAM,0BAA0B,CAAC;AA8alC,eAAO,MAAM,mBAAmB,EAAE,mBAEjC,CAAC"}
|