@amplitude/analytics-core 2.10.1 → 2.11.0-networkautocapture-1.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/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/network-observer.d.ts +3 -1
- package/lib/cjs/network-observer.d.ts.map +1 -1
- package/lib/cjs/network-observer.js +11 -2
- package/lib/cjs/network-observer.js.map +1 -1
- package/lib/cjs/types/browser-config.d.ts +6 -0
- package/lib/cjs/types/browser-config.d.ts.map +1 -1
- package/lib/cjs/types/browser-config.js.map +1 -1
- package/lib/cjs/types/network-tracking.d.ts +31 -0
- package/lib/cjs/types/network-tracking.d.ts.map +1 -0
- package/lib/cjs/types/network-tracking.js +3 -0
- package/lib/cjs/types/network-tracking.js.map +1 -0
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/network-observer.d.ts +3 -1
- package/lib/esm/network-observer.d.ts.map +1 -1
- package/lib/esm/network-observer.js +10 -1
- package/lib/esm/network-observer.js.map +1 -1
- package/lib/esm/types/browser-config.d.ts +6 -0
- package/lib/esm/types/browser-config.d.ts.map +1 -1
- package/lib/esm/types/browser-config.js.map +1 -1
- package/lib/esm/types/network-tracking.d.ts +31 -0
- package/lib/esm/types/network-tracking.d.ts.map +1 -0
- package/lib/esm/types/network-tracking.js +2 -0
- package/lib/esm/types/network-tracking.js.map +1 -0
- package/package.json +2 -2
package/lib/cjs/index.d.ts
CHANGED
|
@@ -40,5 +40,6 @@ export { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges }
|
|
|
40
40
|
export { Status } from './types/status';
|
|
41
41
|
export { BrowserConfig, BrowserOptions, DefaultTrackingOptions, TrackingOptions, AutocaptureOptions, CookieOptions, AttributionOptions, } from './types/browser-config';
|
|
42
42
|
export { BrowserClient } from './types/browser-client';
|
|
43
|
-
export {
|
|
43
|
+
export { NetworkRequestEvent, NetworkEventCallback, networkObserver } from './network-observer';
|
|
44
|
+
export { NetworkTrackingOptions, NetworkCaptureRule } from './types/network-tracking';
|
|
44
45
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,kBAAk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,oBAAoB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,SAAS,EACT,UAAU,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAClH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.networkObserver = exports.NetworkEventCallback = exports.Status = exports.DEFAULT_ACTION_CLICK_ALLOWLIST = exports.DEFAULT_DATA_ATTRIBUTE_PREFIX = exports.DEFAULT_CSS_SELECTOR_ALLOWLIST = exports.OfflineDisabled = exports.ServerZone = exports.SpecialEventType = exports.IdentifyOperation = exports.STORAGE_PREFIX = exports.AMPLITUDE_PREFIX = exports.LogLevel = exports.FetchTransport = exports.BaseTransport = exports.getStorageKey = exports.CookieStorage = exports.MemoryStorage = exports.createIdentifyEvent = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.getQueryParams = exports.getLanguage = exports.getOldCookieName = exports.getCookieName = exports.isNewSession = exports.setConnectorUserId = exports.setConnectorDeviceId = exports.getAnalyticsConnector = exports.getGlobalScope = exports.Logger = exports.RequestMetadata = exports.Config = exports.IdentityEventSender = exports.Destination = exports.RevenueProperty = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0;
|
|
4
4
|
var core_client_1 = require("./core-client");
|
|
5
5
|
Object.defineProperty(exports, "AmplitudeCore", { enumerable: true, get: function () { return core_client_1.AmplitudeCore; } });
|
|
6
6
|
var identify_1 = require("./identify");
|
|
@@ -71,6 +71,6 @@ Object.defineProperty(exports, "DEFAULT_ACTION_CLICK_ALLOWLIST", { enumerable: t
|
|
|
71
71
|
var status_1 = require("./types/status");
|
|
72
72
|
Object.defineProperty(exports, "Status", { enumerable: true, get: function () { return status_1.Status; } });
|
|
73
73
|
var network_observer_1 = require("./network-observer");
|
|
74
|
-
Object.defineProperty(exports, "NetworkObserver", { enumerable: true, get: function () { return network_observer_1.NetworkObserver; } });
|
|
75
74
|
Object.defineProperty(exports, "NetworkEventCallback", { enumerable: true, get: function () { return network_observer_1.NetworkEventCallback; } });
|
|
75
|
+
Object.defineProperty(exports, "networkObserver", { enumerable: true, get: function () { return network_observer_1.networkObserver; } });
|
|
76
76
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAAjD,4GAAA,aAAa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2CAAiD;AAAxC,uGAAA,aAAa,OAAA;AACtB,2CAAiD;AAAxC,uGAAA,aAAa,OAAA;AACtB,6CAAkD;AAAzC,wGAAA,aAAa,OAAA;AAEtB,0CAAkD;AAAzC,qGAAA,aAAa,OAAA;AACtB,4CAAoD;AAA3C,uGAAA,cAAc,OAAA;AAEvB,6CAA4C;AAAnC,oGAAA,QAAQ,OAAA;AACjB,+CAAqE;AAA5D,6GAAA,gBAAgB,OAAA;AAAE,2GAAA,cAAc,OAAA;AAEzC,6CAAoH;AAApG,0GAAA,iBAAiB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAGnD,mDAAiE;AAAxC,yGAAA,UAAU,OAAA;AACnC,2CAAkD;AAAzC,0GAAA,eAAe,OAAA;AAQxB,qEAOsC;AAHpC,sIAAA,8BAA8B,OAAA;AAC9B,qIAAA,6BAA6B,OAAA;AAC7B,sIAAA,8BAA8B,OAAA;AAGhC,yCAAwC;AAA/B,gGAAA,MAAM,OAAA;AAYf,uDAAgG;AAAlE,wHAAA,oBAAoB,OAAA;AAAE,mHAAA,eAAe,OAAA","sourcesContent":["export { AmplitudeCore, CoreClient } from './core-client';\nexport { Identify, IIdentify } from './identify';\nexport { Revenue, IRevenue, RevenueProperty } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { IdentityEventSender } from './plugins/identity';\nexport { IConfig, Config, RequestMetadata } from './config';\nexport { Logger, ILogger, LogConfig } from './logger';\nexport { getGlobalScope } from './global-scope';\nexport { getAnalyticsConnector, setConnectorDeviceId, setConnectorUserId } from './analytics-connector';\nexport { isNewSession } from './session';\nexport { getCookieName, getOldCookieName } from './cookie-name';\nexport { getLanguage } from './language';\nexport { getQueryParams } from './query-params';\n\nexport { returnWrapper, AmplitudeReturn } from './utils/return-wrapper';\nexport { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';\nexport { UUID } from './utils/uuid';\nexport { createIdentifyEvent } from './utils/event-builder';\n\nexport { MemoryStorage } from './storage/memory';\nexport { CookieStorage } from './storage/cookie';\nexport { getStorageKey } from './storage/helpers';\n\nexport { BaseTransport } from './transports/base';\nexport { FetchTransport } from './transports/fetch';\n\nexport { LogLevel } from './types/loglevel';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './types/constants';\nexport { Storage, IdentityStorageType } from './types/storage';\nexport { Event, IdentifyOperation, SpecialEventType, IdentifyEvent, GroupIdentifyEvent } from './types/event/event';\nexport { EventOptions, BaseEvent } from './types/event/base-event';\nexport { IngestionMetadata } from './types/event/ingestion-metadata';\nexport { ServerZoneType, ServerZone } from './types/server-zone';\nexport { OfflineDisabled } from './types/offline';\nexport { Plan } from './types/event/plan';\nexport { TransportType, Transport } from './types/transport';\nexport { Payload } from './types/payload';\nexport { Response } from './types/response';\nexport { UserSession } from './types/user-session';\nexport { Plugin, BeforePlugin, DestinationPlugin, EnrichmentPlugin, PluginType } from './types/plugin';\nexport { Result } from './types/result';\nexport {\n ElementInteractionsOptions,\n Messenger,\n ActionType,\n DEFAULT_CSS_SELECTOR_ALLOWLIST,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n DEFAULT_ACTION_CLICK_ALLOWLIST,\n} from './types/element-interactions';\nexport { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges } from './types/page-view-tracking';\nexport { Status } from './types/status';\nexport {\n BrowserConfig,\n BrowserOptions,\n DefaultTrackingOptions,\n TrackingOptions,\n AutocaptureOptions,\n CookieOptions,\n AttributionOptions,\n} from './types/browser-config';\nexport { BrowserClient } from './types/browser-client';\n\nexport { NetworkRequestEvent, NetworkEventCallback, networkObserver } from './network-observer';\nexport { NetworkTrackingOptions, NetworkCaptureRule } from './types/network-tracking';\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ILogger } from '.';
|
|
2
2
|
export interface NetworkRequestEvent {
|
|
3
|
-
type:
|
|
3
|
+
type: string;
|
|
4
4
|
method: string;
|
|
5
5
|
url: string;
|
|
6
|
+
timestamp: number;
|
|
6
7
|
status?: number;
|
|
7
8
|
duration?: number;
|
|
8
9
|
requestBodySize?: number;
|
|
@@ -40,5 +41,6 @@ export declare class NetworkObserver {
|
|
|
40
41
|
protected triggerEventCallbacks(event: NetworkRequestEvent): void;
|
|
41
42
|
private observeFetch;
|
|
42
43
|
}
|
|
44
|
+
export declare const networkObserver: NetworkObserver;
|
|
43
45
|
export {};
|
|
44
46
|
//# sourceMappingURL=network-observer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-observer.d.ts","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"network-observer.d.ts","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;AAG5B,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD,KAAK,yBAAyB,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD,MAAM,WAAW,eAAe;IAC9B,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC,CAAC;CAClE;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,WAAW,GAAG,eAAe,GAAG,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;AAElH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAyClG;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAE1E,qBAAa,oBAAoB;aACH,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI;aAAkB,EAAE,EAAE,MAAM;gBAA1E,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,EAAkB,EAAE,GAAE,MAAe;CAChH;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,OAAO,CAAC,cAAc,CAAgD;IACtE,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,WAAW,CAAC,CAAoB;gBAE5B,MAAM,CAAC,EAAE,OAAO;IAY5B,MAAM,CAAC,WAAW,IAAI,OAAO;IAK7B,SAAS,CAAC,aAAa,EAAE,oBAAoB;IAQ7C,WAAW,CAAC,aAAa,EAAE,oBAAoB;IAQ/C,SAAS,CAAC,qBAAqB,CAAC,KAAK,EAAE,mBAAmB;IAM1D,OAAO,CAAC,YAAY;CA0DrB;AAGD,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NetworkObserver = exports.NetworkEventCallback = exports.getRequestBodyLength = void 0;
|
|
3
|
+
exports.networkObserver = exports.NetworkObserver = exports.NetworkEventCallback = exports.getRequestBodyLength = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var global_scope_1 = require("./global-scope");
|
|
6
6
|
var uuid_1 = require("./utils/uuid");
|
|
7
|
+
var MAXIMUM_ENTRIES = 100;
|
|
7
8
|
function getRequestBodyLength(body) {
|
|
8
9
|
var e_1, _a;
|
|
9
10
|
var global = (0, global_scope_1.getGlobalScope)();
|
|
@@ -28,9 +29,9 @@ function getRequestBodyLength(body) {
|
|
|
28
29
|
}
|
|
29
30
|
else if (body instanceof FormData) {
|
|
30
31
|
// Estimating only for text parts; not accurate for files
|
|
31
|
-
// TODO: get consensus before deciding if we do this
|
|
32
32
|
var formData = body;
|
|
33
33
|
var total = 0;
|
|
34
|
+
var count = 0;
|
|
34
35
|
try {
|
|
35
36
|
for (var _b = tslib_1.__values(formData.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
36
37
|
var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -42,6 +43,11 @@ function getRequestBodyLength(body) {
|
|
|
42
43
|
// if we encounter a "File" type, we should not count it and just return undefined
|
|
43
44
|
total += value.size;
|
|
44
45
|
}
|
|
46
|
+
// terminate if we reach the maximum number of entries
|
|
47
|
+
// to avoid performance issues in case of very large FormDataß
|
|
48
|
+
if (++count >= MAXIMUM_ENTRIES) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -118,6 +124,7 @@ var NetworkObserver = /** @class */ (function () {
|
|
|
118
124
|
case 0:
|
|
119
125
|
startTime = Date.now();
|
|
120
126
|
requestEvent = {
|
|
127
|
+
timestamp: startTime,
|
|
121
128
|
startTime: startTime,
|
|
122
129
|
type: 'fetch',
|
|
123
130
|
method: (init === null || init === void 0 ? void 0 : init.method) || 'GET',
|
|
@@ -167,4 +174,6 @@ var NetworkObserver = /** @class */ (function () {
|
|
|
167
174
|
return NetworkObserver;
|
|
168
175
|
}());
|
|
169
176
|
exports.NetworkObserver = NetworkObserver;
|
|
177
|
+
// singleton instance of NetworkObserver
|
|
178
|
+
exports.networkObserver = new NetworkObserver();
|
|
170
179
|
//# sourceMappingURL=network-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-observer.js","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":";;;;AAAA,+CAAgD;AAChD,qCAAoC;AA4BpC,SAAgB,oBAAoB,CAAC,IAAyC;;IAC5E,IAAM,MAAM,GAAG,IAAA,6BAAc,GAAE,CAAC;IAChC,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAA,EAAE;QACxB,OAAO;KACR;IACO,IAAA,WAAW,GAAK,MAAM,YAAX,CAAY;IAE/B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;KAC9C;SAAM,IAAI,IAAI,YAAY,IAAI,EAAE;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;KAClB;SAAM,IAAI,IAAI,YAAY,eAAe,EAAE;QAC1C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;KACzD;SAAM,IAAI,IAAI,YAAY,WAAW,EAAE;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC;KACxB;SAAM,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACnC,OAAO,IAAI,CAAC,UAAU,CAAC;KACxB;SAAM,IAAI,IAAI,YAAY,QAAQ,EAAE;QACnC,yDAAyD;QACzD,oDAAoD;QACpD,IAAM,QAAQ,GAAG,IAAuB,CAAC;QACzC,IAAI,KAAK,GAAG,CAAC,CAAC;;YACd,KAA2B,IAAA,KAAA,iBAAA,QAAQ,CAAC,OAAO,EAAE,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S,CAAC;wBAGtC,UAAU,GAAG,OAAc,CAAC;wBAClC,YAAY,CAAC,KAAK,GAAG;4BACnB,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,cAAc;4BACvC,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,2BAA2B;yBAC3D,CAAC;wBAEF,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;wBACzC,MAAM,OAAK,CAAC;;;;aAEf,CAAC;IACJ,CAAC;IACH,sBAAC;AAAD,CAAC,AAvGD,IAuGC;AAvGY,0CAAe","sourcesContent":["import { getGlobalScope } from './global-scope';\nimport { UUID } from './utils/uuid';\nimport { ILogger } from '.';\nexport interface NetworkRequestEvent {\n type: 'fetch';\n method: string;\n url: string;\n status?: number;\n duration?: number;\n requestBodySize?: number;\n requestHeaders?: Record<string, string>;\n responseBodySize?: number;\n responseHeaders?: Record<string, string>;\n error?: {\n name: string;\n message: string;\n };\n startTime?: number;\n endTime?: number;\n}\n\n// using this type instead of the DOM's ttp so that it's Node compatible\ntype FormDataEntryValueBrowser = string | Blob | null;\nexport interface FormDataBrowser {\n entries(): IterableIterator<[string, FormDataEntryValueBrowser]>;\n}\n\nexport type FetchRequestBody = string | Blob | ArrayBuffer | FormDataBrowser | URLSearchParams | null | undefined;\n\nexport function getRequestBodyLength(body: FetchRequestBody | null | undefined): number | undefined {\n const global = getGlobalScope();\n if (!global?.TextEncoder) {\n return;\n }\n const { TextEncoder } = global;\n\n if (typeof body === 'string') {\n return new TextEncoder().encode(body).length;\n } else if (body instanceof Blob) {\n return body.size;\n } else if (body instanceof URLSearchParams) {\n return new TextEncoder().encode(body.toString()).length;\n } else if (body instanceof ArrayBuffer) {\n return body.byteLength;\n } else if (ArrayBuffer.isView(body)) {\n return body.byteLength;\n } else if (body instanceof FormData) {\n // Estimating only for text parts; not accurate for files\n // TODO: get consensus before deciding if we do this\n const formData = body as FormDataBrowser;\n let total = 0;\n for (const [key, value] of formData.entries()) {\n total += key.length;\n if (typeof value === 'string') {\n total += new TextEncoder().encode(value).length;\n } else if ((value as Blob).size) {\n // if we encounter a \"File\" type, we should not count it and just return undefined\n total += (value as Blob).size;\n }\n }\n return total;\n }\n // Stream or unknown\n return;\n}\n\nexport type NetworkEventCallbackFn = (event: NetworkRequestEvent) => void;\n\nexport class NetworkEventCallback {\n constructor(public readonly callback: (event: NetworkRequestEvent) => void, public readonly id: string = UUID()) {}\n}\n\nexport class NetworkObserver {\n private originalFetch?: typeof fetch;\n private eventCallbacks: Map<string, NetworkEventCallback> = new Map();\n private isObserving = false;\n // eslint-disable-next-line no-restricted-globals\n private globalScope?: typeof globalThis;\n\n constructor(logger?: ILogger) {\n const globalScope = getGlobalScope();\n if (!NetworkObserver.isSupported()) {\n /* istanbul ignore next */\n logger?.error('Fetch API is not supported in this environment.');\n return;\n }\n this.globalScope = globalScope;\n /* istanbul ignore next */\n this.originalFetch = this.globalScope?.fetch;\n }\n\n static isSupported(): boolean {\n const globalScope = getGlobalScope();\n return !!globalScope && !!globalScope.fetch;\n }\n\n subscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.set(eventCallback.id, eventCallback);\n if (!this.isObserving) {\n this.observeFetch();\n this.isObserving = true;\n }\n }\n\n unsubscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.delete(eventCallback.id);\n if (this.originalFetch && this.globalScope && this.eventCallbacks.size === 0 && this.isObserving) {\n this.globalScope.fetch = this.originalFetch;\n this.isObserving = false;\n }\n }\n\n protected triggerEventCallbacks(event: NetworkRequestEvent) {\n this.eventCallbacks.forEach((callback) => {\n callback.callback(event);\n });\n }\n\n private observeFetch() {\n /* istanbul ignore next */\n if (!this.globalScope || !this.originalFetch) {\n return;\n }\n const originalFetch = this.globalScope.fetch;\n\n this.globalScope.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {\n const startTime = Date.now();\n const requestEvent: NetworkRequestEvent = {\n startTime,\n type: 'fetch',\n method: init?.method || 'GET', // Fetch API defaulted to GET when no method is provided\n url: input.toString(),\n requestHeaders: init?.headers as Record<string, string>,\n requestBodySize: getRequestBodyLength(init?.body as FetchRequestBody),\n };\n\n try {\n const response = await originalFetch(input, init);\n const endTime = Date.now();\n\n requestEvent.status = response.status;\n requestEvent.duration = endTime - startTime;\n requestEvent.startTime = startTime;\n requestEvent.endTime = endTime;\n\n // Convert Headers\n const headers: Record<string, string> = {};\n let contentLength: number | undefined = undefined;\n response.headers.forEach((value: string, key: string) => {\n headers[key] = value;\n if (key === 'content-length') {\n contentLength = parseInt(value, 10) || undefined;\n }\n });\n requestEvent.responseHeaders = headers;\n requestEvent.responseBodySize = contentLength;\n\n this.triggerEventCallbacks(requestEvent);\n return response;\n } catch (error) {\n const endTime = Date.now();\n requestEvent.duration = endTime - startTime;\n\n // Capture error information\n const typedError = error as Error;\n requestEvent.error = {\n name: typedError.name || 'UnknownError',\n message: typedError.message || 'An unknown error occurred',\n };\n\n this.triggerEventCallbacks(requestEvent);\n throw error;\n }\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"network-observer.js","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":";;;;AAAA,+CAAgD;AAChD,qCAAoC;AAGpC,IAAM,eAAe,GAAG,GAAG,CAAC;AA4B5B,SAAgB,oBAAoB,CAAC,IAAyC;;IAC5E,IAAM,MAAM,GAAG,IAAA,6BAAc,GAAE,CAAC;IAChC,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAA,EAAE;QACxB,OAAO;KACR;IACO,IAAA,WAAW,GAAK,MAAM,YAAX,CAAY;IAE/B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;KAC9C;SAAM,IAAI,IAAI,YAAY,IAAI,EAAE;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;KAClB;SAAM,IAAI,IAAI,YAAY,eAAe,EAAE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,CAAC,OAAO,GAAG,OAAO,CAAC;wBAGzB,YAAkC,EAAE,CAAC;wBACvC,kBAAoC,SAAS,CAAC;wBAClD,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,KAAa,EAAE,GAAW;4BAClD,SAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;4BACrB,IAAI,GAAG,KAAK,gBAAgB,EAAE;gCAC5B,eAAa,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC;6BAClD;wBACH,CAAC,CAAC,CAAC;wBACH,YAAY,CAAC,eAAe,GAAG,SAAO,CAAC;wBACvC,YAAY,CAAC,gBAAgB,GAAG,eAAa,CAAC;wBAE9C,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;wBACzC,sBAAO,QAAQ,EAAC;;;wBAEV,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;wBAC3B,YAAY,CAAC,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;wBAGtC,UAAU,GAAG,OAAc,CAAC;wBAClC,YAAY,CAAC,KAAK,GAAG;4BACnB,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,cAAc;4BACvC,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,2BAA2B;yBAC3D,CAAC;wBAEF,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;wBACzC,MAAM,OAAK,CAAC;;;;aAEf,CAAC;IACJ,CAAC;IACH,sBAAC;AAAD,CAAC,AAxGD,IAwGC;AAxGY,0CAAe;AA0G5B,wCAAwC;AAC3B,QAAA,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC","sourcesContent":["import { getGlobalScope } from './global-scope';\nimport { UUID } from './utils/uuid';\nimport { ILogger } from '.';\n\nconst MAXIMUM_ENTRIES = 100;\nexport interface NetworkRequestEvent {\n type: string;\n method: string;\n url: string;\n timestamp: number;\n status?: number;\n duration?: number;\n requestBodySize?: number;\n requestHeaders?: Record<string, string>;\n responseBodySize?: number;\n responseHeaders?: Record<string, string>;\n error?: {\n name: string;\n message: string;\n };\n startTime?: number;\n endTime?: number;\n}\n\n// using this type instead of the DOM's ttp so that it's Node compatible\ntype FormDataEntryValueBrowser = string | Blob | null;\nexport interface FormDataBrowser {\n entries(): IterableIterator<[string, FormDataEntryValueBrowser]>;\n}\n\nexport type FetchRequestBody = string | Blob | ArrayBuffer | FormDataBrowser | URLSearchParams | null | undefined;\n\nexport function getRequestBodyLength(body: FetchRequestBody | null | undefined): number | undefined {\n const global = getGlobalScope();\n if (!global?.TextEncoder) {\n return;\n }\n const { TextEncoder } = global;\n\n if (typeof body === 'string') {\n return new TextEncoder().encode(body).length;\n } else if (body instanceof Blob) {\n return body.size;\n } else if (body instanceof URLSearchParams) {\n return new TextEncoder().encode(body.toString()).length;\n } else if (body instanceof ArrayBuffer) {\n return body.byteLength;\n } else if (ArrayBuffer.isView(body)) {\n return body.byteLength;\n } else if (body instanceof FormData) {\n // Estimating only for text parts; not accurate for files\n const formData = body as FormDataBrowser;\n\n let total = 0;\n let count = 0;\n for (const [key, value] of formData.entries()) {\n total += key.length;\n if (typeof value === 'string') {\n total += new TextEncoder().encode(value).length;\n } else if ((value as Blob).size) {\n // if we encounter a \"File\" type, we should not count it and just return undefined\n total += (value as Blob).size;\n }\n // terminate if we reach the maximum number of entries\n // to avoid performance issues in case of very large FormDataß\n if (++count >= MAXIMUM_ENTRIES) {\n return;\n }\n }\n return total;\n }\n // Stream or unknown\n return;\n}\n\nexport type NetworkEventCallbackFn = (event: NetworkRequestEvent) => void;\n\nexport class NetworkEventCallback {\n constructor(public readonly callback: (event: NetworkRequestEvent) => void, public readonly id: string = UUID()) {}\n}\n\nexport class NetworkObserver {\n private originalFetch?: typeof fetch;\n private eventCallbacks: Map<string, NetworkEventCallback> = new Map();\n private isObserving = false;\n // eslint-disable-next-line no-restricted-globals\n private globalScope?: typeof globalThis;\n\n constructor(logger?: ILogger) {\n const globalScope = getGlobalScope();\n if (!NetworkObserver.isSupported()) {\n /* istanbul ignore next */\n logger?.error('Fetch API is not supported in this environment.');\n return;\n }\n this.globalScope = globalScope;\n /* istanbul ignore next */\n this.originalFetch = this.globalScope?.fetch;\n }\n\n static isSupported(): boolean {\n const globalScope = getGlobalScope();\n return !!globalScope && !!globalScope.fetch;\n }\n\n subscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.set(eventCallback.id, eventCallback);\n if (!this.isObserving) {\n this.observeFetch();\n this.isObserving = true;\n }\n }\n\n unsubscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.delete(eventCallback.id);\n if (this.originalFetch && this.globalScope && this.eventCallbacks.size === 0 && this.isObserving) {\n this.globalScope.fetch = this.originalFetch;\n this.isObserving = false;\n }\n }\n\n protected triggerEventCallbacks(event: NetworkRequestEvent) {\n this.eventCallbacks.forEach((callback) => {\n callback.callback(event);\n });\n }\n\n private observeFetch() {\n /* istanbul ignore next */\n if (!this.globalScope || !this.originalFetch) {\n return;\n }\n const originalFetch = this.globalScope.fetch;\n\n this.globalScope.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {\n const startTime = Date.now();\n const requestEvent: NetworkRequestEvent = {\n timestamp: startTime,\n startTime,\n type: 'fetch',\n method: init?.method || 'GET', // Fetch API defaulted to GET when no method is provided\n url: input.toString(),\n requestHeaders: init?.headers as Record<string, string>,\n requestBodySize: getRequestBodyLength(init?.body as FetchRequestBody),\n };\n\n try {\n const response = await originalFetch(input, init);\n const endTime = Date.now();\n\n requestEvent.status = response.status;\n requestEvent.duration = endTime - startTime;\n requestEvent.startTime = startTime;\n requestEvent.endTime = endTime;\n\n // Convert Headers\n const headers: Record<string, string> = {};\n let contentLength: number | undefined = undefined;\n response.headers.forEach((value: string, key: string) => {\n headers[key] = value;\n if (key === 'content-length') {\n contentLength = parseInt(value, 10) || undefined;\n }\n });\n requestEvent.responseHeaders = headers;\n requestEvent.responseBodySize = contentLength;\n\n this.triggerEventCallbacks(requestEvent);\n return response;\n } catch (error) {\n const endTime = Date.now();\n requestEvent.duration = endTime - startTime;\n\n // Capture error information\n const typedError = error as Error;\n requestEvent.error = {\n name: typedError.name || 'UnknownError',\n message: typedError.message || 'An unknown error occurred',\n };\n\n this.triggerEventCallbacks(requestEvent);\n throw error;\n }\n };\n }\n}\n\n// singleton instance of NetworkObserver\nexport const networkObserver = new NetworkObserver();\n"]}
|
|
@@ -4,6 +4,7 @@ import { Transport } from './transport';
|
|
|
4
4
|
import { IConfig } from '../config';
|
|
5
5
|
import { ElementInteractionsOptions } from './element-interactions';
|
|
6
6
|
import { PageTrackingOptions } from './page-view-tracking';
|
|
7
|
+
import { NetworkTrackingOptions } from './network-tracking';
|
|
7
8
|
export interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {
|
|
8
9
|
}
|
|
9
10
|
export interface ExternalBrowserConfig extends IConfig {
|
|
@@ -80,6 +81,11 @@ export interface ExternalBrowserConfig extends IConfig {
|
|
|
80
81
|
* @defaultValue `true`
|
|
81
82
|
*/
|
|
82
83
|
fetchRemoteConfig?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Captures network requests and responses.
|
|
86
|
+
* @defaultValue `undefined`
|
|
87
|
+
*/
|
|
88
|
+
networkTrackingOptions?: NetworkTrackingOptions;
|
|
83
89
|
}
|
|
84
90
|
interface InternalBrowserConfig {
|
|
85
91
|
cookieStorage: Storage<UserSession>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-config.d.ts","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;A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IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACvC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,aAAa,GAAG,QAAQ,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAGxE,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,aAAa,CAAC;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-config.js","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"","sourcesContent":["import { UserSession } from './user-session';\nimport { IdentityStorageType, Storage } from './storage';\nimport { Transport } from './transport';\nimport { IConfig } from '../config';\nimport { ElementInteractionsOptions } from './element-interactions';\nimport { PageTrackingOptions } from './page-view-tracking';\n\nexport interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {}\n\nexport interface ExternalBrowserConfig extends IConfig {\n /**\n * An app version for events tracked. This can be the version of your application.\n * @defaultValue `undefined`\n */\n appVersion?: string;\n /**\n * @deprecated This property is deprecated and will be removed in future versions. Please migrate to using `autocapture` instead.\n * The default event tracking configuration.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#tracking-default-events}.\n * @defaultValue `true`\n */\n defaultTracking?: boolean | DefaultTrackingOptions;\n /**\n * The configurations for auto-captured events.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/autocapture/}.\n */\n autocapture?: boolean | AutocaptureOptions;\n /**\n * The identifier for the device running your application.\n * @defaultValue `UUID()`\n */\n deviceId?: string;\n /**\n * Configuration for cookie.\n */\n cookieOptions?: CookieOptions;\n /**\n * The storage for user identify.\n * @defaultValue `\"cookie\"`\n */\n identityStorage?: IdentityStorageType;\n /**\n * The partner identifier.\n * Amplitude requires the customer who built an event ingestion integration to add the partner identifier to partner_id.\n * @defaultValue `undefined`\n */\n partnerId?: string;\n /**\n * The custom Session ID for the current session.\n * @defaultValue `timestamp`\n */\n sessionId?: number;\n /**\n * The period of inactivity from the last tracked event before a session expires in milliseconds.\n * @defaultValue `1,800,000` (30 minutes)\n */\n sessionTimeout: number;\n /**\n * The configurations for tracking additional properties.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#optional-tracking}.\n */\n trackingOptions: TrackingOptions;\n /**\n * Network transport mechanism used to send events.\n * @defaultValue `\"fetch\"`\n */\n transport?: 'fetch' | 'xhr' | 'beacon';\n /**\n * The identifier for the user being tracked.\n * @defaultValue `undefined`\n */\n userId?: string;\n /**\n * User's Nth instance of performing a default Page Viewed event within a session.\n * Used for landing page analysis.\n */\n pageCounter?: number;\n /**\n * Whether to fetch remote configuration. The remote configuration can be updated in the Amplitude platform here:\n * https://app.amplitude.com/data/amplitude/{your_org_name}/settings/autocapture\n * @defaultValue `true`\n */\n fetchRemoteConfig?: boolean;\n}\n\ninterface InternalBrowserConfig {\n cookieStorage: Storage<UserSession>;\n lastEventTime?: number;\n lastEventId?: number;\n transportProvider: Transport;\n version?: string;\n}\n\n/**\n * @deprecated This interface is deprecated and will be removed in future versions. Please migrate to using `AutocaptureOptions` instead.\n */\nexport interface DefaultTrackingOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n}\n\nexport interface AutocaptureOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n /**\n * Enables/disables user interactions tracking.\n * @defaultValue `false`\n */\n elementInteractions?: boolean | ElementInteractionsOptions;\n}\n\nexport interface TrackingOptions {\n /**\n * Enables/disables ip address tracking.\n * @defaultValue `true`\n */\n ipAddress?: boolean;\n /**\n * Enables/disables language tracking.\n * @defaultValue `true`\n */\n language?: boolean;\n /**\n * Enables/disables plantform tracking.\n * @defaultValue `true`\n */\n platform?: boolean;\n}\n\nexport interface AttributionOptions {\n /**\n * The rules to determine which referrers are excluded from being tracked as traffic source.\n * @defaultValue `[/your-domain\\.com$/]`\n */\n excludeReferrers?: (string | RegExp)[];\n /**\n * The value to represent undefined/no initial campaign parameter for first-touch attribution.\n * @defaultValue `\"EMPTY\"`\n */\n initialEmptyValue?: string;\n /**\n * The flag of if Amplitude to start a new session if any campaign parameter changes.\n * @defaultValue `false`\n */\n resetSessionOnNewCampaign?: boolean;\n}\n\nexport interface CookieOptions {\n /**\n * The domain property of cookies created.\n * @defaultValue `Your top level domain`\n */\n domain?: string;\n /**\n * The expiration of cookies created in days.\n * @defaultValue `365`\n */\n expiration?: number;\n /**\n * How cookies are sent with cross-site requests.\n * @defaultValue `\"Lax\"`\n */\n sameSite?: 'Strict' | 'Lax' | 'None';\n /**\n * The flag of if send cookies over secure protocols.\n * @defaultValue `false`\n */\n secure?: boolean;\n /**\n * The flag of if upgrade the cookies created by maintenance Browser SDK.\n * @defaultValue `true`\n */\n upgrade?: boolean;\n}\n\ntype HiddenOptions = 'apiKey' | 'transportProvider' | 'requestMetadata';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface BrowserOptions extends Omit<Partial<ExternalBrowserConfig>, HiddenOptions> {}\n"]}
|
|
1
|
+
{"version":3,"file":"browser-config.js","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"","sourcesContent":["import { UserSession } from './user-session';\nimport { IdentityStorageType, Storage } from './storage';\nimport { Transport } from './transport';\nimport { IConfig } from '../config';\nimport { ElementInteractionsOptions } from './element-interactions';\nimport { PageTrackingOptions } from './page-view-tracking';\nimport { NetworkTrackingOptions } from './network-tracking';\n\nexport interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {}\n\nexport interface ExternalBrowserConfig extends IConfig {\n /**\n * An app version for events tracked. This can be the version of your application.\n * @defaultValue `undefined`\n */\n appVersion?: string;\n /**\n * @deprecated This property is deprecated and will be removed in future versions. Please migrate to using `autocapture` instead.\n * The default event tracking configuration.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#tracking-default-events}.\n * @defaultValue `true`\n */\n defaultTracking?: boolean | DefaultTrackingOptions;\n /**\n * The configurations for auto-captured events.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/autocapture/}.\n */\n autocapture?: boolean | AutocaptureOptions;\n /**\n * The identifier for the device running your application.\n * @defaultValue `UUID()`\n */\n deviceId?: string;\n /**\n * Configuration for cookie.\n */\n cookieOptions?: CookieOptions;\n /**\n * The storage for user identify.\n * @defaultValue `\"cookie\"`\n */\n identityStorage?: IdentityStorageType;\n /**\n * The partner identifier.\n * Amplitude requires the customer who built an event ingestion integration to add the partner identifier to partner_id.\n * @defaultValue `undefined`\n */\n partnerId?: string;\n /**\n * The custom Session ID for the current session.\n * @defaultValue `timestamp`\n */\n sessionId?: number;\n /**\n * The period of inactivity from the last tracked event before a session expires in milliseconds.\n * @defaultValue `1,800,000` (30 minutes)\n */\n sessionTimeout: number;\n /**\n * The configurations for tracking additional properties.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#optional-tracking}.\n */\n trackingOptions: TrackingOptions;\n /**\n * Network transport mechanism used to send events.\n * @defaultValue `\"fetch\"`\n */\n transport?: 'fetch' | 'xhr' | 'beacon';\n /**\n * The identifier for the user being tracked.\n * @defaultValue `undefined`\n */\n userId?: string;\n /**\n * User's Nth instance of performing a default Page Viewed event within a session.\n * Used for landing page analysis.\n */\n pageCounter?: number;\n /**\n * Whether to fetch remote configuration. The remote configuration can be updated in the Amplitude platform here:\n * https://app.amplitude.com/data/amplitude/{your_org_name}/settings/autocapture\n * @defaultValue `true`\n */\n fetchRemoteConfig?: boolean;\n /**\n * Captures network requests and responses.\n * @defaultValue `undefined`\n */\n networkTrackingOptions?: NetworkTrackingOptions;\n}\n\ninterface InternalBrowserConfig {\n cookieStorage: Storage<UserSession>;\n lastEventTime?: number;\n lastEventId?: number;\n transportProvider: Transport;\n version?: string;\n}\n\n/**\n * @deprecated This interface is deprecated and will be removed in future versions. Please migrate to using `AutocaptureOptions` instead.\n */\nexport interface DefaultTrackingOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n}\n\nexport interface AutocaptureOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n /**\n * Enables/disables user interactions tracking.\n * @defaultValue `false`\n */\n elementInteractions?: boolean | ElementInteractionsOptions;\n}\n\nexport interface TrackingOptions {\n /**\n * Enables/disables ip address tracking.\n * @defaultValue `true`\n */\n ipAddress?: boolean;\n /**\n * Enables/disables language tracking.\n * @defaultValue `true`\n */\n language?: boolean;\n /**\n * Enables/disables plantform tracking.\n * @defaultValue `true`\n */\n platform?: boolean;\n}\n\nexport interface AttributionOptions {\n /**\n * The rules to determine which referrers are excluded from being tracked as traffic source.\n * @defaultValue `[/your-domain\\.com$/]`\n */\n excludeReferrers?: (string | RegExp)[];\n /**\n * The value to represent undefined/no initial campaign parameter for first-touch attribution.\n * @defaultValue `\"EMPTY\"`\n */\n initialEmptyValue?: string;\n /**\n * The flag of if Amplitude to start a new session if any campaign parameter changes.\n * @defaultValue `false`\n */\n resetSessionOnNewCampaign?: boolean;\n}\n\nexport interface CookieOptions {\n /**\n * The domain property of cookies created.\n * @defaultValue `Your top level domain`\n */\n domain?: string;\n /**\n * The expiration of cookies created in days.\n * @defaultValue `365`\n */\n expiration?: number;\n /**\n * How cookies are sent with cross-site requests.\n * @defaultValue `\"Lax\"`\n */\n sameSite?: 'Strict' | 'Lax' | 'None';\n /**\n * The flag of if send cookies over secure protocols.\n * @defaultValue `false`\n */\n secure?: boolean;\n /**\n * The flag of if upgrade the cookies created by maintenance Browser SDK.\n * @defaultValue `true`\n */\n upgrade?: boolean;\n}\n\ntype HiddenOptions = 'apiKey' | 'transportProvider' | 'requestMetadata';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface BrowserOptions extends Omit<Partial<ExternalBrowserConfig>, HiddenOptions> {}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface NetworkTrackingOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Suppresses tracking Amplitude requests from network capture.
|
|
4
|
+
* @defaultValue `true`
|
|
5
|
+
*/
|
|
6
|
+
ignoreAmplitudeRequests?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Hosts to ignore for network capture. Supports wildcard.
|
|
9
|
+
* @defaultValue `[]`
|
|
10
|
+
*/
|
|
11
|
+
ignoreHosts?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Rules to determine which network requests should be captured.
|
|
14
|
+
*
|
|
15
|
+
* Performs matching on array in reverse order.
|
|
16
|
+
*/
|
|
17
|
+
captureRules?: NetworkCaptureRule[];
|
|
18
|
+
}
|
|
19
|
+
export interface NetworkCaptureRule {
|
|
20
|
+
/**
|
|
21
|
+
* Hosts to allow for network capture. Supports wildcard.
|
|
22
|
+
* @defaultValue `["*"]` all hosts (except amplitude)
|
|
23
|
+
*/
|
|
24
|
+
hosts?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Range list that defines the status codes to be captured.
|
|
27
|
+
* @defaultValue `500-599`
|
|
28
|
+
*/
|
|
29
|
+
statusCodeRange?: string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=network-tracking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-tracking.d.ts","sourceRoot":"","sources":["../../../src/types/network-tracking.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;;OAIG;IACH,YAAY,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAM1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-tracking.js","sourceRoot":"","sources":["../../../src/types/network-tracking.ts"],"names":[],"mappings":"","sourcesContent":["export interface NetworkTrackingOptions {\n /**\n * Suppresses tracking Amplitude requests from network capture.\n * @defaultValue `true`\n */\n ignoreAmplitudeRequests?: boolean;\n /**\n * Hosts to ignore for network capture. Supports wildcard.\n * @defaultValue `[]`\n */\n ignoreHosts?: string[];\n /**\n * Rules to determine which network requests should be captured.\n *\n * Performs matching on array in reverse order.\n */\n captureRules?: NetworkCaptureRule[];\n}\n\nexport interface NetworkCaptureRule {\n /**\n * Hosts to allow for network capture. Supports wildcard.\n * @defaultValue `[\"*\"]` all hosts (except amplitude)\n */\n hosts?: string[];\n /**\n * Range list that defines the status codes to be captured.\n * @defaultValue `500-599`\n */\n statusCodeRange?: string;\n /**\n * Threshold for what is classified as a slow request (in seconds).\n * @defaultValue `3`\n */\n // slowThreshold?: number;\n}\n"]}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -40,5 +40,6 @@ export { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges }
|
|
|
40
40
|
export { Status } from './types/status';
|
|
41
41
|
export { BrowserConfig, BrowserOptions, DefaultTrackingOptions, TrackingOptions, AutocaptureOptions, CookieOptions, AttributionOptions, } from './types/browser-config';
|
|
42
42
|
export { BrowserClient } from './types/browser-client';
|
|
43
|
-
export {
|
|
43
|
+
export { NetworkRequestEvent, NetworkEventCallback, networkObserver } from './network-observer';
|
|
44
|
+
export { NetworkTrackingOptions, NetworkCaptureRule } from './types/network-tracking';
|
|
44
45
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE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EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,SAAS,EACT,UAAU,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAClH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -27,5 +27,5 @@ export { ServerZone } from './types/server-zone';
|
|
|
27
27
|
export { OfflineDisabled } from './types/offline';
|
|
28
28
|
export { DEFAULT_CSS_SELECTOR_ALLOWLIST, DEFAULT_DATA_ATTRIBUTE_PREFIX, DEFAULT_ACTION_CLICK_ALLOWLIST, } from './types/element-interactions';
|
|
29
29
|
export { Status } from './types/status';
|
|
30
|
-
export {
|
|
30
|
+
export { NetworkEventCallback, networkObserver } from './network-observer';
|
|
31
31
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js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CAAC;AAEhD,OAAO,EAAE,aAAa,EAAmB,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAS,iBAAiB,EAAE,gBAAgB,EAAqC,MAAM,qBAAqB,CAAC;AAGpH,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAQlD,OAAO,EAIL,8BAA8B,EAC9B,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAYxC,OAAO,EAAuB,oBAAoB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { AmplitudeCore, CoreClient } from './core-client';\nexport { Identify, IIdentify } from './identify';\nexport { Revenue, IRevenue, RevenueProperty } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { IdentityEventSender } from './plugins/identity';\nexport { IConfig, Config, RequestMetadata } from './config';\nexport { Logger, ILogger, LogConfig } from './logger';\nexport { getGlobalScope } from './global-scope';\nexport { getAnalyticsConnector, setConnectorDeviceId, setConnectorUserId } from './analytics-connector';\nexport { isNewSession } from './session';\nexport { getCookieName, getOldCookieName } from './cookie-name';\nexport { getLanguage } from './language';\nexport { getQueryParams } from './query-params';\n\nexport { returnWrapper, AmplitudeReturn } from './utils/return-wrapper';\nexport { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';\nexport { UUID } from './utils/uuid';\nexport { createIdentifyEvent } from './utils/event-builder';\n\nexport { MemoryStorage } from './storage/memory';\nexport { CookieStorage } from './storage/cookie';\nexport { getStorageKey } from './storage/helpers';\n\nexport { BaseTransport } from './transports/base';\nexport { FetchTransport } from './transports/fetch';\n\nexport { LogLevel } from './types/loglevel';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './types/constants';\nexport { Storage, IdentityStorageType } from './types/storage';\nexport { Event, IdentifyOperation, SpecialEventType, IdentifyEvent, GroupIdentifyEvent } from './types/event/event';\nexport { EventOptions, BaseEvent } from './types/event/base-event';\nexport { IngestionMetadata } from './types/event/ingestion-metadata';\nexport { ServerZoneType, ServerZone } from './types/server-zone';\nexport { OfflineDisabled } from './types/offline';\nexport { Plan } from './types/event/plan';\nexport { TransportType, Transport } from './types/transport';\nexport { Payload } from './types/payload';\nexport { Response } from './types/response';\nexport { UserSession } from './types/user-session';\nexport { Plugin, BeforePlugin, DestinationPlugin, EnrichmentPlugin, PluginType } from './types/plugin';\nexport { Result } from './types/result';\nexport {\n ElementInteractionsOptions,\n Messenger,\n ActionType,\n DEFAULT_CSS_SELECTOR_ALLOWLIST,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n DEFAULT_ACTION_CLICK_ALLOWLIST,\n} from './types/element-interactions';\nexport { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges } from './types/page-view-tracking';\nexport { Status } from './types/status';\nexport {\n BrowserConfig,\n BrowserOptions,\n DefaultTrackingOptions,\n TrackingOptions,\n AutocaptureOptions,\n CookieOptions,\n AttributionOptions,\n} from './types/browser-config';\nexport { BrowserClient } from './types/browser-client';\n\nexport { NetworkRequestEvent, NetworkEventCallback, networkObserver } from './network-observer';\nexport { NetworkTrackingOptions, NetworkCaptureRule } from './types/network-tracking';\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ILogger } from '.';
|
|
2
2
|
export interface NetworkRequestEvent {
|
|
3
|
-
type:
|
|
3
|
+
type: string;
|
|
4
4
|
method: string;
|
|
5
5
|
url: string;
|
|
6
|
+
timestamp: number;
|
|
6
7
|
status?: number;
|
|
7
8
|
duration?: number;
|
|
8
9
|
requestBodySize?: number;
|
|
@@ -40,5 +41,6 @@ export declare class NetworkObserver {
|
|
|
40
41
|
protected triggerEventCallbacks(event: NetworkRequestEvent): void;
|
|
41
42
|
private observeFetch;
|
|
42
43
|
}
|
|
44
|
+
export declare const networkObserver: NetworkObserver;
|
|
43
45
|
export {};
|
|
44
46
|
//# sourceMappingURL=network-observer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-observer.d.ts","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"network-observer.d.ts","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;AAG5B,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAA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AAE,mBAAmB;IAM1D,OAAO,CAAC,YAAY;CA0DrB;AAGD,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __generator, __read, __values } from "tslib";
|
|
2
2
|
import { getGlobalScope } from './global-scope';
|
|
3
3
|
import { UUID } from './utils/uuid';
|
|
4
|
+
var MAXIMUM_ENTRIES = 100;
|
|
4
5
|
export function getRequestBodyLength(body) {
|
|
5
6
|
var e_1, _a;
|
|
6
7
|
var global = getGlobalScope();
|
|
@@ -25,9 +26,9 @@ export function getRequestBodyLength(body) {
|
|
|
25
26
|
}
|
|
26
27
|
else if (body instanceof FormData) {
|
|
27
28
|
// Estimating only for text parts; not accurate for files
|
|
28
|
-
// TODO: get consensus before deciding if we do this
|
|
29
29
|
var formData = body;
|
|
30
30
|
var total = 0;
|
|
31
|
+
var count = 0;
|
|
31
32
|
try {
|
|
32
33
|
for (var _b = __values(formData.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
33
34
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -39,6 +40,11 @@ export function getRequestBodyLength(body) {
|
|
|
39
40
|
// if we encounter a "File" type, we should not count it and just return undefined
|
|
40
41
|
total += value.size;
|
|
41
42
|
}
|
|
43
|
+
// terminate if we reach the maximum number of entries
|
|
44
|
+
// to avoid performance issues in case of very large FormDataß
|
|
45
|
+
if (++count >= MAXIMUM_ENTRIES) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -114,6 +120,7 @@ var NetworkObserver = /** @class */ (function () {
|
|
|
114
120
|
case 0:
|
|
115
121
|
startTime = Date.now();
|
|
116
122
|
requestEvent = {
|
|
123
|
+
timestamp: startTime,
|
|
117
124
|
startTime: startTime,
|
|
118
125
|
type: 'fetch',
|
|
119
126
|
method: (init === null || init === void 0 ? void 0 : init.method) || 'GET',
|
|
@@ -163,4 +170,6 @@ var NetworkObserver = /** @class */ (function () {
|
|
|
163
170
|
return NetworkObserver;
|
|
164
171
|
}());
|
|
165
172
|
export { NetworkObserver };
|
|
173
|
+
// singleton instance of NetworkObserver
|
|
174
|
+
export var networkObserver = new NetworkObserver();
|
|
166
175
|
//# sourceMappingURL=network-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-observer.js","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AA4BpC,MAAM,UAAU,oBAAoB,CAAC,IAAyC;;IAC5E,IAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAA,EAAE;QACxB,OAAO;KACR;IACO,IAAA,WAAW,GAAK,MAAM,YAAX,CAAY;IAE/B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;KAC9C;SAAM,IAAI,IAAI,YAAY,IAAI,EAAE;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;KAClB;SAAM,IAAI,IAAI,YAAY,eAAe,EAAE;QAC1C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;KACzD;SAAM,IAAI,IAAI,YAAY,WAAW,EAAE;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC;KACxB;SAAM,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACnC,OAAO,IAAI,CAAC,UAAU,CAAC;KACxB;SAAM,IAAI,IAAI,YAAY,QAAQ,EAAE;QACnC,yDAAyD;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;wBAEV,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;wBAC3B,YAAY,CAAC,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;wBAGtC,UAAU,GAAG,OAAc,CAAC;wBAClC,YAAY,CAAC,KAAK,GAAG;4BACnB,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,cAAc;4BACvC,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,2BAA2B;yBAC3D,CAAC;wBAEF,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;wBACzC,MAAM,OAAK,CAAC;;;;aAEf,CAAC;IACJ,CAAC;IACH,sBAAC;AAAD,CAAC,AAvGD,IAuGC","sourcesContent":["import { getGlobalScope } from './global-scope';\nimport { UUID } from './utils/uuid';\nimport { ILogger } from '.';\nexport interface NetworkRequestEvent {\n type: 'fetch';\n method: string;\n url: string;\n status?: number;\n duration?: number;\n requestBodySize?: number;\n requestHeaders?: Record<string, string>;\n responseBodySize?: number;\n responseHeaders?: Record<string, string>;\n error?: {\n name: string;\n message: string;\n };\n startTime?: number;\n endTime?: number;\n}\n\n// using this type instead of the DOM's ttp so that it's Node compatible\ntype FormDataEntryValueBrowser = string | Blob | null;\nexport interface FormDataBrowser {\n entries(): IterableIterator<[string, FormDataEntryValueBrowser]>;\n}\n\nexport type FetchRequestBody = string | Blob | ArrayBuffer | FormDataBrowser | URLSearchParams | null | undefined;\n\nexport function getRequestBodyLength(body: FetchRequestBody | null | undefined): number | undefined {\n const global = getGlobalScope();\n if (!global?.TextEncoder) {\n return;\n }\n const { TextEncoder } = global;\n\n if (typeof body === 'string') {\n return new TextEncoder().encode(body).length;\n } else if (body instanceof Blob) {\n return body.size;\n } else if (body instanceof URLSearchParams) {\n return new TextEncoder().encode(body.toString()).length;\n } else if (body instanceof ArrayBuffer) {\n return body.byteLength;\n } else if (ArrayBuffer.isView(body)) {\n return body.byteLength;\n } else if (body instanceof FormData) {\n // Estimating only for text parts; not accurate for files\n // TODO: get consensus before deciding if we do this\n const formData = body as FormDataBrowser;\n let total = 0;\n for (const [key, value] of formData.entries()) {\n total += key.length;\n if (typeof value === 'string') {\n total += new TextEncoder().encode(value).length;\n } else if ((value as Blob).size) {\n // if we encounter a \"File\" type, we should not count it and just return undefined\n total += (value as Blob).size;\n }\n }\n return total;\n }\n // Stream or unknown\n return;\n}\n\nexport type NetworkEventCallbackFn = (event: NetworkRequestEvent) => void;\n\nexport class NetworkEventCallback {\n constructor(public readonly callback: (event: NetworkRequestEvent) => void, public readonly id: string = UUID()) {}\n}\n\nexport class NetworkObserver {\n private originalFetch?: typeof fetch;\n private eventCallbacks: Map<string, NetworkEventCallback> = new Map();\n private isObserving = false;\n // eslint-disable-next-line no-restricted-globals\n private globalScope?: typeof globalThis;\n\n constructor(logger?: ILogger) {\n const globalScope = getGlobalScope();\n if (!NetworkObserver.isSupported()) {\n /* istanbul ignore next */\n logger?.error('Fetch API is not supported in this environment.');\n return;\n }\n this.globalScope = globalScope;\n /* istanbul ignore next */\n this.originalFetch = this.globalScope?.fetch;\n }\n\n static isSupported(): boolean {\n const globalScope = getGlobalScope();\n return !!globalScope && !!globalScope.fetch;\n }\n\n subscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.set(eventCallback.id, eventCallback);\n if (!this.isObserving) {\n this.observeFetch();\n this.isObserving = true;\n }\n }\n\n unsubscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.delete(eventCallback.id);\n if (this.originalFetch && this.globalScope && this.eventCallbacks.size === 0 && this.isObserving) {\n this.globalScope.fetch = this.originalFetch;\n this.isObserving = false;\n }\n }\n\n protected triggerEventCallbacks(event: NetworkRequestEvent) {\n this.eventCallbacks.forEach((callback) => {\n callback.callback(event);\n });\n }\n\n private observeFetch() {\n /* istanbul ignore next */\n if (!this.globalScope || !this.originalFetch) {\n return;\n }\n const originalFetch = this.globalScope.fetch;\n\n this.globalScope.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {\n const startTime = Date.now();\n const requestEvent: NetworkRequestEvent = {\n startTime,\n type: 'fetch',\n method: init?.method || 'GET', // Fetch API defaulted to GET when no method is provided\n url: input.toString(),\n requestHeaders: init?.headers as Record<string, string>,\n requestBodySize: getRequestBodyLength(init?.body as FetchRequestBody),\n };\n\n try {\n const response = await originalFetch(input, init);\n const endTime = Date.now();\n\n requestEvent.status = response.status;\n requestEvent.duration = endTime - startTime;\n requestEvent.startTime = startTime;\n requestEvent.endTime = endTime;\n\n // Convert Headers\n const headers: Record<string, string> = {};\n let contentLength: number | undefined = undefined;\n response.headers.forEach((value: string, key: string) => {\n headers[key] = value;\n if (key === 'content-length') {\n contentLength = parseInt(value, 10) || undefined;\n }\n });\n requestEvent.responseHeaders = headers;\n requestEvent.responseBodySize = contentLength;\n\n this.triggerEventCallbacks(requestEvent);\n return response;\n } catch (error) {\n const endTime = Date.now();\n requestEvent.duration = endTime - startTime;\n\n // Capture error information\n const typedError = error as Error;\n requestEvent.error = {\n name: typedError.name || 'UnknownError',\n message: typedError.message || 'An unknown error occurred',\n };\n\n this.triggerEventCallbacks(requestEvent);\n throw error;\n }\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"network-observer.js","sourceRoot":"","sources":["../../src/network-observer.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,IAAM,eAAe,GAAG,GAAG,CAAC;AA4B5B,MAAM,UAAU,oBAAoB,CAAC,IAAyC;;IAC5E,IAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAA,EAAE;QACxB,OAAO;KACR;IACO,IAAA,WAAW,GAAK,MAAM,YAAX,CAAY;IAE/B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IA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Y,CAAC,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;wBAC5C,YAAY,CAAC,SAAS,GAAG,SAAS,CAAC;wBACnC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;wBAGzB,YAAkC,EAAE,CAAC;wBACvC,kBAAoC,SAAS,CAAC;wBAClD,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,KAAa,EAAE,GAAW;4BAClD,SAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;4BACrB,IAAI,GAAG,KAAK,gBAAgB,EAAE;gCAC5B,eAAa,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC;6BAClD;wBACH,CAAC,CAAC,CAAC;wBACH,YAAY,CAAC,eAAe,GAAG,SAAO,CAAC;wBACvC,YAAY,CAAC,gBAAgB,GAAG,eAAa,CAAC;wBAE9C,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;wBACzC,sBAAO,QAAQ,EAAC;;;wBAEV,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;wBAC3B,YAAY,CAAC,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;wBAGtC,UAAU,GAAG,OAAc,CAAC;wBAClC,YAAY,CAAC,KAAK,GAAG;4BACnB,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,cAAc;4BACvC,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,2BAA2B;yBAC3D,CAAC;wBAEF,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;wBACzC,MAAM,OAAK,CAAC;;;;aAEf,CAAC;IACJ,CAAC;IACH,sBAAC;AAAD,CAAC,AAxGD,IAwGC;;AAED,wCAAwC;AACxC,MAAM,CAAC,IAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC","sourcesContent":["import { getGlobalScope } from './global-scope';\nimport { UUID } from './utils/uuid';\nimport { ILogger } from '.';\n\nconst MAXIMUM_ENTRIES = 100;\nexport interface NetworkRequestEvent {\n type: string;\n method: string;\n url: string;\n timestamp: number;\n status?: number;\n duration?: number;\n requestBodySize?: number;\n requestHeaders?: Record<string, string>;\n responseBodySize?: number;\n responseHeaders?: Record<string, string>;\n error?: {\n name: string;\n message: string;\n };\n startTime?: number;\n endTime?: number;\n}\n\n// using this type instead of the DOM's ttp so that it's Node compatible\ntype FormDataEntryValueBrowser = string | Blob | null;\nexport interface FormDataBrowser {\n entries(): IterableIterator<[string, FormDataEntryValueBrowser]>;\n}\n\nexport type FetchRequestBody = string | Blob | ArrayBuffer | FormDataBrowser | URLSearchParams | null | undefined;\n\nexport function getRequestBodyLength(body: FetchRequestBody | null | undefined): number | undefined {\n const global = getGlobalScope();\n if (!global?.TextEncoder) {\n return;\n }\n const { TextEncoder } = global;\n\n if (typeof body === 'string') {\n return new TextEncoder().encode(body).length;\n } else if (body instanceof Blob) {\n return body.size;\n } else if (body instanceof URLSearchParams) {\n return new TextEncoder().encode(body.toString()).length;\n } else if (body instanceof ArrayBuffer) {\n return body.byteLength;\n } else if (ArrayBuffer.isView(body)) {\n return body.byteLength;\n } else if (body instanceof FormData) {\n // Estimating only for text parts; not accurate for files\n const formData = body as FormDataBrowser;\n\n let total = 0;\n let count = 0;\n for (const [key, value] of formData.entries()) {\n total += key.length;\n if (typeof value === 'string') {\n total += new TextEncoder().encode(value).length;\n } else if ((value as Blob).size) {\n // if we encounter a \"File\" type, we should not count it and just return undefined\n total += (value as Blob).size;\n }\n // terminate if we reach the maximum number of entries\n // to avoid performance issues in case of very large FormDataß\n if (++count >= MAXIMUM_ENTRIES) {\n return;\n }\n }\n return total;\n }\n // Stream or unknown\n return;\n}\n\nexport type NetworkEventCallbackFn = (event: NetworkRequestEvent) => void;\n\nexport class NetworkEventCallback {\n constructor(public readonly callback: (event: NetworkRequestEvent) => void, public readonly id: string = UUID()) {}\n}\n\nexport class NetworkObserver {\n private originalFetch?: typeof fetch;\n private eventCallbacks: Map<string, NetworkEventCallback> = new Map();\n private isObserving = false;\n // eslint-disable-next-line no-restricted-globals\n private globalScope?: typeof globalThis;\n\n constructor(logger?: ILogger) {\n const globalScope = getGlobalScope();\n if (!NetworkObserver.isSupported()) {\n /* istanbul ignore next */\n logger?.error('Fetch API is not supported in this environment.');\n return;\n }\n this.globalScope = globalScope;\n /* istanbul ignore next */\n this.originalFetch = this.globalScope?.fetch;\n }\n\n static isSupported(): boolean {\n const globalScope = getGlobalScope();\n return !!globalScope && !!globalScope.fetch;\n }\n\n subscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.set(eventCallback.id, eventCallback);\n if (!this.isObserving) {\n this.observeFetch();\n this.isObserving = true;\n }\n }\n\n unsubscribe(eventCallback: NetworkEventCallback) {\n this.eventCallbacks.delete(eventCallback.id);\n if (this.originalFetch && this.globalScope && this.eventCallbacks.size === 0 && this.isObserving) {\n this.globalScope.fetch = this.originalFetch;\n this.isObserving = false;\n }\n }\n\n protected triggerEventCallbacks(event: NetworkRequestEvent) {\n this.eventCallbacks.forEach((callback) => {\n callback.callback(event);\n });\n }\n\n private observeFetch() {\n /* istanbul ignore next */\n if (!this.globalScope || !this.originalFetch) {\n return;\n }\n const originalFetch = this.globalScope.fetch;\n\n this.globalScope.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {\n const startTime = Date.now();\n const requestEvent: NetworkRequestEvent = {\n timestamp: startTime,\n startTime,\n type: 'fetch',\n method: init?.method || 'GET', // Fetch API defaulted to GET when no method is provided\n url: input.toString(),\n requestHeaders: init?.headers as Record<string, string>,\n requestBodySize: getRequestBodyLength(init?.body as FetchRequestBody),\n };\n\n try {\n const response = await originalFetch(input, init);\n const endTime = Date.now();\n\n requestEvent.status = response.status;\n requestEvent.duration = endTime - startTime;\n requestEvent.startTime = startTime;\n requestEvent.endTime = endTime;\n\n // Convert Headers\n const headers: Record<string, string> = {};\n let contentLength: number | undefined = undefined;\n response.headers.forEach((value: string, key: string) => {\n headers[key] = value;\n if (key === 'content-length') {\n contentLength = parseInt(value, 10) || undefined;\n }\n });\n requestEvent.responseHeaders = headers;\n requestEvent.responseBodySize = contentLength;\n\n this.triggerEventCallbacks(requestEvent);\n return response;\n } catch (error) {\n const endTime = Date.now();\n requestEvent.duration = endTime - startTime;\n\n // Capture error information\n const typedError = error as Error;\n requestEvent.error = {\n name: typedError.name || 'UnknownError',\n message: typedError.message || 'An unknown error occurred',\n };\n\n this.triggerEventCallbacks(requestEvent);\n throw error;\n }\n };\n }\n}\n\n// singleton instance of NetworkObserver\nexport const networkObserver = new NetworkObserver();\n"]}
|
|
@@ -4,6 +4,7 @@ import { Transport } from './transport';
|
|
|
4
4
|
import { IConfig } from '../config';
|
|
5
5
|
import { ElementInteractionsOptions } from './element-interactions';
|
|
6
6
|
import { PageTrackingOptions } from './page-view-tracking';
|
|
7
|
+
import { NetworkTrackingOptions } from './network-tracking';
|
|
7
8
|
export interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {
|
|
8
9
|
}
|
|
9
10
|
export interface ExternalBrowserConfig extends IConfig {
|
|
@@ -80,6 +81,11 @@ export interface ExternalBrowserConfig extends IConfig {
|
|
|
80
81
|
* @defaultValue `true`
|
|
81
82
|
*/
|
|
82
83
|
fetchRemoteConfig?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Captures network requests and responses.
|
|
86
|
+
* @defaultValue `undefined`
|
|
87
|
+
*/
|
|
88
|
+
networkTrackingOptions?: NetworkTrackingOptions;
|
|
83
89
|
}
|
|
84
90
|
interface InternalBrowserConfig {
|
|
85
91
|
cookieStorage: Storage<UserSession>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-config.d.ts","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,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B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACvC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,aAAa,GAAG,QAAQ,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAGxE,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,aAAa,CAAC;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-config.js","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"","sourcesContent":["import { UserSession } from './user-session';\nimport { IdentityStorageType, Storage } from './storage';\nimport { Transport } from './transport';\nimport { IConfig } from '../config';\nimport { ElementInteractionsOptions } from './element-interactions';\nimport { PageTrackingOptions } from './page-view-tracking';\n\nexport interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {}\n\nexport interface ExternalBrowserConfig extends IConfig {\n /**\n * An app version for events tracked. This can be the version of your application.\n * @defaultValue `undefined`\n */\n appVersion?: string;\n /**\n * @deprecated This property is deprecated and will be removed in future versions. Please migrate to using `autocapture` instead.\n * The default event tracking configuration.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#tracking-default-events}.\n * @defaultValue `true`\n */\n defaultTracking?: boolean | DefaultTrackingOptions;\n /**\n * The configurations for auto-captured events.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/autocapture/}.\n */\n autocapture?: boolean | AutocaptureOptions;\n /**\n * The identifier for the device running your application.\n * @defaultValue `UUID()`\n */\n deviceId?: string;\n /**\n * Configuration for cookie.\n */\n cookieOptions?: CookieOptions;\n /**\n * The storage for user identify.\n * @defaultValue `\"cookie\"`\n */\n identityStorage?: IdentityStorageType;\n /**\n * The partner identifier.\n * Amplitude requires the customer who built an event ingestion integration to add the partner identifier to partner_id.\n * @defaultValue `undefined`\n */\n partnerId?: string;\n /**\n * The custom Session ID for the current session.\n * @defaultValue `timestamp`\n */\n sessionId?: number;\n /**\n * The period of inactivity from the last tracked event before a session expires in milliseconds.\n * @defaultValue `1,800,000` (30 minutes)\n */\n sessionTimeout: number;\n /**\n * The configurations for tracking additional properties.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#optional-tracking}.\n */\n trackingOptions: TrackingOptions;\n /**\n * Network transport mechanism used to send events.\n * @defaultValue `\"fetch\"`\n */\n transport?: 'fetch' | 'xhr' | 'beacon';\n /**\n * The identifier for the user being tracked.\n * @defaultValue `undefined`\n */\n userId?: string;\n /**\n * User's Nth instance of performing a default Page Viewed event within a session.\n * Used for landing page analysis.\n */\n pageCounter?: number;\n /**\n * Whether to fetch remote configuration. The remote configuration can be updated in the Amplitude platform here:\n * https://app.amplitude.com/data/amplitude/{your_org_name}/settings/autocapture\n * @defaultValue `true`\n */\n fetchRemoteConfig?: boolean;\n}\n\ninterface InternalBrowserConfig {\n cookieStorage: Storage<UserSession>;\n lastEventTime?: number;\n lastEventId?: number;\n transportProvider: Transport;\n version?: string;\n}\n\n/**\n * @deprecated This interface is deprecated and will be removed in future versions. Please migrate to using `AutocaptureOptions` instead.\n */\nexport interface DefaultTrackingOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n}\n\nexport interface AutocaptureOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n /**\n * Enables/disables user interactions tracking.\n * @defaultValue `false`\n */\n elementInteractions?: boolean | ElementInteractionsOptions;\n}\n\nexport interface TrackingOptions {\n /**\n * Enables/disables ip address tracking.\n * @defaultValue `true`\n */\n ipAddress?: boolean;\n /**\n * Enables/disables language tracking.\n * @defaultValue `true`\n */\n language?: boolean;\n /**\n * Enables/disables plantform tracking.\n * @defaultValue `true`\n */\n platform?: boolean;\n}\n\nexport interface AttributionOptions {\n /**\n * The rules to determine which referrers are excluded from being tracked as traffic source.\n * @defaultValue `[/your-domain\\.com$/]`\n */\n excludeReferrers?: (string | RegExp)[];\n /**\n * The value to represent undefined/no initial campaign parameter for first-touch attribution.\n * @defaultValue `\"EMPTY\"`\n */\n initialEmptyValue?: string;\n /**\n * The flag of if Amplitude to start a new session if any campaign parameter changes.\n * @defaultValue `false`\n */\n resetSessionOnNewCampaign?: boolean;\n}\n\nexport interface CookieOptions {\n /**\n * The domain property of cookies created.\n * @defaultValue `Your top level domain`\n */\n domain?: string;\n /**\n * The expiration of cookies created in days.\n * @defaultValue `365`\n */\n expiration?: number;\n /**\n * How cookies are sent with cross-site requests.\n * @defaultValue `\"Lax\"`\n */\n sameSite?: 'Strict' | 'Lax' | 'None';\n /**\n * The flag of if send cookies over secure protocols.\n * @defaultValue `false`\n */\n secure?: boolean;\n /**\n * The flag of if upgrade the cookies created by maintenance Browser SDK.\n * @defaultValue `true`\n */\n upgrade?: boolean;\n}\n\ntype HiddenOptions = 'apiKey' | 'transportProvider' | 'requestMetadata';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface BrowserOptions extends Omit<Partial<ExternalBrowserConfig>, HiddenOptions> {}\n"]}
|
|
1
|
+
{"version":3,"file":"browser-config.js","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"","sourcesContent":["import { UserSession } from './user-session';\nimport { IdentityStorageType, Storage } from './storage';\nimport { Transport } from './transport';\nimport { IConfig } from '../config';\nimport { ElementInteractionsOptions } from './element-interactions';\nimport { PageTrackingOptions } from './page-view-tracking';\nimport { NetworkTrackingOptions } from './network-tracking';\n\nexport interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {}\n\nexport interface ExternalBrowserConfig extends IConfig {\n /**\n * An app version for events tracked. This can be the version of your application.\n * @defaultValue `undefined`\n */\n appVersion?: string;\n /**\n * @deprecated This property is deprecated and will be removed in future versions. Please migrate to using `autocapture` instead.\n * The default event tracking configuration.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#tracking-default-events}.\n * @defaultValue `true`\n */\n defaultTracking?: boolean | DefaultTrackingOptions;\n /**\n * The configurations for auto-captured events.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/autocapture/}.\n */\n autocapture?: boolean | AutocaptureOptions;\n /**\n * The identifier for the device running your application.\n * @defaultValue `UUID()`\n */\n deviceId?: string;\n /**\n * Configuration for cookie.\n */\n cookieOptions?: CookieOptions;\n /**\n * The storage for user identify.\n * @defaultValue `\"cookie\"`\n */\n identityStorage?: IdentityStorageType;\n /**\n * The partner identifier.\n * Amplitude requires the customer who built an event ingestion integration to add the partner identifier to partner_id.\n * @defaultValue `undefined`\n */\n partnerId?: string;\n /**\n * The custom Session ID for the current session.\n * @defaultValue `timestamp`\n */\n sessionId?: number;\n /**\n * The period of inactivity from the last tracked event before a session expires in milliseconds.\n * @defaultValue `1,800,000` (30 minutes)\n */\n sessionTimeout: number;\n /**\n * The configurations for tracking additional properties.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#optional-tracking}.\n */\n trackingOptions: TrackingOptions;\n /**\n * Network transport mechanism used to send events.\n * @defaultValue `\"fetch\"`\n */\n transport?: 'fetch' | 'xhr' | 'beacon';\n /**\n * The identifier for the user being tracked.\n * @defaultValue `undefined`\n */\n userId?: string;\n /**\n * User's Nth instance of performing a default Page Viewed event within a session.\n * Used for landing page analysis.\n */\n pageCounter?: number;\n /**\n * Whether to fetch remote configuration. The remote configuration can be updated in the Amplitude platform here:\n * https://app.amplitude.com/data/amplitude/{your_org_name}/settings/autocapture\n * @defaultValue `true`\n */\n fetchRemoteConfig?: boolean;\n /**\n * Captures network requests and responses.\n * @defaultValue `undefined`\n */\n networkTrackingOptions?: NetworkTrackingOptions;\n}\n\ninterface InternalBrowserConfig {\n cookieStorage: Storage<UserSession>;\n lastEventTime?: number;\n lastEventId?: number;\n transportProvider: Transport;\n version?: string;\n}\n\n/**\n * @deprecated This interface is deprecated and will be removed in future versions. Please migrate to using `AutocaptureOptions` instead.\n */\nexport interface DefaultTrackingOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n}\n\nexport interface AutocaptureOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n /**\n * Enables/disables user interactions tracking.\n * @defaultValue `false`\n */\n elementInteractions?: boolean | ElementInteractionsOptions;\n}\n\nexport interface TrackingOptions {\n /**\n * Enables/disables ip address tracking.\n * @defaultValue `true`\n */\n ipAddress?: boolean;\n /**\n * Enables/disables language tracking.\n * @defaultValue `true`\n */\n language?: boolean;\n /**\n * Enables/disables plantform tracking.\n * @defaultValue `true`\n */\n platform?: boolean;\n}\n\nexport interface AttributionOptions {\n /**\n * The rules to determine which referrers are excluded from being tracked as traffic source.\n * @defaultValue `[/your-domain\\.com$/]`\n */\n excludeReferrers?: (string | RegExp)[];\n /**\n * The value to represent undefined/no initial campaign parameter for first-touch attribution.\n * @defaultValue `\"EMPTY\"`\n */\n initialEmptyValue?: string;\n /**\n * The flag of if Amplitude to start a new session if any campaign parameter changes.\n * @defaultValue `false`\n */\n resetSessionOnNewCampaign?: boolean;\n}\n\nexport interface CookieOptions {\n /**\n * The domain property of cookies created.\n * @defaultValue `Your top level domain`\n */\n domain?: string;\n /**\n * The expiration of cookies created in days.\n * @defaultValue `365`\n */\n expiration?: number;\n /**\n * How cookies are sent with cross-site requests.\n * @defaultValue `\"Lax\"`\n */\n sameSite?: 'Strict' | 'Lax' | 'None';\n /**\n * The flag of if send cookies over secure protocols.\n * @defaultValue `false`\n */\n secure?: boolean;\n /**\n * The flag of if upgrade the cookies created by maintenance Browser SDK.\n * @defaultValue `true`\n */\n upgrade?: boolean;\n}\n\ntype HiddenOptions = 'apiKey' | 'transportProvider' | 'requestMetadata';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface BrowserOptions extends Omit<Partial<ExternalBrowserConfig>, HiddenOptions> {}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface NetworkTrackingOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Suppresses tracking Amplitude requests from network capture.
|
|
4
|
+
* @defaultValue `true`
|
|
5
|
+
*/
|
|
6
|
+
ignoreAmplitudeRequests?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Hosts to ignore for network capture. Supports wildcard.
|
|
9
|
+
* @defaultValue `[]`
|
|
10
|
+
*/
|
|
11
|
+
ignoreHosts?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Rules to determine which network requests should be captured.
|
|
14
|
+
*
|
|
15
|
+
* Performs matching on array in reverse order.
|
|
16
|
+
*/
|
|
17
|
+
captureRules?: NetworkCaptureRule[];
|
|
18
|
+
}
|
|
19
|
+
export interface NetworkCaptureRule {
|
|
20
|
+
/**
|
|
21
|
+
* Hosts to allow for network capture. Supports wildcard.
|
|
22
|
+
* @defaultValue `["*"]` all hosts (except amplitude)
|
|
23
|
+
*/
|
|
24
|
+
hosts?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Range list that defines the status codes to be captured.
|
|
27
|
+
* @defaultValue `500-599`
|
|
28
|
+
*/
|
|
29
|
+
statusCodeRange?: string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=network-tracking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-tracking.d.ts","sourceRoot":"","sources":["../../../src/types/network-tracking.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;;OAIG;IACH,YAAY,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAM1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-tracking.js","sourceRoot":"","sources":["../../../src/types/network-tracking.ts"],"names":[],"mappings":"","sourcesContent":["export interface NetworkTrackingOptions {\n /**\n * Suppresses tracking Amplitude requests from network capture.\n * @defaultValue `true`\n */\n ignoreAmplitudeRequests?: boolean;\n /**\n * Hosts to ignore for network capture. Supports wildcard.\n * @defaultValue `[]`\n */\n ignoreHosts?: string[];\n /**\n * Rules to determine which network requests should be captured.\n *\n * Performs matching on array in reverse order.\n */\n captureRules?: NetworkCaptureRule[];\n}\n\nexport interface NetworkCaptureRule {\n /**\n * Hosts to allow for network capture. Supports wildcard.\n * @defaultValue `[\"*\"]` all hosts (except amplitude)\n */\n hosts?: string[];\n /**\n * Range list that defines the status codes to be captured.\n * @defaultValue `500-599`\n */\n statusCodeRange?: string;\n /**\n * Threshold for what is classified as a slow request (in seconds).\n * @defaultValue `3`\n */\n // slowThreshold?: number;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0-networkautocapture-1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"files": [
|
|
42
42
|
"lib"
|
|
43
43
|
],
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "b8f0675f96af3e9c31c6dbf9537c6861da798dbd"
|
|
45
45
|
}
|