@amplitude/plugin-session-replay-browser
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -19,3 +19,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultSessionStore = { | ||
shouldRecord: true, | ||
currentSequenceId: 0, | ||
@@ -22,0 +21,0 @@ sessionSequences: {}, |
export declare const maskInputFn: (text: string, element: HTMLElement) => string; | ||
export declare const generateHashCode: (str: string) => number; | ||
export declare const isSessionInSample: (sessionId: number, sampleRate: number) => boolean; | ||
//# sourceMappingURL=helpers.d.ts.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.maskInputFn = void 0; | ||
exports.isSessionInSample = exports.generateHashCode = exports.maskInputFn = void 0; | ||
var constants_1 = require("./constants"); | ||
@@ -12,2 +12,22 @@ var maskInputFn = function (text, element) { | ||
exports.maskInputFn = maskInputFn; | ||
var generateHashCode = function (str) { | ||
var hash = 0; | ||
if (str.length === 0) | ||
return hash; | ||
for (var i = 0; i < str.length; i++) { | ||
var chr = str.charCodeAt(i); | ||
hash = (hash << 5) - hash + chr; | ||
hash |= 0; | ||
} | ||
return hash; | ||
}; | ||
exports.generateHashCode = generateHashCode; | ||
var isSessionInSample = function (sessionId, sampleRate) { | ||
var hashNumber = (0, exports.generateHashCode)(sessionId.toString()); | ||
var absHash = Math.abs(hashNumber); | ||
var absHashMultiply = absHash * 31; | ||
var mod = absHashMultiply % 100; | ||
return mod / 100 < sampleRate; | ||
}; | ||
exports.isSessionInSample = isSessionInSample; | ||
//# sourceMappingURL=helpers.js.map |
@@ -28,3 +28,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this.timeAtLastSend = null; | ||
this.shouldRecord = true; | ||
/** | ||
@@ -97,3 +96,3 @@ * Determines whether to send the events list to the backend and start a new | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var GlobalScope; | ||
var GlobalScope, shouldRecord; | ||
var _a; | ||
@@ -105,7 +104,3 @@ return tslib_1.__generator(this, function (_b) { | ||
} | ||
if (this.shouldRecord) { | ||
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.setShouldRecord(); | ||
this.recordEvents(); | ||
@@ -126,2 +121,6 @@ } | ||
} | ||
shouldRecord = this.getShouldRecord(); | ||
if (shouldRecord) { | ||
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), (_a = {}, _a[constants_1.DEFAULT_SESSION_REPLAY_PROPERTY] = true, _a)); | ||
} | ||
return [2 /*return*/, Promise.resolve(event)]; | ||
@@ -165,3 +164,2 @@ }); | ||
} | ||
this.setShouldRecord(storedSequencesForSession); | ||
if (shouldSendStoredEvents && storedReplaySessions) { | ||
@@ -176,16 +174,13 @@ this.sendStoredEvents(storedReplaySessions); | ||
}; | ||
SessionReplay.prototype.setShouldRecord = function (sessionStore) { | ||
if (sessionStore && typeof sessionStore.shouldRecord === 'boolean') { | ||
this.shouldRecord = sessionStore.shouldRecord; | ||
SessionReplay.prototype.getShouldRecord = function () { | ||
if (this.config.optOut) { | ||
return false; | ||
} | ||
else if (this.config.optOut) { | ||
this.shouldRecord = false; | ||
else if (!this.config.sessionId) { | ||
return false; | ||
} | ||
else if (this.options && this.options.sampleRate) { | ||
this.shouldRecord = Math.random() < this.options.sampleRate; | ||
return (0, helpers_1.isSessionInSample)(this.config.sessionId, this.options.sampleRate); | ||
} | ||
this.config.sessionId && void this.storeShouldRecordForSession(this.config.sessionId, this.shouldRecord); | ||
if (!this.shouldRecord && this.config.sessionId) { | ||
this.config.loggerProvider.log("Opting session ".concat(this.config.sessionId, " out of recording.")); | ||
} | ||
return true; | ||
}; | ||
@@ -214,3 +209,5 @@ SessionReplay.prototype.sendStoredEvents = function (storedReplaySessions) { | ||
var _this = this; | ||
if (!this.shouldRecord) { | ||
var shouldRecord = this.getShouldRecord(); | ||
if (!shouldRecord && this.config.sessionId) { | ||
this.config.loggerProvider.log("Opting session ".concat(this.config.sessionId, " out of recording.")); | ||
return; | ||
@@ -452,3 +449,3 @@ } | ||
}; | ||
SessionReplay.prototype.storeShouldRecordForSession = function (sessionId, shouldRecord) { | ||
SessionReplay.prototype.cleanUpSessionEventsStore = function (sessionId, sequenceId) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
@@ -461,29 +458,3 @@ var e_4; | ||
return [4 /*yield*/, IDBKeyVal.update(this.storageKey, function (sessionMap) { | ||
var _a; | ||
if (sessionMap === void 0) { sessionMap = {}; } | ||
var session = sessionMap[sessionId] || tslib_1.__assign({}, constants_1.defaultSessionStore); | ||
session.shouldRecord = shouldRecord; | ||
return tslib_1.__assign(tslib_1.__assign({}, sessionMap), (_a = {}, _a[sessionId] = session, _a)); | ||
})]; | ||
case 1: | ||
_a.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
e_4 = _a.sent(); | ||
this.config.loggerProvider.error("".concat(messages_1.STORAGE_FAILURE, ": ").concat(e_4)); | ||
return [3 /*break*/, 3]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SessionReplay.prototype.cleanUpSessionEventsStore = function (sessionId, sequenceId) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var e_5; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, IDBKeyVal.update(this.storageKey, function (sessionMap) { | ||
if (sessionMap === void 0) { sessionMap = {}; } | ||
var session = sessionMap[sessionId]; | ||
@@ -517,4 +488,4 @@ var sequenceToUpdate = (session === null || session === void 0 ? void 0 : session.sessionSequences) && session.sessionSequences[sequenceId]; | ||
case 2: | ||
e_5 = _a.sent(); | ||
this.config.loggerProvider.error("".concat(messages_1.STORAGE_FAILURE, ": ").concat(e_5)); | ||
e_4 = _a.sent(); | ||
this.config.loggerProvider.error("".concat(messages_1.STORAGE_FAILURE, ": ").concat(e_4)); | ||
return [3 /*break*/, 3]; | ||
@@ -521,0 +492,0 @@ case 3: return [2 /*return*/]; |
@@ -24,3 +24,2 @@ import { BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
export interface IDBStoreSession { | ||
shouldRecord: boolean; | ||
currentSequenceId: number; | ||
@@ -42,3 +41,2 @@ sessionSequences: { | ||
interval: number; | ||
shouldRecord: boolean; | ||
queue: SessionReplayContext[]; | ||
@@ -49,3 +47,3 @@ timeAtLastSend: number | null; | ||
initialize: (shouldSendStoredEvents?: boolean) => Promise<void>; | ||
setShouldRecord: (sessionStore?: IDBStoreSession) => void; | ||
getShouldRecord: () => boolean; | ||
recordEvents: () => void; | ||
@@ -70,3 +68,2 @@ shouldSplitEventsList: (nextEventString: string) => boolean; | ||
storeEventsForSession: (events: Events, sequenceId: number, sessionId: number) => Promise<void>; | ||
storeShouldRecordForSession: (sessionId: number, shouldRecord: boolean) => Promise<void>; | ||
cleanUpSessionEventsStore: (sessionId: number, sequenceId: number) => Promise<void>; | ||
@@ -73,0 +70,0 @@ } |
@@ -17,3 +17,2 @@ import { AMPLITUDE_PREFIX } from '@amplitude/analytics-core'; | ||
export var defaultSessionStore = { | ||
shouldRecord: true, | ||
currentSequenceId: 0, | ||
@@ -20,0 +19,0 @@ sessionSequences: {}, |
export declare const maskInputFn: (text: string, element: HTMLElement) => string; | ||
export declare const generateHashCode: (str: string) => number; | ||
export declare const isSessionInSample: (sessionId: number, sampleRate: number) => boolean; | ||
//# sourceMappingURL=helpers.d.ts.map |
@@ -9,2 +9,20 @@ import { UNMASK_TEXT_CLASS } from './constants'; | ||
}; | ||
export var generateHashCode = function (str) { | ||
var hash = 0; | ||
if (str.length === 0) | ||
return hash; | ||
for (var i = 0; i < str.length; i++) { | ||
var chr = str.charCodeAt(i); | ||
hash = (hash << 5) - hash + chr; | ||
hash |= 0; | ||
} | ||
return hash; | ||
}; | ||
export var isSessionInSample = function (sessionId, sampleRate) { | ||
var hashNumber = generateHashCode(sessionId.toString()); | ||
var absHash = Math.abs(hashNumber); | ||
var absHashMultiply = absHash * 31; | ||
var mod = absHashMultiply % 100; | ||
return mod / 100 < sampleRate; | ||
}; | ||
//# sourceMappingURL=helpers.js.map |
@@ -7,4 +7,4 @@ import { __assign, __awaiter, __generator, __read } from "tslib"; | ||
import { pack, record } from 'rrweb'; | ||
import { BLOCK_CLASS, DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_REPLAY_PROPERTY, DEFAULT_SESSION_START_EVENT, MASK_TEXT_CLASS, MAX_EVENT_LIST_SIZE_IN_BYTES, MAX_IDB_STORAGE_LENGTH, MAX_INTERVAL, MIN_INTERVAL, SESSION_REPLAY_SERVER_URL, STORAGE_PREFIX, defaultSessionStore, SESSION_REPLAY_EU_URL as SESSION_REPLAY_EU_SERVER_URL, } from './constants'; | ||
import { maskInputFn } from './helpers'; | ||
import { BLOCK_CLASS, DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_REPLAY_PROPERTY, DEFAULT_SESSION_START_EVENT, MASK_TEXT_CLASS, MAX_EVENT_LIST_SIZE_IN_BYTES, MAX_IDB_STORAGE_LENGTH, MAX_INTERVAL, MIN_INTERVAL, SESSION_REPLAY_EU_URL as SESSION_REPLAY_EU_SERVER_URL, SESSION_REPLAY_SERVER_URL, STORAGE_PREFIX, defaultSessionStore, } from './constants'; | ||
import { isSessionInSample, maskInputFn } from './helpers'; | ||
import { MAX_RETRIES_EXCEEDED_MESSAGE, STORAGE_FAILURE, UNEXPECTED_ERROR_MESSAGE, getSuccessMessage } from './messages'; | ||
@@ -27,3 +27,2 @@ import { RecordingStatus, } from './typings/session-replay'; | ||
this.timeAtLastSend = null; | ||
this.shouldRecord = true; | ||
/** | ||
@@ -96,3 +95,3 @@ * Determines whether to send the events list to the backend and start a new | ||
return __awaiter(this, void 0, void 0, function () { | ||
var GlobalScope; | ||
var GlobalScope, shouldRecord; | ||
var _a; | ||
@@ -104,7 +103,3 @@ return __generator(this, function (_b) { | ||
} | ||
if (this.shouldRecord) { | ||
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.setShouldRecord(); | ||
this.recordEvents(); | ||
@@ -125,2 +120,6 @@ } | ||
} | ||
shouldRecord = this.getShouldRecord(); | ||
if (shouldRecord) { | ||
event.event_properties = __assign(__assign({}, event.event_properties), (_a = {}, _a[DEFAULT_SESSION_REPLAY_PROPERTY] = true, _a)); | ||
} | ||
return [2 /*return*/, Promise.resolve(event)]; | ||
@@ -164,3 +163,2 @@ }); | ||
} | ||
this.setShouldRecord(storedSequencesForSession); | ||
if (shouldSendStoredEvents && storedReplaySessions) { | ||
@@ -175,16 +173,13 @@ this.sendStoredEvents(storedReplaySessions); | ||
}; | ||
SessionReplay.prototype.setShouldRecord = function (sessionStore) { | ||
if (sessionStore && typeof sessionStore.shouldRecord === 'boolean') { | ||
this.shouldRecord = sessionStore.shouldRecord; | ||
SessionReplay.prototype.getShouldRecord = function () { | ||
if (this.config.optOut) { | ||
return false; | ||
} | ||
else if (this.config.optOut) { | ||
this.shouldRecord = false; | ||
else if (!this.config.sessionId) { | ||
return false; | ||
} | ||
else if (this.options && this.options.sampleRate) { | ||
this.shouldRecord = Math.random() < this.options.sampleRate; | ||
return isSessionInSample(this.config.sessionId, this.options.sampleRate); | ||
} | ||
this.config.sessionId && void this.storeShouldRecordForSession(this.config.sessionId, this.shouldRecord); | ||
if (!this.shouldRecord && this.config.sessionId) { | ||
this.config.loggerProvider.log("Opting session ".concat(this.config.sessionId, " out of recording.")); | ||
} | ||
return true; | ||
}; | ||
@@ -213,3 +208,5 @@ SessionReplay.prototype.sendStoredEvents = function (storedReplaySessions) { | ||
var _this = this; | ||
if (!this.shouldRecord) { | ||
var shouldRecord = this.getShouldRecord(); | ||
if (!shouldRecord && this.config.sessionId) { | ||
this.config.loggerProvider.log("Opting session ".concat(this.config.sessionId, " out of recording.")); | ||
return; | ||
@@ -451,3 +448,3 @@ } | ||
}; | ||
SessionReplay.prototype.storeShouldRecordForSession = function (sessionId, shouldRecord) { | ||
SessionReplay.prototype.cleanUpSessionEventsStore = function (sessionId, sequenceId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -460,29 +457,3 @@ var e_4; | ||
return [4 /*yield*/, IDBKeyVal.update(this.storageKey, function (sessionMap) { | ||
var _a; | ||
if (sessionMap === void 0) { sessionMap = {}; } | ||
var session = sessionMap[sessionId] || __assign({}, defaultSessionStore); | ||
session.shouldRecord = shouldRecord; | ||
return __assign(__assign({}, sessionMap), (_a = {}, _a[sessionId] = session, _a)); | ||
})]; | ||
case 1: | ||
_a.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
e_4 = _a.sent(); | ||
this.config.loggerProvider.error("".concat(STORAGE_FAILURE, ": ").concat(e_4)); | ||
return [3 /*break*/, 3]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SessionReplay.prototype.cleanUpSessionEventsStore = function (sessionId, sequenceId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var e_5; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, IDBKeyVal.update(this.storageKey, function (sessionMap) { | ||
if (sessionMap === void 0) { sessionMap = {}; } | ||
var session = sessionMap[sessionId]; | ||
@@ -516,4 +487,4 @@ var sequenceToUpdate = (session === null || session === void 0 ? void 0 : session.sessionSequences) && session.sessionSequences[sequenceId]; | ||
case 2: | ||
e_5 = _a.sent(); | ||
this.config.loggerProvider.error("".concat(STORAGE_FAILURE, ": ").concat(e_5)); | ||
e_4 = _a.sent(); | ||
this.config.loggerProvider.error("".concat(STORAGE_FAILURE, ": ").concat(e_4)); | ||
return [3 /*break*/, 3]; | ||
@@ -520,0 +491,0 @@ case 3: return [2 /*return*/]; |
@@ -24,3 +24,2 @@ import { BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
export interface IDBStoreSession { | ||
shouldRecord: boolean; | ||
currentSequenceId: number; | ||
@@ -42,3 +41,2 @@ sessionSequences: { | ||
interval: number; | ||
shouldRecord: boolean; | ||
queue: SessionReplayContext[]; | ||
@@ -49,3 +47,3 @@ timeAtLastSend: number | null; | ||
initialize: (shouldSendStoredEvents?: boolean) => Promise<void>; | ||
setShouldRecord: (sessionStore?: IDBStoreSession) => void; | ||
getShouldRecord: () => boolean; | ||
recordEvents: () => void; | ||
@@ -70,3 +68,2 @@ shouldSplitEventsList: (nextEventString: string) => boolean; | ||
storeEventsForSession: (events: Events, sequenceId: number, sessionId: number) => Promise<void>; | ||
storeShouldRecordForSession: (sessionId: number, shouldRecord: boolean) => Promise<void>; | ||
cleanUpSessionEventsStore: (sessionId: number, sequenceId: number) => Promise<void>; | ||
@@ -73,0 +70,0 @@ } |
export declare const maskInputFn: (text: string, element: HTMLElement) => string; | ||
export declare const generateHashCode: (str: string) => number; | ||
export declare const isSessionInSample: (sessionId: number, sampleRate: number) => boolean; | ||
//# sourceMappingURL=helpers.d.ts.map |
@@ -24,3 +24,2 @@ import { BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
export interface IDBStoreSession { | ||
shouldRecord: boolean; | ||
currentSequenceId: number; | ||
@@ -42,3 +41,2 @@ sessionSequences: { | ||
interval: number; | ||
shouldRecord: boolean; | ||
queue: SessionReplayContext[]; | ||
@@ -49,3 +47,3 @@ timeAtLastSend: number | null; | ||
initialize: (shouldSendStoredEvents?: boolean) => Promise<void>; | ||
setShouldRecord: (sessionStore?: IDBStoreSession) => void; | ||
getShouldRecord: () => boolean; | ||
recordEvents: () => void; | ||
@@ -70,3 +68,2 @@ shouldSplitEventsList: (nextEventString: string) => boolean; | ||
storeEventsForSession: (events: Events, sequenceId: number, sessionId: number) => Promise<void>; | ||
storeShouldRecordForSession: (sessionId: number, shouldRecord: boolean) => Promise<void>; | ||
cleanUpSessionEventsStore: (sessionId: number, sequenceId: number) => Promise<void>; | ||
@@ -73,0 +70,0 @@ } |
{ | ||
"name": "@amplitude/plugin-session-replay-browser", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "", | ||
@@ -58,3 +58,3 @@ "author": "Amplitude Inc", | ||
], | ||
"gitHead": "a9293cb635a4c088ec928f2205f2d19cc47ec4e1" | ||
"gitHead": "ca2bca168a8982724cde32abd12cb40821ef69c6" | ||
} |
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 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
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 2 instances 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
412989
2146
6