@amplitude/segment-session-replay-plugin 0.0.0-beta.1 → 0.0.0-prereleasenetworkcapture.0

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.
package/README.md CHANGED
@@ -16,10 +16,10 @@ Replay SDK is included in this package, and does not need to be installed separa
16
16
 
17
17
  ```sh
18
18
  # npm
19
- npm install @amplitude/segment-session-replay-plugin" --save
19
+ npm install @amplitude/segment-session-replay-plugin --save
20
20
 
21
21
  # yarn
22
- yarn add @amplitude/segment-session-replay-plugin"
22
+ yarn add @amplitude/segment-session-replay-plugin
23
23
  ```
24
24
 
25
25
  ## Usage
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAKlD,eAAO,MAAM,YAAY,QAAO,MAAM,GAAG,SAcxC,CAAC;AAEF,eAAO,MAAM,YAAY,cAAe,MAAM,YAAY,MAAM,GAAG,SAAS,KAAG,QAAQ,IAAI,CAM1F,CAAC;AAEF,eAAO,MAAM,+BAA+B,QAAe,OAAO,YAAY,MAAM,GAAG,SAAS,KAAG,QAAQ,OAAO,CA0BjH,CAAC"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAKlD,eAAO,MAAM,YAAY,QAAO,MAAM,GAAG,SAcxC,CAAC;AAEF,eAAO,MAAM,YAAY,cAAe,MAAM,YAAY,MAAM,GAAG,SAAS,KAAG,QAAQ,IAAI,CAM1F,CAAC;AAEF,eAAO,MAAM,+BAA+B,2BAAkC,MAAM,GAAG,SAAS,KAAG,QAAQ,OAAO,CA0BjH,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.0.0-beta.1";
1
+ export declare const VERSION = "0.0.0-beta.0";
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 = '0.0.0-beta.1';
2
+ export var VERSION = '0.0.0-beta.0';
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,cAAc,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '0.0.0-beta.1';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,cAAc,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '0.0.0-beta.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/segment-session-replay-plugin",
3
- "version": "0.0.0-beta.1",
3
+ "version": "0.0.0-prereleasenetworkcapture.0",
4
4
  "description": "Plugin for Segment's analytics.js library to support Amplitude's Session Replay.",
5
5
  "keywords": [
6
6
  "amplitude",
@@ -47,7 +47,7 @@
47
47
  "version-file": "echo '// Autogenerated by `yarn version-file`. DO NOT EDIT' > src/version.ts && node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" >> src/version.ts"
48
48
  },
49
49
  "dependencies": {
50
- "@amplitude/session-replay-browser": "^1.22.5",
50
+ "@amplitude/session-replay-browser": "^1.22.7-prereleasenetworkcapture.0",
51
51
  "@segment/analytics-next": "^1.81.0",
52
52
  "js-cookie": "^3.0.5"
53
53
  },
@@ -61,5 +61,5 @@
61
61
  "rollup-plugin-gzip": "^3.1.0",
62
62
  "rollup-plugin-terser": "^7.0.2"
63
63
  },
64
- "gitHead": "05b7a56b3bd34efb1a3e7b6ed0bc6421b042c264"
64
+ "gitHead": "bd3f0cbb9079182d6bbb15fe6b6ddaae5f894616"
65
65
  }
@@ -1,6 +0,0 @@
1
- export declare const COOKIE_NAME = "amp_session_id";
2
- export declare const DEBUG_LOG_PREFIX = "Amplitude Session Replay Segment Plugin [Debug]:";
3
- export declare const INITIAL_EVENT_NAME = "Immediate Event";
4
- export declare const PLUGIN_NAME = "Session Replay Events";
5
- export declare const PLUGIN_TYPE = "enrichment";
6
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAC5C,eAAO,MAAM,gBAAgB,qDAAqD,CAAC;AACnF,eAAO,MAAM,kBAAkB,oBAAoB,CAAC;AACpD,eAAO,MAAM,WAAW,0BAA0B,CAAC;AACnD,eAAO,MAAM,WAAW,eAAe,CAAC"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PLUGIN_TYPE = exports.PLUGIN_NAME = exports.INITIAL_EVENT_NAME = exports.DEBUG_LOG_PREFIX = exports.COOKIE_NAME = void 0;
4
- exports.COOKIE_NAME = 'amp_session_id';
5
- exports.DEBUG_LOG_PREFIX = 'Amplitude Session Replay Segment Plugin [Debug]:';
6
- exports.INITIAL_EVENT_NAME = 'Immediate Event';
7
- exports.PLUGIN_NAME = 'Session Replay Events';
8
- exports.PLUGIN_TYPE = 'enrichment'; // https://github.com/segmentio/analytics-next/blob/c45d445/packages/core/src/plugins/index.ts#L11
9
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,gBAAgB,CAAC;AAC/B,QAAA,gBAAgB,GAAG,kDAAkD,CAAC;AACtE,QAAA,kBAAkB,GAAG,iBAAiB,CAAC;AACvC,QAAA,WAAW,GAAG,uBAAuB,CAAC;AACtC,QAAA,WAAW,GAAG,YAAY,CAAC,CAAC,kGAAkG","sourcesContent":["export const COOKIE_NAME = 'amp_session_id';\nexport const DEBUG_LOG_PREFIX = 'Amplitude Session Replay Segment Plugin [Debug]:';\nexport const INITIAL_EVENT_NAME = 'Immediate Event';\nexport const PLUGIN_NAME = 'Session Replay Events';\nexport const PLUGIN_TYPE = 'enrichment'; // https://github.com/segmentio/analytics-next/blob/c45d445/packages/core/src/plugins/index.ts#L11\n"]}
@@ -1,5 +0,0 @@
1
- import { Context } from '@segment/analytics-next';
2
- export declare const getSessionId: () => number | undefined;
3
- export declare const setSessionId: (sessionId: number, deviceId: string | undefined) => Promise<void>;
4
- export declare const updateSessionIdAndAddProperties: (ctx: Context, deviceId: string | undefined) => Promise<Context>;
5
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAKlD,eAAO,MAAM,YAAY,QAAO,MAAM,GAAG,SAcxC,CAAC;AAEF,eAAO,MAAM,YAAY,cAAe,MAAM,YAAY,MAAM,GAAG,SAAS,KAAG,QAAQ,IAAI,CAM1F,CAAC;AAEF,eAAO,MAAM,+BAA+B,QAAe,OAAO,YAAY,MAAM,GAAG,SAAS,KAAG,QAAQ,OAAO,CA0BjH,CAAC"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateSessionIdAndAddProperties = exports.setSessionId = exports.getSessionId = void 0;
4
- var tslib_1 = require("tslib");
5
- var sessionReplay = tslib_1.__importStar(require("@amplitude/session-replay-browser"));
6
- var js_cookie_1 = tslib_1.__importDefault(require("js-cookie"));
7
- var constants_1 = require("./constants");
8
- var getSessionId = function () {
9
- // First try to get the sessionId from the Session Replay SDK
10
- // If that fails, try to get the sessionId from the persistent storage
11
- var sessionId = sessionReplay.getSessionId() || js_cookie_1.default.get(constants_1.COOKIE_NAME);
12
- if (sessionId) {
13
- var result = parseInt(sessionId.toString(), 10);
14
- if (isNaN(result)) {
15
- return undefined;
16
- }
17
- return result;
18
- }
19
- // If sessionId is not found in either the Session Replay SDK nor persistent storage, return undefined
20
- return undefined;
21
- };
22
- exports.getSessionId = getSessionId;
23
- var setSessionId = function (sessionId, deviceId) {
24
- // Set the sessionId in the persistent storage
25
- js_cookie_1.default.set(constants_1.COOKIE_NAME, sessionId.toString());
26
- // Set the sessionId in the Session Replay SDK
27
- return sessionReplay.setSessionId(sessionId, deviceId).promise;
28
- };
29
- exports.setSessionId = setSessionId;
30
- var updateSessionIdAndAddProperties = function (ctx, deviceId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
31
- var sessionId, nextSessionId, sessionReplayProperties, properties;
32
- return tslib_1.__generator(this, function (_a) {
33
- switch (_a.label) {
34
- case 0:
35
- sessionId = (0, exports.getSessionId)() || 0;
36
- if (ctx.event.integrations && ctx.event.integrations['Actions Amplitude']) {
37
- nextSessionId = ctx.event.integrations['Actions Amplitude'].session_id;
38
- }
39
- if (!(nextSessionId && sessionId < nextSessionId)) return [3 /*break*/, 2];
40
- return [4 /*yield*/, (0, exports.setSessionId)(nextSessionId, deviceId)];
41
- case 1:
42
- _a.sent();
43
- _a.label = 2;
44
- case 2:
45
- sessionReplayProperties = sessionReplay.getSessionReplayProperties();
46
- properties = tslib_1.__assign(tslib_1.__assign({}, sessionReplayProperties), ctx.event.properties);
47
- ctx.updateEvent('properties', properties);
48
- return [2 /*return*/, ctx];
49
- }
50
- });
51
- }); };
52
- exports.updateSessionIdAndAddProperties = updateSessionIdAndAddProperties;
53
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;;AAAA,uFAAmE;AAEnE,gEAA+B;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C,uBAAuB,GAAG,aAAa,CAAC,0BAA0B,EAAE,CAAC;gBACrE,UAAU,yCACX,uBAAuB,GACvB,GAAG,CAAC,KAAK,CAAC,UAAU,CACxB,CAAC;gBAEF,GAAG,CAAC,WAAW,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;gBAE1C,sBAAO,GAAG,EAAC;;;KACZ,CAAC;AA1BW,QAAA,+BAA+B,mCA0B1C","sourcesContent":["import * as sessionReplay from '@amplitude/session-replay-browser';\nimport { Context } from '@segment/analytics-next';\nimport Cookie from 'js-cookie';\nimport { COOKIE_NAME } from './constants';\nimport { AmplitudeIntegrationData } from './typings/wrapper';\n\nexport const getSessionId = (): number | undefined => {\n // First try to get the sessionId from the Session Replay SDK\n // If that fails, try to get the sessionId from the persistent storage\n const sessionId: string | number | undefined = sessionReplay.getSessionId() || Cookie.get(COOKIE_NAME);\n if (sessionId) {\n const result = parseInt(sessionId.toString(), 10);\n if (isNaN(result)) {\n return undefined;\n }\n return result;\n }\n\n // If sessionId is not found in either the Session Replay SDK nor persistent storage, return undefined\n return undefined;\n};\n\nexport const setSessionId = (sessionId: number, deviceId: string | undefined): Promise<void> => {\n // Set the sessionId in the persistent storage\n Cookie.set(COOKIE_NAME, sessionId.toString());\n\n // Set the sessionId in the Session Replay SDK\n return sessionReplay.setSessionId(sessionId, deviceId).promise;\n};\n\nexport const updateSessionIdAndAddProperties = async (ctx: Context, deviceId: string | undefined): Promise<Context> => {\n // Get the current session id or default to 0 if it does not exist\n const sessionId: number = getSessionId() || 0;\n\n // Get the next session id from the event, if it exists\n let nextSessionId: number | undefined;\n if (ctx.event.integrations && (ctx.event.integrations['Actions Amplitude'] as AmplitudeIntegrationData)) {\n nextSessionId = (ctx.event.integrations['Actions Amplitude'] as AmplitudeIntegrationData).session_id;\n }\n\n // Update the session id if it is new\n if (nextSessionId && sessionId < nextSessionId) {\n await setSessionId(nextSessionId, deviceId);\n }\n\n // Enrich the event with the session replay properties\n // NOTE: This is what will add the `[Amplitude] Session Replay ID` attribute to the event\n const sessionReplayProperties = sessionReplay.getSessionReplayProperties();\n const properties = {\n ...sessionReplayProperties,\n ...ctx.event.properties,\n };\n\n ctx.updateEvent('properties', properties);\n\n return ctx;\n};\n"]}
@@ -1,3 +0,0 @@
1
- import { PluginOptions } from './typings/wrapper';
2
- export declare const createSegmentActionsPlugin: ({ amplitudeApiKey, sessionReplayOptions, segmentInstance, enableWrapperDebug, }: PluginOptions) => Promise<void>;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,eAAO,MAAM,0BAA0B,oFAKpC,aAAa,KAAG,QAAQ,IAAI,CAuE9B,CAAC"}
package/lib/cjs/index.js DELETED
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSegmentActionsPlugin = void 0;
4
- var tslib_1 = require("tslib");
5
- var sessionReplay = tslib_1.__importStar(require("@amplitude/session-replay-browser"));
6
- var constants_1 = require("./constants");
7
- var helpers_1 = require("./helpers");
8
- var version_1 = require("./version");
9
- var createSegmentActionsPlugin = function (_a) {
10
- var amplitudeApiKey = _a.amplitudeApiKey, sessionReplayOptions = _a.sessionReplayOptions, segmentInstance = _a.segmentInstance, _b = _a.enableWrapperDebug, enableWrapperDebug = _b === void 0 ? false : _b;
11
- return tslib_1.__awaiter(void 0, void 0, void 0, function () {
12
- var initPromise, isInitialized, deviceId, _plugin;
13
- return tslib_1.__generator(this, function (_c) {
14
- switch (_c.label) {
15
- case 0:
16
- isInitialized = false;
17
- deviceId = sessionReplayOptions === null || sessionReplayOptions === void 0 ? void 0 : sessionReplayOptions.deviceId;
18
- _plugin = {
19
- name: constants_1.PLUGIN_NAME,
20
- type: constants_1.PLUGIN_TYPE,
21
- version: version_1.VERSION,
22
- isLoaded: function () { return isInitialized; },
23
- load: function (_ctx, ajs) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
24
- var user, sessionId;
25
- return tslib_1.__generator(this, function (_a) {
26
- switch (_a.label) {
27
- case 0:
28
- // If the deviceId is not provided via the plugin parameters,
29
- // default to use the anonymousId from the user
30
- if (!deviceId) {
31
- user = ajs.user();
32
- deviceId = user.anonymousId() || undefined;
33
- }
34
- sessionId = (0, helpers_1.getSessionId)();
35
- // Initialize the session replay plugin
36
- enableWrapperDebug &&
37
- console.log("".concat(constants_1.DEBUG_LOG_PREFIX, " initializing session replay with sessionId=").concat(sessionId !== null && sessionId !== void 0 ? sessionId : 'undefined', " and deviceId=").concat(deviceId !== null && deviceId !== void 0 ? deviceId : 'undefined'));
38
- initPromise = sessionReplay.init(amplitudeApiKey, tslib_1.__assign(tslib_1.__assign({}, sessionReplayOptions), { sessionId: sessionId, deviceId: deviceId || undefined, version: { type: 'segment', version: version_1.VERSION } })).promise;
39
- return [4 /*yield*/, initPromise];
40
- case 1:
41
- _a.sent();
42
- isInitialized = true;
43
- return [2 /*return*/];
44
- }
45
- });
46
- }); },
47
- track: function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
48
- return tslib_1.__generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0: return [4 /*yield*/, initPromise];
51
- case 1:
52
- _a.sent();
53
- return [4 /*yield*/, (0, helpers_1.updateSessionIdAndAddProperties)(ctx, deviceId)];
54
- case 2: return [2 /*return*/, _a.sent()];
55
- }
56
- });
57
- }); },
58
- page: function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
59
- return tslib_1.__generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0: return [4 /*yield*/, initPromise];
62
- case 1:
63
- _a.sent();
64
- return [4 /*yield*/, (0, helpers_1.updateSessionIdAndAddProperties)(ctx, deviceId)];
65
- case 2: return [2 /*return*/, _a.sent()];
66
- }
67
- });
68
- }); },
69
- identify: function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
70
- var sessionId;
71
- return tslib_1.__generator(this, function (_a) {
72
- switch (_a.label) {
73
- case 0: return [4 /*yield*/, initPromise];
74
- case 1:
75
- _a.sent();
76
- sessionId = (0, helpers_1.getSessionId)();
77
- if (!sessionId) return [3 /*break*/, 3];
78
- enableWrapperDebug &&
79
- console.log("".concat(constants_1.DEBUG_LOG_PREFIX, " calling setSessionId() with sessionId=").concat(sessionId, " and deviceId=").concat(deviceId !== null && deviceId !== void 0 ? deviceId : 'undefined'));
80
- return [4 /*yield*/, (0, helpers_1.setSessionId)(sessionId, deviceId)];
81
- case 2:
82
- _a.sent();
83
- _a.label = 3;
84
- case 3: return [2 /*return*/, ctx];
85
- }
86
- });
87
- }); },
88
- };
89
- return [4 /*yield*/, segmentInstance.register(_plugin)];
90
- case 1:
91
- _c.sent();
92
- return [2 /*return*/];
93
- }
94
- });
95
- });
96
- };
97
- exports.createSegmentActionsPlugin = createSegmentActionsPlugin;
98
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,uFAAmE;AAGnE,yCAAyE;AACzE,qCAAwF;AAExF,qCAAoC;AAE7B,IAAM,0BAA0B,GAAG,UAAO,EAKjC;QAJd,eAAe,qBAAA,EACf,oBAAoB,0BAAA,EACpB,eAAe,qBAAA,EACf,0BAA0B,EAA1B,kBAAkB,mBAAG,KAAK,KAAA;;;;;;oBAGtB,aAAa,GAAG,KAAK,CAAC;oBACtB,QAAQ,GAAuB,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,QAAQ,CAAC;oBAE5D,OAAO,GAAW;wBACtB,IAAI,EAAE,uBAAW;wBACjB,IAAI,EAAE,uBAAW;wBACjB,OAAO,EAAE,iBAAO;wBAEhB,QAAQ,EAAE,cAAe,OAAA,aAAa,EAAb,CAAa;wBAEtC,IAAI,EAAE,UAAO,IAAa,EAAE,GAAc;;;;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AAY,GAAE,CAAC;6CAEjD,SAAS,EAAT,wBAAS;wCACX,kBAAkB;4CAChB,OAAO,CAAC,GAAG,CACT,UAAG,4BAAgB,oDAA0C,SAAS,2BACpE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,WAAW,CACvB,CACH,CAAC;wCACJ,qBAAM,IAAA,sBAAY,EAAC,SAAS,EAAE,QAAQ,CAAC,EAAA;;wCAAvC,SAAuC,CAAC;;4CAG1C,sBAAO,GAAG,EAAC;;;6BACZ;qBACF,CAAC;oBAEF,qBAAM,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAA;;oBAAvC,SAAuC,CAAC;;;;;CACzC,CAAC;AA5EW,QAAA,0BAA0B,8BA4ErC","sourcesContent":["import * as sessionReplay from '@amplitude/session-replay-browser';\nimport { Analytics, Context, Plugin, User } from '@segment/analytics-next';\n\nimport { DEBUG_LOG_PREFIX, PLUGIN_NAME, PLUGIN_TYPE } from './constants';\nimport { getSessionId, setSessionId, updateSessionIdAndAddProperties } from './helpers';\nimport { PluginOptions } from './typings/wrapper';\nimport { VERSION } from './version';\n\nexport const createSegmentActionsPlugin = async ({\n amplitudeApiKey,\n sessionReplayOptions,\n segmentInstance,\n enableWrapperDebug = false,\n}: PluginOptions): Promise<void> => {\n let initPromise: Promise<void>;\n let isInitialized = false;\n let deviceId: string | undefined = sessionReplayOptions?.deviceId;\n\n const _plugin: Plugin = {\n name: PLUGIN_NAME,\n type: PLUGIN_TYPE,\n version: VERSION,\n\n isLoaded: (): boolean => isInitialized,\n\n load: async (_ctx: Context, ajs: Analytics): Promise<void> => {\n // If the deviceId is not provided via the plugin parameters,\n // default to use the anonymousId from the user\n if (!deviceId) {\n const user: User = ajs.user();\n deviceId = user.anonymousId() || undefined;\n }\n\n const sessionId: number | undefined = getSessionId();\n\n // Initialize the session replay plugin\n enableWrapperDebug &&\n console.log(\n `${DEBUG_LOG_PREFIX} initializing session replay with sessionId=${sessionId ?? 'undefined'} and deviceId=${\n deviceId ?? 'undefined'\n }`,\n );\n\n initPromise = sessionReplay.init(amplitudeApiKey, {\n ...sessionReplayOptions,\n sessionId,\n deviceId: deviceId || undefined,\n version: { type: 'segment', version: VERSION },\n }).promise;\n\n await initPromise;\n isInitialized = true;\n },\n\n track: async (ctx: Context): Promise<Context> => {\n await initPromise;\n return await updateSessionIdAndAddProperties(ctx, deviceId);\n },\n\n page: async (ctx: Context): Promise<Context> => {\n await initPromise;\n return await updateSessionIdAndAddProperties(ctx, deviceId);\n },\n\n identify: async (ctx: Context): Promise<Context> => {\n await initPromise;\n\n const sessionId: number | undefined = getSessionId();\n\n if (sessionId) {\n enableWrapperDebug &&\n console.log(\n `${DEBUG_LOG_PREFIX} calling setSessionId() with sessionId=${sessionId} and deviceId=${\n deviceId ?? 'undefined'\n }`,\n );\n await setSessionId(sessionId, deviceId);\n }\n\n return ctx;\n },\n };\n\n await segmentInstance.register(_plugin);\n};\n"]}
@@ -1,12 +0,0 @@
1
- import { SessionReplayOptions } from '@amplitude/session-replay-browser';
2
- import { AnalyticsBrowser } from '@segment/analytics-next';
3
- export interface PluginOptions {
4
- segmentInstance: AnalyticsBrowser;
5
- amplitudeApiKey: string;
6
- sessionReplayOptions?: SessionReplayOptions;
7
- enableWrapperDebug?: boolean;
8
- }
9
- export type AmplitudeIntegrationData = {
10
- session_id: number;
11
- };
12
- //# sourceMappingURL=wrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../../src/typings/wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,gBAAgB,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,MAAM,wBAAwB,GAAG;IAErC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=wrapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../../../src/typings/wrapper.ts"],"names":[],"mappings":"","sourcesContent":["import { SessionReplayOptions } from '@amplitude/session-replay-browser';\nimport { AnalyticsBrowser } from '@segment/analytics-next';\n\nexport interface PluginOptions {\n segmentInstance: AnalyticsBrowser;\n amplitudeApiKey: string;\n sessionReplayOptions?: SessionReplayOptions;\n enableWrapperDebug?: boolean;\n}\n\nexport type AmplitudeIntegrationData = {\n // https://github.com/segmentio/analytics-next/blob/3f15dfae034d101fb1847bc7228c0354b414d68a/packages/browser-integration-tests/src/index.test.ts#L64-L66\n session_id: number;\n};\n"]}
@@ -1,2 +0,0 @@
1
- export declare const VERSION = "0.0.0-beta.1";
2
- //# sourceMappingURL=version.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERSION = void 0;
4
- // Autogenerated by `yarn version-file`. DO NOT EDIT
5
- exports.VERSION = '0.0.0-beta.1';
6
- //# sourceMappingURL=version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,cAAc,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '0.0.0-beta.1';\n"]}