New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@amplitude/session-replay-browser

Package Overview
Dependencies
Maintainers
21
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplitude/session-replay-browser - npm Package Compare versions

Comparing version 1.14.0-srtargeting.2 to 1.14.0

lib/cjs/events/event-compressor.d.ts

1

lib/cjs/beacon-transport.d.ts

@@ -24,2 +24,3 @@ import { SessionReplayJoinedConfig } from './config/types';

private readonly context;
private readonly apiKey;
constructor(context: Omit<SessionReplayDestinationSessionMetadata, 'deviceId'>, config: SessionReplayJoinedConfig);

@@ -26,0 +27,0 @@ send(deviceId: string, payload: T): void;

@@ -48,2 +48,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

this.basePageUrl = (0, helpers_1.getServerUrl)(config.serverZone);
this.apiKey = config.apiKey;
this.context = context;

@@ -57,2 +58,3 @@ }

type: String(type),
api_key: this.apiKey,
});

@@ -59,0 +61,0 @@ var pageUrl = "".concat(this.basePageUrl, "?").concat(urlParams.toString());

25

lib/cjs/config/joined-config.js

@@ -62,3 +62,3 @@ var _this = this;

return tslib_1.__awaiter(this, void 0, void 0, function () {
var config, remoteConfig, samplingConfig_1, privacyConfig, targetingConfig_1, _d, err_1, knownError, samplingConfig, remotePrivacyConfig, targetingConfig, localPrivacyConfig, joinedPrivacyConfig, privacyConfigSelectorMap, selectorMap, _e, _f, _g, selector, selectorType;
var config, remoteConfig, samplingConfig_1, privacyConfig, _d, err_1, knownError, samplingConfig, remotePrivacyConfig, localPrivacyConfig, joinedPrivacyConfig, privacyConfigSelectorMap, selectorMap, _e, _f, _g, selector, selectorType;
var e_1, _h;

@@ -76,3 +76,3 @@ return tslib_1.__generator(this, function (_j) {

case 1:
_j.trys.push([1, 6, , 7]);
_j.trys.push([1, 5, , 6]);
if (!this.remoteConfigFetch) {

@@ -88,9 +88,6 @@ config.captureEnabled = false;

privacyConfig = _j.sent();
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_targeting_config', sessionId)];
case 4:
targetingConfig_1 = _j.sent();
// This is intentionally forced to only be set through the remote config.
_d = config;
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_interaction_config', sessionId)];
case 5:
case 4:
// This is intentionally forced to only be set through the remote config.

@@ -106,8 +103,5 @@ _d.interactionConfig = _j.sent();

}
if (targetingConfig_1) {
remoteConfig.sr_targeting_config = targetingConfig_1;
}
}
return [3 /*break*/, 7];
case 6:
return [3 /*break*/, 6];
case 5:
err_1 = _j.sent();

@@ -117,8 +111,8 @@ knownError = err_1;

config.captureEnabled = false;
return [3 /*break*/, 7];
case 7:
return [3 /*break*/, 6];
case 6:
if (!remoteConfig) {
return [2 /*return*/, config];
}
samplingConfig = remoteConfig.sr_sampling_config, remotePrivacyConfig = remoteConfig.sr_privacy_config, targetingConfig = remoteConfig.sr_targeting_config;
samplingConfig = remoteConfig.sr_sampling_config, remotePrivacyConfig = remoteConfig.sr_privacy_config;
if (samplingConfig && Object.keys(samplingConfig).length > 0) {

@@ -235,5 +229,2 @@ if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {

}
if (targetingConfig && Object.keys(targetingConfig).length > 0) {
config.targetingConfig = targetingConfig;
}
this.localConfig.loggerProvider.debug(JSON.stringify({ name: 'session replay joined config', config: (0, helpers_1.getDebugConfig)(config) }, null, 2));

@@ -240,0 +231,0 @@ return [2 /*return*/, config];

@@ -5,3 +5,3 @@ import { FetchTransport } from '@amplitude/analytics-client-common';

import { SessionReplayOptions } from '../typings/session-replay';
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, InteractionConfig, PrivacyConfig } from './types';
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, InteractionConfig, PrivacyConfig, SessionReplayPerformanceConfig, SessionReplayVersion } from './types';
export declare const getDefaultConfig: () => {

@@ -21,4 +21,6 @@ flushMaxRetries: number;

shouldInlineStylesheet?: boolean;
version?: SessionReplayVersion;
performanceConfig?: SessionReplayPerformanceConfig;
constructor(apiKey: string, options: SessionReplayOptions);
}
//# sourceMappingURL=local-config.d.ts.map

@@ -30,2 +30,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

_this.shouldInlineStylesheet = options.shouldInlineStylesheet;
_this.version = options.version;
_this.performanceConfig = options.performanceConfig;
if (options.privacyConfig) {

@@ -32,0 +34,0 @@ _this.privacyConfig = options.privacyConfig;

import { Config, LogLevel, Logger } from '@amplitude/analytics-types';
import { TargetingFlag } from '@amplitude/targeting';
export interface SamplingConfig {

@@ -12,3 +11,2 @@ sample_rate: number;

}
export type TargetingConfig = TargetingFlag;
export type SessionReplayRemoteConfig = {

@@ -18,3 +16,2 @@ sr_sampling_config?: SamplingConfig;

sr_interaction_config?: InteractionConfig;
sr_targeting_config?: TargetingConfig;
};

@@ -45,5 +42,3 @@ export interface SessionReplayRemoteConfigAPIResponse {

version?: SessionReplayVersion;
userProperties?: {
[key: string]: any;
};
performanceConfig?: SessionReplayPerformanceConfig;
}

@@ -53,3 +48,2 @@ export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {

interactionConfig?: InteractionConfig;
targetingConfig?: TargetingConfig;
}

@@ -69,3 +63,7 @@ export interface SessionReplayRemoteConfigFetch {

}
export interface SessionReplayPerformanceConfig {
enabled: boolean;
timeout?: number;
}
export type SessionReplayType = 'standalone' | 'plugin' | 'segment';
//# sourceMappingURL=types.d.ts.map

@@ -14,3 +14,2 @@ import { PrivacyConfig, SessionReplayJoinedConfig } from './config/types';

interactionConfig?: import("./config/types").InteractionConfig | undefined;
targetingConfig?: import("@amplitude/experiment-core").EvaluationFlag | undefined;
apiKey: string;

@@ -26,11 +25,3 @@ loggerProvider: import("@amplitude/analytics-types").Logger;

version?: import("./config/types").SessionReplayVersion | undefined;
userProperties?: {
[key: string]: any;
} | undefined; /**
* Checks if the given element set to be masked by rrweb
*
* Priority is:
* 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking
* 2. Use app defaults
*/
performanceConfig?: import("./config/types").SessionReplayPerformanceConfig | undefined;
flushIntervalMillis: number;

@@ -37,0 +28,0 @@ flushQueueSize: number;

@@ -16,2 +16,6 @@ import { scrollCallback, scrollPosition } from '@amplitude/rrweb-types';

};
export type ScrollEventPayload = {
version: number;
events: ScrollEvent[];
};
/**

@@ -32,3 +36,3 @@ * This is intended to watch and update max scroll activity when loaded for a particular page.

static default(context: Omit<SessionReplayDestinationSessionMetadata, 'deviceId'>, config: SessionReplayJoinedConfig): ScrollWatcher;
constructor(transport: BeaconTransport<ScrollEvent>);
constructor(transport: BeaconTransport<ScrollEventPayload>);
get maxScrollX(): number;

@@ -35,0 +39,0 @@ get maxScrollY(): number;

@@ -26,11 +26,16 @@ Object.defineProperty(exports, "__esModule", { value: true });

_this.transport.send(deviceId, {
maxScrollX: _this._maxScrollX,
maxScrollY: _this._maxScrollY,
maxScrollWidth: _this._maxScrollWidth,
maxScrollHeight: _this._maxScrollHeight,
viewportHeight: getWindowHeight(),
viewportWidth: getWindowWidth(),
pageUrl: globalScope.location.href,
timestamp: _this.timestamp,
type: 'scroll',
version: 1,
events: [
{
maxScrollX: _this._maxScrollX,
maxScrollY: _this._maxScrollY,
maxScrollWidth: _this._maxScrollWidth,
maxScrollHeight: _this._maxScrollHeight,
viewportHeight: getWindowHeight(),
viewportWidth: getWindowWidth(),
pageUrl: globalScope.location.href,
timestamp: _this.timestamp,
type: 'scroll',
},
],
});

@@ -37,0 +42,0 @@ }

@@ -1,6 +0,2 @@

export declare const init: (apiKey: string, options: import("./typings/session-replay").SessionReplayOptions) => import("@amplitude/analytics-types").AmplitudeReturn<void>, setSessionId: (sessionId: number, deviceId?: string | undefined, options?: {
userProperties?: {
[key: string]: any;
} | undefined;
} | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<void>, getSessionId: () => number | undefined, evaluateTargetingAndCapture: (targetingParams?: Pick<import("@amplitude/targeting").TargetingParameters, "event" | "userProperties"> | undefined) => Promise<void>, getSessionReplayProperties: () => {
export declare const init: (apiKey: string, options: import("./typings/session-replay").SessionReplayOptions) => import("@amplitude/analytics-types").AmplitudeReturn<void>, setSessionId: (sessionId: number, deviceId?: string | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<void>, getSessionId: () => number | undefined, getSessionReplayProperties: () => {
[key: string]: string | boolean | null;

@@ -7,0 +3,0 @@ }, flush: (useRetry: boolean) => Promise<void>, shutdown: () => void;

Object.defineProperty(exports, "__esModule", { value: true });
exports.shutdown = exports.flush = exports.getSessionReplayProperties = exports.evaluateTargetingAndCapture = exports.getSessionId = exports.setSessionId = exports.init = void 0;
exports.shutdown = exports.flush = exports.getSessionReplayProperties = exports.getSessionId = exports.setSessionId = exports.init = void 0;
var tslib_1 = require("tslib");
var session_replay_factory_1 = tslib_1.__importDefault(require("./session-replay-factory"));
exports.init = session_replay_factory_1.default.init, exports.setSessionId = session_replay_factory_1.default.setSessionId, exports.getSessionId = session_replay_factory_1.default.getSessionId, exports.evaluateTargetingAndCapture = session_replay_factory_1.default.evaluateTargetingAndCapture, exports.getSessionReplayProperties = session_replay_factory_1.default.getSessionReplayProperties, exports.flush = session_replay_factory_1.default.flush, exports.shutdown = session_replay_factory_1.default.shutdown;
exports.init = session_replay_factory_1.default.init, exports.setSessionId = session_replay_factory_1.default.setSessionId, exports.getSessionId = session_replay_factory_1.default.getSessionId, exports.getSessionReplayProperties = session_replay_factory_1.default.getSessionReplayProperties, exports.flush = session_replay_factory_1.default.flush, exports.shutdown = session_replay_factory_1.default.shutdown;
//# sourceMappingURL=index.js.map

@@ -19,5 +19,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

init: (0, analytics_core_1.debugWrapper)(sessionReplay.init.bind(sessionReplay), 'init', (0, exports.getLogConfig)(sessionReplay)),
evaluateTargetingAndCapture: (0, analytics_core_1.debugWrapper)(sessionReplay.evaluateTargetingAndCapture.bind(sessionReplay), 'evaluateTargetingAndRecord', (0, exports.getLogConfig)(sessionReplay)),
setSessionId: (0, analytics_core_1.debugWrapper)(sessionReplay.setSessionId.bind(sessionReplay), 'setSessionId', (0, exports.getLogConfig)(sessionReplay)),
getSessionId: sessionReplay.getSessionId.bind(sessionReplay),
getSessionId: (0, analytics_core_1.debugWrapper)(sessionReplay.getSessionId.bind(sessionReplay), 'getSessionId', (0, exports.getLogConfig)(sessionReplay)),
getSessionReplayProperties: (0, analytics_core_1.debugWrapper)(sessionReplay.getSessionReplayProperties.bind(sessionReplay), 'getSessionReplayProperties', (0, exports.getLogConfig)(sessionReplay)),

@@ -24,0 +23,0 @@ flush: (0, analytics_core_1.debugWrapper)(sessionReplay.flush.bind(sessionReplay), 'flush', (0, exports.getLogConfig)(sessionReplay)),

import { Logger as ILogger } from '@amplitude/analytics-types';
import { record } from '@amplitude/rrweb';
import { TargetingParameters } from '@amplitude/targeting';
import { SessionReplayJoinedConfig, SessionReplayJoinedConfigGenerator } from './config/types';
import { CustomRRwebEvent } from './constants';
import { AmplitudeSessionReplay, SessionReplayEventsManager as AmplitudeSessionReplayEventsManager, SessionIdentifiers as ISessionIdentifiers, SessionReplayOptions } from './typings/session-replay';
import { EventCompressor } from './events/event-compressor';
type PageLeaveFn = (e: PageTransitionEvent | Event) => void;

@@ -17,3 +17,3 @@ export declare class SessionReplay implements AmplitudeSessionReplay {

eventCount: number;
sessionTargetingMatch: boolean;
eventCompressor: EventCompressor | undefined;
pageLeaveFns: PageLeaveFn[];

@@ -25,12 +25,4 @@ private scrollHook?;

protected _init(apiKey: string, options: SessionReplayOptions): Promise<void>;
setSessionId(sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}): import("@amplitude/analytics-types").AmplitudeReturn<void>;
asyncSetSessionId(sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}): Promise<void>;
setSessionId(sessionId: number, deviceId?: string): import("@amplitude/analytics-types").AmplitudeReturn<void>;
asyncSetSessionId(sessionId: number, deviceId?: string): Promise<void>;
getSessionReplayDebugPropertyValue(): string;

@@ -48,9 +40,9 @@ getSessionReplayProperties(): {

private pageLeaveListener;
evaluateTargetingAndCapture: (targetingParams?: Pick<TargetingParameters, 'event' | 'userProperties'>) => Promise<void>;
sendEvents(sessionId?: number): void;
initialize(shouldSendStoredEvents?: boolean): void;
shouldOptOut(): boolean | undefined;
getShouldCapture(): boolean;
getShouldRecord(): boolean;
getBlockSelectors(): string | string[] | undefined;
getMaskTextSelectors(): string | undefined;
captureEvents(): void;
recordEvents(): void;
addCustomRRWebEvent: (eventName: CustomRRwebEvent, eventData?: {

@@ -57,0 +49,0 @@ [key: string]: any;

@@ -6,3 +6,2 @@ Object.defineProperty(exports, "__esModule", { value: true });

var analytics_core_1 = require("@amplitude/analytics-core");
var analytics_types_1 = require("@amplitude/analytics-types");
var rrweb_1 = require("@amplitude/rrweb");

@@ -17,4 +16,4 @@ var joined_config_1 = require("./config/joined-config");

var identifiers_1 = require("./identifiers");
var targeting_manager_1 = require("./targeting/targeting-manager");
var version_1 = require("./version");
var event_compressor_1 = require("./events/event-compressor");
var SessionReplay = /** @class */ (function () {

@@ -26,3 +25,2 @@ function SessionReplay() {

this.eventCount = 0;
this.sessionTargetingMatch = false;
// Visible for testing

@@ -57,4 +55,3 @@ this.pageLeaveFns = [];

// switches tabs, we take a full snapshot
_this.stopRecordingEvents();
_this.captureEvents();
_this.recordEvents();
};

@@ -71,45 +68,2 @@ /**

};
this.evaluateTargetingAndCapture = function (targetingParams) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var eventForTargeting, _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!this.identifiers || !this.identifiers.sessionId || !this.config) {
if (this.identifiers && !this.identifiers.sessionId) {
this.loggerProvider.log('Session ID has not been set yet, cannot evaluate targeting for Session Replay.');
}
else {
this.loggerProvider.warn('Session replay init has not been called, cannot evaluate targeting.');
}
return [2 /*return*/];
}
if (!(this.config.targetingConfig && !this.sessionTargetingMatch)) return [3 /*break*/, 2];
eventForTargeting = targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.event;
if (eventForTargeting &&
Object.values(analytics_types_1.SpecialEventType).includes(eventForTargeting.event_type)) {
eventForTargeting = undefined;
}
// We're setting this on this class because fetching the value from idb
// is async, we need to access this value synchronously (for record
// and for getSessionReplayProperties - both synchronous fns)
_a = this;
return [4 /*yield*/, (0, targeting_manager_1.evaluateTargetingAndStore)({
sessionId: this.identifiers.sessionId,
targetingConfig: this.config.targetingConfig,
loggerProvider: this.loggerProvider,
apiKey: this.config.apiKey,
targetingParams: { userProperties: targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.userProperties, event: eventForTargeting },
})];
case 1:
// We're setting this on this class because fetching the value from idb
// is async, we need to access this value synchronously (for record
// and for getSessionReplayProperties - both synchronous fns)
_a.sessionTargetingMatch = _b.sent();
_b.label = 2;
case 2:
this.captureEvents();
return [2 /*return*/];
}
});
}); };
this.addCustomRRWebEvent = function (eventName, eventData, addStorageInfo) {

@@ -156,5 +110,3 @@ if (eventData === void 0) { eventData = {}; }

try {
if (_this.recordCancelCallback) {
_this.loggerProvider.log('Session Replay capture stopping.');
}
_this.loggerProvider.log('Session Replay capture stopping.');
_this.recordCancelCallback && _this.recordCancelCallback();

@@ -176,3 +128,3 @@ _this.recordCancelCallback = null;

return tslib_1.__awaiter(this, void 0, void 0, function () {
var _d, _e, scrollWatcher, managers, rrwebEventManager, payloadBatcher, interactionEventManager;
var _d, _e, scrollWatcher, managers, rrwebEventManager, error_1, typedError, payloadBatcher, interactionEventManager, error_2, typedError;
return tslib_1.__generator(this, function (_f) {

@@ -198,6 +150,9 @@ switch (_f.label) {

}, this.config);
this.pageLeaveFns = [scrollWatcher.send(this.getDeviceId.bind(this))];
this.pageLeaveFns = [scrollWatcher.send(this.getDeviceId.bind(this)).bind(scrollWatcher)];
this.scrollHook = scrollWatcher.hook.bind(scrollWatcher);
}
managers = [];
_f.label = 3;
case 3:
_f.trys.push([3, 5, , 6]);
return [4 /*yield*/, (0, events_manager_1.createEventsManager)({

@@ -208,7 +163,17 @@ config: this.config,

})];
case 3:
case 4:
rrwebEventManager = _f.sent();
managers.push({ name: 'replay', manager: rrwebEventManager });
if (!((_b = this.config.interactionConfig) === null || _b === void 0 ? void 0 : _b.enabled)) return [3 /*break*/, 5];
return [3 /*break*/, 6];
case 5:
error_1 = _f.sent();
typedError = error_1;
this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(typedError.toString()));
return [3 /*break*/, 6];
case 6:
if (!((_b = this.config.interactionConfig) === null || _b === void 0 ? void 0 : _b.enabled)) return [3 /*break*/, 10];
payloadBatcher = this.config.interactionConfig.batch ? click_1.clickBatcher : click_1.clickNonBatcher;
_f.label = 7;
case 7:
_f.trys.push([7, 9, , 10]);
return [4 /*yield*/, (0, events_manager_1.createEventsManager)({

@@ -222,18 +187,17 @@ config: this.config,

})];
case 4:
case 8:
interactionEventManager = _f.sent();
managers.push({ name: 'interaction', manager: interactionEventManager });
_f.label = 5;
case 5:
return [3 /*break*/, 10];
case 9:
error_2 = _f.sent();
typedError = error_2;
this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(typedError.toString()));
return [3 /*break*/, 10];
case 10:
this.eventsManager = new (multi_manager_1.MultiEventManager.bind.apply(multi_manager_1.MultiEventManager, tslib_1.__spreadArray([void 0], tslib_1.__read(managers), false)))();
this.identifiers.deviceId &&
void this.eventsManager.sendStoredEvents({
deviceId: this.identifiers.deviceId,
});
this.eventCompressor = new event_compressor_1.EventCompressor(this.eventsManager, this.config, this.getDeviceId());
this.loggerProvider.log('Installing @amplitude/session-replay-browser.');
this.teardownEventListeners(false);
this.stopRecordingEvents();
return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options.userProperties })];
case 6:
_f.sent();
this.initialize(true);
return [2 /*return*/];

@@ -244,6 +208,6 @@ }

};
SessionReplay.prototype.setSessionId = function (sessionId, deviceId, options) {
return (0, analytics_core_1.returnWrapper)(this.asyncSetSessionId(sessionId, deviceId, options));
SessionReplay.prototype.setSessionId = function (sessionId, deviceId) {
return (0, analytics_core_1.returnWrapper)(this.asyncSetSessionId(sessionId, deviceId));
};
SessionReplay.prototype.asyncSetSessionId = function (sessionId, deviceId, options) {
SessionReplay.prototype.asyncSetSessionId = function (sessionId, deviceId) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -254,4 +218,2 @@ var previousSessionId, deviceIdForReplayId, _a;

case 0:
this.stopRecordingEvents();
this.sessionTargetingMatch = false;
previousSessionId = this.identifiers && this.identifiers.sessionId;

@@ -272,5 +234,4 @@ if (previousSessionId) {

_b.label = 2;
case 2: return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options === null || options === void 0 ? void 0 : options.userProperties })];
case 3:
_b.sent();
case 2:
this.recordEvents();
return [2 /*return*/];

@@ -296,3 +257,3 @@ }

}
var shouldRecord = this.getShouldCapture();
var shouldRecord = this.getShouldRecord();
var eventProperties = {};

@@ -326,2 +287,17 @@ if (shouldRecord) {

};
SessionReplay.prototype.initialize = function (shouldSendStoredEvents) {
var _a;
if (shouldSendStoredEvents === void 0) { shouldSendStoredEvents = false; }
if (!((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId)) {
this.loggerProvider.log("Session is not being recorded due to lack of session id.");
return;
}
var deviceId = this.getDeviceId();
if (!deviceId) {
this.loggerProvider.log("Session is not being recorded due to lack of device id.");
return;
}
this.eventsManager && shouldSendStoredEvents && this.eventsManager.sendStoredEvents({ deviceId: deviceId });
this.recordEvents();
};
SessionReplay.prototype.shouldOptOut = function () {

@@ -336,5 +312,5 @@ var _a, _b;

};
SessionReplay.prototype.getShouldCapture = function () {
SessionReplay.prototype.getShouldRecord = function () {
if (!this.identifiers || !this.config || !this.identifiers.sessionId) {
this.loggerProvider.warn("Session is not being captured due to lack of config, please call sessionReplay.init.");
this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init.");
return false;

@@ -347,23 +323,10 @@ }

if (this.shouldOptOut()) {
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of replay capture due to optOut config."));
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of recording due to optOut config."));
return false;
}
// If targetingConfig exists, we'll use the sessionTargetingMatch to determine whether to record
// Otherwise, we'll evaluate the session against the overall sample rate
if (this.config.targetingConfig) {
if (!this.sessionTargetingMatch) {
this.loggerProvider.log("Not capturing replays for session ".concat(this.identifiers.sessionId, " due to not matching targeting conditions."));
return false;
}
this.loggerProvider.log("Capturing replays for session ".concat(this.identifiers.sessionId, " due to matching targeting conditions."));
var isInSample = (0, helpers_1.isSessionInSample)(this.identifiers.sessionId, this.config.sampleRate);
if (!isInSample) {
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of recording due to sample rate."));
}
else {
var isInSample = (0, helpers_1.isSessionInSample)(this.identifiers.sessionId, this.config.sampleRate);
if (!isInSample) {
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of replay capture due to sample rate."));
return false;
}
this.loggerProvider.log("Capturing replays for session ".concat(this.identifiers.sessionId, " due to inclusion in sample rate."));
}
return true;
return isInSample;
};

@@ -392,13 +355,11 @@ SessionReplay.prototype.getBlockSelectors = function () {

};
SessionReplay.prototype.captureEvents = function () {
SessionReplay.prototype.recordEvents = function () {
var _this = this;
if (this.recordCancelCallback) {
this.loggerProvider.debug('captureEvents method fired - Session Replay capture already in progress.');
return;
}
var shouldRecord = this.getShouldCapture();
var sessionId = this.identifiers && this.identifiers.sessionId;
var _a;
var shouldRecord = this.getShouldRecord();
var sessionId = (_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId;
if (!shouldRecord || !sessionId || !this.config) {
return;
}
this.stopRecordingEvents();
var privacyConfig = this.config.privacyConfig;

@@ -409,3 +370,3 @@ this.loggerProvider.log('Session Replay capture beginning.');

if (_this.shouldOptOut()) {
_this.loggerProvider.log("Opting session ".concat(sessionId, " out of replay capture due to optOut config."));
_this.loggerProvider.log("Opting session ".concat(sessionId, " out of recording due to optOut config."));
_this.stopRecordingEvents();

@@ -415,9 +376,7 @@ _this.sendEvents();

}
var eventString = JSON.stringify(event);
var deviceId = _this.getDeviceId();
_this.eventsManager &&
deviceId &&
_this.eventsManager.addEvent({ event: { type: 'replay', data: eventString }, sessionId: sessionId, deviceId: deviceId });
if (_this.eventCompressor) {
// Schedule processing during idle time if the browser supports requestIdleCallback
_this.eventCompressor.enqueueEvent(event, sessionId);
}
},
packFn: rrweb_1.pack,
inlineStylesheet: this.config.shouldInlineStylesheet,

@@ -463,9 +422,4 @@ hooks: {

SessionReplay.prototype.getDeviceId = function () {
var _a, _b;
var identityStoreDeviceId;
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.instanceName) {
var identityStore = (0, analytics_client_common_1.getAnalyticsConnector)(this.config.instanceName).identityStore;
identityStoreDeviceId = identityStore.getIdentity().deviceId;
}
return identityStoreDeviceId || ((_b = this.identifiers) === null || _b === void 0 ? void 0 : _b.deviceId);
var _a;
return (_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.deviceId;
};

@@ -472,0 +426,0 @@ SessionReplay.prototype.getSessionId = function () {

import { AmplitudeReturn, ServerZone } from '@amplitude/analytics-types';
import { SessionReplayJoinedConfig, SessionReplayLocalConfig, SessionReplayVersion } from '../config/types';
import { TargetingParameters } from '@amplitude/targeting';
export type StorageData = {

@@ -63,7 +62,3 @@ totalStorageSize: number;

init: (apiKey: string, options: SessionReplayOptions) => AmplitudeReturn<void>;
setSessionId: (sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}) => AmplitudeReturn<void>;
setSessionId: (sessionId: number, deviceId?: string) => AmplitudeReturn<void>;
getSessionId: () => number | undefined;

@@ -73,3 +68,2 @@ getSessionReplayProperties: () => {

};
evaluateTargetingAndCapture: (targetingParams?: Pick<TargetingParameters, 'event' | 'userProperties'>) => Promise<void>;
flush: (useRetry: boolean) => Promise<void>;

@@ -76,0 +70,0 @@ shutdown: () => void;

@@ -1,2 +0,2 @@

export declare const VERSION = "1.14.0-srtargeting.2";
export declare const VERSION = "1.14.0";
//# sourceMappingURL=version.d.ts.map
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
// Autogenerated by `yarn version-file`. DO NOT EDIT
exports.VERSION = '1.14.0-srtargeting.2';
exports.VERSION = '1.14.0';
//# sourceMappingURL=version.js.map

@@ -24,2 +24,3 @@ import { SessionReplayJoinedConfig } from './config/types';

private readonly context;
private readonly apiKey;
constructor(context: Omit<SessionReplayDestinationSessionMetadata, 'deviceId'>, config: SessionReplayJoinedConfig);

@@ -26,0 +27,0 @@ send(deviceId: string, payload: T): void;

@@ -46,2 +46,3 @@ import { getGlobalScope } from '@amplitude/analytics-client-common';

this.basePageUrl = getServerUrl(config.serverZone);
this.apiKey = config.apiKey;
this.context = context;

@@ -55,2 +56,3 @@ }

type: String(type),
api_key: this.apiKey,
});

@@ -57,0 +59,0 @@ var pageUrl = "".concat(this.basePageUrl, "?").concat(urlParams.toString());

@@ -58,3 +58,3 @@ import { __assign, __awaiter, __generator, __read, __values } from "tslib";

return __awaiter(this, void 0, void 0, function () {
var config, remoteConfig, samplingConfig_1, privacyConfig, targetingConfig_1, _d, err_1, knownError, samplingConfig, remotePrivacyConfig, targetingConfig, localPrivacyConfig, joinedPrivacyConfig, privacyConfigSelectorMap, selectorMap, _e, _f, _g, selector, selectorType;
var config, remoteConfig, samplingConfig_1, privacyConfig, _d, err_1, knownError, samplingConfig, remotePrivacyConfig, localPrivacyConfig, joinedPrivacyConfig, privacyConfigSelectorMap, selectorMap, _e, _f, _g, selector, selectorType;
var e_1, _h;

@@ -72,3 +72,3 @@ return __generator(this, function (_j) {

case 1:
_j.trys.push([1, 6, , 7]);
_j.trys.push([1, 5, , 6]);
if (!this.remoteConfigFetch) {

@@ -84,9 +84,6 @@ config.captureEnabled = false;

privacyConfig = _j.sent();
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_targeting_config', sessionId)];
case 4:
targetingConfig_1 = _j.sent();
// This is intentionally forced to only be set through the remote config.
_d = config;
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_interaction_config', sessionId)];
case 5:
case 4:
// This is intentionally forced to only be set through the remote config.

@@ -102,8 +99,5 @@ _d.interactionConfig = _j.sent();

}
if (targetingConfig_1) {
remoteConfig.sr_targeting_config = targetingConfig_1;
}
}
return [3 /*break*/, 7];
case 6:
return [3 /*break*/, 6];
case 5:
err_1 = _j.sent();

@@ -113,8 +107,8 @@ knownError = err_1;

config.captureEnabled = false;
return [3 /*break*/, 7];
case 7:
return [3 /*break*/, 6];
case 6:
if (!remoteConfig) {
return [2 /*return*/, config];
}
samplingConfig = remoteConfig.sr_sampling_config, remotePrivacyConfig = remoteConfig.sr_privacy_config, targetingConfig = remoteConfig.sr_targeting_config;
samplingConfig = remoteConfig.sr_sampling_config, remotePrivacyConfig = remoteConfig.sr_privacy_config;
if (samplingConfig && Object.keys(samplingConfig).length > 0) {

@@ -231,5 +225,2 @@ if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {

}
if (targetingConfig && Object.keys(targetingConfig).length > 0) {
config.targetingConfig = targetingConfig;
}
this.localConfig.loggerProvider.debug(JSON.stringify({ name: 'session replay joined config', config: getDebugConfig(config) }, null, 2));

@@ -236,0 +227,0 @@ return [2 /*return*/, config];

@@ -5,3 +5,3 @@ import { FetchTransport } from '@amplitude/analytics-client-common';

import { SessionReplayOptions } from '../typings/session-replay';
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, InteractionConfig, PrivacyConfig } from './types';
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, InteractionConfig, PrivacyConfig, SessionReplayPerformanceConfig, SessionReplayVersion } from './types';
export declare const getDefaultConfig: () => {

@@ -21,4 +21,6 @@ flushMaxRetries: number;

shouldInlineStylesheet?: boolean;
version?: SessionReplayVersion;
performanceConfig?: SessionReplayPerformanceConfig;
constructor(apiKey: string, options: SessionReplayOptions);
}
//# sourceMappingURL=local-config.d.ts.map

@@ -27,2 +27,4 @@ import { __assign, __extends } from "tslib";

_this.shouldInlineStylesheet = options.shouldInlineStylesheet;
_this.version = options.version;
_this.performanceConfig = options.performanceConfig;
if (options.privacyConfig) {

@@ -29,0 +31,0 @@ _this.privacyConfig = options.privacyConfig;

import { Config, LogLevel, Logger } from '@amplitude/analytics-types';
import { TargetingFlag } from '@amplitude/targeting';
export interface SamplingConfig {

@@ -12,3 +11,2 @@ sample_rate: number;

}
export type TargetingConfig = TargetingFlag;
export type SessionReplayRemoteConfig = {

@@ -18,3 +16,2 @@ sr_sampling_config?: SamplingConfig;

sr_interaction_config?: InteractionConfig;
sr_targeting_config?: TargetingConfig;
};

@@ -45,5 +42,3 @@ export interface SessionReplayRemoteConfigAPIResponse {

version?: SessionReplayVersion;
userProperties?: {
[key: string]: any;
};
performanceConfig?: SessionReplayPerformanceConfig;
}

@@ -53,3 +48,2 @@ export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {

interactionConfig?: InteractionConfig;
targetingConfig?: TargetingConfig;
}

@@ -69,3 +63,7 @@ export interface SessionReplayRemoteConfigFetch {

}
export interface SessionReplayPerformanceConfig {
enabled: boolean;
timeout?: number;
}
export type SessionReplayType = 'standalone' | 'plugin' | 'segment';
//# sourceMappingURL=types.d.ts.map

@@ -14,3 +14,2 @@ import { PrivacyConfig, SessionReplayJoinedConfig } from './config/types';

interactionConfig?: import("./config/types").InteractionConfig | undefined;
targetingConfig?: import("@amplitude/experiment-core").EvaluationFlag | undefined;
apiKey: string;

@@ -26,11 +25,3 @@ loggerProvider: import("@amplitude/analytics-types").Logger;

version?: import("./config/types").SessionReplayVersion | undefined;
userProperties?: {
[key: string]: any;
} | undefined; /**
* Checks if the given element set to be masked by rrweb
*
* Priority is:
* 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking
* 2. Use app defaults
*/
performanceConfig?: import("./config/types").SessionReplayPerformanceConfig | undefined;
flushIntervalMillis: number;

@@ -37,0 +28,0 @@ flushQueueSize: number;

@@ -16,2 +16,6 @@ import { scrollCallback, scrollPosition } from '@amplitude/rrweb-types';

};
export type ScrollEventPayload = {
version: number;
events: ScrollEvent[];
};
/**

@@ -32,3 +36,3 @@ * This is intended to watch and update max scroll activity when loaded for a particular page.

static default(context: Omit<SessionReplayDestinationSessionMetadata, 'deviceId'>, config: SessionReplayJoinedConfig): ScrollWatcher;
constructor(transport: BeaconTransport<ScrollEvent>);
constructor(transport: BeaconTransport<ScrollEventPayload>);
get maxScrollX(): number;

@@ -35,0 +39,0 @@ get maxScrollY(): number;

@@ -24,11 +24,16 @@ import { utils } from '@amplitude/rrweb';

_this.transport.send(deviceId, {
maxScrollX: _this._maxScrollX,
maxScrollY: _this._maxScrollY,
maxScrollWidth: _this._maxScrollWidth,
maxScrollHeight: _this._maxScrollHeight,
viewportHeight: getWindowHeight(),
viewportWidth: getWindowWidth(),
pageUrl: globalScope.location.href,
timestamp: _this.timestamp,
type: 'scroll',
version: 1,
events: [
{
maxScrollX: _this._maxScrollX,
maxScrollY: _this._maxScrollY,
maxScrollWidth: _this._maxScrollWidth,
maxScrollHeight: _this._maxScrollHeight,
viewportHeight: getWindowHeight(),
viewportWidth: getWindowWidth(),
pageUrl: globalScope.location.href,
timestamp: _this.timestamp,
type: 'scroll',
},
],
});

@@ -35,0 +40,0 @@ }

@@ -1,6 +0,2 @@

export declare const init: (apiKey: string, options: import("./typings/session-replay").SessionReplayOptions) => import("@amplitude/analytics-types").AmplitudeReturn<void>, setSessionId: (sessionId: number, deviceId?: string | undefined, options?: {
userProperties?: {
[key: string]: any;
} | undefined;
} | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<void>, getSessionId: () => number | undefined, evaluateTargetingAndCapture: (targetingParams?: Pick<import("@amplitude/targeting").TargetingParameters, "event" | "userProperties"> | undefined) => Promise<void>, getSessionReplayProperties: () => {
export declare const init: (apiKey: string, options: import("./typings/session-replay").SessionReplayOptions) => import("@amplitude/analytics-types").AmplitudeReturn<void>, setSessionId: (sessionId: number, deviceId?: string | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<void>, getSessionId: () => number | undefined, getSessionReplayProperties: () => {
[key: string]: string | boolean | null;

@@ -7,0 +3,0 @@ }, flush: (useRetry: boolean) => Promise<void>, shutdown: () => void;

import sessionReplay from './session-replay-factory';
export var init = sessionReplay.init, setSessionId = sessionReplay.setSessionId, getSessionId = sessionReplay.getSessionId, evaluateTargetingAndCapture = sessionReplay.evaluateTargetingAndCapture, getSessionReplayProperties = sessionReplay.getSessionReplayProperties, flush = sessionReplay.flush, shutdown = sessionReplay.shutdown;
export var init = sessionReplay.init, setSessionId = sessionReplay.setSessionId, getSessionId = sessionReplay.getSessionId, getSessionReplayProperties = sessionReplay.getSessionReplayProperties, flush = sessionReplay.flush, shutdown = sessionReplay.shutdown;
//# sourceMappingURL=index.js.map

@@ -16,5 +16,4 @@ import { debugWrapper } from '@amplitude/analytics-core';

init: debugWrapper(sessionReplay.init.bind(sessionReplay), 'init', getLogConfig(sessionReplay)),
evaluateTargetingAndCapture: debugWrapper(sessionReplay.evaluateTargetingAndCapture.bind(sessionReplay), 'evaluateTargetingAndRecord', getLogConfig(sessionReplay)),
setSessionId: debugWrapper(sessionReplay.setSessionId.bind(sessionReplay), 'setSessionId', getLogConfig(sessionReplay)),
getSessionId: sessionReplay.getSessionId.bind(sessionReplay),
getSessionId: debugWrapper(sessionReplay.getSessionId.bind(sessionReplay), 'getSessionId', getLogConfig(sessionReplay)),
getSessionReplayProperties: debugWrapper(sessionReplay.getSessionReplayProperties.bind(sessionReplay), 'getSessionReplayProperties', getLogConfig(sessionReplay)),

@@ -21,0 +20,0 @@ flush: debugWrapper(sessionReplay.flush.bind(sessionReplay), 'flush', getLogConfig(sessionReplay)),

import { Logger as ILogger } from '@amplitude/analytics-types';
import { record } from '@amplitude/rrweb';
import { TargetingParameters } from '@amplitude/targeting';
import { SessionReplayJoinedConfig, SessionReplayJoinedConfigGenerator } from './config/types';
import { CustomRRwebEvent } from './constants';
import { AmplitudeSessionReplay, SessionReplayEventsManager as AmplitudeSessionReplayEventsManager, SessionIdentifiers as ISessionIdentifiers, SessionReplayOptions } from './typings/session-replay';
import { EventCompressor } from './events/event-compressor';
type PageLeaveFn = (e: PageTransitionEvent | Event) => void;

@@ -17,3 +17,3 @@ export declare class SessionReplay implements AmplitudeSessionReplay {

eventCount: number;
sessionTargetingMatch: boolean;
eventCompressor: EventCompressor | undefined;
pageLeaveFns: PageLeaveFn[];

@@ -25,12 +25,4 @@ private scrollHook?;

protected _init(apiKey: string, options: SessionReplayOptions): Promise<void>;
setSessionId(sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}): import("@amplitude/analytics-types").AmplitudeReturn<void>;
asyncSetSessionId(sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}): Promise<void>;
setSessionId(sessionId: number, deviceId?: string): import("@amplitude/analytics-types").AmplitudeReturn<void>;
asyncSetSessionId(sessionId: number, deviceId?: string): Promise<void>;
getSessionReplayDebugPropertyValue(): string;

@@ -48,9 +40,9 @@ getSessionReplayProperties(): {

private pageLeaveListener;
evaluateTargetingAndCapture: (targetingParams?: Pick<TargetingParameters, 'event' | 'userProperties'>) => Promise<void>;
sendEvents(sessionId?: number): void;
initialize(shouldSendStoredEvents?: boolean): void;
shouldOptOut(): boolean | undefined;
getShouldCapture(): boolean;
getShouldRecord(): boolean;
getBlockSelectors(): string | string[] | undefined;
getMaskTextSelectors(): string | undefined;
captureEvents(): void;
recordEvents(): void;
addCustomRRWebEvent: (eventName: CustomRRwebEvent, eventData?: {

@@ -57,0 +49,0 @@ [key: string]: any;

import { __assign, __awaiter, __generator, __read, __spreadArray } from "tslib";
import { getAnalyticsConnector, getGlobalScope } from '@amplitude/analytics-client-common';
import { Logger, returnWrapper } from '@amplitude/analytics-core';
import { SpecialEventType } from '@amplitude/analytics-types';
import { pack, record } from '@amplitude/rrweb';
import { record } from '@amplitude/rrweb';
import { createSessionReplayJoinedConfigGenerator } from './config/joined-config';

@@ -14,4 +13,4 @@ import { BLOCK_CLASS, CustomRRwebEvent, DEFAULT_SESSION_REPLAY_PROPERTY, INTERACTION_MAX_INTERVAL, INTERACTION_MIN_INTERVAL, MASK_TEXT_CLASS, SESSION_REPLAY_DEBUG_PROPERTY, } from './constants';

import { SessionIdentifiers } from './identifiers';
import { evaluateTargetingAndStore } from './targeting/targeting-manager';
import { VERSION } from './version';
import { EventCompressor } from './events/event-compressor';
var SessionReplay = /** @class */ (function () {

@@ -23,3 +22,2 @@ function SessionReplay() {

this.eventCount = 0;
this.sessionTargetingMatch = false;
// Visible for testing

@@ -54,4 +52,3 @@ this.pageLeaveFns = [];

// switches tabs, we take a full snapshot
_this.stopRecordingEvents();
_this.captureEvents();
_this.recordEvents();
};

@@ -68,45 +65,2 @@ /**

};
this.evaluateTargetingAndCapture = function (targetingParams) { return __awaiter(_this, void 0, void 0, function () {
var eventForTargeting, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!this.identifiers || !this.identifiers.sessionId || !this.config) {
if (this.identifiers && !this.identifiers.sessionId) {
this.loggerProvider.log('Session ID has not been set yet, cannot evaluate targeting for Session Replay.');
}
else {
this.loggerProvider.warn('Session replay init has not been called, cannot evaluate targeting.');
}
return [2 /*return*/];
}
if (!(this.config.targetingConfig && !this.sessionTargetingMatch)) return [3 /*break*/, 2];
eventForTargeting = targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.event;
if (eventForTargeting &&
Object.values(SpecialEventType).includes(eventForTargeting.event_type)) {
eventForTargeting = undefined;
}
// We're setting this on this class because fetching the value from idb
// is async, we need to access this value synchronously (for record
// and for getSessionReplayProperties - both synchronous fns)
_a = this;
return [4 /*yield*/, evaluateTargetingAndStore({
sessionId: this.identifiers.sessionId,
targetingConfig: this.config.targetingConfig,
loggerProvider: this.loggerProvider,
apiKey: this.config.apiKey,
targetingParams: { userProperties: targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.userProperties, event: eventForTargeting },
})];
case 1:
// We're setting this on this class because fetching the value from idb
// is async, we need to access this value synchronously (for record
// and for getSessionReplayProperties - both synchronous fns)
_a.sessionTargetingMatch = _b.sent();
_b.label = 2;
case 2:
this.captureEvents();
return [2 /*return*/];
}
});
}); };
this.addCustomRRWebEvent = function (eventName, eventData, addStorageInfo) {

@@ -153,5 +107,3 @@ if (eventData === void 0) { eventData = {}; }

try {
if (_this.recordCancelCallback) {
_this.loggerProvider.log('Session Replay capture stopping.');
}
_this.loggerProvider.log('Session Replay capture stopping.');
_this.recordCancelCallback && _this.recordCancelCallback();

@@ -173,3 +125,3 @@ _this.recordCancelCallback = null;

return __awaiter(this, void 0, void 0, function () {
var _d, _e, scrollWatcher, managers, rrwebEventManager, payloadBatcher, interactionEventManager;
var _d, _e, scrollWatcher, managers, rrwebEventManager, error_1, typedError, payloadBatcher, interactionEventManager, error_2, typedError;
return __generator(this, function (_f) {

@@ -195,6 +147,9 @@ switch (_f.label) {

}, this.config);
this.pageLeaveFns = [scrollWatcher.send(this.getDeviceId.bind(this))];
this.pageLeaveFns = [scrollWatcher.send(this.getDeviceId.bind(this)).bind(scrollWatcher)];
this.scrollHook = scrollWatcher.hook.bind(scrollWatcher);
}
managers = [];
_f.label = 3;
case 3:
_f.trys.push([3, 5, , 6]);
return [4 /*yield*/, createEventsManager({

@@ -205,7 +160,17 @@ config: this.config,

})];
case 3:
case 4:
rrwebEventManager = _f.sent();
managers.push({ name: 'replay', manager: rrwebEventManager });
if (!((_b = this.config.interactionConfig) === null || _b === void 0 ? void 0 : _b.enabled)) return [3 /*break*/, 5];
return [3 /*break*/, 6];
case 5:
error_1 = _f.sent();
typedError = error_1;
this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(typedError.toString()));
return [3 /*break*/, 6];
case 6:
if (!((_b = this.config.interactionConfig) === null || _b === void 0 ? void 0 : _b.enabled)) return [3 /*break*/, 10];
payloadBatcher = this.config.interactionConfig.batch ? clickBatcher : clickNonBatcher;
_f.label = 7;
case 7:
_f.trys.push([7, 9, , 10]);
return [4 /*yield*/, createEventsManager({

@@ -219,18 +184,17 @@ config: this.config,

})];
case 4:
case 8:
interactionEventManager = _f.sent();
managers.push({ name: 'interaction', manager: interactionEventManager });
_f.label = 5;
case 5:
return [3 /*break*/, 10];
case 9:
error_2 = _f.sent();
typedError = error_2;
this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(typedError.toString()));
return [3 /*break*/, 10];
case 10:
this.eventsManager = new (MultiEventManager.bind.apply(MultiEventManager, __spreadArray([void 0], __read(managers), false)))();
this.identifiers.deviceId &&
void this.eventsManager.sendStoredEvents({
deviceId: this.identifiers.deviceId,
});
this.eventCompressor = new EventCompressor(this.eventsManager, this.config, this.getDeviceId());
this.loggerProvider.log('Installing @amplitude/session-replay-browser.');
this.teardownEventListeners(false);
this.stopRecordingEvents();
return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options.userProperties })];
case 6:
_f.sent();
this.initialize(true);
return [2 /*return*/];

@@ -241,6 +205,6 @@ }

};
SessionReplay.prototype.setSessionId = function (sessionId, deviceId, options) {
return returnWrapper(this.asyncSetSessionId(sessionId, deviceId, options));
SessionReplay.prototype.setSessionId = function (sessionId, deviceId) {
return returnWrapper(this.asyncSetSessionId(sessionId, deviceId));
};
SessionReplay.prototype.asyncSetSessionId = function (sessionId, deviceId, options) {
SessionReplay.prototype.asyncSetSessionId = function (sessionId, deviceId) {
return __awaiter(this, void 0, void 0, function () {

@@ -251,4 +215,2 @@ var previousSessionId, deviceIdForReplayId, _a;

case 0:
this.stopRecordingEvents();
this.sessionTargetingMatch = false;
previousSessionId = this.identifiers && this.identifiers.sessionId;

@@ -269,5 +231,4 @@ if (previousSessionId) {

_b.label = 2;
case 2: return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options === null || options === void 0 ? void 0 : options.userProperties })];
case 3:
_b.sent();
case 2:
this.recordEvents();
return [2 /*return*/];

@@ -293,3 +254,3 @@ }

}
var shouldRecord = this.getShouldCapture();
var shouldRecord = this.getShouldRecord();
var eventProperties = {};

@@ -323,2 +284,17 @@ if (shouldRecord) {

};
SessionReplay.prototype.initialize = function (shouldSendStoredEvents) {
var _a;
if (shouldSendStoredEvents === void 0) { shouldSendStoredEvents = false; }
if (!((_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId)) {
this.loggerProvider.log("Session is not being recorded due to lack of session id.");
return;
}
var deviceId = this.getDeviceId();
if (!deviceId) {
this.loggerProvider.log("Session is not being recorded due to lack of device id.");
return;
}
this.eventsManager && shouldSendStoredEvents && this.eventsManager.sendStoredEvents({ deviceId: deviceId });
this.recordEvents();
};
SessionReplay.prototype.shouldOptOut = function () {

@@ -333,5 +309,5 @@ var _a, _b;

};
SessionReplay.prototype.getShouldCapture = function () {
SessionReplay.prototype.getShouldRecord = function () {
if (!this.identifiers || !this.config || !this.identifiers.sessionId) {
this.loggerProvider.warn("Session is not being captured due to lack of config, please call sessionReplay.init.");
this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init.");
return false;

@@ -344,23 +320,10 @@ }

if (this.shouldOptOut()) {
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of replay capture due to optOut config."));
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of recording due to optOut config."));
return false;
}
// If targetingConfig exists, we'll use the sessionTargetingMatch to determine whether to record
// Otherwise, we'll evaluate the session against the overall sample rate
if (this.config.targetingConfig) {
if (!this.sessionTargetingMatch) {
this.loggerProvider.log("Not capturing replays for session ".concat(this.identifiers.sessionId, " due to not matching targeting conditions."));
return false;
}
this.loggerProvider.log("Capturing replays for session ".concat(this.identifiers.sessionId, " due to matching targeting conditions."));
var isInSample = isSessionInSample(this.identifiers.sessionId, this.config.sampleRate);
if (!isInSample) {
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of recording due to sample rate."));
}
else {
var isInSample = isSessionInSample(this.identifiers.sessionId, this.config.sampleRate);
if (!isInSample) {
this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId, " out of replay capture due to sample rate."));
return false;
}
this.loggerProvider.log("Capturing replays for session ".concat(this.identifiers.sessionId, " due to inclusion in sample rate."));
}
return true;
return isInSample;
};

@@ -389,13 +352,11 @@ SessionReplay.prototype.getBlockSelectors = function () {

};
SessionReplay.prototype.captureEvents = function () {
SessionReplay.prototype.recordEvents = function () {
var _this = this;
if (this.recordCancelCallback) {
this.loggerProvider.debug('captureEvents method fired - Session Replay capture already in progress.');
return;
}
var shouldRecord = this.getShouldCapture();
var sessionId = this.identifiers && this.identifiers.sessionId;
var _a;
var shouldRecord = this.getShouldRecord();
var sessionId = (_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId;
if (!shouldRecord || !sessionId || !this.config) {
return;
}
this.stopRecordingEvents();
var privacyConfig = this.config.privacyConfig;

@@ -406,3 +367,3 @@ this.loggerProvider.log('Session Replay capture beginning.');

if (_this.shouldOptOut()) {
_this.loggerProvider.log("Opting session ".concat(sessionId, " out of replay capture due to optOut config."));
_this.loggerProvider.log("Opting session ".concat(sessionId, " out of recording due to optOut config."));
_this.stopRecordingEvents();

@@ -412,9 +373,7 @@ _this.sendEvents();

}
var eventString = JSON.stringify(event);
var deviceId = _this.getDeviceId();
_this.eventsManager &&
deviceId &&
_this.eventsManager.addEvent({ event: { type: 'replay', data: eventString }, sessionId: sessionId, deviceId: deviceId });
if (_this.eventCompressor) {
// Schedule processing during idle time if the browser supports requestIdleCallback
_this.eventCompressor.enqueueEvent(event, sessionId);
}
},
packFn: pack,
inlineStylesheet: this.config.shouldInlineStylesheet,

@@ -460,9 +419,4 @@ hooks: {

SessionReplay.prototype.getDeviceId = function () {
var _a, _b;
var identityStoreDeviceId;
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.instanceName) {
var identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;
identityStoreDeviceId = identityStore.getIdentity().deviceId;
}
return identityStoreDeviceId || ((_b = this.identifiers) === null || _b === void 0 ? void 0 : _b.deviceId);
var _a;
return (_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.deviceId;
};

@@ -469,0 +423,0 @@ SessionReplay.prototype.getSessionId = function () {

import { AmplitudeReturn, ServerZone } from '@amplitude/analytics-types';
import { SessionReplayJoinedConfig, SessionReplayLocalConfig, SessionReplayVersion } from '../config/types';
import { TargetingParameters } from '@amplitude/targeting';
export type StorageData = {

@@ -63,7 +62,3 @@ totalStorageSize: number;

init: (apiKey: string, options: SessionReplayOptions) => AmplitudeReturn<void>;
setSessionId: (sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}) => AmplitudeReturn<void>;
setSessionId: (sessionId: number, deviceId?: string) => AmplitudeReturn<void>;
getSessionId: () => number | undefined;

@@ -73,3 +68,2 @@ getSessionReplayProperties: () => {

};
evaluateTargetingAndCapture: (targetingParams?: Pick<TargetingParameters, 'event' | 'userProperties'>) => Promise<void>;
flush: (useRetry: boolean) => Promise<void>;

@@ -76,0 +70,0 @@ shutdown: () => void;

@@ -1,2 +0,2 @@

export declare const VERSION = "1.14.0-srtargeting.2";
export declare const VERSION = "1.14.0";
//# sourceMappingURL=version.d.ts.map
// Autogenerated by `yarn version-file`. DO NOT EDIT
export var VERSION = '1.14.0-srtargeting.2';
export var VERSION = '1.14.0';
//# sourceMappingURL=version.js.map

@@ -24,2 +24,3 @@ import { SessionReplayJoinedConfig } from './config/types';

private readonly context;
private readonly apiKey;
constructor(context: Omit<SessionReplayDestinationSessionMetadata, 'deviceId'>, config: SessionReplayJoinedConfig);

@@ -26,0 +27,0 @@ send(deviceId: string, payload: T): void;

@@ -5,3 +5,3 @@ import { FetchTransport } from '@amplitude/analytics-client-common';

import { SessionReplayOptions } from '../typings/session-replay';
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, InteractionConfig, PrivacyConfig } from './types';
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, InteractionConfig, PrivacyConfig, SessionReplayPerformanceConfig, SessionReplayVersion } from './types';
export declare const getDefaultConfig: () => {

@@ -21,4 +21,6 @@ flushMaxRetries: number;

shouldInlineStylesheet?: boolean;
version?: SessionReplayVersion;
performanceConfig?: SessionReplayPerformanceConfig;
constructor(apiKey: string, options: SessionReplayOptions);
}
//# sourceMappingURL=local-config.d.ts.map
import { Config, LogLevel, Logger } from '@amplitude/analytics-types';
import { TargetingFlag } from '@amplitude/targeting';
export interface SamplingConfig {

@@ -12,3 +11,2 @@ sample_rate: number;

}
export type TargetingConfig = TargetingFlag;
export type SessionReplayRemoteConfig = {

@@ -18,3 +16,2 @@ sr_sampling_config?: SamplingConfig;

sr_interaction_config?: InteractionConfig;
sr_targeting_config?: TargetingConfig;
};

@@ -45,5 +42,3 @@ export interface SessionReplayRemoteConfigAPIResponse {

version?: SessionReplayVersion;
userProperties?: {
[key: string]: any;
};
performanceConfig?: SessionReplayPerformanceConfig;
}

@@ -53,3 +48,2 @@ export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {

interactionConfig?: InteractionConfig;
targetingConfig?: TargetingConfig;
}

@@ -69,3 +63,7 @@ export interface SessionReplayRemoteConfigFetch {

}
export interface SessionReplayPerformanceConfig {
enabled: boolean;
timeout?: number;
}
export type SessionReplayType = 'standalone' | 'plugin' | 'segment';
//# sourceMappingURL=types.d.ts.map

@@ -14,3 +14,2 @@ import { PrivacyConfig, SessionReplayJoinedConfig } from './config/types';

interactionConfig?: import("./config/types").InteractionConfig | undefined;
targetingConfig?: import("@amplitude/experiment-core").EvaluationFlag | undefined;
apiKey: string;

@@ -26,11 +25,3 @@ loggerProvider: import("@amplitude/analytics-types").Logger;

version?: import("./config/types").SessionReplayVersion | undefined;
userProperties?: {
[key: string]: any;
} | undefined; /**
* Checks if the given element set to be masked by rrweb
*
* Priority is:
* 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking
* 2. Use app defaults
*/
performanceConfig?: import("./config/types").SessionReplayPerformanceConfig | undefined;
flushIntervalMillis: number;

@@ -37,0 +28,0 @@ flushQueueSize: number;

@@ -16,2 +16,6 @@ import { scrollCallback, scrollPosition } from '@amplitude/rrweb-types';

};
export type ScrollEventPayload = {
version: number;
events: ScrollEvent[];
};
/**

@@ -32,3 +36,3 @@ * This is intended to watch and update max scroll activity when loaded for a particular page.

static default(context: Omit<SessionReplayDestinationSessionMetadata, 'deviceId'>, config: SessionReplayJoinedConfig): ScrollWatcher;
constructor(transport: BeaconTransport<ScrollEvent>);
constructor(transport: BeaconTransport<ScrollEventPayload>);
get maxScrollX(): number;

@@ -35,0 +39,0 @@ get maxScrollY(): number;

@@ -1,6 +0,2 @@

export declare const init: (apiKey: string, options: import("./typings/session-replay").SessionReplayOptions) => import("@amplitude/analytics-types").AmplitudeReturn<void>, setSessionId: (sessionId: number, deviceId?: string | undefined, options?: {
userProperties?: {
[key: string]: any;
} | undefined;
} | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<void>, getSessionId: () => number | undefined, evaluateTargetingAndCapture: (targetingParams?: Pick<import("@amplitude/targeting").TargetingParameters, "userProperties" | "event"> | undefined) => Promise<void>, getSessionReplayProperties: () => {
export declare const init: (apiKey: string, options: import("./typings/session-replay").SessionReplayOptions) => import("@amplitude/analytics-types").AmplitudeReturn<void>, setSessionId: (sessionId: number, deviceId?: string | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<void>, getSessionId: () => number | undefined, getSessionReplayProperties: () => {
[key: string]: string | boolean | null;

@@ -7,0 +3,0 @@ }, flush: (useRetry: boolean) => Promise<void>, shutdown: () => void;

import { Logger as ILogger } from '@amplitude/analytics-types';
import { record } from '@amplitude/rrweb';
import { TargetingParameters } from '@amplitude/targeting';
import { SessionReplayJoinedConfig, SessionReplayJoinedConfigGenerator } from './config/types';
import { CustomRRwebEvent } from './constants';
import { AmplitudeSessionReplay, SessionReplayEventsManager as AmplitudeSessionReplayEventsManager, SessionIdentifiers as ISessionIdentifiers, SessionReplayOptions } from './typings/session-replay';
import { EventCompressor } from './events/event-compressor';
type PageLeaveFn = (e: PageTransitionEvent | Event) => void;

@@ -17,3 +17,3 @@ export declare class SessionReplay implements AmplitudeSessionReplay {

eventCount: number;
sessionTargetingMatch: boolean;
eventCompressor: EventCompressor | undefined;
pageLeaveFns: PageLeaveFn[];

@@ -25,12 +25,4 @@ private scrollHook?;

protected _init(apiKey: string, options: SessionReplayOptions): Promise<void>;
setSessionId(sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}): import("@amplitude/analytics-types").AmplitudeReturn<void>;
asyncSetSessionId(sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}): Promise<void>;
setSessionId(sessionId: number, deviceId?: string): import("@amplitude/analytics-types").AmplitudeReturn<void>;
asyncSetSessionId(sessionId: number, deviceId?: string): Promise<void>;
getSessionReplayDebugPropertyValue(): string;

@@ -48,9 +40,9 @@ getSessionReplayProperties(): {

private pageLeaveListener;
evaluateTargetingAndCapture: (targetingParams?: Pick<TargetingParameters, 'event' | 'userProperties'>) => Promise<void>;
sendEvents(sessionId?: number): void;
initialize(shouldSendStoredEvents?: boolean): void;
shouldOptOut(): boolean | undefined;
getShouldCapture(): boolean;
getShouldRecord(): boolean;
getBlockSelectors(): string | string[] | undefined;
getMaskTextSelectors(): string | undefined;
captureEvents(): void;
recordEvents(): void;
addCustomRRWebEvent: (eventName: CustomRRwebEvent, eventData?: {

@@ -57,0 +49,0 @@ [key: string]: any;

import { AmplitudeReturn, ServerZone } from '@amplitude/analytics-types';
import { SessionReplayJoinedConfig, SessionReplayLocalConfig, SessionReplayVersion } from '../config/types';
import { TargetingParameters } from '@amplitude/targeting';
export type StorageData = {

@@ -63,7 +62,3 @@ totalStorageSize: number;

init: (apiKey: string, options: SessionReplayOptions) => AmplitudeReturn<void>;
setSessionId: (sessionId: number, deviceId?: string, options?: {
userProperties?: {
[key: string]: any;
};
}) => AmplitudeReturn<void>;
setSessionId: (sessionId: number, deviceId?: string) => AmplitudeReturn<void>;
getSessionId: () => number | undefined;

@@ -73,3 +68,2 @@ getSessionReplayProperties: () => {

};
evaluateTargetingAndCapture: (targetingParams?: Pick<TargetingParameters, 'event' | 'userProperties'>) => Promise<void>;
flush: (useRetry: boolean) => Promise<void>;

@@ -76,0 +70,0 @@ shutdown: () => void;

@@ -1,2 +0,2 @@

export declare const VERSION = "1.14.0-srtargeting.2";
export declare const VERSION = "1.14.0";
//# sourceMappingURL=version.d.ts.map
{
"name": "@amplitude/session-replay-browser",
"version": "1.14.0-srtargeting.2",
"version": "1.14.0",
"description": "",

@@ -46,3 +46,2 @@ "author": "Amplitude Inc",

"@amplitude/rrweb": "2.0.0-alpha.20",
"@amplitude/targeting": "0.2.0",
"idb": "^8.0.0",

@@ -68,3 +67,3 @@ "tslib": "^2.4.1"

],
"gitHead": "6fa590f6c4e09e8cc0748aa0b04ac74345e2175c"
"gitHead": "6667874e8e3e054631ce29afca03094ac0805cf3"
}

@@ -50,15 +50,5 @@ <p align="center">

### 3. Evaluate targeting (optional)
Any event that occurs within the span of a session replay must be passed to the SDK to evaluate against targeting conditions. This should be done *before* step 4, getting the event properties. If you are not using the targeting condition logic provided via the Amplitude UI, this step is not required.
### 3. Get session replay event properties
Any event that occurs within the span of a session replay must be tagged with properties that signal to Amplitude to include it in the scope of the replay. The following shows an example of how to use the properties
```typescript
const sessionTargetingMatch = sessionReplay.evaluateTargetingAndCapture({ event: {
event_type: EVENT_NAME,
time: EVENT_TIMESTAMP,
event_properties: eventProperties
} });
```
### 4. Get session replay event properties
Any event must be tagged with properties that signal to Amplitude to include it in the scope of the replay. The following shows an example of how to use the properties.
```typescript
const sessionReplayProperties = sessionReplay.getSessionReplayProperties();

@@ -71,3 +61,3 @@ track(EVENT_NAME, {

### 5. Update session id
### 4. Update session id
Any time that the session id for the user changes, the session replay SDK must be notified of that change. Update the session id via the following method:

@@ -82,3 +72,3 @@ ```typescript

### 6. Shutdown (optional)
### 5. Shutdown (optional)
If at any point you would like to discontinue collection of session replays, for example in a part of your application where you would not like sessions to be collected, you can use the following method to stop collection and remove collection event listeners.

@@ -85,0 +75,0 @@ ```typescript

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 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 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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc