@amplitude/session-replay-browser
Advanced tools
Comparing version 1.2.2 to 1.2.3
import { Logger as ILogger } from '@amplitude/analytics-types'; | ||
import { record } from '@amplitude/rrweb'; | ||
import { AmplitudeSessionReplay, SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore, SessionReplayTrackDestination as AmplitudeSessionReplayTrackDestination, Events, IDBStore, SessionIdentifiers as ISessionIdentifiers, SessionReplayConfig as ISessionReplayConfig, SessionReplayOptions } from './typings/session-replay'; | ||
import { AmplitudeSessionReplay, SessionReplayEventsManager as AmplitudeSessionReplayEventsManager, SessionIdentifiers as ISessionIdentifiers, SessionReplayConfig as ISessionReplayConfig, SessionReplayOptions } from './typings/session-replay'; | ||
export declare class SessionReplay implements AmplitudeSessionReplay { | ||
@@ -8,11 +8,5 @@ name: string; | ||
identifiers: ISessionIdentifiers | undefined; | ||
trackDestination: AmplitudeSessionReplayTrackDestination; | ||
sessionIDBStore: AmplitudeSessionReplaySessionIDBStore | undefined; | ||
eventsManager: AmplitudeSessionReplayEventsManager | undefined; | ||
loggerProvider: ILogger; | ||
events: Events; | ||
currentSequenceId: number; | ||
stopRecordingEvents: ReturnType<typeof record> | null; | ||
maxPersistedEventsSize: number; | ||
interval: number; | ||
timeAtLastSend: number | null; | ||
constructor(); | ||
@@ -33,16 +27,3 @@ init(apiKey: string, options: SessionReplayOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>; | ||
getBlockSelectors(): string | string[] | undefined; | ||
sendStoredEvents(storedReplaySessions: IDBStore): void; | ||
recordEvents(): void; | ||
/** | ||
* 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 | ||
*/ | ||
shouldSplitEventsList: (nextEventString: string) => boolean; | ||
sendEventsList({ events, sequenceId, sessionId }: { | ||
events: string[]; | ||
sequenceId: number; | ||
sessionId: number; | ||
}): void; | ||
getDeviceId(): string | undefined; | ||
@@ -49,0 +30,0 @@ getSessionId(): number | undefined; |
@@ -9,7 +9,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var constants_1 = require("./constants"); | ||
var events_manager_1 = require("./events-manager"); | ||
var helpers_1 = require("./helpers"); | ||
var identifiers_1 = require("./identifiers"); | ||
var session_idb_store_1 = require("./session-idb-store"); | ||
var track_destination_1 = require("./track-destination"); | ||
var session_replay_1 = require("./typings/session-replay"); | ||
var SessionReplay = /** @class */ (function () { | ||
@@ -19,8 +17,3 @@ function SessionReplay() { | ||
this.name = '@amplitude/session-replay-browser'; | ||
this.events = []; | ||
this.currentSequenceId = 0; | ||
this.stopRecordingEvents = null; | ||
this.maxPersistedEventsSize = constants_1.MAX_EVENT_LIST_SIZE_IN_BYTES; | ||
this.interval = constants_1.MIN_INTERVAL; | ||
this.timeAtLastSend = null; | ||
this.blurListener = function () { | ||
@@ -32,23 +25,3 @@ _this.stopRecordingAndSendEvents(); | ||
}; | ||
/** | ||
* 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.events.length) { | ||
_this.interval = Math.min(constants_1.MAX_INTERVAL, _this.interval + constants_1.MIN_INTERVAL); | ||
_this.timeAtLastSend = Date.now(); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
this.loggerProvider = new analytics_core_1.Logger(); | ||
this.trackDestination = new track_destination_1.SessionReplayTrackDestination({ loggerProvider: this.loggerProvider }); | ||
} | ||
@@ -67,7 +40,4 @@ SessionReplay.prototype.init = function (apiKey, options) { | ||
this.identifiers = new identifiers_1.SessionIdentifiers(options, this.loggerProvider); | ||
// Update logger provider in trackDestination | ||
this.trackDestination.setLoggerProvider(this.loggerProvider); | ||
this.sessionIDBStore = new session_idb_store_1.SessionReplaySessionIDBStore({ | ||
loggerProvider: this.loggerProvider, | ||
apiKey: this.config.apiKey, | ||
this.eventsManager = new events_manager_1.SessionReplayEventsManager({ | ||
config: this.config, | ||
}); | ||
@@ -109,4 +79,3 @@ this.loggerProvider.log('Installing @amplitude/session-replay-browser.'); | ||
this.identifiers.sessionId = sessionId; | ||
this.events = []; | ||
this.currentSequenceId = 0; | ||
this.eventsManager && this.eventsManager.resetSequence(); | ||
this.recordEvents(); | ||
@@ -155,9 +124,7 @@ }; | ||
var sessionIdToSend = sessionId || ((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId); | ||
if (this.events.length && sessionIdToSend) { | ||
this.sendEventsList({ | ||
events: this.events, | ||
sequenceId: this.currentSequenceId, | ||
sessionId: sessionIdToSend, | ||
}); | ||
} | ||
var deviceId = this.getDeviceId(); | ||
this.eventsManager && | ||
sessionIdToSend && | ||
deviceId && | ||
this.eventsManager.sendEvents({ sessionId: sessionIdToSend, deviceId: deviceId }); | ||
}; | ||
@@ -168,7 +135,6 @@ SessionReplay.prototype.initialize = function (shouldSendStoredEvents) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var storedReplaySessions, _b, storedSequencesForSession, storedSeqId, lastSequence; | ||
var deviceId, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
this.timeAtLastSend = Date.now(); // Initialize this so we have a point of comparison when events are recorded | ||
if (!((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId)) { | ||
@@ -178,5 +144,11 @@ this.loggerProvider.warn("Session is not being recorded due to lack of session id."); | ||
} | ||
_b = this.sessionIDBStore; | ||
deviceId = this.getDeviceId(); | ||
_b = this.eventsManager && | ||
deviceId; | ||
if (!_b) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.sessionIDBStore.getAllSessionDataFromStore()]; | ||
return [4 /*yield*/, this.eventsManager.initialize({ | ||
sessionId: this.identifiers.sessionId, | ||
shouldSendStoredEvents: shouldSendStoredEvents, | ||
deviceId: deviceId, | ||
})]; | ||
case 1: | ||
@@ -186,26 +158,3 @@ _b = (_c.sent()); | ||
case 2: | ||
storedReplaySessions = _b; | ||
// This resolves a timing issue when focus is fired multiple times in short succession, | ||
// we only want the rest of this function to run once. We can be sure that initialize has | ||
// already been called if this.stopRecordingEvents is defined | ||
if (this.stopRecordingEvents) { | ||
return [2 /*return*/]; | ||
} | ||
storedSequencesForSession = storedReplaySessions && storedReplaySessions[this.identifiers.sessionId]; | ||
if (storedReplaySessions && storedSequencesForSession && storedSequencesForSession.sessionSequences) { | ||
storedSeqId = storedSequencesForSession.currentSequenceId; | ||
lastSequence = storedSequencesForSession.sessionSequences[storedSeqId]; | ||
if (lastSequence && lastSequence.status !== session_replay_1.RecordingStatus.RECORDING) { | ||
this.currentSequenceId = storedSeqId + 1; | ||
this.events = []; | ||
} | ||
else { | ||
// Pick up recording where it was left off in another tab or window | ||
this.currentSequenceId = storedSeqId; | ||
this.events = (lastSequence === null || lastSequence === void 0 ? void 0 : lastSequence.events) || []; | ||
} | ||
} | ||
if (shouldSendStoredEvents && storedReplaySessions) { | ||
this.sendStoredEvents(storedReplaySessions); | ||
} | ||
_b; | ||
this.recordEvents(); | ||
@@ -259,23 +208,2 @@ return [2 /*return*/]; | ||
}; | ||
SessionReplay.prototype.sendStoredEvents = function (storedReplaySessions) { | ||
var _a; | ||
for (var sessionId in storedReplaySessions) { | ||
var storedSequences = storedReplaySessions[sessionId].sessionSequences; | ||
for (var storedSeqId in storedSequences) { | ||
var seq = storedSequences[storedSeqId]; | ||
var numericSeqId = parseInt(storedSeqId, 10); | ||
var numericSessionId = parseInt(sessionId, 10); | ||
if (numericSessionId === ((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId) && numericSeqId === this.currentSequenceId) { | ||
continue; | ||
} | ||
if (seq.events && seq.events.length && seq.status === session_replay_1.RecordingStatus.RECORDING) { | ||
this.sendEventsList({ | ||
events: seq.events, | ||
sequenceId: numericSeqId, | ||
sessionId: numericSessionId, | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
SessionReplay.prototype.recordEvents = function () { | ||
@@ -297,15 +225,4 @@ var _this = this; | ||
var eventString = JSON.stringify(event); | ||
var shouldSplit = _this.shouldSplitEventsList(eventString); | ||
if (shouldSplit && _this.config) { | ||
_this.sendEventsList({ | ||
events: _this.events, | ||
sequenceId: _this.currentSequenceId, | ||
sessionId: sessionId, | ||
}); | ||
_this.events = []; | ||
_this.currentSequenceId++; | ||
} | ||
_this.events.push(eventString); | ||
_this.sessionIDBStore && | ||
void _this.sessionIDBStore.storeEventsForSession(_this.events, _this.currentSequenceId, sessionId); | ||
var deviceId = _this.getDeviceId(); | ||
deviceId && _this.eventsManager && _this.eventsManager.addEvent({ event: eventString, sessionId: sessionId, deviceId: deviceId }); | ||
}, | ||
@@ -327,20 +244,2 @@ packFn: rrweb_1.pack, | ||
}; | ||
SessionReplay.prototype.sendEventsList = function (_a) { | ||
var events = _a.events, sequenceId = _a.sequenceId, sessionId = _a.sessionId; | ||
if (!this.config || !this.sessionIDBStore) { | ||
this.loggerProvider.error("Session is not being recorded due to lack of config, please call sessionReplay.init."); | ||
return; | ||
} | ||
this.trackDestination.sendEventsList({ | ||
events: events, | ||
sequenceId: sequenceId, | ||
sessionId: sessionId, | ||
flushMaxRetries: this.config.flushMaxRetries, | ||
apiKey: this.config.apiKey, | ||
deviceId: this.getDeviceId(), | ||
sampleRate: this.config.sampleRate, | ||
serverZone: this.config.serverZone, | ||
onComplete: this.sessionIDBStore.cleanUpSessionEventsStore.bind(this.sessionIDBStore), | ||
}); | ||
}; | ||
SessionReplay.prototype.getDeviceId = function () { | ||
@@ -363,4 +262,4 @@ var _a, _b; | ||
return tslib_1.__generator(this, function (_a) { | ||
if (this.trackDestination) { | ||
return [2 /*return*/, this.trackDestination.flush(useRetry)]; | ||
if (this.eventsManager) { | ||
return [2 /*return*/, this.eventsManager.flush(useRetry)]; | ||
} | ||
@@ -367,0 +266,0 @@ return [2 /*return*/]; |
@@ -12,3 +12,2 @@ import { Logger as ILogger, ServerZone } from '@amplitude/analytics-types'; | ||
}); | ||
setLoggerProvider(loggerProvider: ILogger): void; | ||
sendEventsList(destinationData: SessionReplayDestination): void; | ||
@@ -15,0 +14,0 @@ getServerUrl(serverZone?: keyof typeof ServerZone): "https://api-sr.amplitude.com/sessions/v2/track" | "https://api-sr.eu.amplitude.com/sessions/v2/track" | "https://api-sr.stag2.amplitude.com//sessions/v2/track"; |
@@ -19,5 +19,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
} | ||
SessionReplayTrackDestination.prototype.setLoggerProvider = function (loggerProvider) { | ||
this.loggerProvider = loggerProvider; | ||
}; | ||
SessionReplayTrackDestination.prototype.sendEventsList = function (destinationData) { | ||
@@ -24,0 +21,0 @@ this.addToQueue(tslib_1.__assign(tslib_1.__assign({}, destinationData), { attempts: 0, timeout: 0 })); |
@@ -70,5 +70,23 @@ import { AmplitudeReturn, Config, LogLevel, Logger, ServerZone } from '@amplitude/analytics-types'; | ||
sendEventsList: (destinationData: SessionReplayDestination) => void; | ||
setLoggerProvider: (loggerProvider: Logger) => void; | ||
flush: (useRetry: boolean) => Promise<void>; | ||
} | ||
export interface SessionReplayEventsManager { | ||
initialize({ sessionId, shouldSendStoredEvents, deviceId, }: { | ||
sessionId: number; | ||
shouldSendStoredEvents: boolean; | ||
deviceId: string; | ||
}): Promise<void>; | ||
addEvent({ sessionId, event, deviceId }: { | ||
sessionId: number; | ||
event: string; | ||
deviceId: string; | ||
}): void; | ||
sendEvents({ sessionId, deviceId }: { | ||
sessionId: number; | ||
deviceId: string; | ||
}): void; | ||
resetSequence(): void; | ||
flush(useRetry?: boolean): Promise<void>; | ||
events: Events; | ||
} | ||
//# sourceMappingURL=session-replay.d.ts.map |
import { Logger as ILogger } from '@amplitude/analytics-types'; | ||
import { record } from '@amplitude/rrweb'; | ||
import { AmplitudeSessionReplay, SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore, SessionReplayTrackDestination as AmplitudeSessionReplayTrackDestination, Events, IDBStore, SessionIdentifiers as ISessionIdentifiers, SessionReplayConfig as ISessionReplayConfig, SessionReplayOptions } from './typings/session-replay'; | ||
import { AmplitudeSessionReplay, SessionReplayEventsManager as AmplitudeSessionReplayEventsManager, SessionIdentifiers as ISessionIdentifiers, SessionReplayConfig as ISessionReplayConfig, SessionReplayOptions } from './typings/session-replay'; | ||
export declare class SessionReplay implements AmplitudeSessionReplay { | ||
@@ -8,11 +8,5 @@ name: string; | ||
identifiers: ISessionIdentifiers | undefined; | ||
trackDestination: AmplitudeSessionReplayTrackDestination; | ||
sessionIDBStore: AmplitudeSessionReplaySessionIDBStore | undefined; | ||
eventsManager: AmplitudeSessionReplayEventsManager | undefined; | ||
loggerProvider: ILogger; | ||
events: Events; | ||
currentSequenceId: number; | ||
stopRecordingEvents: ReturnType<typeof record> | null; | ||
maxPersistedEventsSize: number; | ||
interval: number; | ||
timeAtLastSend: number | null; | ||
constructor(); | ||
@@ -33,16 +27,3 @@ init(apiKey: string, options: SessionReplayOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>; | ||
getBlockSelectors(): string | string[] | undefined; | ||
sendStoredEvents(storedReplaySessions: IDBStore): void; | ||
recordEvents(): void; | ||
/** | ||
* 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 | ||
*/ | ||
shouldSplitEventsList: (nextEventString: string) => boolean; | ||
sendEventsList({ events, sequenceId, sessionId }: { | ||
events: string[]; | ||
sequenceId: number; | ||
sessionId: number; | ||
}): void; | ||
getDeviceId(): string | undefined; | ||
@@ -49,0 +30,0 @@ getSessionId(): number | undefined; |
@@ -6,8 +6,6 @@ import { __awaiter, __generator } from "tslib"; | ||
import { SessionReplayConfig } from './config'; | ||
import { BLOCK_CLASS, DEFAULT_SESSION_REPLAY_PROPERTY, MASK_TEXT_CLASS, MAX_EVENT_LIST_SIZE_IN_BYTES, MAX_INTERVAL, MIN_INTERVAL, SESSION_REPLAY_DEBUG_PROPERTY, } from './constants'; | ||
import { BLOCK_CLASS, DEFAULT_SESSION_REPLAY_PROPERTY, MASK_TEXT_CLASS, SESSION_REPLAY_DEBUG_PROPERTY, } from './constants'; | ||
import { SessionReplayEventsManager } from './events-manager'; | ||
import { generateHashCode, generateSessionReplayId, isSessionInSample, maskInputFn } from './helpers'; | ||
import { SessionIdentifiers } from './identifiers'; | ||
import { SessionReplaySessionIDBStore } from './session-idb-store'; | ||
import { SessionReplayTrackDestination } from './track-destination'; | ||
import { RecordingStatus, } from './typings/session-replay'; | ||
var SessionReplay = /** @class */ (function () { | ||
@@ -17,8 +15,3 @@ function SessionReplay() { | ||
this.name = '@amplitude/session-replay-browser'; | ||
this.events = []; | ||
this.currentSequenceId = 0; | ||
this.stopRecordingEvents = null; | ||
this.maxPersistedEventsSize = MAX_EVENT_LIST_SIZE_IN_BYTES; | ||
this.interval = MIN_INTERVAL; | ||
this.timeAtLastSend = null; | ||
this.blurListener = function () { | ||
@@ -30,23 +23,3 @@ _this.stopRecordingAndSendEvents(); | ||
}; | ||
/** | ||
* 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.events.length) { | ||
_this.interval = Math.min(MAX_INTERVAL, _this.interval + MIN_INTERVAL); | ||
_this.timeAtLastSend = Date.now(); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
this.loggerProvider = new Logger(); | ||
this.trackDestination = new SessionReplayTrackDestination({ loggerProvider: this.loggerProvider }); | ||
} | ||
@@ -65,7 +38,4 @@ SessionReplay.prototype.init = function (apiKey, options) { | ||
this.identifiers = new SessionIdentifiers(options, this.loggerProvider); | ||
// Update logger provider in trackDestination | ||
this.trackDestination.setLoggerProvider(this.loggerProvider); | ||
this.sessionIDBStore = new SessionReplaySessionIDBStore({ | ||
loggerProvider: this.loggerProvider, | ||
apiKey: this.config.apiKey, | ||
this.eventsManager = new SessionReplayEventsManager({ | ||
config: this.config, | ||
}); | ||
@@ -107,4 +77,3 @@ this.loggerProvider.log('Installing @amplitude/session-replay-browser.'); | ||
this.identifiers.sessionId = sessionId; | ||
this.events = []; | ||
this.currentSequenceId = 0; | ||
this.eventsManager && this.eventsManager.resetSequence(); | ||
this.recordEvents(); | ||
@@ -153,9 +122,7 @@ }; | ||
var sessionIdToSend = sessionId || ((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId); | ||
if (this.events.length && sessionIdToSend) { | ||
this.sendEventsList({ | ||
events: this.events, | ||
sequenceId: this.currentSequenceId, | ||
sessionId: sessionIdToSend, | ||
}); | ||
} | ||
var deviceId = this.getDeviceId(); | ||
this.eventsManager && | ||
sessionIdToSend && | ||
deviceId && | ||
this.eventsManager.sendEvents({ sessionId: sessionIdToSend, deviceId: deviceId }); | ||
}; | ||
@@ -166,7 +133,6 @@ SessionReplay.prototype.initialize = function (shouldSendStoredEvents) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var storedReplaySessions, _b, storedSequencesForSession, storedSeqId, lastSequence; | ||
var deviceId, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
this.timeAtLastSend = Date.now(); // Initialize this so we have a point of comparison when events are recorded | ||
if (!((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId)) { | ||
@@ -176,5 +142,11 @@ this.loggerProvider.warn("Session is not being recorded due to lack of session id."); | ||
} | ||
_b = this.sessionIDBStore; | ||
deviceId = this.getDeviceId(); | ||
_b = this.eventsManager && | ||
deviceId; | ||
if (!_b) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.sessionIDBStore.getAllSessionDataFromStore()]; | ||
return [4 /*yield*/, this.eventsManager.initialize({ | ||
sessionId: this.identifiers.sessionId, | ||
shouldSendStoredEvents: shouldSendStoredEvents, | ||
deviceId: deviceId, | ||
})]; | ||
case 1: | ||
@@ -184,26 +156,3 @@ _b = (_c.sent()); | ||
case 2: | ||
storedReplaySessions = _b; | ||
// This resolves a timing issue when focus is fired multiple times in short succession, | ||
// we only want the rest of this function to run once. We can be sure that initialize has | ||
// already been called if this.stopRecordingEvents is defined | ||
if (this.stopRecordingEvents) { | ||
return [2 /*return*/]; | ||
} | ||
storedSequencesForSession = storedReplaySessions && storedReplaySessions[this.identifiers.sessionId]; | ||
if (storedReplaySessions && storedSequencesForSession && storedSequencesForSession.sessionSequences) { | ||
storedSeqId = storedSequencesForSession.currentSequenceId; | ||
lastSequence = storedSequencesForSession.sessionSequences[storedSeqId]; | ||
if (lastSequence && lastSequence.status !== RecordingStatus.RECORDING) { | ||
this.currentSequenceId = storedSeqId + 1; | ||
this.events = []; | ||
} | ||
else { | ||
// Pick up recording where it was left off in another tab or window | ||
this.currentSequenceId = storedSeqId; | ||
this.events = (lastSequence === null || lastSequence === void 0 ? void 0 : lastSequence.events) || []; | ||
} | ||
} | ||
if (shouldSendStoredEvents && storedReplaySessions) { | ||
this.sendStoredEvents(storedReplaySessions); | ||
} | ||
_b; | ||
this.recordEvents(); | ||
@@ -257,23 +206,2 @@ return [2 /*return*/]; | ||
}; | ||
SessionReplay.prototype.sendStoredEvents = function (storedReplaySessions) { | ||
var _a; | ||
for (var sessionId in storedReplaySessions) { | ||
var storedSequences = storedReplaySessions[sessionId].sessionSequences; | ||
for (var storedSeqId in storedSequences) { | ||
var seq = storedSequences[storedSeqId]; | ||
var numericSeqId = parseInt(storedSeqId, 10); | ||
var numericSessionId = parseInt(sessionId, 10); | ||
if (numericSessionId === ((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId) && numericSeqId === this.currentSequenceId) { | ||
continue; | ||
} | ||
if (seq.events && seq.events.length && seq.status === RecordingStatus.RECORDING) { | ||
this.sendEventsList({ | ||
events: seq.events, | ||
sequenceId: numericSeqId, | ||
sessionId: numericSessionId, | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
SessionReplay.prototype.recordEvents = function () { | ||
@@ -295,15 +223,4 @@ var _this = this; | ||
var eventString = JSON.stringify(event); | ||
var shouldSplit = _this.shouldSplitEventsList(eventString); | ||
if (shouldSplit && _this.config) { | ||
_this.sendEventsList({ | ||
events: _this.events, | ||
sequenceId: _this.currentSequenceId, | ||
sessionId: sessionId, | ||
}); | ||
_this.events = []; | ||
_this.currentSequenceId++; | ||
} | ||
_this.events.push(eventString); | ||
_this.sessionIDBStore && | ||
void _this.sessionIDBStore.storeEventsForSession(_this.events, _this.currentSequenceId, sessionId); | ||
var deviceId = _this.getDeviceId(); | ||
deviceId && _this.eventsManager && _this.eventsManager.addEvent({ event: eventString, sessionId: sessionId, deviceId: deviceId }); | ||
}, | ||
@@ -325,20 +242,2 @@ packFn: pack, | ||
}; | ||
SessionReplay.prototype.sendEventsList = function (_a) { | ||
var events = _a.events, sequenceId = _a.sequenceId, sessionId = _a.sessionId; | ||
if (!this.config || !this.sessionIDBStore) { | ||
this.loggerProvider.error("Session is not being recorded due to lack of config, please call sessionReplay.init."); | ||
return; | ||
} | ||
this.trackDestination.sendEventsList({ | ||
events: events, | ||
sequenceId: sequenceId, | ||
sessionId: sessionId, | ||
flushMaxRetries: this.config.flushMaxRetries, | ||
apiKey: this.config.apiKey, | ||
deviceId: this.getDeviceId(), | ||
sampleRate: this.config.sampleRate, | ||
serverZone: this.config.serverZone, | ||
onComplete: this.sessionIDBStore.cleanUpSessionEventsStore.bind(this.sessionIDBStore), | ||
}); | ||
}; | ||
SessionReplay.prototype.getDeviceId = function () { | ||
@@ -361,4 +260,4 @@ var _a, _b; | ||
return __generator(this, function (_a) { | ||
if (this.trackDestination) { | ||
return [2 /*return*/, this.trackDestination.flush(useRetry)]; | ||
if (this.eventsManager) { | ||
return [2 /*return*/, this.eventsManager.flush(useRetry)]; | ||
} | ||
@@ -365,0 +264,0 @@ return [2 /*return*/]; |
@@ -12,3 +12,2 @@ import { Logger as ILogger, ServerZone } from '@amplitude/analytics-types'; | ||
}); | ||
setLoggerProvider(loggerProvider: ILogger): void; | ||
sendEventsList(destinationData: SessionReplayDestination): void; | ||
@@ -15,0 +14,0 @@ getServerUrl(serverZone?: keyof typeof ServerZone): "https://api-sr.amplitude.com/sessions/v2/track" | "https://api-sr.eu.amplitude.com/sessions/v2/track" | "https://api-sr.stag2.amplitude.com//sessions/v2/track"; |
@@ -17,5 +17,2 @@ import { __assign, __awaiter, __generator } from "tslib"; | ||
} | ||
SessionReplayTrackDestination.prototype.setLoggerProvider = function (loggerProvider) { | ||
this.loggerProvider = loggerProvider; | ||
}; | ||
SessionReplayTrackDestination.prototype.sendEventsList = function (destinationData) { | ||
@@ -22,0 +19,0 @@ this.addToQueue(__assign(__assign({}, destinationData), { attempts: 0, timeout: 0 })); |
@@ -70,5 +70,23 @@ import { AmplitudeReturn, Config, LogLevel, Logger, ServerZone } from '@amplitude/analytics-types'; | ||
sendEventsList: (destinationData: SessionReplayDestination) => void; | ||
setLoggerProvider: (loggerProvider: Logger) => void; | ||
flush: (useRetry: boolean) => Promise<void>; | ||
} | ||
export interface SessionReplayEventsManager { | ||
initialize({ sessionId, shouldSendStoredEvents, deviceId, }: { | ||
sessionId: number; | ||
shouldSendStoredEvents: boolean; | ||
deviceId: string; | ||
}): Promise<void>; | ||
addEvent({ sessionId, event, deviceId }: { | ||
sessionId: number; | ||
event: string; | ||
deviceId: string; | ||
}): void; | ||
sendEvents({ sessionId, deviceId }: { | ||
sessionId: number; | ||
deviceId: string; | ||
}): void; | ||
resetSequence(): void; | ||
flush(useRetry?: boolean): Promise<void>; | ||
events: Events; | ||
} | ||
//# sourceMappingURL=session-replay.d.ts.map |
import { Logger as ILogger } from '@amplitude/analytics-types'; | ||
import { record } from '@amplitude/rrweb'; | ||
import { AmplitudeSessionReplay, SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore, SessionReplayTrackDestination as AmplitudeSessionReplayTrackDestination, Events, IDBStore, SessionIdentifiers as ISessionIdentifiers, SessionReplayConfig as ISessionReplayConfig, SessionReplayOptions } from './typings/session-replay'; | ||
import { AmplitudeSessionReplay, SessionReplayEventsManager as AmplitudeSessionReplayEventsManager, SessionIdentifiers as ISessionIdentifiers, SessionReplayConfig as ISessionReplayConfig, SessionReplayOptions } from './typings/session-replay'; | ||
export declare class SessionReplay implements AmplitudeSessionReplay { | ||
@@ -8,11 +8,5 @@ name: string; | ||
identifiers: ISessionIdentifiers | undefined; | ||
trackDestination: AmplitudeSessionReplayTrackDestination; | ||
sessionIDBStore: AmplitudeSessionReplaySessionIDBStore | undefined; | ||
eventsManager: AmplitudeSessionReplayEventsManager | undefined; | ||
loggerProvider: ILogger; | ||
events: Events; | ||
currentSequenceId: number; | ||
stopRecordingEvents: ReturnType<typeof record> | null; | ||
maxPersistedEventsSize: number; | ||
interval: number; | ||
timeAtLastSend: number | null; | ||
constructor(); | ||
@@ -33,16 +27,3 @@ init(apiKey: string, options: SessionReplayOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>; | ||
getBlockSelectors(): string | string[] | undefined; | ||
sendStoredEvents(storedReplaySessions: IDBStore): void; | ||
recordEvents(): void; | ||
/** | ||
* 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 | ||
*/ | ||
shouldSplitEventsList: (nextEventString: string) => boolean; | ||
sendEventsList({ events, sequenceId, sessionId }: { | ||
events: string[]; | ||
sequenceId: number; | ||
sessionId: number; | ||
}): void; | ||
getDeviceId(): string | undefined; | ||
@@ -49,0 +30,0 @@ getSessionId(): number | undefined; |
@@ -12,3 +12,2 @@ import { Logger as ILogger, ServerZone } from '@amplitude/analytics-types'; | ||
}); | ||
setLoggerProvider(loggerProvider: ILogger): void; | ||
sendEventsList(destinationData: SessionReplayDestination): void; | ||
@@ -15,0 +14,0 @@ getServerUrl(serverZone?: keyof typeof ServerZone): "https://api-sr.amplitude.com/sessions/v2/track" | "https://api-sr.eu.amplitude.com/sessions/v2/track" | "https://api-sr.stag2.amplitude.com//sessions/v2/track"; |
@@ -70,5 +70,23 @@ import { AmplitudeReturn, Config, LogLevel, Logger, ServerZone } from '@amplitude/analytics-types'; | ||
sendEventsList: (destinationData: SessionReplayDestination) => void; | ||
setLoggerProvider: (loggerProvider: Logger) => void; | ||
flush: (useRetry: boolean) => Promise<void>; | ||
} | ||
export interface SessionReplayEventsManager { | ||
initialize({ sessionId, shouldSendStoredEvents, deviceId, }: { | ||
sessionId: number; | ||
shouldSendStoredEvents: boolean; | ||
deviceId: string; | ||
}): Promise<void>; | ||
addEvent({ sessionId, event, deviceId }: { | ||
sessionId: number; | ||
event: string; | ||
deviceId: string; | ||
}): void; | ||
sendEvents({ sessionId, deviceId }: { | ||
sessionId: number; | ||
deviceId: string; | ||
}): void; | ||
resetSequence(): void; | ||
flush(useRetry?: boolean): Promise<void>; | ||
events: Events; | ||
} | ||
//# sourceMappingURL=session-replay.d.ts.map |
{ | ||
"name": "@amplitude/session-replay-browser", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "", | ||
@@ -60,3 +60,3 @@ "author": "Amplitude Inc", | ||
], | ||
"gitHead": "d8890068210e67d23ab1a853b553e4685a55253c" | ||
"gitHead": "223e05b7591afe6ae2876f4b0b6dbcb1147d231d" | ||
} |
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 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
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
571105
137
3416
10