@amplitude/plugin-session-replay-browser
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -9,3 +9,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var constants_1 = require("./constants"); | ||
var helpers_1 = require("./helpers"); | ||
var messages_1 = require("./messages"); | ||
@@ -16,4 +15,7 @@ var SESSION_REPLAY_SERVER_URL = 'https://api-secure.amplitude.com/sessions/track'; | ||
var MAX_EVENT_LIST_SIZE_IN_BYTES = 20 * 1000000 - PAYLOAD_ESTIMATED_SIZE_IN_BYTES_WITHOUT_EVENTS; | ||
var MIN_INTERVAL = 1 * 1000; // 1 second | ||
var MAX_INTERVAL = 10 * 1000; // 10 seconds | ||
var SessionReplay = /** @class */ (function () { | ||
function SessionReplay() { | ||
var _this = this; | ||
this.name = '@amplitude/plugin-session-replay-browser'; | ||
@@ -29,2 +31,22 @@ this.type = 'enrichment'; | ||
this.maxPersistedEventsSize = MAX_EVENT_LIST_SIZE_IN_BYTES; | ||
this.interval = MIN_INTERVAL; | ||
this.timeAtLastSend = null; | ||
/** | ||
* Determines whether to send the events list to the backend and start a new | ||
* empty events list, based on the size of the list as well as the last time sent | ||
* @param nextEventString | ||
* @returns boolean | ||
*/ | ||
this.shouldSplitEventsList = function (nextEventString) { | ||
var sizeOfNextEvent = new Blob([nextEventString]).size; | ||
var sizeOfEventsList = new Blob(_this.events).size; | ||
if (sizeOfEventsList + sizeOfNextEvent >= _this.maxPersistedEventsSize) { | ||
return true; | ||
} | ||
if (_this.timeAtLastSend !== null && Date.now() - _this.timeAtLastSend > _this.interval) { | ||
_this.interval = Math.min(MAX_INTERVAL, _this.interval + MIN_INTERVAL); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
} | ||
@@ -47,4 +69,3 @@ SessionReplay.prototype.setup = function (config) { | ||
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), (_a = {}, _a[constants_1.DEFAULT_SESSION_REPLAY_PROPERTY] = true, _a)); | ||
if (event.event_type === constants_1.DEFAULT_SESSION_START_EVENT && this.stopRecordingEvents) { | ||
this.stopRecordingEvents(); | ||
if (event.event_type === constants_1.DEFAULT_SESSION_START_EVENT) { | ||
this.recordEvents(); | ||
@@ -60,2 +81,3 @@ } | ||
} | ||
this.stopRecordingEvents && this.stopRecordingEvents(); | ||
this.events = []; | ||
@@ -103,3 +125,14 @@ this.currentSequenceId = 0; | ||
var eventString = JSON.stringify(event); | ||
var shouldSplit = (0, helpers_1.shouldSplitEventsList)(_this.events, eventString, _this.maxPersistedEventsSize); | ||
// Send the first two recorded events immediately | ||
if (_this.events.length === 1 && _this.currentSequenceId === 0) { | ||
_this.sendEventsList({ | ||
events: _this.events.concat(eventString), | ||
sequenceId: _this.currentSequenceId, | ||
sessionId: _this.config.sessionId, | ||
}); | ||
_this.events = []; | ||
_this.currentSequenceId++; | ||
return; | ||
} | ||
var shouldSplit = _this.shouldSplitEventsList(eventString); | ||
if (shouldSplit) { | ||
@@ -118,2 +151,3 @@ _this.sendEventsList({ | ||
packFn: rrweb_1.pack, | ||
maskAllInputs: true, | ||
}); | ||
@@ -151,3 +185,3 @@ }; | ||
if (context.timeout === 0) { | ||
_this.schedule(_this.config.flushIntervalMillis); | ||
_this.schedule(0); | ||
return; | ||
@@ -352,2 +386,3 @@ } | ||
else if (success) { | ||
this.timeAtLastSend = Date.now(); | ||
this.config.loggerProvider.log(success); | ||
@@ -354,0 +389,0 @@ } |
@@ -25,3 +25,5 @@ import { BrowserClient, BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
currentSequenceId: number; | ||
interval: number; | ||
queue: SessionReplayContext[]; | ||
timeAtLastSend: number | null; | ||
stopRecordingEvents: ReturnType<typeof record> | null; | ||
@@ -31,2 +33,3 @@ maxPersistedEventsSize: number; | ||
recordEvents: () => void; | ||
shouldSplitEventsList: (nextEventString: string) => boolean; | ||
sendEventsList: ({ events, sequenceId, sessionId, }: { | ||
@@ -33,0 +36,0 @@ events: string[]; |
@@ -7,3 +7,2 @@ import { __assign, __awaiter, __generator } from "tslib"; | ||
import { DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_REPLAY_PROPERTY, DEFAULT_SESSION_START_EVENT } from './constants'; | ||
import { shouldSplitEventsList } from './helpers'; | ||
import { MAX_RETRIES_EXCEEDED_MESSAGE, STORAGE_FAILURE, SUCCESS_MESSAGE, UNEXPECTED_ERROR_MESSAGE } from './messages'; | ||
@@ -14,4 +13,7 @@ var SESSION_REPLAY_SERVER_URL = 'https://api-secure.amplitude.com/sessions/track'; | ||
var MAX_EVENT_LIST_SIZE_IN_BYTES = 20 * 1000000 - PAYLOAD_ESTIMATED_SIZE_IN_BYTES_WITHOUT_EVENTS; | ||
var MIN_INTERVAL = 1 * 1000; // 1 second | ||
var MAX_INTERVAL = 10 * 1000; // 10 seconds | ||
var SessionReplay = /** @class */ (function () { | ||
function SessionReplay() { | ||
var _this = this; | ||
this.name = '@amplitude/plugin-session-replay-browser'; | ||
@@ -27,2 +29,22 @@ this.type = 'enrichment'; | ||
this.maxPersistedEventsSize = MAX_EVENT_LIST_SIZE_IN_BYTES; | ||
this.interval = MIN_INTERVAL; | ||
this.timeAtLastSend = null; | ||
/** | ||
* Determines whether to send the events list to the backend and start a new | ||
* empty events list, based on the size of the list as well as the last time sent | ||
* @param nextEventString | ||
* @returns boolean | ||
*/ | ||
this.shouldSplitEventsList = function (nextEventString) { | ||
var sizeOfNextEvent = new Blob([nextEventString]).size; | ||
var sizeOfEventsList = new Blob(_this.events).size; | ||
if (sizeOfEventsList + sizeOfNextEvent >= _this.maxPersistedEventsSize) { | ||
return true; | ||
} | ||
if (_this.timeAtLastSend !== null && Date.now() - _this.timeAtLastSend > _this.interval) { | ||
_this.interval = Math.min(MAX_INTERVAL, _this.interval + MIN_INTERVAL); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
} | ||
@@ -45,4 +67,3 @@ SessionReplay.prototype.setup = function (config) { | ||
event.event_properties = __assign(__assign({}, event.event_properties), (_a = {}, _a[DEFAULT_SESSION_REPLAY_PROPERTY] = true, _a)); | ||
if (event.event_type === DEFAULT_SESSION_START_EVENT && this.stopRecordingEvents) { | ||
this.stopRecordingEvents(); | ||
if (event.event_type === DEFAULT_SESSION_START_EVENT) { | ||
this.recordEvents(); | ||
@@ -58,2 +79,3 @@ } | ||
} | ||
this.stopRecordingEvents && this.stopRecordingEvents(); | ||
this.events = []; | ||
@@ -101,3 +123,14 @@ this.currentSequenceId = 0; | ||
var eventString = JSON.stringify(event); | ||
var shouldSplit = shouldSplitEventsList(_this.events, eventString, _this.maxPersistedEventsSize); | ||
// Send the first two recorded events immediately | ||
if (_this.events.length === 1 && _this.currentSequenceId === 0) { | ||
_this.sendEventsList({ | ||
events: _this.events.concat(eventString), | ||
sequenceId: _this.currentSequenceId, | ||
sessionId: _this.config.sessionId, | ||
}); | ||
_this.events = []; | ||
_this.currentSequenceId++; | ||
return; | ||
} | ||
var shouldSplit = _this.shouldSplitEventsList(eventString); | ||
if (shouldSplit) { | ||
@@ -116,2 +149,3 @@ _this.sendEventsList({ | ||
packFn: pack, | ||
maskAllInputs: true, | ||
}); | ||
@@ -149,3 +183,3 @@ }; | ||
if (context.timeout === 0) { | ||
_this.schedule(_this.config.flushIntervalMillis); | ||
_this.schedule(0); | ||
return; | ||
@@ -350,2 +384,3 @@ } | ||
else if (success) { | ||
this.timeAtLastSend = Date.now(); | ||
this.config.loggerProvider.log(success); | ||
@@ -352,0 +387,0 @@ } |
@@ -25,3 +25,5 @@ import { BrowserClient, BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
currentSequenceId: number; | ||
interval: number; | ||
queue: SessionReplayContext[]; | ||
timeAtLastSend: number | null; | ||
stopRecordingEvents: ReturnType<typeof record> | null; | ||
@@ -31,2 +33,3 @@ maxPersistedEventsSize: number; | ||
recordEvents: () => void; | ||
shouldSplitEventsList: (nextEventString: string) => boolean; | ||
sendEventsList: ({ events, sequenceId, sessionId, }: { | ||
@@ -33,0 +36,0 @@ events: string[]; |
@@ -25,3 +25,5 @@ import { BrowserClient, BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
currentSequenceId: number; | ||
interval: number; | ||
queue: SessionReplayContext[]; | ||
timeAtLastSend: number | null; | ||
stopRecordingEvents: ReturnType<typeof record> | null; | ||
@@ -31,2 +33,3 @@ maxPersistedEventsSize: number; | ||
recordEvents: () => void; | ||
shouldSplitEventsList: (nextEventString: string) => boolean; | ||
sendEventsList: ({ events, sequenceId, sessionId, }: { | ||
@@ -33,0 +36,0 @@ events: string[]; |
{ | ||
"name": "@amplitude/plugin-session-replay-browser", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "", | ||
@@ -40,4 +40,3 @@ "author": "Amplitude Inc", | ||
"dependencies": { | ||
"@amplitude/analytics-client-common": "^1.1.1", | ||
"@amplitude/analytics-types": "^1.3.1", | ||
"@amplitude/analytics-types": ">=1 <3", | ||
"idb-keyval": "^6.2.1", | ||
@@ -48,3 +47,3 @@ "rrweb": "^2.0.0-alpha.4", | ||
"devDependencies": { | ||
"@amplitude/analytics-browser": "^1.12.1", | ||
"@amplitude/analytics-client-common": ">=1 <3", | ||
"@rollup/plugin-commonjs": "^23.0.4", | ||
@@ -61,3 +60,3 @@ "@rollup/plugin-node-resolve": "^15.0.1", | ||
], | ||
"gitHead": "bc426d86b020aa96c9dc3a824aaaecf22213b32f" | ||
"gitHead": "ee064fe94bd1f5c24f106c70b14cbfca2cda1364" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
344443
4
1680
57
+ Added@amplitude/analytics-types@2.8.4(transitive)
- Removed@amplitude/analytics-client-common@1.2.3(transitive)
- Removed@amplitude/analytics-connector@1.6.1(transitive)
- Removed@amplitude/analytics-core@1.2.5(transitive)
- Removed@amplitude/analytics-types@1.3.4(transitive)
- Removed@amplitude/experiment-core@0.10.0(transitive)
- Removedjs-base64@3.7.7(transitive)