@amplitude/plugin-session-replay-browser 1.2.1 → 1.2.3

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.
@@ -3,7 +3,7 @@ import { SessionReplayOptions } from './typings/session-replay';
3
3
  export declare class SessionReplayPlugin implements DestinationPlugin {
4
4
  name: string;
5
5
  type: "destination";
6
- client: BrowserClient;
6
+ clientRemove: BrowserClient['remove'];
7
7
  config: BrowserConfig;
8
8
  options: SessionReplayOptions;
9
9
  constructor(options?: SessionReplayOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EACP,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAoChE,qBAAa,mBAAoB,YAAW,iBAAiB;IAC3D,IAAI,SAA8C;IAClD,IAAI,gBAA0B;IAI9B,MAAM,EAAE,aAAa,CAAC;IAItB,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;IAiDnD,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":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EACP,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAoChE,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;IAiDnD,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"}
@@ -62,7 +62,7 @@ var SessionReplayPlugin = /** @class */ (function () {
62
62
  return [2 /*return*/];
63
63
  }
64
64
  config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');
65
- this.client = client;
65
+ this.clientRemove = client.remove.bind(client);
66
66
  this.config = config;
67
67
  if (this.options.forceSessionTracking) {
68
68
  if (typeof config.defaultTracking === 'boolean') {
@@ -133,7 +133,7 @@ var SessionReplayPlugin = /** @class */ (function () {
133
133
  return tslib_1.__awaiter(this, void 0, void 0, function () {
134
134
  return tslib_1.__generator(this, function (_a) {
135
135
  switch (_a.label) {
136
- case 0: return [4 /*yield*/, this.client.remove(ENRICHMENT_PLUGIN_NAME).promise];
136
+ case 0: return [4 /*yield*/, this.clientRemove(ENRICHMENT_PLUGIN_NAME).promise];
137
137
  case 1:
138
138
  _a.sent();
139
139
  sessionReplay.shutdown();
@@ -144,7 +144,7 @@ var SessionReplayPlugin = /** @class */ (function () {
144
144
  this.config = null;
145
145
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
146
146
  // @ts-ignore
147
- this.client = null;
147
+ this.clientRemove = null;
148
148
  return [2 /*return*/];
149
149
  }
150
150
  });
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAQA,uFAAmE;AAEnE,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,SAAI,GAAG,sBAAsB,CAAC;QAC9B,SAAI,GAAG,YAAqB,CAAC;IA6B/B,CAAC;IAvBO,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;wBACjF,qBAAM,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAA;;wBAA/D,SAA+D,CAAC;;;wBAGlE,6FAA6F;wBAC7F,gGAAgG;wBAChG,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,CAAC,UAAU,EAAE;4BACjE,0BAA0B,GAAG,aAAa,CAAC,0BAA0B,EAAE,CAAC;4BAC9E,KAAK,CAAC,gBAAgB,yCACjB,KAAK,CAAC,gBAAgB,GACtB,0BAA0B,CAC9B,CAAC;yBACH;wBACD,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;KAC/B;IACH,oCAAC;AAAD,CAAC,AA/BD,IA+BC;AAED;IAaE,6BAAY,OAA8B;QAZ1C,SAAI,GAAG,0CAA0C,CAAC;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KACpB;IAED,wDAA0B,GAA1B;QACE,OAAO,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACpD,CAAC;IACH,0BAAC;AAAD,CAAC,AAlGD,IAkGC;AAlGY,kDAAmB;AAoGzB,IAAM,mBAAmB,GAA0D,UACxF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import {\n BrowserClient,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\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 await sessionReplay.setSessionId(this.config.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 (this.config.sessionId && this.config.sessionId === event.session_id) {\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 client: BrowserClient;\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.');\n\n this.client = 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 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 },\n debugMode: this.options.debugMode,\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.client.remove(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.client = 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":";;;AAQA,uFAAmE;AAEnE,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,SAAI,GAAG,sBAAsB,CAAC;QAC9B,SAAI,GAAG,YAAqB,CAAC;IA6B/B,CAAC;IAvBO,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;wBACjF,qBAAM,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAA;;wBAA/D,SAA+D,CAAC;;;wBAGlE,6FAA6F;wBAC7F,gGAAgG;wBAChG,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,CAAC,UAAU,EAAE;4BACjE,0BAA0B,GAAG,aAAa,CAAC,0BAA0B,EAAE,CAAC;4BAC9E,KAAK,CAAC,gBAAgB,yCACjB,KAAK,CAAC,gBAAgB,GACtB,0BAA0B,CAC9B,CAAC;yBACH;wBACD,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;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6D;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,AAlGD,IAkGC;AAlGY,kDAAmB;AAoGzB,IAAM,mBAAmB,GAA0D,UACxF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import {\n BrowserClient,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\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 await sessionReplay.setSessionId(this.config.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 (this.config.sessionId && this.config.sessionId === event.session_id) {\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.');\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 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 },\n debugMode: this.options.debugMode,\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"]}
@@ -3,7 +3,7 @@ import { SessionReplayOptions } from './typings/session-replay';
3
3
  export declare class SessionReplayPlugin implements DestinationPlugin {
4
4
  name: string;
5
5
  type: "destination";
6
- client: BrowserClient;
6
+ clientRemove: BrowserClient['remove'];
7
7
  config: BrowserConfig;
8
8
  options: SessionReplayOptions;
9
9
  constructor(options?: SessionReplayOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EACP,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAoChE,qBAAa,mBAAoB,YAAW,iBAAiB;IAC3D,IAAI,SAA8C;IAClD,IAAI,gBAA0B;IAI9B,MAAM,EAAE,aAAa,CAAC;IAItB,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;IAiDnD,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":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAEjB,KAAK,EACL,MAAM,EACP,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAoChE,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;IAiDnD,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"}
@@ -60,7 +60,7 @@ var SessionReplayPlugin = /** @class */ (function () {
60
60
  return [2 /*return*/];
61
61
  }
62
62
  config.loggerProvider.log('Installing @amplitude/plugin-session-replay.');
63
- this.client = client;
63
+ this.clientRemove = client.remove.bind(client);
64
64
  this.config = config;
65
65
  if (this.options.forceSessionTracking) {
66
66
  if (typeof config.defaultTracking === 'boolean') {
@@ -131,7 +131,7 @@ var SessionReplayPlugin = /** @class */ (function () {
131
131
  return __awaiter(this, void 0, void 0, function () {
132
132
  return __generator(this, function (_a) {
133
133
  switch (_a.label) {
134
- case 0: return [4 /*yield*/, this.client.remove(ENRICHMENT_PLUGIN_NAME).promise];
134
+ case 0: return [4 /*yield*/, this.clientRemove(ENRICHMENT_PLUGIN_NAME).promise];
135
135
  case 1:
136
136
  _a.sent();
137
137
  sessionReplay.shutdown();
@@ -142,7 +142,7 @@ var SessionReplayPlugin = /** @class */ (function () {
142
142
  this.config = null;
143
143
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
144
144
  // @ts-ignore
145
- this.client = null;
145
+ this.clientRemove = null;
146
146
  return [2 /*return*/];
147
147
  }
148
148
  });
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AAEnE,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,SAAI,GAAG,sBAAsB,CAAC;QAC9B,SAAI,GAAG,YAAqB,CAAC;IA6B/B,CAAC;IAvBO,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;wBACjF,qBAAM,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAA;;wBAA/D,SAA+D,CAAC;;;wBAGlE,6FAA6F;wBAC7F,gGAAgG;wBAChG,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,KA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,GAAd;;;;4BACE,qBAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,OAAO,EAAA;;wBAAxD,SAAwD,CAAC;wBACzD,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,MAAM,GAAG,IAAI,CAAC;;;;;KACpB;IAED,wDAA0B,GAA1B;QACE,OAAO,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACpD,CAAC;IACH,0BAAC;AAAD,CAAC,AAlGD,IAkGC;;AAED,MAAM,CAAC,IAAM,mBAAmB,GAA0D,UACxF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import {\n BrowserClient,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\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 await sessionReplay.setSessionId(this.config.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 (this.config.sessionId && this.config.sessionId === event.session_id) {\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 client: BrowserClient;\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.');\n\n this.client = 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 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 },\n debugMode: this.options.debugMode,\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.client.remove(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.client = 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":";AAQA,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AAEnE,IAAM,sBAAsB,GAAG,qDAAqD,CAAC;AAErF;IAAA;QACE,SAAI,GAAG,sBAAsB,CAAC;QAC9B,SAAI,GAAG,YAAqB,CAAC;IA6B/B,CAAC;IAvBO,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;wBACjF,qBAAM,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAA;;wBAA/D,SAA+D,CAAC;;;wBAGlE,6FAA6F;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AC,EAAC;;;KACJ;IAEK,mCAAK,GAAX;;;;4BACE,qBAAM,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,EAAA;;wBAAhC,SAAgC,CAAC;;;;;KAClC;IAEK,sCAAQ,GAAd;;;;4BACE,qBAAM,IAAI,CAAC,YAAY,CAAC,sBAAsB,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,AAlGD,IAkGC;;AAED,MAAM,CAAC,IAAM,mBAAmB,GAA0D,UACxF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import {\n BrowserClient,\n BrowserConfig,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n Result,\n} from '@amplitude/analytics-types';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\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 await sessionReplay.setSessionId(this.config.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 (this.config.sessionId && this.config.sessionId === event.session_id) {\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.');\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 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 },\n debugMode: this.options.debugMode,\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"]}