@amplitude/plugin-session-replay-browser 1.7.0-srtargeting.0 → 1.7.0-srtargeting.2

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.
@@ -1,19 +1,17 @@
1
- import { BrowserClient, BrowserConfig, DestinationPlugin, Event, Result } from '@amplitude/analytics-types';
1
+ import { BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-types';
2
2
  import { SessionReplayOptions } from './typings/session-replay';
3
- export declare class SessionReplayPlugin implements DestinationPlugin {
3
+ export declare class SessionReplayPlugin implements EnrichmentPlugin {
4
4
  name: string;
5
- type: "destination";
6
- clientRemove: BrowserClient['remove'];
5
+ type: "enrichment";
7
6
  config: BrowserConfig;
8
7
  options: SessionReplayOptions;
9
8
  constructor(options?: SessionReplayOptions);
10
- setup(config: BrowserConfig, client?: BrowserClient): Promise<void>;
11
- execute(event: Event): Promise<Result>;
12
- flush(): Promise<void>;
9
+ setup(config: BrowserConfig): Promise<void>;
10
+ execute(event: Event): Promise<Event>;
13
11
  teardown(): Promise<void>;
14
12
  getSessionReplayProperties(): {
15
13
  [key: string]: string | boolean | null;
16
14
  };
17
15
  }
18
- export declare const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin;
16
+ export declare const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin;
19
17
  //# sourceMappingURL=session-replay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EAEP,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAiDhE,qBAAa,mBAAoB,YAAW,iBAAiB;IAC3D,IAAI,SAA8C;IAClD,IAAI,gBAA0B;IAI9B,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAItC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;gBAElB,OAAO,CAAC,EAAE,oBAAoB;IAQpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa;IA2DnD,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAQtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,iBAIrE,CAAC"}
1
+ {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAoB,MAAM,4BAA4B,CAAC;AAGtG,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGhE,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,IAAI,SAA8C;IAClD,IAAI,eAAyB;IAI7B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;gBAElB,OAAO,CAAC,EAAE,oBAAoB;IAQpC,KAAK,CAAC,MAAM,EAAE,aAAa;IAkD3B,OAAO,CAAC,KAAK,EAAE,KAAK;IA4BpB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,gBAIrE,CAAC"}
@@ -6,80 +6,24 @@ var analytics_types_1 = require("@amplitude/analytics-types");
6
6
  var sessionReplay = tslib_1.__importStar(require("@amplitude/session-replay-browser"));
7
7
  var helpers_1 = require("./helpers");
8
8
  var version_1 = require("./version");
9
- var ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';
10
- var SessionReplayEnrichmentPlugin = /** @class */ (function () {
11
- function SessionReplayEnrichmentPlugin() {
12
- this.name = ENRICHMENT_PLUGIN_NAME;
13
- this.type = 'enrichment';
14
- }
15
- SessionReplayEnrichmentPlugin.prototype.setup = function (_config, _client) {
16
- return tslib_1.__awaiter(this, void 0, void 0, function () {
17
- return tslib_1.__generator(this, function (_a) {
18
- this.config = _config;
19
- return [2 /*return*/];
20
- });
21
- });
22
- };
23
- SessionReplayEnrichmentPlugin.prototype.execute = function (event) {
24
- return tslib_1.__awaiter(this, void 0, void 0, function () {
25
- var userProperties, identityStore, userProperties, sessionRecordingProperties;
26
- return tslib_1.__generator(this, function (_a) {
27
- switch (_a.label) {
28
- case 0:
29
- if (!(this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId())) return [3 /*break*/, 2];
30
- userProperties = void 0;
31
- if (this.config.instanceName) {
32
- identityStore = (0, analytics_client_common_1.getAnalyticsConnector)(this.config.instanceName).identityStore;
33
- userProperties = identityStore.getIdentity().userProperties;
34
- }
35
- return [4 /*yield*/, sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {
36
- userProperties: userProperties || {},
37
- }).promise];
38
- case 1:
39
- _a.sent();
40
- _a.label = 2;
41
- case 2:
42
- if (!(this.config.sessionId && this.config.sessionId === event.session_id)) return [3 /*break*/, 4];
43
- userProperties = void 0;
44
- if (event.event_type === analytics_types_1.SpecialEventType.IDENTIFY) {
45
- userProperties = (0, helpers_1.parseUserProperties)(event);
46
- }
47
- return [4 /*yield*/, sessionReplay.evaluateTargetingAndCapture({ event: event, userProperties: userProperties })];
48
- case 3:
49
- _a.sent();
50
- sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
51
- event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
52
- _a.label = 4;
53
- case 4: return [2 /*return*/, Promise.resolve(event)];
54
- }
55
- });
56
- });
57
- };
58
- return SessionReplayEnrichmentPlugin;
59
- }());
60
9
  var SessionReplayPlugin = /** @class */ (function () {
61
10
  function SessionReplayPlugin(options) {
62
11
  this.name = '@amplitude/plugin-session-replay-browser';
63
- this.type = 'destination';
12
+ this.type = 'enrichment';
64
13
  this.options = tslib_1.__assign({}, options);
65
14
  // The user did not explicitly configure forceSessionTracking to false, default to true.
66
15
  if (this.options.forceSessionTracking !== false) {
67
16
  this.options.forceSessionTracking = true;
68
17
  }
69
18
  }
70
- SessionReplayPlugin.prototype.setup = function (config, client) {
19
+ SessionReplayPlugin.prototype.setup = function (config) {
71
20
  var _a, _b, _c, _d;
72
21
  return tslib_1.__awaiter(this, void 0, void 0, function () {
73
22
  var identityStore, userProperties;
74
23
  return tslib_1.__generator(this, function (_e) {
75
24
  switch (_e.label) {
76
25
  case 0:
77
- if (!client) {
78
- config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');
79
- return [2 /*return*/];
80
- }
81
26
  config.loggerProvider.log("Installing @amplitude/plugin-session-replay, version ".concat(version_1.VERSION, "."));
82
- this.clientRemove = client.remove.bind(client);
83
27
  this.config = config;
84
28
  if (this.options.forceSessionTracking) {
85
29
  if (typeof config.defaultTracking === 'boolean') {
@@ -121,11 +65,6 @@ var SessionReplayPlugin = /** @class */ (function () {
121
65
  userProperties: userProperties,
122
66
  }).promise];
123
67
  case 1:
124
- _e.sent();
125
- // add enrichment plugin to add session replay properties to events
126
- return [4 /*yield*/, client.add(new SessionReplayEnrichmentPlugin()).promise];
127
- case 2:
128
- // add enrichment plugin to add session replay properties to events
129
68
  _e.sent();
130
69
  return [2 /*return*/];
131
70
  }
@@ -134,23 +73,32 @@ var SessionReplayPlugin = /** @class */ (function () {
134
73
  };
135
74
  SessionReplayPlugin.prototype.execute = function (event) {
136
75
  return tslib_1.__awaiter(this, void 0, void 0, function () {
137
- return tslib_1.__generator(this, function (_a) {
138
- return [2 /*return*/, Promise.resolve({
139
- event: event,
140
- code: 200,
141
- message: 'success',
142
- })];
143
- });
144
- });
145
- };
146
- SessionReplayPlugin.prototype.flush = function () {
147
- return tslib_1.__awaiter(this, void 0, void 0, function () {
76
+ var identityStore, userProperties, userProperties, sessionRecordingProperties;
148
77
  return tslib_1.__generator(this, function (_a) {
149
78
  switch (_a.label) {
150
- case 0: return [4 /*yield*/, sessionReplay.flush(false)];
79
+ case 0:
80
+ if (!(this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId())) return [3 /*break*/, 2];
81
+ identityStore = (0, analytics_client_common_1.getAnalyticsConnector)(this.config.instanceName).identityStore;
82
+ userProperties = identityStore.getIdentity().userProperties;
83
+ return [4 /*yield*/, sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {
84
+ userProperties: userProperties || {},
85
+ }).promise];
151
86
  case 1:
152
87
  _a.sent();
153
- return [2 /*return*/];
88
+ _a.label = 2;
89
+ case 2:
90
+ if (!(this.config.sessionId && this.config.sessionId === event.session_id)) return [3 /*break*/, 4];
91
+ userProperties = void 0;
92
+ if (event.event_type === analytics_types_1.SpecialEventType.IDENTIFY) {
93
+ userProperties = (0, helpers_1.parseUserProperties)(event);
94
+ }
95
+ return [4 /*yield*/, sessionReplay.evaluateTargetingAndCapture({ event: event, userProperties: userProperties })];
96
+ case 3:
97
+ _a.sent();
98
+ sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
99
+ event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
100
+ _a.label = 4;
101
+ case 4: return [2 /*return*/, Promise.resolve(event)];
154
102
  }
155
103
  });
156
104
  });
@@ -158,21 +106,13 @@ var SessionReplayPlugin = /** @class */ (function () {
158
106
  SessionReplayPlugin.prototype.teardown = function () {
159
107
  return tslib_1.__awaiter(this, void 0, void 0, function () {
160
108
  return tslib_1.__generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0: return [4 /*yield*/, this.clientRemove(ENRICHMENT_PLUGIN_NAME).promise];
163
- case 1:
164
- _a.sent();
165
- sessionReplay.shutdown();
166
- // the following are initialized in setup() which will always be called first
167
- // here we reset them to null to prevent memory leaks
168
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
169
- // @ts-ignore
170
- this.config = null;
171
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
172
- // @ts-ignore
173
- this.clientRemove = null;
174
- return [2 /*return*/];
175
- }
109
+ sessionReplay.shutdown();
110
+ // the following are initialized in setup() which will always be called first
111
+ // here we reset them to null to prevent memory leaks
112
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
113
+ // @ts-ignore
114
+ this.config = null;
115
+ return [2 /*return*/];
176
116
  });
177
117
  });
178
118
  };
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAAA,8EAA2E;AAC3E,8DAQoC;AACpC,uFAAmE;AACnE,qCAAgD;AAEhD,qCAAoC;AACpC,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,SAAI,GAAG,sBAAsB,CAAC;QAC9B,SAAI,GAAG,YAAqB,CAAC;IAyC/B,CAAC;IAnCO,6CAAK,GAAX,UAAY,OAAsB,EAAE,OAAsB;;;gBACxD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;;;;KACvB;IAEK,+CAAO,GAAb,UAAc,KAAY;;;;;;6BAIpB,CAAA,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,KAAK,aAAa,CAAC,YAAY,EAAE,CAAA,EAA/E,wBAA+E;wBAC7E,cAAc,SAAA,CAAC;wBACnB,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;4BACtB,aAAa,GAAG,IAAA,+CAAqB,EAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,aAAa,CAAC;4BACpF,cAAc,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC;yBAC7D;wBACD,qBAAM,aAAa,CAAC,YAAY,CAAC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AsB,CAAC,CAAC,OAAO,EAAA;;wBAAvD,SAAuD,CAAC;wBACxD,aAAa,CAAC,QAAQ,EAAE,CAAC;wBACzB,6EAA6E;wBAC7E,qDAAqD;wBACrD,6DAA6D;wBAC7D,aAAa;wBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;wBACnB,6DAA6D;wBAC7D,aAAa;wBACb,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;;;;;KAC1B;IAED,wDAA0B,GAA1B;QACE,OAAO,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACpD,CAAC;IACH,0BAAC;AAAD,CAAC,AA5GD,IA4GC;AA5GY,kDAAmB;AA8GzB,IAAM,mBAAmB,GAA0D,UACxF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import { getAnalyticsConnector } from '@amplitude/analytics-client-common';\nimport {\n BrowserClient,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n SpecialEventType,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { parseUserProperties } from './helpers';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\nconst ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';\n\nclass SessionReplayEnrichmentPlugin implements EnrichmentPlugin {\n name = ENRICHMENT_PLUGIN_NAME;\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\n async setup(_config: BrowserConfig, _client: BrowserClient) {\n this.config = _config;\n }\n\n async execute(event: Event) {\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 if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {\n let userProperties;\n if (this.config.instanceName) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n userProperties = identityStore.getIdentity().userProperties;\n }\n await sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {\n userProperties: userProperties || {},\n }).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 (this.config.sessionId && this.config.sessionId === event.session_id) {\n let userProperties;\n if (event.event_type === SpecialEventType.IDENTIFY) {\n userProperties = parseUserProperties(event);\n }\n await sessionReplay.evaluateTargetingAndCapture({ event, userProperties });\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n return Promise.resolve(event);\n }\n}\n\nexport class SessionReplayPlugin implements DestinationPlugin {\n name = '@amplitude/plugin-session-replay-browser';\n type = 'destination' as const;\n // this.client is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n clientRemove: BrowserClient['remove'];\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\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n // The user did not explicitly configure forceSessionTracking to false, default to true.\n if (this.options.forceSessionTracking !== false) {\n this.options.forceSessionTracking = true;\n }\n }\n\n async setup(config: BrowserConfig, client?: BrowserClient) {\n if (!client) {\n config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');\n return;\n }\n\n config.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.clientRemove = client.remove.bind(client);\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 const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\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 configEndpointUrl: this.options.configEndpointUrl,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n userProperties: userProperties,\n }).promise;\n\n // add enrichment plugin to add session replay properties to events\n await client.add(new SessionReplayEnrichmentPlugin()).promise;\n }\n\n async execute(event: Event): Promise<Result> {\n return Promise.resolve({\n event,\n code: 200,\n message: 'success',\n });\n }\n\n async flush(): Promise<void> {\n await sessionReplay.flush(false);\n }\n\n async teardown(): Promise<void> {\n await this.clientRemove(ENRICHMENT_PLUGIN_NAME).promise;\n 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 // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.clientRemove = null;\n }\n\n getSessionReplayProperties() {\n return sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
1
+ {"version":3,"file":"session-replay.js","sourceR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ACH,0BAAC;AAAD,CAAC,AA3GD,IA2GC;AA3GY,kDAAmB;AA6GzB,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import { getAnalyticsConnector } from '@amplitude/analytics-client-common';\nimport { BrowserConfig, EnrichmentPlugin, Event, SpecialEventType } from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { parseUserProperties } from './helpers';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin {\n name = '@amplitude/plugin-session-replay-browser';\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\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n // The user did not explicitly configure forceSessionTracking to false, default to true.\n if (this.options.forceSessionTracking !== false) {\n this.options.forceSessionTracking = true;\n }\n }\n\n async setup(config: BrowserConfig) {\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 const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\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 configEndpointUrl: this.options.configEndpointUrl,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n userProperties: userProperties,\n }).promise;\n }\n\n async execute(event: Event) {\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 if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n await sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {\n userProperties: userProperties || {},\n }).promise;\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 (this.config.sessionId && this.config.sessionId === event.session_id) {\n let userProperties;\n if (event.event_type === SpecialEventType.IDENTIFY) {\n userProperties = parseUserProperties(event);\n }\n await sessionReplay.evaluateTargetingAndCapture({ event, userProperties });\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n return Promise.resolve(event);\n }\n\n async teardown(): Promise<void> {\n 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 }\n\n getSessionReplayProperties() {\n return 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.7.0-srtargeting.0";
1
+ export declare const VERSION = "1.7.0-srtargeting.2";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.VERSION = void 0;
3
3
  // Autogenerated by `yarn version-file`. DO NOT EDIT
4
- exports.VERSION = '1.7.0-srtargeting.0';
4
+ exports.VERSION = '1.7.0-srtargeting.2';
5
5
  //# 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,qBAAqB,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.7.0-srtargeting.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,qBAAqB,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.7.0-srtargeting.2';\n"]}
@@ -1,19 +1,17 @@
1
- import { BrowserClient, BrowserConfig, DestinationPlugin, Event, Result } from '@amplitude/analytics-types';
1
+ import { BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-types';
2
2
  import { SessionReplayOptions } from './typings/session-replay';
3
- export declare class SessionReplayPlugin implements DestinationPlugin {
3
+ export declare class SessionReplayPlugin implements EnrichmentPlugin {
4
4
  name: string;
5
- type: "destination";
6
- clientRemove: BrowserClient['remove'];
5
+ type: "enrichment";
7
6
  config: BrowserConfig;
8
7
  options: SessionReplayOptions;
9
8
  constructor(options?: SessionReplayOptions);
10
- setup(config: BrowserConfig, client?: BrowserClient): Promise<void>;
11
- execute(event: Event): Promise<Result>;
12
- flush(): Promise<void>;
9
+ setup(config: BrowserConfig): Promise<void>;
10
+ execute(event: Event): Promise<Event>;
13
11
  teardown(): Promise<void>;
14
12
  getSessionReplayProperties(): {
15
13
  [key: string]: string | boolean | null;
16
14
  };
17
15
  }
18
- export declare const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin;
16
+ export declare const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin;
19
17
  //# sourceMappingURL=session-replay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EAEP,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAiDhE,qBAAa,mBAAoB,YAAW,iBAAiB;IAC3D,IAAI,SAA8C;IAClD,IAAI,gBAA0B;IAI9B,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAItC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;gBAElB,OAAO,CAAC,EAAE,oBAAoB;IAQpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa;IA2DnD,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAQtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,iBAIrE,CAAC"}
1
+ {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAoB,MAAM,4BAA4B,CAAC;AAGtG,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGhE,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,IAAI,SAA8C;IAClD,IAAI,eAAyB;IAI7B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;gBAElB,OAAO,CAAC,EAAE,oBAAoB;IAQpC,KAAK,CAAC,MAAM,EAAE,aAAa;IAkD3B,OAAO,CAAC,KAAK,EAAE,KAAK;IA4BpB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,gBAIrE,CAAC"}
@@ -1,83 +1,27 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
2
  import { getAnalyticsConnector } from '@amplitude/analytics-client-common';
3
- import { SpecialEventType, } from '@amplitude/analytics-types';
3
+ import { SpecialEventType } from '@amplitude/analytics-types';
4
4
  import * as sessionReplay from '@amplitude/session-replay-browser';
5
5
  import { parseUserProperties } from './helpers';
6
6
  import { VERSION } from './version';
7
- var ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';
8
- var SessionReplayEnrichmentPlugin = /** @class */ (function () {
9
- function SessionReplayEnrichmentPlugin() {
10
- this.name = ENRICHMENT_PLUGIN_NAME;
11
- this.type = 'enrichment';
12
- }
13
- SessionReplayEnrichmentPlugin.prototype.setup = function (_config, _client) {
14
- return __awaiter(this, void 0, void 0, function () {
15
- return __generator(this, function (_a) {
16
- this.config = _config;
17
- return [2 /*return*/];
18
- });
19
- });
20
- };
21
- SessionReplayEnrichmentPlugin.prototype.execute = function (event) {
22
- return __awaiter(this, void 0, void 0, function () {
23
- var userProperties, identityStore, userProperties, sessionRecordingProperties;
24
- return __generator(this, function (_a) {
25
- switch (_a.label) {
26
- case 0:
27
- if (!(this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId())) return [3 /*break*/, 2];
28
- userProperties = void 0;
29
- if (this.config.instanceName) {
30
- identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;
31
- userProperties = identityStore.getIdentity().userProperties;
32
- }
33
- return [4 /*yield*/, sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {
34
- userProperties: userProperties || {},
35
- }).promise];
36
- case 1:
37
- _a.sent();
38
- _a.label = 2;
39
- case 2:
40
- if (!(this.config.sessionId && this.config.sessionId === event.session_id)) return [3 /*break*/, 4];
41
- userProperties = void 0;
42
- if (event.event_type === SpecialEventType.IDENTIFY) {
43
- userProperties = parseUserProperties(event);
44
- }
45
- return [4 /*yield*/, sessionReplay.evaluateTargetingAndCapture({ event: event, userProperties: userProperties })];
46
- case 3:
47
- _a.sent();
48
- sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
49
- event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
50
- _a.label = 4;
51
- case 4: return [2 /*return*/, Promise.resolve(event)];
52
- }
53
- });
54
- });
55
- };
56
- return SessionReplayEnrichmentPlugin;
57
- }());
58
7
  var SessionReplayPlugin = /** @class */ (function () {
59
8
  function SessionReplayPlugin(options) {
60
9
  this.name = '@amplitude/plugin-session-replay-browser';
61
- this.type = 'destination';
10
+ this.type = 'enrichment';
62
11
  this.options = __assign({}, options);
63
12
  // The user did not explicitly configure forceSessionTracking to false, default to true.
64
13
  if (this.options.forceSessionTracking !== false) {
65
14
  this.options.forceSessionTracking = true;
66
15
  }
67
16
  }
68
- SessionReplayPlugin.prototype.setup = function (config, client) {
17
+ SessionReplayPlugin.prototype.setup = function (config) {
69
18
  var _a, _b, _c, _d;
70
19
  return __awaiter(this, void 0, void 0, function () {
71
20
  var identityStore, userProperties;
72
21
  return __generator(this, function (_e) {
73
22
  switch (_e.label) {
74
23
  case 0:
75
- if (!client) {
76
- config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');
77
- return [2 /*return*/];
78
- }
79
24
  config.loggerProvider.log("Installing @amplitude/plugin-session-replay, version ".concat(VERSION, "."));
80
- this.clientRemove = client.remove.bind(client);
81
25
  this.config = config;
82
26
  if (this.options.forceSessionTracking) {
83
27
  if (typeof config.defaultTracking === 'boolean') {
@@ -119,11 +63,6 @@ var SessionReplayPlugin = /** @class */ (function () {
119
63
  userProperties: userProperties,
120
64
  }).promise];
121
65
  case 1:
122
- _e.sent();
123
- // add enrichment plugin to add session replay properties to events
124
- return [4 /*yield*/, client.add(new SessionReplayEnrichmentPlugin()).promise];
125
- case 2:
126
- // add enrichment plugin to add session replay properties to events
127
66
  _e.sent();
128
67
  return [2 /*return*/];
129
68
  }
@@ -132,23 +71,32 @@ var SessionReplayPlugin = /** @class */ (function () {
132
71
  };
133
72
  SessionReplayPlugin.prototype.execute = function (event) {
134
73
  return __awaiter(this, void 0, void 0, function () {
135
- return __generator(this, function (_a) {
136
- return [2 /*return*/, Promise.resolve({
137
- event: event,
138
- code: 200,
139
- message: 'success',
140
- })];
141
- });
142
- });
143
- };
144
- SessionReplayPlugin.prototype.flush = function () {
145
- return __awaiter(this, void 0, void 0, function () {
74
+ var identityStore, userProperties, userProperties, sessionRecordingProperties;
146
75
  return __generator(this, function (_a) {
147
76
  switch (_a.label) {
148
- case 0: return [4 /*yield*/, sessionReplay.flush(false)];
77
+ case 0:
78
+ if (!(this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId())) return [3 /*break*/, 2];
79
+ identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;
80
+ userProperties = identityStore.getIdentity().userProperties;
81
+ return [4 /*yield*/, sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {
82
+ userProperties: userProperties || {},
83
+ }).promise];
149
84
  case 1:
150
85
  _a.sent();
151
- return [2 /*return*/];
86
+ _a.label = 2;
87
+ case 2:
88
+ if (!(this.config.sessionId && this.config.sessionId === event.session_id)) return [3 /*break*/, 4];
89
+ userProperties = void 0;
90
+ if (event.event_type === SpecialEventType.IDENTIFY) {
91
+ userProperties = parseUserProperties(event);
92
+ }
93
+ return [4 /*yield*/, sessionReplay.evaluateTargetingAndCapture({ event: event, userProperties: userProperties })];
94
+ case 3:
95
+ _a.sent();
96
+ sessionRecordingProperties = sessionReplay.getSessionReplayProperties();
97
+ event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
98
+ _a.label = 4;
99
+ case 4: return [2 /*return*/, Promise.resolve(event)];
152
100
  }
153
101
  });
154
102
  });
@@ -156,21 +104,13 @@ var SessionReplayPlugin = /** @class */ (function () {
156
104
  SessionReplayPlugin.prototype.teardown = function () {
157
105
  return __awaiter(this, void 0, void 0, function () {
158
106
  return __generator(this, function (_a) {
159
- switch (_a.label) {
160
- case 0: return [4 /*yield*/, this.clientRemove(ENRICHMENT_PLUGIN_NAME).promise];
161
- case 1:
162
- _a.sent();
163
- sessionReplay.shutdown();
164
- // the following are initialized in setup() which will always be called first
165
- // here we reset them to null to prevent memory leaks
166
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
167
- // @ts-ignore
168
- this.config = null;
169
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
170
- // @ts-ignore
171
- this.clientRemove = null;
172
- return [2 /*return*/];
173
- }
107
+ sessionReplay.shutdown();
108
+ // the following are initialized in setup() which will always be called first
109
+ // here we reset them to null to prevent memory leaks
110
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
111
+ // @ts-ignore
112
+ this.config = null;
113
+ return [2 /*return*/];
174
114
  });
175
115
  });
176
116
  };
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAOL,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACp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,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n SpecialEventType,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { parseUserProperties } from './helpers';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\nconst ENRICHMENT_PLUGIN_NAME = '@amplitude/plugin-session-replay-enrichment-browser';\n\nclass SessionReplayEnrichmentPlugin implements EnrichmentPlugin {\n name = ENRICHMENT_PLUGIN_NAME;\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\n async setup(_config: BrowserConfig, _client: BrowserClient) {\n this.config = _config;\n }\n\n async execute(event: Event) {\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 if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {\n let userProperties;\n if (this.config.instanceName) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n userProperties = identityStore.getIdentity().userProperties;\n }\n await sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {\n userProperties: userProperties || {},\n }).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 (this.config.sessionId && this.config.sessionId === event.session_id) {\n let userProperties;\n if (event.event_type === SpecialEventType.IDENTIFY) {\n userProperties = parseUserProperties(event);\n }\n await sessionReplay.evaluateTargetingAndCapture({ event, userProperties });\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n return Promise.resolve(event);\n }\n}\n\nexport class SessionReplayPlugin implements DestinationPlugin {\n name = '@amplitude/plugin-session-replay-browser';\n type = 'destination' as const;\n // this.client is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n clientRemove: BrowserClient['remove'];\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\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n // The user did not explicitly configure forceSessionTracking to false, default to true.\n if (this.options.forceSessionTracking !== false) {\n this.options.forceSessionTracking = true;\n }\n }\n\n async setup(config: BrowserConfig, client?: BrowserClient) {\n if (!client) {\n config.loggerProvider.error('SessionReplayPlugin requires v1.9.1+ of the Amplitude SDK.');\n return;\n }\n\n config.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.clientRemove = client.remove.bind(client);\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 const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\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 configEndpointUrl: this.options.configEndpointUrl,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n userProperties: userProperties,\n }).promise;\n\n // add enrichment plugin to add session replay properties to events\n await client.add(new SessionReplayEnrichmentPlugin()).promise;\n }\n\n async execute(event: Event): Promise<Result> {\n return Promise.resolve({\n event,\n code: 200,\n message: 'success',\n });\n }\n\n async flush(): Promise<void> {\n await sessionReplay.flush(false);\n }\n\n async teardown(): Promise<void> {\n await this.clientRemove(ENRICHMENT_PLUGIN_NAME).promise;\n 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 // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.clientRemove = null;\n }\n\n getSessionReplayProperties() {\n return sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => DestinationPlugin = (\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,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAA0C,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;IASE,6BAAY,OAA8B;QAR1C,SAAI,GAAG,0CAA0C,CAAC;QAClD,SAAI,GAAG,YAAqB,CAAC;QAQ3B,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;QAC9B,wFAAwF;QACxF,IAAI,IAAI,CAAC,OAAO,CAAC,oBAAoB,KAAK,KAAK,EAAE;YAC/C,IAAI,CAAC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;SAC1C;IACH,CAAC;IAEK,mCAAK,GAAX,UA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,KAAK,KAAK,CAAC,UAAU,CAAA,EAAnE,wBAAmE;wBACjE,cAAc,SAAA,CAAC;wBACnB,IAAI,KAAK,CAAC,UAAU,KAAK,gBAAgB,CAAC,QAAQ,EAAE;4BAClD,cAAc,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;yBAC7C;wBACD,qBAAM,aAAa,CAAC,2BAA2B,CAAC,EAAE,KAAK,OAAA,EAAE,cAAc,gBAAA,EAAE,CAAC,EAAA;;wBAA1E,SAA0E,CAAC;wBACrE,0BAA0B,GAAG,aAAa,CAAC,0BAA0B,EAAE,CAAC;wBAC9E,KAAK,CAAC,gBAAgB,yBACjB,KAAK,CAAC,gBAAgB,GACtB,0BAA0B,CAC9B,CAAC;;4BAEJ,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;KAC/B;IAEK,sCAAQ,GAAd;;;gBACE,aAAa,CAAC,QAAQ,EAAE,CAAC;gBACzB,6EAA6E;gBAC7E,qDAAqD;gBACrD,6DAA6D;gBAC7D,aAAa;gBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;;;;KACpB;IAED,wDAA0B,GAA1B;QACE,OAAO,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACpD,CAAC;IACH,0BAAC;AAAD,CAAC,AA3GD,IA2GC;;AAED,MAAM,CAAC,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { getAnalyticsConnector } from '@amplitude/analytics-client-common';\nimport { BrowserConfig, EnrichmentPlugin, Event, SpecialEventType } from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { parseUserProperties } from './helpers';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin {\n name = '@amplitude/plugin-session-replay-browser';\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\n constructor(options?: SessionReplayOptions) {\n this.options = { ...options };\n // The user did not explicitly configure forceSessionTracking to false, default to true.\n if (this.options.forceSessionTracking !== false) {\n this.options.forceSessionTracking = true;\n }\n }\n\n async setup(config: BrowserConfig) {\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 const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\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 configEndpointUrl: this.options.configEndpointUrl,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n userProperties: userProperties,\n }).promise;\n }\n\n async execute(event: Event) {\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 if (this.config.sessionId && this.config.sessionId !== sessionReplay.getSessionId()) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n const userProperties = identityStore.getIdentity().userProperties;\n await sessionReplay.setSessionId(this.config.sessionId, this.config.deviceId, {\n userProperties: userProperties || {},\n }).promise;\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 (this.config.sessionId && this.config.sessionId === event.session_id) {\n let userProperties;\n if (event.event_type === SpecialEventType.IDENTIFY) {\n userProperties = parseUserProperties(event);\n }\n await sessionReplay.evaluateTargetingAndCapture({ event, userProperties });\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n return Promise.resolve(event);\n }\n\n async teardown(): Promise<void> {\n 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 }\n\n getSessionReplayProperties() {\n return 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.7.0-srtargeting.0";
1
+ export declare const VERSION = "1.7.0-srtargeting.2";
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.7.0-srtargeting.0';
2
+ export var VERSION = '1.7.0-srtargeting.2';
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,qBAAqB,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.7.0-srtargeting.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,qBAAqB,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.7.0-srtargeting.2';\n"]}