@amplitude/plugin-session-replay-browser 1.21.1 → 1.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/cjs/constants.d.ts +2 -0
  2. package/lib/cjs/constants.d.ts.map +1 -1
  3. package/lib/cjs/constants.js +12 -0
  4. package/lib/cjs/constants.js.map +1 -1
  5. package/lib/cjs/helpers.d.ts +3 -0
  6. package/lib/cjs/helpers.d.ts.map +1 -0
  7. package/lib/cjs/helpers.js +21 -0
  8. package/lib/cjs/helpers.js.map +1 -0
  9. package/lib/cjs/session-replay.d.ts +2 -3
  10. package/lib/cjs/session-replay.d.ts.map +1 -1
  11. package/lib/cjs/session-replay.js +31 -20
  12. package/lib/cjs/session-replay.js.map +1 -1
  13. package/lib/cjs/version.d.ts +1 -1
  14. package/lib/cjs/version.js +1 -1
  15. package/lib/cjs/version.js.map +1 -1
  16. package/lib/esm/constants.d.ts +2 -0
  17. package/lib/esm/constants.d.ts.map +1 -1
  18. package/lib/esm/constants.js +9 -0
  19. package/lib/esm/constants.js.map +1 -1
  20. package/lib/esm/helpers.d.ts +3 -0
  21. package/lib/esm/helpers.d.ts.map +1 -0
  22. package/lib/esm/helpers.js +17 -0
  23. package/lib/esm/helpers.js.map +1 -0
  24. package/lib/esm/session-replay.d.ts +2 -3
  25. package/lib/esm/session-replay.d.ts.map +1 -1
  26. package/lib/esm/session-replay.js +31 -20
  27. package/lib/esm/session-replay.js.map +1 -1
  28. package/lib/esm/version.d.ts +1 -1
  29. package/lib/esm/version.js +1 -1
  30. package/lib/esm/version.js.map +1 -1
  31. package/lib/scripts/index-min.js +1 -1
  32. package/lib/scripts/index-min.js.gz +0 -0
  33. package/lib/scripts/index-min.js.map +1 -1
  34. package/lib/scripts/index-min2.js +2 -0
  35. package/lib/scripts/index-min2.js.gz +0 -0
  36. package/lib/scripts/index-min2.js.map +1 -0
  37. package/lib/scripts/plugin-session-replay-browser-min.js +1 -1
  38. package/lib/scripts/plugin-session-replay-browser-min.js.gz +0 -0
  39. package/lib/scripts/plugin-session-replay-browser-min.js.map +1 -1
  40. package/package.json +7 -5
@@ -1 +1,3 @@
1
+ import { IdentifyOperation } from '@amplitude/analytics-types';
2
+ export declare const PROPERTY_ADD_OPERATIONS: IdentifyOperation[];
1
3
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,eAAO,MAAM,uBAAuB,qBAOnC,CAAC"}
@@ -1 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROPERTY_ADD_OPERATIONS = void 0;
4
+ var analytics_types_1 = require("@amplitude/analytics-types");
5
+ exports.PROPERTY_ADD_OPERATIONS = [
6
+ analytics_types_1.IdentifyOperation.SET,
7
+ analytics_types_1.IdentifyOperation.SET_ONCE,
8
+ analytics_types_1.IdentifyOperation.ADD,
9
+ analytics_types_1.IdentifyOperation.APPEND,
10
+ analytics_types_1.IdentifyOperation.PREPEND,
11
+ analytics_types_1.IdentifyOperation.POSTINSERT,
12
+ ];
1
13
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"","sourcesContent":[""]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,8DAA+D;AAElD,QAAA,uBAAuB,GAAG;IACrC,mCAAiB,CAAC,GAAG;IACrB,mCAAiB,CAAC,QAAQ;IAC1B,mCAAiB,CAAC,GAAG;IACrB,mCAAiB,CAAC,MAAM;IACxB,mCAAiB,CAAC,OAAO;IACzB,mCAAiB,CAAC,UAAU;CAC7B,CAAC","sourcesContent":["import { IdentifyOperation } from '@amplitude/analytics-types';\n\nexport const PROPERTY_ADD_OPERATIONS = [\n IdentifyOperation.SET,\n IdentifyOperation.SET_ONCE,\n IdentifyOperation.ADD,\n IdentifyOperation.APPEND,\n IdentifyOperation.PREPEND,\n IdentifyOperation.POSTINSERT,\n];\n"]}
@@ -0,0 +1,3 @@
1
+ import { Event } from '@amplitude/analytics-types';
2
+ export declare const parseUserProperties: (event: Event) => {} | undefined;
3
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,4BAA4B,CAAC;AAGtE,eAAO,MAAM,mBAAmB,UAAW,KAAK,mBAkB/C,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseUserProperties = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var constants_1 = require("./constants");
6
+ var parseUserProperties = function (event) {
7
+ if (!event.user_properties) {
8
+ return;
9
+ }
10
+ var userPropertiesObj = {};
11
+ var userPropertyKeys = Object.keys(event.user_properties);
12
+ userPropertyKeys.forEach(function (identifyKey) {
13
+ if (constants_1.PROPERTY_ADD_OPERATIONS.includes(identifyKey)) {
14
+ var typedUserPropertiesOperation = event.user_properties && event.user_properties[identifyKey];
15
+ userPropertiesObj = tslib_1.__assign(tslib_1.__assign({}, userPropertiesObj), typedUserPropertiesOperation);
16
+ }
17
+ });
18
+ return userPropertiesObj;
19
+ };
20
+ exports.parseUserProperties = parseUserProperties;
21
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;;AACA,yCAAsD;AAE/C,IAAM,mBAAmB,GAAG,UAAC,KAAY;IAC9C,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE;QAC1B,OAAO;KACR;IACD,IAAI,iBAAiB,GAAG,EAAE,CAAC;IAC3B,IAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAE5D,gBAAgB,CAAC,OAAO,CAAC,UAAC,WAAW;QACnC,IAAI,mCAAuB,CAAC,QAAQ,CAAC,WAAgC,CAAC,EAAE;YACtE,IAAM,4BAA4B,GAChC,KAAK,CAAC,eAAe,IAAK,KAAK,CAAC,eAAe,CAAC,WAAgC,CAAyB,CAAC;YAC5G,iBAAiB,yCACZ,iBAAiB,GACjB,4BAA4B,CAChC,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAlBW,QAAA,mBAAmB,uBAkB9B","sourcesContent":["import { Event, IdentifyOperation } from '@amplitude/analytics-types';\nimport { PROPERTY_ADD_OPERATIONS } from './constants';\n\nexport const parseUserProperties = (event: Event) => {\n if (!event.user_properties) {\n return;\n }\n let userPropertiesObj = {};\n const userPropertyKeys = Object.keys(event.user_properties);\n\n userPropertyKeys.forEach((identifyKey) => {\n if (PROPERTY_ADD_OPERATIONS.includes(identifyKey as IdentifyOperation)) {\n const typedUserPropertiesOperation =\n event.user_properties && (event.user_properties[identifyKey as IdentifyOperation] as Record<string, any>);\n userPropertiesObj = {\n ...userPropertiesObj,\n ...typedUserPropertiesOperation,\n };\n }\n });\n return userPropertiesObj;\n};\n"]}
@@ -1,14 +1,13 @@
1
1
  import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';
2
- import * as sessionReplay from '@amplitude/session-replay-browser';
2
+ import { AmplitudeSessionReplay, SessionReplayOptions as SessionReplayBrowserOptions } from '@amplitude/session-replay-browser';
3
3
  import { SessionReplayOptions } from './typings/session-replay';
4
- import { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';
5
4
  export declare class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {
6
5
  static pluginName: string;
7
6
  name: string;
8
7
  type: "enrichment";
9
8
  config: BrowserConfig;
10
9
  options: SessionReplayOptions;
11
- srInitOptions: sessionReplay.SessionReplayOptions;
10
+ srInitOptions: SessionReplayBrowserOptions;
12
11
  sessionReplay: AmplitudeSessionReplay;
13
12
  constructor(options?: SessionReplayOptions);
14
13
  setup(config: BrowserConfig, _client: BrowserClient): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,qBAAa,mBAAoB,YAAW,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;IACxF,MAAM,CAAC,UAAU,SAA8C;IAC/D,IAAI,SAAkC;IACtC,IAAI,eAAyB;IAI7B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,aAAa,EAAE,aAAa,CAAC,oBAAoB,CAAC;IAClD,aAAa,EAAE,sBAAsB,CAOnC;gBAEU,OAAO,CAAC,EAAE,oBAAoB;IAKpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa;IAgEnD,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpD,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAe/C,OAAO,CAAC,KAAK,EAAE,KAAK;IA6CpB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,gBAIrE,CAAC"}
1
+ {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAoB,MAAM,2BAA2B,CAAC;AACpH,OAAO,EAQL,sBAAsB,EACtB,oBAAoB,IAAI,2BAA2B,EACpD,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGhE,qBAAa,mBAAoB,YAAW,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;IACxF,MAAM,CAAC,UAAU,SAA8C;IAC/D,IAAI,SAAkC;IACtC,IAAI,eAAyB;IAI7B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,aAAa,EAAE,2BAA2B,CAAC;IAC3C,aAAa,EAAE,sBAAsB,CAQnC;gBAEU,OAAO,CAAC,EAAE,oBAAoB;IAKpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa;IAmEnD,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpD,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAe/C,OAAO,CAAC,KAAK,EAAE,KAAK;IAkDpB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,gBAIrE,CAAC"}
@@ -2,19 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sessionReplayPlugin = exports.SessionReplayPlugin = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var sessionReplay = tslib_1.__importStar(require("@amplitude/session-replay-browser"));
5
+ var analytics_core_1 = require("@amplitude/analytics-core");
6
+ var session_replay_browser_1 = require("@amplitude/session-replay-browser");
7
+ var analytics_client_common_1 = require("@amplitude/analytics-client-common");
8
+ var helpers_1 = require("./helpers");
6
9
  var version_1 = require("./version");
7
10
  var SessionReplayPlugin = /** @class */ (function () {
8
11
  function SessionReplayPlugin(options) {
9
12
  this.name = SessionReplayPlugin.pluginName;
10
13
  this.type = 'enrichment';
11
14
  this.sessionReplay = {
12
- flush: sessionReplay.flush,
13
- getSessionId: sessionReplay.getSessionId,
14
- getSessionReplayProperties: sessionReplay.getSessionReplayProperties,
15
- init: sessionReplay.init,
16
- setSessionId: sessionReplay.setSessionId,
17
- shutdown: sessionReplay.shutdown,
15
+ flush: session_replay_browser_1.flush,
16
+ getSessionId: session_replay_browser_1.getSessionId,
17
+ getSessionReplayProperties: session_replay_browser_1.getSessionReplayProperties,
18
+ init: session_replay_browser_1.init,
19
+ setSessionId: session_replay_browser_1.setSessionId,
20
+ shutdown: session_replay_browser_1.shutdown,
21
+ evaluateTargetingAndCapture: session_replay_browser_1.evaluateTargetingAndCapture,
18
22
  };
19
23
  this.options = tslib_1.__assign({ forceSessionTracking: false }, options);
20
24
  this.srInitOptions = this.options;
@@ -22,7 +26,7 @@ var SessionReplayPlugin = /** @class */ (function () {
22
26
  SessionReplayPlugin.prototype.setup = function (config, _client) {
23
27
  var _a, _b, _c, _d, _e;
24
28
  return tslib_1.__awaiter(this, void 0, void 0, function () {
25
- var error_1;
29
+ var identityStore, userProperties, error_1;
26
30
  return tslib_1.__generator(this, function (_f) {
27
31
  switch (_f.label) {
28
32
  case 0:
@@ -45,6 +49,8 @@ var SessionReplayPlugin = /** @class */ (function () {
45
49
  config.defaultTracking = tslib_1.__assign(tslib_1.__assign({}, config.defaultTracking), { sessions: true });
46
50
  }
47
51
  }
52
+ identityStore = (0, analytics_client_common_1.getAnalyticsConnector)(this.config.instanceName).identityStore;
53
+ userProperties = identityStore.getIdentity().userProperties;
48
54
  this.srInitOptions = {
49
55
  instanceName: this.config.instanceName,
50
56
  deviceId: (_a = this.options.deviceId) !== null && _a !== void 0 ? _a : this.config.deviceId,
@@ -69,6 +75,7 @@ var SessionReplayPlugin = /** @class */ (function () {
69
75
  performanceConfig: this.options.performanceConfig,
70
76
  storeType: this.options.storeType,
71
77
  experimental: this.options.experimental,
78
+ userProperties: userProperties,
72
79
  omitElementTags: this.options.omitElementTags,
73
80
  applyBackgroundColorToBlockedElements: this.options.applyBackgroundColorToBlockedElements,
74
81
  interactionConfig: this.options.interactionConfig,
@@ -125,11 +132,11 @@ var SessionReplayPlugin = /** @class */ (function () {
125
132
  SessionReplayPlugin.prototype.execute = function (event) {
126
133
  var _a;
127
134
  return tslib_1.__awaiter(this, void 0, void 0, function () {
128
- var sessionId, sessionRecordingProperties, sessionId, sessionRecordingProperties, error_2;
135
+ var sessionId, sessionRecordingProperties, sessionId, userProperties, sessionRecordingProperties, error_2;
129
136
  return tslib_1.__generator(this, function (_b) {
130
137
  switch (_b.label) {
131
138
  case 0:
132
- _b.trys.push([0, 8, , 9]);
139
+ _b.trys.push([0, 9, , 10]);
133
140
  if (!this.options.customSessionId) return [3 /*break*/, 4];
134
141
  sessionId = this.options.customSessionId(event);
135
142
  if (!sessionId) return [3 /*break*/, 3];
@@ -142,7 +149,7 @@ var SessionReplayPlugin = /** @class */ (function () {
142
149
  sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();
143
150
  event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
144
151
  _b.label = 3;
145
- case 3: return [3 /*break*/, 7];
152
+ case 3: return [3 /*break*/, 8];
146
153
  case 4:
147
154
  sessionId = this.config.sessionId;
148
155
  if (!(sessionId && sessionId !== this.sessionReplay.getSessionId())) return [3 /*break*/, 6];
@@ -151,20 +158,24 @@ var SessionReplayPlugin = /** @class */ (function () {
151
158
  _b.sent();
152
159
  _b.label = 6;
153
160
  case 6:
154
- // Treating config.sessionId as source of truth, if the event's session id doesn't match, the
155
- // event is not of the current session (offline/late events). In that case, don't tag the events
156
- if (sessionId && sessionId === event.session_id) {
157
- sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();
158
- event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
161
+ if (!(sessionId && sessionId === event.session_id)) return [3 /*break*/, 8];
162
+ userProperties = void 0;
163
+ if (event.event_type === analytics_core_1.SpecialEventType.IDENTIFY) {
164
+ userProperties = (0, helpers_1.parseUserProperties)(event);
159
165
  }
160
- _b.label = 7;
161
- case 7: return [2 /*return*/, Promise.resolve(event)];
162
- case 8:
166
+ return [4 /*yield*/, this.sessionReplay.evaluateTargetingAndCapture({ event: event, userProperties: userProperties })];
167
+ case 7:
168
+ _b.sent();
169
+ sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();
170
+ event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
171
+ _b.label = 8;
172
+ case 8: return [2 /*return*/, Promise.resolve(event)];
173
+ case 9:
163
174
  error_2 = _b.sent();
164
175
  /* istanbul ignore next */
165
176
  (_a = this.config) === null || _a === void 0 ? void 0 : _a.loggerProvider.error("Session Replay: Failed to enrich event due to ".concat(error_2.message));
166
177
  return [2 /*return*/, Promise.resolve(event)];
167
- case 9: return [2 /*return*/];
178
+ case 10: return [2 /*return*/];
168
179
  }
169
180
  });
170
181
  });
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;;AACA,uFAAmE;AAEnE,qCAAoC;AAGpC;IAmBE,6BAAY,OAA8B;QAjB1C,SAAI,GAAG,mBAAmB,CAAC,UAAU,CAAC;QACtC,SAAI,GAAG,YAAqB,CAAC;QAO7B,kBAAa,GAA2B;YACtC,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,YAAY,EAAE,aAAa,C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,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;;KAEjC;IAEK,sCAAQ,GAAd;;;;gBACE,IAAI;oBACF,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;oBAC9B,6EAA6E;oBAC7E,qDAAqD;oBACrD,6DAA6D;oBAC7D,aAAa;oBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;iBACpB;gBAAC,OAAO,KAAK,EAAE;oBACd,0BAA0B;oBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,iDAA2C,KAAe,CAAC,OAAO,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAED,wDAA0B,GAA1B;QACE,OAAO,IAAI,CAAC,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACzD,CAAC;IA1KM,8BAAU,GAAG,0CAA0C,CAAC;IA2KjE,0BAAC;CAAA,AA5KD,IA4KC;AA5KY,kDAAmB;AA8KzB,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\nimport { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n static pluginName = '@amplitude/plugin-session-replay-browser';\n name = SessionReplayPlugin.pluginName;\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n srInitOptions: sessionReplay.SessionReplayOptions;\n sessionReplay: AmplitudeSessionReplay = {\n flush: sessionReplay.flush,\n getSessionId: sessionReplay.getSessionId,\n getSessionReplayProperties: sessionReplay.getSessionReplayProperties,\n init: sessionReplay.init,\n setSessionId: sessionReplay.setSessionId,\n shutdown: sessionReplay.shutdown,\n };\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n this.srInitOptions = this.options;\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n\n this.srInitOptions = {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n omitElementTags: this.options.omitElementTags,\n applyBackgroundColorToBlockedElements: this.options.applyBackgroundColorToBlockedElements,\n interactionConfig: this.options.interactionConfig,\n captureDocumentTitle: this.options.captureDocumentTitle,\n enableUrlChangePolling: this.options.enableUrlChangePolling,\n urlChangePollingInterval: this.options.urlChangePollingInterval,\n };\n\n await this.sessionReplay.init(config.apiKey, this.srInitOptions).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async onSessionIdChanged(sessionId: number): Promise<void> {\n this.config.loggerProvider.debug(\n `Analytics session id is changed to ${sessionId}, SR session id is ${String(this.sessionReplay.getSessionId())}.`,\n );\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n async onOptOutChanged(optOut: boolean): Promise<void> {\n this.config.loggerProvider.debug(\n `optOut is changed to ${String(optOut)}, calling ${\n optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()'\n }.`,\n );\n // TODO: compare optOut with this.sessionReplay.getOptOut().\n // Need to add getOptOut() to the interface AmplitudeSessionReplay first.\n if (optOut) {\n this.sessionReplay.shutdown();\n } else {\n await this.sessionReplay.init(this.config.apiKey, this.srInitOptions).promise;\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n this.sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return this.sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
1
+ {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;;AAAA,4DAAoH;AACpH,4EAU2C;AAC3C,8EAA2E;AAC3E,qCAAgD;AAEhD,qCAAoC;AAEpC;IAoBE,6BAAY,OAA8B;QAlB1C,SAAI,GAAG,mBAAmB,CAAC,UAAU,CAAC;QACtC,SAAI,GAAG,YAAqB,CAAC;QAO7B,kBAAa,GAA2B;YACtC,KAAK,EAAE,8BAAK;YACZ,YAAY,EAAE,qCAAY;YAC1B,0BAA0B,EAAE,mDAA0B;YACtD,IAAI,EAAE,6BAAI;YACV,YAAY,EAAE,qCAAY;YAC1B,QAAQ,EAAE,iCAAQ;YAClB,2BAA2B,EAAE,oDAA2B;SACzD,CAAC;QAGA,IAAI,CAAC,OAAO,sBAAK,oBAAoB,EAAE,KAAK,IAAK,OAAO,CAAE,CAAC;QAC3D,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC;IACpC,CAAC;IAEK,mCAAK,GA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MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,wDAAkD,OAAe,CAAC,OAAO,CAAE,CAAC,CAAC;wBAC/G,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;;KAEjC;IAEK,sCAAQ,GAAd;;;;gBACE,IAAI;oBACF,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;oBAC9B,6EAA6E;oBAC7E,qDAAqD;oBACrD,6DAA6D;oBAC7D,aAAa;oBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;iBACpB;gBAAC,OAAO,KAAK,EAAE;oBACd,0BAA0B;oBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,iDAA2C,KAAe,CAAC,OAAO,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAED,wDAA0B,GAA1B;QACE,OAAO,IAAI,CAAC,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACzD,CAAC;IAnLM,8BAAU,GAAG,0CAA0C,CAAC;IAoLjE,0BAAC;CAAA,AArLD,IAqLC;AArLY,kDAAmB;AAuLzB,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event, SpecialEventType } from '@amplitude/analytics-core';\nimport {\n init,\n setSessionId,\n getSessionId,\n getSessionReplayProperties,\n flush,\n shutdown,\n evaluateTargetingAndCapture,\n AmplitudeSessionReplay,\n SessionReplayOptions as SessionReplayBrowserOptions,\n} from '@amplitude/session-replay-browser';\nimport { getAnalyticsConnector } from '@amplitude/analytics-client-common';\nimport { parseUserProperties } from './helpers';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n static pluginName = '@amplitude/plugin-session-replay-browser';\n name = SessionReplayPlugin.pluginName;\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n srInitOptions: SessionReplayBrowserOptions;\n sessionReplay: AmplitudeSessionReplay = {\n flush: flush,\n getSessionId: getSessionId,\n getSessionReplayProperties: getSessionReplayProperties,\n init: init,\n setSessionId: setSessionId,\n shutdown: shutdown,\n evaluateTargetingAndCapture: evaluateTargetingAndCapture,\n };\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n this.srInitOptions = this.options;\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n\n this.srInitOptions = {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n userProperties: userProperties,\n omitElementTags: this.options.omitElementTags,\n applyBackgroundColorToBlockedElements: this.options.applyBackgroundColorToBlockedElements,\n interactionConfig: this.options.interactionConfig,\n captureDocumentTitle: this.options.captureDocumentTitle,\n enableUrlChangePolling: this.options.enableUrlChangePolling,\n urlChangePollingInterval: this.options.urlChangePollingInterval,\n };\n\n await this.sessionReplay.init(config.apiKey, this.srInitOptions).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async onSessionIdChanged(sessionId: number): Promise<void> {\n this.config.loggerProvider.debug(\n `Analytics session id is changed to ${sessionId}, SR session id is ${String(this.sessionReplay.getSessionId())}.`,\n );\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n async onOptOutChanged(optOut: boolean): Promise<void> {\n this.config.loggerProvider.debug(\n `optOut is changed to ${String(optOut)}, calling ${\n optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()'\n }.`,\n );\n // TODO: compare optOut with this.sessionReplay.getOptOut().\n // Need to add getOptOut() to the interface AmplitudeSessionReplay first.\n if (optOut) {\n this.sessionReplay.shutdown();\n } else {\n await this.sessionReplay.init(this.config.apiKey, this.srInitOptions).promise;\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n let userProperties;\n if (event.event_type === SpecialEventType.IDENTIFY) {\n userProperties = parseUserProperties(event);\n }\n await this.sessionReplay.evaluateTargetingAndCapture({ event, userProperties });\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n this.sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return this.sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.21.1";
1
+ export declare const VERSION = "1.22.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Autogenerated by `yarn version-file`. DO NOT EDIT
5
- exports.VERSION = '1.21.1';
5
+ exports.VERSION = '1.22.1';
6
6
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.21.1';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.22.1';\n"]}
@@ -1 +1,3 @@
1
+ import { IdentifyOperation } from '@amplitude/analytics-types';
2
+ export declare const PROPERTY_ADD_OPERATIONS: IdentifyOperation[];
1
3
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,eAAO,MAAM,uBAAuB,qBAOnC,CAAC"}
@@ -1 +1,10 @@
1
+ import { IdentifyOperation } from '@amplitude/analytics-types';
2
+ export var PROPERTY_ADD_OPERATIONS = [
3
+ IdentifyOperation.SET,
4
+ IdentifyOperation.SET_ONCE,
5
+ IdentifyOperation.ADD,
6
+ IdentifyOperation.APPEND,
7
+ IdentifyOperation.PREPEND,
8
+ IdentifyOperation.POSTINSERT,
9
+ ];
1
10
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"","sourcesContent":[""]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,CAAC,IAAM,uBAAuB,GAAG;IACrC,iBAAiB,CAAC,GAAG;IACrB,iBAAiB,CAAC,QAAQ;IAC1B,iBAAiB,CAAC,GAAG;IACrB,iBAAiB,CAAC,MAAM;IACxB,iBAAiB,CAAC,OAAO;IACzB,iBAAiB,CAAC,UAAU;CAC7B,CAAC","sourcesContent":["import { IdentifyOperation } from '@amplitude/analytics-types';\n\nexport const PROPERTY_ADD_OPERATIONS = [\n IdentifyOperation.SET,\n IdentifyOperation.SET_ONCE,\n IdentifyOperation.ADD,\n IdentifyOperation.APPEND,\n IdentifyOperation.PREPEND,\n IdentifyOperation.POSTINSERT,\n];\n"]}
@@ -0,0 +1,3 @@
1
+ import { Event } from '@amplitude/analytics-types';
2
+ export declare const parseUserProperties: (event: Event) => {} | undefined;
3
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,4BAA4B,CAAC;AAGtE,eAAO,MAAM,mBAAmB,UAAW,KAAK,mBAkB/C,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { __assign } from "tslib";
2
+ import { PROPERTY_ADD_OPERATIONS } from './constants';
3
+ export var parseUserProperties = function (event) {
4
+ if (!event.user_properties) {
5
+ return;
6
+ }
7
+ var userPropertiesObj = {};
8
+ var userPropertyKeys = Object.keys(event.user_properties);
9
+ userPropertyKeys.forEach(function (identifyKey) {
10
+ if (PROPERTY_ADD_OPERATIONS.includes(identifyKey)) {
11
+ var typedUserPropertiesOperation = event.user_properties && event.user_properties[identifyKey];
12
+ userPropertiesObj = __assign(__assign({}, userPropertiesObj), typedUserPropertiesOperation);
13
+ }
14
+ });
15
+ return userPropertiesObj;
16
+ };
17
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,CAAC,IAAM,mBAAmB,GAAG,UAAC,KAAY;IAC9C,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE;QAC1B,OAAO;KACR;IACD,IAAI,iBAAiB,GAAG,EAAE,CAAC;IAC3B,IAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAE5D,gBAAgB,CAAC,OAAO,CAAC,UAAC,WAAW;QACnC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,WAAgC,CAAC,EAAE;YACtE,IAAM,4BAA4B,GAChC,KAAK,CAAC,eAAe,IAAK,KAAK,CAAC,eAAe,CAAC,WAAgC,CAAyB,CAAC;YAC5G,iBAAiB,yBACZ,iBAAiB,GACjB,4BAA4B,CAChC,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { Event, IdentifyOperation } from '@amplitude/analytics-types';\nimport { PROPERTY_ADD_OPERATIONS } from './constants';\n\nexport const parseUserProperties = (event: Event) => {\n if (!event.user_properties) {\n return;\n }\n let userPropertiesObj = {};\n const userPropertyKeys = Object.keys(event.user_properties);\n\n userPropertyKeys.forEach((identifyKey) => {\n if (PROPERTY_ADD_OPERATIONS.includes(identifyKey as IdentifyOperation)) {\n const typedUserPropertiesOperation =\n event.user_properties && (event.user_properties[identifyKey as IdentifyOperation] as Record<string, any>);\n userPropertiesObj = {\n ...userPropertiesObj,\n ...typedUserPropertiesOperation,\n };\n }\n });\n return userPropertiesObj;\n};\n"]}
@@ -1,14 +1,13 @@
1
1
  import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';
2
- import * as sessionReplay from '@amplitude/session-replay-browser';
2
+ import { AmplitudeSessionReplay, SessionReplayOptions as SessionReplayBrowserOptions } from '@amplitude/session-replay-browser';
3
3
  import { SessionReplayOptions } from './typings/session-replay';
4
- import { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';
5
4
  export declare class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {
6
5
  static pluginName: string;
7
6
  name: string;
8
7
  type: "enrichment";
9
8
  config: BrowserConfig;
10
9
  options: SessionReplayOptions;
11
- srInitOptions: sessionReplay.SessionReplayOptions;
10
+ srInitOptions: SessionReplayBrowserOptions;
12
11
  sessionReplay: AmplitudeSessionReplay;
13
12
  constructor(options?: SessionReplayOptions);
14
13
  setup(config: BrowserConfig, _client: BrowserClient): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,qBAAa,mBAAoB,YAAW,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;IACxF,MAAM,CAAC,UAAU,SAA8C;IAC/D,IAAI,SAAkC;IACtC,IAAI,eAAyB;IAI7B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,aAAa,EAAE,aAAa,CAAC,oBAAoB,CAAC;IAClD,aAAa,EAAE,sBAAsB,CAOnC;gBAEU,OAAO,CAAC,EAAE,oBAAoB;IAKpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa;IAgEnD,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OA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,OAAO,CAAC,EAAE,oBAAoB,KAAK,gBAIrE,CAAC"}
@@ -1,17 +1,21 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
- import * as sessionReplay from '@amplitude/session-replay-browser';
2
+ import { SpecialEventType } from '@amplitude/analytics-core';
3
+ import { init, setSessionId, getSessionId, getSessionReplayProperties, flush, shutdown, evaluateTargetingAndCapture, } from '@amplitude/session-replay-browser';
4
+ import { getAnalyticsConnector } from '@amplitude/analytics-client-common';
5
+ import { parseUserProperties } from './helpers';
3
6
  import { VERSION } from './version';
4
7
  var SessionReplayPlugin = /** @class */ (function () {
5
8
  function SessionReplayPlugin(options) {
6
9
  this.name = SessionReplayPlugin.pluginName;
7
10
  this.type = 'enrichment';
8
11
  this.sessionReplay = {
9
- flush: sessionReplay.flush,
10
- getSessionId: sessionReplay.getSessionId,
11
- getSessionReplayProperties: sessionReplay.getSessionReplayProperties,
12
- init: sessionReplay.init,
13
- setSessionId: sessionReplay.setSessionId,
14
- shutdown: sessionReplay.shutdown,
12
+ flush: flush,
13
+ getSessionId: getSessionId,
14
+ getSessionReplayProperties: getSessionReplayProperties,
15
+ init: init,
16
+ setSessionId: setSessionId,
17
+ shutdown: shutdown,
18
+ evaluateTargetingAndCapture: evaluateTargetingAndCapture,
15
19
  };
16
20
  this.options = __assign({ forceSessionTracking: false }, options);
17
21
  this.srInitOptions = this.options;
@@ -19,7 +23,7 @@ var SessionReplayPlugin = /** @class */ (function () {
19
23
  SessionReplayPlugin.prototype.setup = function (config, _client) {
20
24
  var _a, _b, _c, _d, _e;
21
25
  return __awaiter(this, void 0, void 0, function () {
22
- var error_1;
26
+ var identityStore, userProperties, error_1;
23
27
  return __generator(this, function (_f) {
24
28
  switch (_f.label) {
25
29
  case 0:
@@ -42,6 +46,8 @@ var SessionReplayPlugin = /** @class */ (function () {
42
46
  config.defaultTracking = __assign(__assign({}, config.defaultTracking), { sessions: true });
43
47
  }
44
48
  }
49
+ identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;
50
+ userProperties = identityStore.getIdentity().userProperties;
45
51
  this.srInitOptions = {
46
52
  instanceName: this.config.instanceName,
47
53
  deviceId: (_a = this.options.deviceId) !== null && _a !== void 0 ? _a : this.config.deviceId,
@@ -66,6 +72,7 @@ var SessionReplayPlugin = /** @class */ (function () {
66
72
  performanceConfig: this.options.performanceConfig,
67
73
  storeType: this.options.storeType,
68
74
  experimental: this.options.experimental,
75
+ userProperties: userProperties,
69
76
  omitElementTags: this.options.omitElementTags,
70
77
  applyBackgroundColorToBlockedElements: this.options.applyBackgroundColorToBlockedElements,
71
78
  interactionConfig: this.options.interactionConfig,
@@ -122,11 +129,11 @@ var SessionReplayPlugin = /** @class */ (function () {
122
129
  SessionReplayPlugin.prototype.execute = function (event) {
123
130
  var _a;
124
131
  return __awaiter(this, void 0, void 0, function () {
125
- var sessionId, sessionRecordingProperties, sessionId, sessionRecordingProperties, error_2;
132
+ var sessionId, sessionRecordingProperties, sessionId, userProperties, sessionRecordingProperties, error_2;
126
133
  return __generator(this, function (_b) {
127
134
  switch (_b.label) {
128
135
  case 0:
129
- _b.trys.push([0, 8, , 9]);
136
+ _b.trys.push([0, 9, , 10]);
130
137
  if (!this.options.customSessionId) return [3 /*break*/, 4];
131
138
  sessionId = this.options.customSessionId(event);
132
139
  if (!sessionId) return [3 /*break*/, 3];
@@ -139,7 +146,7 @@ var SessionReplayPlugin = /** @class */ (function () {
139
146
  sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();
140
147
  event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
141
148
  _b.label = 3;
142
- case 3: return [3 /*break*/, 7];
149
+ case 3: return [3 /*break*/, 8];
143
150
  case 4:
144
151
  sessionId = this.config.sessionId;
145
152
  if (!(sessionId && sessionId !== this.sessionReplay.getSessionId())) return [3 /*break*/, 6];
@@ -148,20 +155,24 @@ var SessionReplayPlugin = /** @class */ (function () {
148
155
  _b.sent();
149
156
  _b.label = 6;
150
157
  case 6:
151
- // Treating config.sessionId as source of truth, if the event's session id doesn't match, the
152
- // event is not of the current session (offline/late events). In that case, don't tag the events
153
- if (sessionId && sessionId === event.session_id) {
154
- sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();
155
- event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
158
+ if (!(sessionId && sessionId === event.session_id)) return [3 /*break*/, 8];
159
+ userProperties = void 0;
160
+ if (event.event_type === SpecialEventType.IDENTIFY) {
161
+ userProperties = parseUserProperties(event);
156
162
  }
157
- _b.label = 7;
158
- case 7: return [2 /*return*/, Promise.resolve(event)];
159
- case 8:
163
+ return [4 /*yield*/, this.sessionReplay.evaluateTargetingAndCapture({ event: event, userProperties: userProperties })];
164
+ case 7:
165
+ _b.sent();
166
+ sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();
167
+ event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
168
+ _b.label = 8;
169
+ case 8: return [2 /*return*/, Promise.resolve(event)];
170
+ case 9:
160
171
  error_2 = _b.sent();
161
172
  /* istanbul ignore next */
162
173
  (_a = this.config) === null || _a === void 0 ? void 0 : _a.loggerProvider.error("Session Replay: Failed to enrich event due to ".concat(error_2.message));
163
174
  return [2 /*return*/, Promise.resolve(event)];
164
- case 9: return [2 /*return*/];
175
+ case 10: return [2 /*return*/];
165
176
  }
166
177
  });
167
178
  });
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC;IAmBE,6BAAY,OAA8B;QAjB1C,SAAI,GAAG,mBAAmB,CAAC,UAAU,CAAC;QACtC,SAAI,GAAG,YAAqB,CAAC;QAO7B,kBAAa,GAA2B;YACtC,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,YAAY,EAAE,aAAa,CAAC,YAAY;YACxC,0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AC,KAAK,CAAC,EAAC;;;;;KAEjC;IAEK,sCAAQ,GAAd;;;;gBACE,IAAI;oBACF,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;oBAC9B,6EAA6E;oBAC7E,qDAAqD;oBACrD,6DAA6D;oBAC7D,aAAa;oBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;iBACpB;gBAAC,OAAO,KAAK,EAAE;oBACd,0BAA0B;oBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,iDAA2C,KAAe,CAAC,OAAO,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAED,wDAA0B,GAA1B;QACE,OAAO,IAAI,CAAC,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACzD,CAAC;IA1KM,8BAAU,GAAG,0CAA0C,CAAC;IA2KjE,0BAAC;CAAA,AA5KD,IA4KC;SA5KY,mBAAmB;AA8KhC,MAAM,CAAC,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\nimport { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n static pluginName = '@amplitude/plugin-session-replay-browser';\n name = SessionReplayPlugin.pluginName;\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n srInitOptions: sessionReplay.SessionReplayOptions;\n sessionReplay: AmplitudeSessionReplay = {\n flush: sessionReplay.flush,\n getSessionId: sessionReplay.getSessionId,\n getSessionReplayProperties: sessionReplay.getSessionReplayProperties,\n init: sessionReplay.init,\n setSessionId: sessionReplay.setSessionId,\n shutdown: sessionReplay.shutdown,\n };\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n this.srInitOptions = this.options;\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n\n this.srInitOptions = {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n omitElementTags: this.options.omitElementTags,\n applyBackgroundColorToBlockedElements: this.options.applyBackgroundColorToBlockedElements,\n interactionConfig: this.options.interactionConfig,\n captureDocumentTitle: this.options.captureDocumentTitle,\n enableUrlChangePolling: this.options.enableUrlChangePolling,\n urlChangePollingInterval: this.options.urlChangePollingInterval,\n };\n\n await this.sessionReplay.init(config.apiKey, this.srInitOptions).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async onSessionIdChanged(sessionId: number): Promise<void> {\n this.config.loggerProvider.debug(\n `Analytics session id is changed to ${sessionId}, SR session id is ${String(this.sessionReplay.getSessionId())}.`,\n );\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n async onOptOutChanged(optOut: boolean): Promise<void> {\n this.config.loggerProvider.debug(\n `optOut is changed to ${String(optOut)}, calling ${\n optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()'\n }.`,\n );\n // TODO: compare optOut with this.sessionReplay.getOptOut().\n // Need to add getOptOut() to the interface AmplitudeSessionReplay first.\n if (optOut) {\n this.sessionReplay.shutdown();\n } else {\n await this.sessionReplay.init(this.config.apiKey, this.srInitOptions).promise;\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n this.sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return this.sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
1
+ {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AAAA,OAAO,EAAyD,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACpH,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,0BAA0B,EAC1B,KAAK,EACL,QAAQ,EACR,2BAA2B,GAG5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;IAoBE,6BAAY,OAA8B;QAlB1C,SAAI,GAAG,mBAAmB,CAAC,UAAU,CAAC;QACtC,SAAI,GAAG,YAAqB,CAAC;QAO7B,kBAAa,GAA2B;YACtC,KAAK,EAAE,KAAK;YACZ,YAAY,EAAE,YAAY;YAC1B,0BAA0B,EAAE,0BAA0B;YACtD,IAAI,EAAE,IAAI;YACV,YAAY,EAAE,YAAY;YAC1B,QAAQ,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a,CAAC,0BAA0B,EAAE,CAAC;wBACnF,KAAK,CAAC,gBAAgB,yBACjB,KAAK,CAAC,gBAAgB,GACtB,0BAA0B,CAC9B,CAAC;;4BAIN,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;wBAE9B,0BAA0B;wBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,wDAAkD,OAAe,CAAC,OAAO,CAAE,CAAC,CAAC;wBAC/G,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;;KAEjC;IAEK,sCAAQ,GAAd;;;;gBACE,IAAI;oBACF,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;oBAC9B,6EAA6E;oBAC7E,qDAAqD;oBACrD,6DAA6D;oBAC7D,aAAa;oBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;iBACpB;gBAAC,OAAO,KAAK,EAAE;oBACd,0BAA0B;oBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,iDAA2C,KAAe,CAAC,OAAO,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAED,wDAA0B,GAA1B;QACE,OAAO,IAAI,CAAC,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACzD,CAAC;IAnLM,8BAAU,GAAG,0CAA0C,CAAC;IAoLjE,0BAAC;CAAA,AArLD,IAqLC;SArLY,mBAAmB;AAuLhC,MAAM,CAAC,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event, SpecialEventType } from '@amplitude/analytics-core';\nimport {\n init,\n setSessionId,\n getSessionId,\n getSessionReplayProperties,\n flush,\n shutdown,\n evaluateTargetingAndCapture,\n AmplitudeSessionReplay,\n SessionReplayOptions as SessionReplayBrowserOptions,\n} from '@amplitude/session-replay-browser';\nimport { getAnalyticsConnector } from '@amplitude/analytics-client-common';\nimport { parseUserProperties } from './helpers';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n static pluginName = '@amplitude/plugin-session-replay-browser';\n name = SessionReplayPlugin.pluginName;\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n srInitOptions: SessionReplayBrowserOptions;\n sessionReplay: AmplitudeSessionReplay = {\n flush: flush,\n getSessionId: getSessionId,\n getSessionReplayProperties: getSessionReplayProperties,\n init: init,\n setSessionId: setSessionId,\n shutdown: shutdown,\n evaluateTargetingAndCapture: evaluateTargetingAndCapture,\n };\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n this.srInitOptions = this.options;\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n\n this.srInitOptions = {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n userProperties: userProperties,\n omitElementTags: this.options.omitElementTags,\n applyBackgroundColorToBlockedElements: this.options.applyBackgroundColorToBlockedElements,\n interactionConfig: this.options.interactionConfig,\n captureDocumentTitle: this.options.captureDocumentTitle,\n enableUrlChangePolling: this.options.enableUrlChangePolling,\n urlChangePollingInterval: this.options.urlChangePollingInterval,\n };\n\n await this.sessionReplay.init(config.apiKey, this.srInitOptions).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async onSessionIdChanged(sessionId: number): Promise<void> {\n this.config.loggerProvider.debug(\n `Analytics session id is changed to ${sessionId}, SR session id is ${String(this.sessionReplay.getSessionId())}.`,\n );\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n async onOptOutChanged(optOut: boolean): Promise<void> {\n this.config.loggerProvider.debug(\n `optOut is changed to ${String(optOut)}, calling ${\n optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()'\n }.`,\n );\n // TODO: compare optOut with this.sessionReplay.getOptOut().\n // Need to add getOptOut() to the interface AmplitudeSessionReplay first.\n if (optOut) {\n this.sessionReplay.shutdown();\n } else {\n await this.sessionReplay.init(this.config.apiKey, this.srInitOptions).promise;\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== this.sessionReplay.getSessionId()) {\n await this.sessionReplay.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n let userProperties;\n if (event.event_type === SpecialEventType.IDENTIFY) {\n userProperties = parseUserProperties(event);\n }\n await this.sessionReplay.evaluateTargetingAndCapture({ event, userProperties });\n const sessionRecordingProperties = this.sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n this.sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return this.sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.21.1";
1
+ export declare const VERSION = "1.22.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Autogenerated by `yarn version-file`. DO NOT EDIT
2
- export var VERSION = '1.21.1';
2
+ export var VERSION = '1.22.1';
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.21.1';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.22.1';\n"]}