@amplitude/plugin-web-vitals-browser 0.1.0-SR-1975.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/LICENSE +21 -0
- package/README.md +48 -0
- package/lib/cjs/constants.d.ts +3 -0
- package/lib/cjs/constants.d.ts.map +1 -0
- package/lib/cjs/constants.js +6 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +9 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/version.d.ts +2 -0
- package/lib/cjs/version.d.ts.map +1 -0
- package/lib/cjs/version.js +5 -0
- package/lib/cjs/version.js.map +1 -0
- package/lib/cjs/web-vitals-plugin.d.ts +4 -0
- package/lib/cjs/web-vitals-plugin.d.ts.map +1 -0
- package/lib/cjs/web-vitals-plugin.js +94 -0
- package/lib/cjs/web-vitals-plugin.js.map +1 -0
- package/lib/esm/constants.d.ts +3 -0
- package/lib/esm/constants.d.ts.map +1 -0
- package/lib/esm/constants.js +3 -0
- package/lib/esm/constants.js.map +1 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/version.d.ts +2 -0
- package/lib/esm/version.d.ts.map +1 -0
- package/lib/esm/version.js +2 -0
- package/lib/esm/version.js.map +1 -0
- package/lib/esm/web-vitals-plugin.d.ts +4 -0
- package/lib/esm/web-vitals-plugin.d.ts.map +1 -0
- package/lib/esm/web-vitals-plugin.js +90 -0
- package/lib/esm/web-vitals-plugin.js.map +1 -0
- package/lib/scripts/amplitude-min.js +2 -0
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.js.map +1 -0
- package/lib/scripts/amplitude-min.umd.js +1 -0
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/constants.d.ts +3 -0
- package/lib/scripts/constants.d.ts.map +1 -0
- package/lib/scripts/index.d.ts +3 -0
- package/lib/scripts/index.d.ts.map +1 -0
- package/lib/scripts/version.d.ts +2 -0
- package/lib/scripts/version.d.ts.map +1 -0
- package/lib/scripts/web-vitals-plugin.d.ts +4 -0
- package/lib/scripts/web-vitals-plugin.d.ts.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Amplitude Analytics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://amplitude.com" target="_blank" align="center">
|
|
3
|
+
<img src="https://static.amplitude.com/lightning/46c85bfd91905de8047f1ee65c7c93d6fa9ee6ea/static/media/amplitude-logo-with-text.4fb9e463.svg" width="280">
|
|
4
|
+
</a>
|
|
5
|
+
<br />
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# @amplitude/plugin-web-vitals-browser (beta)
|
|
9
|
+
**This plugin is in beta at the moment, naming and interface might change in the future.**
|
|
10
|
+
|
|
11
|
+
Autocaptures [web-vitals](https://www.npmjs.com/package/web-vitals) metrics (INP, LCP, FCP, CLS)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
This package is published on NPM registry and is available to be installed using npm and yarn.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
# npm
|
|
19
|
+
npm install @amplitude/plugin-web-vitals-browser@beta
|
|
20
|
+
|
|
21
|
+
# yarn
|
|
22
|
+
yarn add @amplitude/plugin-web-vitals-browser@beta
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import * as amplitude from '@amplitude/analytics-browser';
|
|
29
|
+
import { webVitalsPlugin } from '@amplitude/plugin-web-vitals-browser';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 2. Instantiate the plugin
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const plugin = webVitalsPlugin();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 3. Install plugin to Amplitude SDK
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
amplitude.add(plugin);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 4. Initialize Amplitude SDK
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
amplitude.init('API_KEY');
|
|
48
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAChD,eAAO,MAAM,qBAAqB,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WEB_VITALS_EVENT_NAME = exports.PLUGIN_NAME = void 0;
|
|
4
|
+
exports.PLUGIN_NAME = 'web-vitals-browser';
|
|
5
|
+
exports.WEB_VITALS_EVENT_NAME = '[Amplitude] Web Vitals';
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,oBAAoB,CAAC;AACnC,QAAA,qBAAqB,GAAG,wBAAwB,CAAC","sourcesContent":["export const PLUGIN_NAME = 'web-vitals-browser';\nexport const WEB_VITALS_EVENT_NAME = '[Amplitude] Web Vitals';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION = exports.webVitalsPlugin = exports.plugin = void 0;
|
|
4
|
+
var web_vitals_plugin_1 = require("./web-vitals-plugin");
|
|
5
|
+
Object.defineProperty(exports, "plugin", { enumerable: true, get: function () { return web_vitals_plugin_1.webVitalsPlugin; } });
|
|
6
|
+
Object.defineProperty(exports, "webVitalsPlugin", { enumerable: true, get: function () { return web_vitals_plugin_1.webVitalsPlugin; } });
|
|
7
|
+
var version_1 = require("./version");
|
|
8
|
+
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAiF;AAAxE,2GAAA,eAAe,OAAU;AAAE,oHAAA,eAAe,OAAA;AACnD,qCAAoC;AAA3B,kGAAA,OAAO,OAAA","sourcesContent":["export { webVitalsPlugin as plugin, webVitalsPlugin } from './web-vitals-plugin';\nexport { VERSION } from './version';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,iBAAiB,CAAC","sourcesContent":["export const VERSION = '0.1.0-SR-1975.0';\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BrowserClient, BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-core';
|
|
2
|
+
export type BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;
|
|
3
|
+
export declare const webVitalsPlugin: () => BrowserEnrichmentPlugin;
|
|
4
|
+
//# sourceMappingURL=web-vitals-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-vitals-plugin.d.ts","sourceRoot":"","sources":["../../src/web-vitals-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAGjB,MAAM,2BAA2B,CAAC;AAInC,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AA2CrF,eAAO,MAAM,eAAe,QAAO,uBAkElC,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webVitalsPlugin = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable no-restricted-globals */
|
|
6
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
var web_vitals_1 = require("web-vitals");
|
|
9
|
+
function getMetricStartTime(metric) {
|
|
10
|
+
var _a;
|
|
11
|
+
/* istanbul ignore next */
|
|
12
|
+
var startTime = ((_a = metric.entries[0]) === null || _a === void 0 ? void 0 : _a.startTime) || 0;
|
|
13
|
+
return performance.timeOrigin + startTime;
|
|
14
|
+
}
|
|
15
|
+
function processMetric(metric) {
|
|
16
|
+
return {
|
|
17
|
+
value: metric.value,
|
|
18
|
+
rating: metric.rating,
|
|
19
|
+
delta: metric.delta,
|
|
20
|
+
navigationType: metric.navigationType,
|
|
21
|
+
id: metric.id,
|
|
22
|
+
timestamp: Math.floor(getMetricStartTime(metric)),
|
|
23
|
+
navigationStart: Math.floor(performance.timeOrigin),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var webVitalsPlugin = function () {
|
|
27
|
+
var visibilityListener = null;
|
|
28
|
+
var globalScope = (0, analytics_core_1.getGlobalScope)();
|
|
29
|
+
var doc = globalScope === null || globalScope === void 0 ? void 0 : globalScope.document;
|
|
30
|
+
var location = globalScope === null || globalScope === void 0 ? void 0 : globalScope.location;
|
|
31
|
+
var setup = function (config, amplitude) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
32
|
+
var locationHref, webVitalsPayload;
|
|
33
|
+
return tslib_1.__generator(this, function (_a) {
|
|
34
|
+
if (doc === undefined) {
|
|
35
|
+
return [2 /*return*/];
|
|
36
|
+
}
|
|
37
|
+
locationHref = (0, analytics_core_1.getDecodeURI)(/* istanbul ignore next */ (location === null || location === void 0 ? void 0 : location.href) || '', config.loggerProvider);
|
|
38
|
+
webVitalsPayload = {
|
|
39
|
+
'[Amplitude] Page Domain': /* istanbul ignore next */ (location === null || location === void 0 ? void 0 : location.hostname) || '',
|
|
40
|
+
'[Amplitude] Page Location': locationHref,
|
|
41
|
+
'[Amplitude] Page Path': (0, analytics_core_1.getDecodeURI)(/* istanbul ignore next */ (location === null || location === void 0 ? void 0 : location.pathname) || '', config.loggerProvider),
|
|
42
|
+
'[Amplitude] Page Title': /* istanbul ignore next */ (typeof document !== 'undefined' && document.title) || '',
|
|
43
|
+
'[Amplitude] Page URL': (0, analytics_core_1.getDecodeURI)(locationHref.split('?')[0], config.loggerProvider),
|
|
44
|
+
};
|
|
45
|
+
(0, web_vitals_1.onLCP)(function (metric) {
|
|
46
|
+
webVitalsPayload['[Amplitude] LCP'] = processMetric(metric);
|
|
47
|
+
});
|
|
48
|
+
(0, web_vitals_1.onFCP)(function (metric) {
|
|
49
|
+
webVitalsPayload['[Amplitude] FCP'] = processMetric(metric);
|
|
50
|
+
});
|
|
51
|
+
(0, web_vitals_1.onINP)(function (metric) {
|
|
52
|
+
webVitalsPayload['[Amplitude] INP'] = processMetric(metric);
|
|
53
|
+
});
|
|
54
|
+
(0, web_vitals_1.onCLS)(function (metric) {
|
|
55
|
+
webVitalsPayload['[Amplitude] CLS'] = processMetric(metric);
|
|
56
|
+
});
|
|
57
|
+
(0, web_vitals_1.onTTFB)(function (metric) {
|
|
58
|
+
webVitalsPayload['[Amplitude] TTFB'] = processMetric(metric);
|
|
59
|
+
});
|
|
60
|
+
visibilityListener = function () {
|
|
61
|
+
if (doc.visibilityState === 'hidden' && visibilityListener) {
|
|
62
|
+
amplitude.track(constants_1.WEB_VITALS_EVENT_NAME, webVitalsPayload);
|
|
63
|
+
doc.removeEventListener('visibilitychange', visibilityListener);
|
|
64
|
+
visibilityListener = null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
doc.addEventListener('visibilitychange', visibilityListener);
|
|
68
|
+
return [2 /*return*/];
|
|
69
|
+
});
|
|
70
|
+
}); };
|
|
71
|
+
var execute = function (event) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
72
|
+
return tslib_1.__generator(this, function (_a) {
|
|
73
|
+
return [2 /*return*/, event];
|
|
74
|
+
});
|
|
75
|
+
}); };
|
|
76
|
+
var teardown = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
return tslib_1.__generator(this, function (_a) {
|
|
78
|
+
if (visibilityListener) {
|
|
79
|
+
/* istanbul ignore next */
|
|
80
|
+
doc === null || doc === void 0 ? void 0 : doc.removeEventListener('visibilitychange', visibilityListener);
|
|
81
|
+
}
|
|
82
|
+
return [2 /*return*/];
|
|
83
|
+
});
|
|
84
|
+
}); };
|
|
85
|
+
return {
|
|
86
|
+
name: constants_1.PLUGIN_NAME,
|
|
87
|
+
type: 'enrichment',
|
|
88
|
+
setup: setup,
|
|
89
|
+
execute: execute,
|
|
90
|
+
teardown: teardown,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
exports.webVitalsPlugin = webVitalsPlugin;
|
|
94
|
+
//# sourceMappingURL=web-vitals-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-vitals-plugin.js","sourceRoot":"","sources":["../../src/web-vitals-plugin.ts"],"names":[],"mappings":";;;;AAAA,0CAA0C;AAC1C,4DAMmC;AACnC,yCAAiE;AACjE,yCAAwE;AA2BxE,SAAS,kBAAkB,CAAC,MAAc;;IACxC,0BAA0B;IAC1B,IAAM,SAAS,GAAG,CAAA,MAAA,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,0CAAE,SAAS,KAAI,CAAC,CAAC;IACpD,OAAO,WAAW,CAAC,UAAU,GAAG,SAAS,CAAC;AAC5C,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,OAAO;QACL,KAAK,EA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,UAAO,KAAK;;YAC9D,sBAAO,KAAK,EAAC;;SACd,CAAC;IAEF,IAAM,QAAQ,GAAG;;YACf,IAAI,kBAAkB,EAAE;gBACtB,0BAA0B;gBAC1B,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,mBAAmB,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;aAClE;;;SACF,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,uBAAW;QACjB,IAAI,EAAE,YAAY;QAClB,KAAK,OAAA;QACL,OAAO,SAAA;QACP,QAAQ,UAAA;KACT,CAAC;AACJ,CAAC,CAAC;AAlEW,QAAA,eAAe,mBAkE1B","sourcesContent":["/* eslint-disable no-restricted-globals */\nimport {\n BrowserClient,\n BrowserConfig,\n EnrichmentPlugin,\n getGlobalScope,\n getDecodeURI,\n} from '@amplitude/analytics-core';\nimport { PLUGIN_NAME, WEB_VITALS_EVENT_NAME } from './constants';\nimport { onLCP, onINP, onCLS, onFCP, onTTFB, Metric } from 'web-vitals';\n\nexport type BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;\n\ntype WebVitalsMetricPayload = {\n value: number;\n rating: Metric['rating'];\n delta: number;\n navigationType: Metric['navigationType'];\n id: string;\n timestamp: number;\n navigationStart: number;\n};\n\ntype WebVitalsEventPayload = {\n '[Amplitude] LCP'?: WebVitalsMetricPayload;\n '[Amplitude] FCP'?: WebVitalsMetricPayload;\n '[Amplitude] INP'?: WebVitalsMetricPayload;\n '[Amplitude] CLS'?: WebVitalsMetricPayload;\n '[Amplitude] TTFB'?: WebVitalsMetricPayload;\n '[Amplitude] Page Domain'?: string;\n '[Amplitude] Page Location'?: string;\n '[Amplitude] Page Path'?: string;\n '[Amplitude] Page Title'?: string;\n '[Amplitude] Page URL'?: string;\n};\n\nfunction getMetricStartTime(metric: Metric) {\n /* istanbul ignore next */\n const startTime = metric.entries[0]?.startTime || 0;\n return performance.timeOrigin + startTime;\n}\n\nfunction processMetric(metric: Metric) {\n return {\n value: metric.value,\n rating: metric.rating,\n delta: metric.delta,\n navigationType: metric.navigationType,\n id: metric.id,\n timestamp: Math.floor(getMetricStartTime(metric)),\n navigationStart: Math.floor(performance.timeOrigin),\n };\n}\n\nexport const webVitalsPlugin = (): BrowserEnrichmentPlugin => {\n let visibilityListener: ((this: Document, ev: Event) => void) | null = null;\n const globalScope = getGlobalScope();\n const doc = globalScope?.document;\n const location = globalScope?.location;\n const setup: BrowserEnrichmentPlugin['setup'] = async (config, amplitude) => {\n if (doc === undefined) {\n return;\n }\n const locationHref = getDecodeURI(/* istanbul ignore next */ location?.href || '', config.loggerProvider);\n const webVitalsPayload: WebVitalsEventPayload = {\n '[Amplitude] Page Domain': /* istanbul ignore next */ location?.hostname || '',\n '[Amplitude] Page Location': locationHref,\n '[Amplitude] Page Path': getDecodeURI(/* istanbul ignore next */ location?.pathname || '', config.loggerProvider),\n '[Amplitude] Page Title': /* istanbul ignore next */ (typeof document !== 'undefined' && document.title) || '',\n '[Amplitude] Page URL': getDecodeURI(locationHref.split('?')[0], config.loggerProvider),\n };\n\n onLCP((metric) => {\n webVitalsPayload['[Amplitude] LCP'] = processMetric(metric);\n });\n\n onFCP((metric) => {\n webVitalsPayload['[Amplitude] FCP'] = processMetric(metric);\n });\n\n onINP((metric) => {\n webVitalsPayload['[Amplitude] INP'] = processMetric(metric);\n });\n\n onCLS((metric) => {\n webVitalsPayload['[Amplitude] CLS'] = processMetric(metric);\n });\n\n onTTFB((metric) => {\n webVitalsPayload['[Amplitude] TTFB'] = processMetric(metric);\n });\n\n visibilityListener = () => {\n if (doc.visibilityState === 'hidden' && visibilityListener) {\n amplitude.track(WEB_VITALS_EVENT_NAME, webVitalsPayload);\n doc.removeEventListener('visibilitychange', visibilityListener);\n visibilityListener = null;\n }\n };\n doc.addEventListener('visibilitychange', visibilityListener);\n };\n\n const execute: BrowserEnrichmentPlugin['execute'] = async (event) => {\n return event;\n };\n\n const teardown = async () => {\n if (visibilityListener) {\n /* istanbul ignore next */\n doc?.removeEventListener('visibilitychange', visibilityListener);\n }\n };\n\n return {\n name: PLUGIN_NAME,\n type: 'enrichment',\n setup,\n execute,\n teardown,\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAChD,eAAO,MAAM,qBAAqB,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,WAAW,GAAG,oBAAoB,CAAC;AAChD,MAAM,CAAC,IAAM,qBAAqB,GAAG,wBAAwB,CAAC","sourcesContent":["export const PLUGIN_NAME = 'web-vitals-browser';\nexport const WEB_VITALS_EVENT_NAME = '[Amplitude] Web Vitals';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { webVitalsPlugin as plugin, webVitalsPlugin } from './web-vitals-plugin';\nexport { VERSION } from './version';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,iBAAiB,CAAC","sourcesContent":["export const VERSION = '0.1.0-SR-1975.0';\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BrowserClient, BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-core';
|
|
2
|
+
export type BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;
|
|
3
|
+
export declare const webVitalsPlugin: () => BrowserEnrichmentPlugin;
|
|
4
|
+
//# sourceMappingURL=web-vitals-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-vitals-plugin.d.ts","sourceRoot":"","sources":["../../src/web-vitals-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAGjB,MAAM,2BAA2B,CAAC;AAInC,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AA2CrF,eAAO,MAAM,eAAe,QAAO,uBAkElC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
/* eslint-disable no-restricted-globals */
|
|
3
|
+
import { getGlobalScope, getDecodeURI, } from '@amplitude/analytics-core';
|
|
4
|
+
import { PLUGIN_NAME, WEB_VITALS_EVENT_NAME } from './constants';
|
|
5
|
+
import { onLCP, onINP, onCLS, onFCP, onTTFB } from 'web-vitals';
|
|
6
|
+
function getMetricStartTime(metric) {
|
|
7
|
+
var _a;
|
|
8
|
+
/* istanbul ignore next */
|
|
9
|
+
var startTime = ((_a = metric.entries[0]) === null || _a === void 0 ? void 0 : _a.startTime) || 0;
|
|
10
|
+
return performance.timeOrigin + startTime;
|
|
11
|
+
}
|
|
12
|
+
function processMetric(metric) {
|
|
13
|
+
return {
|
|
14
|
+
value: metric.value,
|
|
15
|
+
rating: metric.rating,
|
|
16
|
+
delta: metric.delta,
|
|
17
|
+
navigationType: metric.navigationType,
|
|
18
|
+
id: metric.id,
|
|
19
|
+
timestamp: Math.floor(getMetricStartTime(metric)),
|
|
20
|
+
navigationStart: Math.floor(performance.timeOrigin),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export var webVitalsPlugin = function () {
|
|
24
|
+
var visibilityListener = null;
|
|
25
|
+
var globalScope = getGlobalScope();
|
|
26
|
+
var doc = globalScope === null || globalScope === void 0 ? void 0 : globalScope.document;
|
|
27
|
+
var location = globalScope === null || globalScope === void 0 ? void 0 : globalScope.location;
|
|
28
|
+
var setup = function (config, amplitude) { return __awaiter(void 0, void 0, void 0, function () {
|
|
29
|
+
var locationHref, webVitalsPayload;
|
|
30
|
+
return __generator(this, function (_a) {
|
|
31
|
+
if (doc === undefined) {
|
|
32
|
+
return [2 /*return*/];
|
|
33
|
+
}
|
|
34
|
+
locationHref = getDecodeURI(/* istanbul ignore next */ (location === null || location === void 0 ? void 0 : location.href) || '', config.loggerProvider);
|
|
35
|
+
webVitalsPayload = {
|
|
36
|
+
'[Amplitude] Page Domain': /* istanbul ignore next */ (location === null || location === void 0 ? void 0 : location.hostname) || '',
|
|
37
|
+
'[Amplitude] Page Location': locationHref,
|
|
38
|
+
'[Amplitude] Page Path': getDecodeURI(/* istanbul ignore next */ (location === null || location === void 0 ? void 0 : location.pathname) || '', config.loggerProvider),
|
|
39
|
+
'[Amplitude] Page Title': /* istanbul ignore next */ (typeof document !== 'undefined' && document.title) || '',
|
|
40
|
+
'[Amplitude] Page URL': getDecodeURI(locationHref.split('?')[0], config.loggerProvider),
|
|
41
|
+
};
|
|
42
|
+
onLCP(function (metric) {
|
|
43
|
+
webVitalsPayload['[Amplitude] LCP'] = processMetric(metric);
|
|
44
|
+
});
|
|
45
|
+
onFCP(function (metric) {
|
|
46
|
+
webVitalsPayload['[Amplitude] FCP'] = processMetric(metric);
|
|
47
|
+
});
|
|
48
|
+
onINP(function (metric) {
|
|
49
|
+
webVitalsPayload['[Amplitude] INP'] = processMetric(metric);
|
|
50
|
+
});
|
|
51
|
+
onCLS(function (metric) {
|
|
52
|
+
webVitalsPayload['[Amplitude] CLS'] = processMetric(metric);
|
|
53
|
+
});
|
|
54
|
+
onTTFB(function (metric) {
|
|
55
|
+
webVitalsPayload['[Amplitude] TTFB'] = processMetric(metric);
|
|
56
|
+
});
|
|
57
|
+
visibilityListener = function () {
|
|
58
|
+
if (doc.visibilityState === 'hidden' && visibilityListener) {
|
|
59
|
+
amplitude.track(WEB_VITALS_EVENT_NAME, webVitalsPayload);
|
|
60
|
+
doc.removeEventListener('visibilitychange', visibilityListener);
|
|
61
|
+
visibilityListener = null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
doc.addEventListener('visibilitychange', visibilityListener);
|
|
65
|
+
return [2 /*return*/];
|
|
66
|
+
});
|
|
67
|
+
}); };
|
|
68
|
+
var execute = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
return [2 /*return*/, event];
|
|
71
|
+
});
|
|
72
|
+
}); };
|
|
73
|
+
var teardown = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
if (visibilityListener) {
|
|
76
|
+
/* istanbul ignore next */
|
|
77
|
+
doc === null || doc === void 0 ? void 0 : doc.removeEventListener('visibilitychange', visibilityListener);
|
|
78
|
+
}
|
|
79
|
+
return [2 /*return*/];
|
|
80
|
+
});
|
|
81
|
+
}); };
|
|
82
|
+
return {
|
|
83
|
+
name: PLUGIN_NAME,
|
|
84
|
+
type: 'enrichment',
|
|
85
|
+
setup: setup,
|
|
86
|
+
execute: execute,
|
|
87
|
+
teardown: teardown,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+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CAAC,iBAAiB,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,UAAC,MAAM;gBACZ,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;YAC/D,CAAC,CAAC,CAAC;YAEH,kBAAkB,GAAG;gBACnB,IAAI,GAAG,CAAC,eAAe,KAAK,QAAQ,IAAI,kBAAkB,EAAE;oBAC1D,SAAS,CAAC,KAAK,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;oBACzD,GAAG,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;oBAChE,kBAAkB,GAAG,IAAI,CAAC;iBAC3B;YACH,CAAC,CAAC;YACF,GAAG,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;;;SAC9D,CAAC;IAEF,IAAM,OAAO,GAAuC,UAAO,KAAK;;YAC9D,sBAAO,KAAK,EAAC;;SACd,CAAC;IAEF,IAAM,QAAQ,GAAG;;YACf,IAAI,kBAAkB,EAAE;gBACtB,0BAA0B;gBAC1B,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,mBAAmB,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;aAClE;;;SACF,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,YAAY;QAClB,KAAK,OAAA;QACL,OAAO,SAAA;QACP,QAAQ,UAAA;KACT,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\nimport {\n BrowserClient,\n BrowserConfig,\n EnrichmentPlugin,\n getGlobalScope,\n getDecodeURI,\n} from '@amplitude/analytics-core';\nimport { PLUGIN_NAME, WEB_VITALS_EVENT_NAME } from './constants';\nimport { onLCP, onINP, onCLS, onFCP, onTTFB, Metric } from 'web-vitals';\n\nexport type BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;\n\ntype WebVitalsMetricPayload = {\n value: number;\n rating: Metric['rating'];\n delta: number;\n navigationType: Metric['navigationType'];\n id: string;\n timestamp: number;\n navigationStart: number;\n};\n\ntype WebVitalsEventPayload = {\n '[Amplitude] LCP'?: WebVitalsMetricPayload;\n '[Amplitude] FCP'?: WebVitalsMetricPayload;\n '[Amplitude] INP'?: WebVitalsMetricPayload;\n '[Amplitude] CLS'?: WebVitalsMetricPayload;\n '[Amplitude] TTFB'?: WebVitalsMetricPayload;\n '[Amplitude] Page Domain'?: string;\n '[Amplitude] Page Location'?: string;\n '[Amplitude] Page Path'?: string;\n '[Amplitude] Page Title'?: string;\n '[Amplitude] Page URL'?: string;\n};\n\nfunction getMetricStartTime(metric: Metric) {\n /* istanbul ignore next */\n const startTime = metric.entries[0]?.startTime || 0;\n return performance.timeOrigin + startTime;\n}\n\nfunction processMetric(metric: Metric) {\n return {\n value: metric.value,\n rating: metric.rating,\n delta: metric.delta,\n navigationType: metric.navigationType,\n id: metric.id,\n timestamp: Math.floor(getMetricStartTime(metric)),\n navigationStart: Math.floor(performance.timeOrigin),\n };\n}\n\nexport const webVitalsPlugin = (): BrowserEnrichmentPlugin => {\n let visibilityListener: ((this: Document, ev: Event) => void) | null = null;\n const globalScope = getGlobalScope();\n const doc = globalScope?.document;\n const location = globalScope?.location;\n const setup: BrowserEnrichmentPlugin['setup'] = async (config, amplitude) => {\n if (doc === undefined) {\n return;\n }\n const locationHref = getDecodeURI(/* istanbul ignore next */ location?.href || '', config.loggerProvider);\n const webVitalsPayload: WebVitalsEventPayload = {\n '[Amplitude] Page Domain': /* istanbul ignore next */ location?.hostname || '',\n '[Amplitude] Page Location': locationHref,\n '[Amplitude] Page Path': getDecodeURI(/* istanbul ignore next */ location?.pathname || '', config.loggerProvider),\n '[Amplitude] Page Title': /* istanbul ignore next */ (typeof document !== 'undefined' && document.title) || '',\n '[Amplitude] Page URL': getDecodeURI(locationHref.split('?')[0], config.loggerProvider),\n };\n\n onLCP((metric) => {\n webVitalsPayload['[Amplitude] LCP'] = processMetric(metric);\n });\n\n onFCP((metric) => {\n webVitalsPayload['[Amplitude] FCP'] = processMetric(metric);\n });\n\n onINP((metric) => {\n webVitalsPayload['[Amplitude] INP'] = processMetric(metric);\n });\n\n onCLS((metric) => {\n webVitalsPayload['[Amplitude] CLS'] = processMetric(metric);\n });\n\n onTTFB((metric) => {\n webVitalsPayload['[Amplitude] TTFB'] = processMetric(metric);\n });\n\n visibilityListener = () => {\n if (doc.visibilityState === 'hidden' && visibilityListener) {\n amplitude.track(WEB_VITALS_EVENT_NAME, webVitalsPayload);\n doc.removeEventListener('visibilitychange', visibilityListener);\n visibilityListener = null;\n }\n };\n doc.addEventListener('visibilitychange', visibilityListener);\n };\n\n const execute: BrowserEnrichmentPlugin['execute'] = async (event) => {\n return event;\n };\n\n const teardown = async () => {\n if (visibilityListener) {\n /* istanbul ignore next */\n doc?.removeEventListener('visibilitychange', visibilityListener);\n }\n };\n\n return {\n name: PLUGIN_NAME,\n type: 'enrichment',\n setup,\n execute,\n teardown,\n };\n};\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var amplitudeWebVitalsPlugin=function(e){"use strict";function t(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{l(i.next(e))}catch(e){o(e)}}function s(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}l((i=i.apply(e,t||[])).next())})}function n(e,t){var n,i,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(r=o.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var i=function(e,t){var n=e;try{n=decodeURI(e)}catch(e){null==t||t.error("Malformed URI sequence: ",e)}return n};let r=-1;const o=e=>{addEventListener("pageshow",t=>{t.persisted&&(r=t.timeStamp,e(t))},!0)},a=(e,t,n,i)=>{let r,o;return a=>{t.value>=0&&(a||i)&&(o=t.value-(r??0),(o||void 0===r)&&(r=t.value,t.delta=o,t.rating=((e,t)=>e>t[1]?"poor":e>t[0]?"needs-improvement":"good")(t.value,n),e(t)))}},s=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()))},l=()=>{const e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},u=()=>{const e=l();return e?.activationStart??0},c=(e,t=-1)=>{const n=l();let i="navigate";return r>=0?i="back-forward-cache":n&&(document.prerendering||u()>0?i="prerender":document.wasDiscarded?i="restore":n.type&&(i=n.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:i}},d=new WeakMap;function p(e,t){return d.get(e)||d.set(e,new t),d.get(e)}class f{t;i=0;o=[];h(e){if(e.hadRecentInput)return;const t=this.o[0],n=this.o.at(-1);this.i&&t&&n&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(this.i+=e.value,this.o.push(e)):(this.i=e.value,this.o=[e]),this.t?.(e)}}const h=(e,t,n={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){const i=new PerformanceObserver(e=>{Promise.resolve().then(()=>{t(e.getEntries())})});return i.observe({type:e,buffered:!0,...n}),i}}catch{}},v=e=>{let t=!1;return()=>{t||(e(),t=!0)}};let m=-1;const g=new Set,y=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,b=e=>{if("hidden"===document.visibilityState){if("visibilitychange"===e.type)for(const e of g)e();isFinite(m)||(m="visibilitychange"===e.type?e.timeStamp:0,removeEventListener("prerenderingchange",b,!0))}},T=()=>{if(m<0){const e=u(),t=document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter(t=>"hidden"===t.name&&t.startTime>e)[0]?.startTime;m=t??y(),addEventListener("visibilitychange",b,!0),addEventListener("prerenderingchange",b,!0),o(()=>{setTimeout(()=>{m=y()})})}return{get firstHiddenTime(){return m},onHidden(e){g.add(e)}}},P=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),!0):e()},w=[1800,3e3],A=(e,t={})=>{P(()=>{const n=T();let i,r=c("FCP");const l=h("paint",e=>{for(const t of e)"first-contentful-paint"===t.name&&(l.disconnect(),t.startTime<n.firstHiddenTime&&(r.value=Math.max(t.startTime-u(),0),r.entries.push(t),i(!0)))});l&&(i=a(e,r,w,t.reportAllChanges),o(n=>{r=c("FCP"),i=a(e,r,w,t.reportAllChanges),s(()=>{r.value=performance.now()-n.timeStamp,i(!0)})}))})},C=[.1,.25];let S=0,E=1/0,L=0;const I=e=>{for(const t of e)t.interactionId&&(E=Math.min(E,t.interactionId),L=Math.max(L,t.interactionId),S=L?(L-E)/7+1:0)};let M;const k=()=>M?S:performance.interactionCount??0;let x=0;class F{u=[];l=new Map;m;p;v(){x=k(),this.u.length=0,this.l.clear()}L(){const e=Math.min(this.u.length-1,Math.floor((k()-x)/50));return this.u[e]}h(e){if(this.m?.(e),!e.interactionId&&"first-input"!==e.entryType)return;const t=this.u.at(-1);let n=this.l.get(e.interactionId);if(n||this.u.length<10||e.duration>t.P){if(n?e.duration>n.P?(n.entries=[e],n.P=e.duration):e.duration===n.P&&e.startTime===n.entries[0].startTime&&n.entries.push(e):(n={id:e.interactionId,entries:[e],P:e.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((e,t)=>t.P-e.P),this.u.length>10){const e=this.u.splice(10);for(const t of e)this.l.delete(t.id)}this.p?.(n)}}}const R=e=>{const t=globalThis.requestIdleCallback||setTimeout;"hidden"===document.visibilityState?e():(e=v(e),addEventListener("visibilitychange",e,{once:!0,capture:!0}),t(()=>{e(),removeEventListener("visibilitychange",e,{capture:!0})}))},O=[200,500],H=(e,t={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const n=T();P(()=>{"interactionCount"in performance||M||(M=h("event",I,{type:"event",buffered:!0,durationThreshold:0}));let i,r=c("INP");const s=p(t,F),l=e=>{R(()=>{for(const t of e)s.h(t);const t=s.L();t&&t.P!==r.value&&(r.value=t.P,r.entries=t.entries,i())})},u=h("event",l,{durationThreshold:t.durationThreshold??40});i=a(e,r,O,t.reportAllChanges),u&&(u.observe({type:"first-input",buffered:!0}),n.onHidden(()=>{l(u.takeRecords()),i(!0)}),o(()=>{s.v(),r=c("INP"),i=a(e,r,O,t.reportAllChanges)}))})};class B{m;h(e){this.m?.(e)}}const q=[2500,4e3],N=[800,1800],V=e=>{document.prerendering?P(()=>V(e)):"complete"!==document.readyState?addEventListener("load",()=>V(e),!0):setTimeout(e)};function j(e){var t,n=(null===(t=e.entries[0])||void 0===t?void 0:t.startTime)||0;return performance.timeOrigin+n}function D(e){return{value:e.value,rating:e.rating,delta:e.delta,navigationType:e.navigationType,id:e.id,timestamp:Math.floor(j(e)),navigationStart:Math.floor(performance.timeOrigin)}}var U=function(){var e,r=null,d=(e="ampIntegrationContext","undefined"!=typeof globalThis&&void 0!==globalThis[e]?globalThis[e]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0),m=null==d?void 0:d.document,g=null==d?void 0:d.location;return{name:"web-vitals-browser",type:"enrichment",setup:function(e,d){return t(void 0,void 0,void 0,function(){var t,y;return n(this,function(n){return void 0===m||(t=i((null==g?void 0:g.href)||"",e.loggerProvider),y={"[Amplitude] Page Domain":(null==g?void 0:g.hostname)||"","[Amplitude] Page Location":t,"[Amplitude] Page Path":i((null==g?void 0:g.pathname)||"",e.loggerProvider),"[Amplitude] Page Title":"undefined"!=typeof document&&document.title||"","[Amplitude] Page URL":i(t.split("?")[0],e.loggerProvider)},((e,t={})=>{P(()=>{const n=T();let i,r=c("LCP");const l=p(t,B),d=e=>{t.reportAllChanges||(e=e.slice(-1));for(const t of e)l.h(t),t.startTime<n.firstHiddenTime&&(r.value=Math.max(t.startTime-u(),0),r.entries=[t],i())},f=h("largest-contentful-paint",d);if(f){i=a(e,r,q,t.reportAllChanges);const n=v(()=>{d(f.takeRecords()),f.disconnect(),i(!0)}),l=e=>{e.isTrusted&&(R(n),removeEventListener(e.type,l,{capture:!0}))};for(const e of["keydown","click","visibilitychange"])addEventListener(e,l,{capture:!0});o(n=>{r=c("LCP"),i=a(e,r,q,t.reportAllChanges),s(()=>{r.value=performance.now()-n.timeStamp,i(!0)})})}})})(function(e){y["[Amplitude] LCP"]=D(e)}),A(function(e){y["[Amplitude] FCP"]=D(e)}),H(function(e){y["[Amplitude] INP"]=D(e)}),((e,t={})=>{const n=T();A(v(()=>{let i,r=c("CLS",0);const l=p(t,f),u=e=>{for(const t of e)l.h(t);l.i>r.value&&(r.value=l.i,r.entries=l.o,i())},d=h("layout-shift",u);d&&(i=a(e,r,C,t.reportAllChanges),n.onHidden(()=>{u(d.takeRecords()),i(!0)}),o(()=>{l.i=0,r=c("CLS",0),i=a(e,r,C,t.reportAllChanges),s(()=>i())}),setTimeout(i))}))})(function(e){y["[Amplitude] CLS"]=D(e)}),((e,t={})=>{let n=c("TTFB"),i=a(e,n,N,t.reportAllChanges);V(()=>{const r=l();r&&(n.value=Math.max(r.responseStart-u(),0),n.entries=[r],i(!0),o(()=>{n=c("TTFB",0),i=a(e,n,N,t.reportAllChanges),i(!0)}))})})(function(e){y["[Amplitude] TTFB"]=D(e)}),r=function(){"hidden"===m.visibilityState&&r&&(d.track("[Amplitude] Web Vitals",y),m.removeEventListener("visibilitychange",r),r=null)},m.addEventListener("visibilitychange",r)),[2]})})},execute:function(e){return t(void 0,void 0,void 0,function(){return n(this,function(t){return[2,e]})})},teardown:function(){return t(void 0,void 0,void 0,function(){return n(this,function(e){return r&&(null==m||m.removeEventListener("visibilitychange",r)),[2]})})}}};return e.VERSION="0.1.0-SR-1975.0",e.plugin=U,e.webVitalsPlugin=U,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
2
|
+
//# sourceMappingURL=amplitude-min.js.map
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amplitude-min.js","sources":["../../../../node_modules/tslib/tslib.es6.js","../../../analytics-core/lib/esm/global-scope.js","../../../analytics-core/lib/esm/utils/url-utils.js","../../../../node_modules/web-vitals/dist/web-vitals.js","../../../src/web-vitals-plugin.ts","../../../src/constants.ts","../../../src/version.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol, Iterator */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\r\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = Object.create((typeof AsyncIterator === \"function\" ? AsyncIterator : Object).prototype), verb(\"next\"), verb(\"throw\"), verb(\"return\", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }\r\n function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nvar ownKeys = function(o) {\r\n ownKeys = Object.getOwnPropertyNames || function (o) {\r\n var ar = [];\r\n for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;\r\n return ar;\r\n };\r\n return ownKeys(o);\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== \"default\") __createBinding(result, mod, k[i]);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose, inner;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n if (async) inner = dispose;\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n var r, s = 0;\r\n function next() {\r\n while (r = env.stack.pop()) {\r\n try {\r\n if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);\r\n if (r.dispose) {\r\n var result = r.dispose.call(r.value);\r\n if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n else s |= 1;\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport function __rewriteRelativeImportExtension(path, preserveJsx) {\r\n if (typeof path === \"string\" && /^\\.\\.?\\//.test(path)) {\r\n return path.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {\r\n return tsx ? preserveJsx ? \".jsx\" : \".js\" : d && (!ext || !cm) ? m : (d + ext + \".\" + cm.toLowerCase() + \"js\");\r\n });\r\n }\r\n return path;\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __esDecorate: __esDecorate,\r\n __runInitializers: __runInitializers,\r\n __propKey: __propKey,\r\n __setFunctionName: __setFunctionName,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n __rewriteRelativeImportExtension: __rewriteRelativeImportExtension,\r\n};\r\n","/* eslint-disable no-restricted-globals */\n/* Only file allowed to access to globalThis, window, self */\nexport var getGlobalScope = function () {\n // This should only be used for integrations with Amplitude that are not running in a browser environment\n // We need to specify the name of the global variable as a string to prevent it from being minified\n var ampIntegrationContextName = 'ampIntegrationContext';\n if (typeof globalThis !== 'undefined' && typeof globalThis[ampIntegrationContextName] !== 'undefined') {\n return globalThis[ampIntegrationContextName];\n }\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n return undefined;\n};\n//# sourceMappingURL=global-scope.js.map","/**\n * Checks if a given URL matches any pattern in an allowlist of URLs or regex patterns.\n * @param url - The URL to check\n * @param allowlist - Array of allowed URLs (strings) or regex patterns\n * @returns true if the URL matches any pattern in the allowlist, false otherwise\n */\nexport var isUrlMatchAllowlist = function (url, allowlist) {\n if (!allowlist || !allowlist.length) {\n return true;\n }\n return allowlist.some(function (allowedUrl) {\n if (typeof allowedUrl === 'string') {\n return url === allowedUrl;\n }\n return url.match(allowedUrl);\n });\n};\nexport var getDecodeURI = function (locationStr, loggerProvider) {\n var decodedLocationStr = locationStr;\n try {\n decodedLocationStr = decodeURI(locationStr);\n }\n catch (e) {\n /* istanbul ignore next */\n loggerProvider === null || loggerProvider === void 0 ? void 0 : loggerProvider.error('Malformed URI sequence: ', e);\n }\n return decodedLocationStr;\n};\n//# sourceMappingURL=url-utils.js.map","let e=-1;const t=t=>{addEventListener(\"pageshow\",(n=>{n.persisted&&(e=n.timeStamp,t(n))}),!0)},n=(e,t,n,i)=>{let s,o;return r=>{t.value>=0&&(r||i)&&(o=t.value-(s??0),(o||void 0===s)&&(s=t.value,t.delta=o,t.rating=((e,t)=>e>t[1]?\"poor\":e>t[0]?\"needs-improvement\":\"good\")(t.value,n),e(t)))}},i=e=>{requestAnimationFrame((()=>requestAnimationFrame((()=>e()))))},s=()=>{const e=performance.getEntriesByType(\"navigation\")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},o=()=>{const e=s();return e?.activationStart??0},r=(t,n=-1)=>{const i=s();let r=\"navigate\";e>=0?r=\"back-forward-cache\":i&&(document.prerendering||o()>0?r=\"prerender\":document.wasDiscarded?r=\"restore\":i.type&&(r=i.type.replace(/_/g,\"-\")));return{name:t,value:n,rating:\"good\",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:r}},c=new WeakMap;function a(e,t){return c.get(e)||c.set(e,new t),c.get(e)}class d{t;i=0;o=[];h(e){if(e.hadRecentInput)return;const t=this.o[0],n=this.o.at(-1);this.i&&t&&n&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(this.i+=e.value,this.o.push(e)):(this.i=e.value,this.o=[e]),this.t?.(e)}}const h=(e,t,n={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){const i=new PerformanceObserver((e=>{Promise.resolve().then((()=>{t(e.getEntries())}))}));return i.observe({type:e,buffered:!0,...n}),i}}catch{}},f=e=>{let t=!1;return()=>{t||(e(),t=!0)}};let u=-1;const l=new Set,m=()=>\"hidden\"!==document.visibilityState||document.prerendering?1/0:0,p=e=>{if(\"hidden\"===document.visibilityState){if(\"visibilitychange\"===e.type)for(const e of l)e();isFinite(u)||(u=\"visibilitychange\"===e.type?e.timeStamp:0,removeEventListener(\"prerenderingchange\",p,!0))}},v=()=>{if(u<0){const e=o(),n=document.prerendering?void 0:globalThis.performance.getEntriesByType(\"visibility-state\").filter((t=>\"hidden\"===t.name&&t.startTime>e))[0]?.startTime;u=n??m(),addEventListener(\"visibilitychange\",p,!0),addEventListener(\"prerenderingchange\",p,!0),t((()=>{setTimeout((()=>{u=m()}))}))}return{get firstHiddenTime(){return u},onHidden(e){l.add(e)}}},g=e=>{document.prerendering?addEventListener(\"prerenderingchange\",(()=>e()),!0):e()},y=[1800,3e3],E=(e,s={})=>{g((()=>{const c=v();let a,d=r(\"FCP\");const f=h(\"paint\",(e=>{for(const t of e)\"first-contentful-paint\"===t.name&&(f.disconnect(),t.startTime<c.firstHiddenTime&&(d.value=Math.max(t.startTime-o(),0),d.entries.push(t),a(!0)))}));f&&(a=n(e,d,y,s.reportAllChanges),t((t=>{d=r(\"FCP\"),a=n(e,d,y,s.reportAllChanges),i((()=>{d.value=performance.now()-t.timeStamp,a(!0)}))})))}))},b=[.1,.25],L=(e,s={})=>{const o=v();E(f((()=>{let c,f=r(\"CLS\",0);const u=a(s,d),l=e=>{for(const t of e)u.h(t);u.i>f.value&&(f.value=u.i,f.entries=u.o,c())},m=h(\"layout-shift\",l);m&&(c=n(e,f,b,s.reportAllChanges),o.onHidden((()=>{l(m.takeRecords()),c(!0)})),t((()=>{u.i=0,f=r(\"CLS\",0),c=n(e,f,b,s.reportAllChanges),i((()=>c()))})),setTimeout(c))})))};let P=0,T=1/0,_=0;const M=e=>{for(const t of e)t.interactionId&&(T=Math.min(T,t.interactionId),_=Math.max(_,t.interactionId),P=_?(_-T)/7+1:0)};let w;const C=()=>w?P:performance.interactionCount??0,I=()=>{\"interactionCount\"in performance||w||(w=h(\"event\",M,{type:\"event\",buffered:!0,durationThreshold:0}))};let F=0;class k{u=[];l=new Map;m;p;v(){F=C(),this.u.length=0,this.l.clear()}L(){const e=Math.min(this.u.length-1,Math.floor((C()-F)/50));return this.u[e]}h(e){if(this.m?.(e),!e.interactionId&&\"first-input\"!==e.entryType)return;const t=this.u.at(-1);let n=this.l.get(e.interactionId);if(n||this.u.length<10||e.duration>t.P){if(n?e.duration>n.P?(n.entries=[e],n.P=e.duration):e.duration===n.P&&e.startTime===n.entries[0].startTime&&n.entries.push(e):(n={id:e.interactionId,entries:[e],P:e.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort(((e,t)=>t.P-e.P)),this.u.length>10){const e=this.u.splice(10);for(const t of e)this.l.delete(t.id)}this.p?.(n)}}}const A=e=>{const t=globalThis.requestIdleCallback||setTimeout;\"hidden\"===document.visibilityState?e():(e=f(e),addEventListener(\"visibilitychange\",e,{once:!0,capture:!0}),t((()=>{e(),removeEventListener(\"visibilitychange\",e,{capture:!0})})))},B=[200,500],S=(e,i={})=>{if(!globalThis.PerformanceEventTiming||!(\"interactionId\"in PerformanceEventTiming.prototype))return;const s=v();g((()=>{I();let o,c=r(\"INP\");const d=a(i,k),f=e=>{A((()=>{for(const t of e)d.h(t);const t=d.L();t&&t.P!==c.value&&(c.value=t.P,c.entries=t.entries,o())}))},u=h(\"event\",f,{durationThreshold:i.durationThreshold??40});o=n(e,c,B,i.reportAllChanges),u&&(u.observe({type:\"first-input\",buffered:!0}),s.onHidden((()=>{f(u.takeRecords()),o(!0)})),t((()=>{d.v(),c=r(\"INP\"),o=n(e,c,B,i.reportAllChanges)})))}))};class N{m;h(e){this.m?.(e)}}const q=[2500,4e3],x=(e,s={})=>{g((()=>{const c=v();let d,u=r(\"LCP\");const l=a(s,N),m=e=>{s.reportAllChanges||(e=e.slice(-1));for(const t of e)l.h(t),t.startTime<c.firstHiddenTime&&(u.value=Math.max(t.startTime-o(),0),u.entries=[t],d())},p=h(\"largest-contentful-paint\",m);if(p){d=n(e,u,q,s.reportAllChanges);const o=f((()=>{m(p.takeRecords()),p.disconnect(),d(!0)})),c=e=>{e.isTrusted&&(A(o),removeEventListener(e.type,c,{capture:!0}))};for(const e of[\"keydown\",\"click\",\"visibilitychange\"])addEventListener(e,c,{capture:!0});t((t=>{u=r(\"LCP\"),d=n(e,u,q,s.reportAllChanges),i((()=>{u.value=performance.now()-t.timeStamp,d(!0)}))}))}}))},H=[800,1800],O=e=>{document.prerendering?g((()=>O(e))):\"complete\"!==document.readyState?addEventListener(\"load\",(()=>O(e)),!0):setTimeout(e)},$=(e,i={})=>{let c=r(\"TTFB\"),a=n(e,c,H,i.reportAllChanges);O((()=>{const d=s();d&&(c.value=Math.max(d.responseStart-o(),0),c.entries=[d],a(!0),t((()=>{c=r(\"TTFB\",0),a=n(e,c,H,i.reportAllChanges),a(!0)})))}))};export{b as CLSThresholds,y as FCPThresholds,B as INPThresholds,q as LCPThresholds,H as TTFBThresholds,L as onCLS,E as onFCP,S as onINP,x as onLCP,$ as onTTFB};\n","/* eslint-disable no-restricted-globals */\nimport {\n BrowserClient,\n BrowserConfig,\n EnrichmentPlugin,\n getGlobalScope,\n getDecodeURI,\n} from '@amplitude/analytics-core';\nimport { PLUGIN_NAME, WEB_VITALS_EVENT_NAME } from './constants';\nimport { onLCP, onINP, onCLS, onFCP, onTTFB, Metric } from 'web-vitals';\n\nexport type BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;\n\ntype WebVitalsMetricPayload = {\n value: number;\n rating: Metric['rating'];\n delta: number;\n navigationType: Metric['navigationType'];\n id: string;\n timestamp: number;\n navigationStart: number;\n};\n\ntype WebVitalsEventPayload = {\n '[Amplitude] LCP'?: WebVitalsMetricPayload;\n '[Amplitude] FCP'?: WebVitalsMetricPayload;\n '[Amplitude] INP'?: WebVitalsMetricPayload;\n '[Amplitude] CLS'?: WebVitalsMetricPayload;\n '[Amplitude] TTFB'?: WebVitalsMetricPayload;\n '[Amplitude] Page Domain'?: string;\n '[Amplitude] Page Location'?: string;\n '[Amplitude] Page Path'?: string;\n '[Amplitude] Page Title'?: string;\n '[Amplitude] Page URL'?: string;\n};\n\nfunction getMetricStartTime(metric: Metric) {\n /* istanbul ignore next */\n const startTime = metric.entries[0]?.startTime || 0;\n return performance.timeOrigin + startTime;\n}\n\nfunction processMetric(metric: Metric) {\n return {\n value: metric.value,\n rating: metric.rating,\n delta: metric.delta,\n navigationType: metric.navigationType,\n id: metric.id,\n timestamp: Math.floor(getMetricStartTime(metric)),\n navigationStart: Math.floor(performance.timeOrigin),\n };\n}\n\nexport const webVitalsPlugin = (): BrowserEnrichmentPlugin => {\n let visibilityListener: ((this: Document, ev: Event) => void) | null = null;\n const globalScope = getGlobalScope();\n const doc = globalScope?.document;\n const location = globalScope?.location;\n const setup: BrowserEnrichmentPlugin['setup'] = async (config, amplitude) => {\n if (doc === undefined) {\n return;\n }\n const locationHref = getDecodeURI(/* istanbul ignore next */ location?.href || '', config.loggerProvider);\n const webVitalsPayload: WebVitalsEventPayload = {\n '[Amplitude] Page Domain': /* istanbul ignore next */ location?.hostname || '',\n '[Amplitude] Page Location': locationHref,\n '[Amplitude] Page Path': getDecodeURI(/* istanbul ignore next */ location?.pathname || '', config.loggerProvider),\n '[Amplitude] Page Title': /* istanbul ignore next */ (typeof document !== 'undefined' && document.title) || '',\n '[Amplitude] Page URL': getDecodeURI(locationHref.split('?')[0], config.loggerProvider),\n };\n\n onLCP((metric) => {\n webVitalsPayload['[Amplitude] LCP'] = processMetric(metric);\n });\n\n onFCP((metric) => {\n webVitalsPayload['[Amplitude] FCP'] = processMetric(metric);\n });\n\n onINP((metric) => {\n webVitalsPayload['[Amplitude] INP'] = processMetric(metric);\n });\n\n onCLS((metric) => {\n webVitalsPayload['[Amplitude] CLS'] = processMetric(metric);\n });\n\n onTTFB((metric) => {\n webVitalsPayload['[Amplitude] TTFB'] = processMetric(metric);\n });\n\n visibilityListener = () => {\n if (doc.visibilityState === 'hidden' && visibilityListener) {\n amplitude.track(WEB_VITALS_EVENT_NAME, webVitalsPayload);\n doc.removeEventListener('visibilitychange', visibilityListener);\n visibilityListener = null;\n }\n };\n doc.addEventListener('visibilitychange', visibilityListener);\n };\n\n const execute: BrowserEnrichmentPlugin['execute'] = async (event) => {\n return event;\n };\n\n const teardown = async () => {\n if (visibilityListener) {\n /* istanbul ignore next */\n doc?.removeEventListener('visibilitychange', visibilityListener);\n }\n };\n\n return {\n name: PLUGIN_NAME,\n type: 'enrichment',\n setup,\n execute,\n teardown,\n };\n};\n","export const PLUGIN_NAME = 'web-vitals-browser';\nexport const WEB_VITALS_EVENT_NAME = '[Amplitude] Web Vitals';\n","export const VERSION = '0.1.0-SR-1975.0';\n"],"names":["__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","__generator","body","f","y","t","_","label","sent","trys","ops","g","Object","create","Iterator","prototype","verb","Symbol","iterator","this","n","v","op","TypeError","call","pop","length","push","SuppressedError","getDecodeURI","locationStr","loggerProvider","decodedLocationStr","decodeURI","error","addEventListener","persisted","timeStamp","i","s","o","r","delta","rating","requestAnimationFrame","performance","getEntriesByType","responseStart","now","activationStart","document","prerendering","wasDiscarded","type","replace","name","entries","id","Date","Math","floor","random","navigationType","c","WeakMap","a","get","set","d","h","hadRecentInput","at","startTime","PerformanceObserver","supportedEntryTypes","includes","getEntries","observe","buffered","u","l","Set","m","visibilityState","p","isFinite","removeEventListener","globalThis","filter","setTimeout","firstHiddenTime","onHidden","add","E","disconnect","max","reportAllChanges","b","T","M","interactionId","min","w","C","interactionCount","F","k","Map","clear","L","entryType","duration","sort","splice","delete","A","requestIdleCallback","once","capture","B","S","PerformanceEventTiming","durationThreshold","takeRecords","N","q","H","O","readyState","getMetricStartTime","metric","_a","timeOrigin","processMetric","timestamp","navigationStart","webVitalsPlugin","ampIntegrationContextName","visibilityListener","globalScope","window","self","global","doc","location","setup","config","amplitude","undefined","locationHref","href","webVitalsPayload","hostname","pathname","title","split","slice","isTrusted","onLCP","onFCP","onINP","onCLS","onTTFB","track","execute","event","teardown"],"mappings":"sDAkHO,SAASA,EAAUC,EAASC,EAAYC,EAAGC,GAE9C,OAAO,IAAKD,IAAMA,EAAIE,UAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,GAAQ,CAAG,MAAOG,GAAKL,EAAOK,GAAO,CAC3F,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,GAAU,CAAC,MAAOG,GAAKL,EAAOK,GAAO,CAC9F,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,KAAOT,EAAQQ,EAAOL,QAJ1CA,EAIyDK,EAAOL,MAJhDA,aAAiBN,EAAIM,EAAQ,IAAIN,EAAE,SAAUG,GAAWA,EAAQG,EAAO,IAIhBO,KAAKR,EAAWK,EAAY,CAC9GH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,GAAc,KAAKS,OACtE,EACA,CAEO,SAASO,EAAYjB,EAASkB,GACjC,IAAsGC,EAAGC,EAAGC,EAAxGC,EAAI,CAAEC,MAAO,EAAGC,KAAM,WAAa,GAAW,EAAPH,EAAE,GAAQ,MAAMA,EAAE,GAAI,OAAOA,EAAE,EAAG,EAAII,KAAM,GAAIC,IAAK,IAAeC,EAAIC,OAAOC,QAA4B,mBAAbC,SAA0BA,SAAWF,QAAQG,WACtL,OAAOJ,EAAEjB,KAAOsB,EAAK,GAAIL,EAAS,MAAIK,EAAK,GAAIL,EAAU,OAAIK,EAAK,GAAs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,EAAUgB,MC7FmB,yBD6FUZ,GACvCR,EAAIzD,oBAAoB,mBAAoBoD,GAC5CA,EAAqB,KAEzB,EACAK,EAAI5G,iBAAiB,mBAAoBuG,IAtChC,CAAA,QAwDT0B,QAfkD,SAAOC,GAAK,OAAAtL,OAAA,OAAA,OAAA,EAAA,qCAC9D,MAAA,CAAA,EAAOsL,QAePC,SAZe,WAAA,OAAAvL,OAAA,OAAA,OAAA,EAAA,4CACX2J,IAEFK,SAAAA,EAAKzD,oBAAoB,mBAAoBoD,aAWnD,mBExHuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,function(e){"use strict";function t(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{l(i.next(e))}catch(e){o(e)}}function s(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}l((i=i.apply(e,t||[])).next())})}function n(e,t){var n,i,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(r=o.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var i=function(e,t){var n=e;try{n=decodeURI(e)}catch(e){null==t||t.error("Malformed URI sequence: ",e)}return n};let r=-1;const o=e=>{addEventListener("pageshow",t=>{t.persisted&&(r=t.timeStamp,e(t))},!0)},a=(e,t,n,i)=>{let r,o;return a=>{t.value>=0&&(a||i)&&(o=t.value-(r??0),(o||void 0===r)&&(r=t.value,t.delta=o,t.rating=((e,t)=>e>t[1]?"poor":e>t[0]?"needs-improvement":"good")(t.value,n),e(t)))}},s=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()))},l=()=>{const e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},u=()=>{const e=l();return e?.activationStart??0},c=(e,t=-1)=>{const n=l();let i="navigate";return r>=0?i="back-forward-cache":n&&(document.prerendering||u()>0?i="prerender":document.wasDiscarded?i="restore":n.type&&(i=n.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:i}},d=new WeakMap;function f(e,t){return d.get(e)||d.set(e,new t),d.get(e)}class p{t;i=0;o=[];h(e){if(e.hadRecentInput)return;const t=this.o[0],n=this.o.at(-1);this.i&&t&&n&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(this.i+=e.value,this.o.push(e)):(this.i=e.value,this.o=[e]),this.t?.(e)}}const h=(e,t,n={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){const i=new PerformanceObserver(e=>{Promise.resolve().then(()=>{t(e.getEntries())})});return i.observe({type:e,buffered:!0,...n}),i}}catch{}},m=e=>{let t=!1;return()=>{t||(e(),t=!0)}};let v=-1;const g=new Set,y=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,b=e=>{if("hidden"===document.visibilityState){if("visibilitychange"===e.type)for(const e of g)e();isFinite(v)||(v="visibilitychange"===e.type?e.timeStamp:0,removeEventListener("prerenderingchange",b,!0))}},T=()=>{if(v<0){const e=u(),t=document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter(t=>"hidden"===t.name&&t.startTime>e)[0]?.startTime;v=t??y(),addEventListener("visibilitychange",b,!0),addEventListener("prerenderingchange",b,!0),o(()=>{setTimeout(()=>{v=y()})})}return{get firstHiddenTime(){return v},onHidden(e){g.add(e)}}},P=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),!0):e()},w=[1800,3e3],A=(e,t={})=>{P(()=>{const n=T();let i,r=c("FCP");const l=h("paint",e=>{for(const t of e)"first-contentful-paint"===t.name&&(l.disconnect(),t.startTime<n.firstHiddenTime&&(r.value=Math.max(t.startTime-u(),0),r.entries.push(t),i(!0)))});l&&(i=a(e,r,w,t.reportAllChanges),o(n=>{r=c("FCP"),i=a(e,r,w,t.reportAllChanges),s(()=>{r.value=performance.now()-n.timeStamp,i(!0)})}))})},C=[.1,.25];let S=0,E=1/0,L=0;const I=e=>{for(const t of e)t.interactionId&&(E=Math.min(E,t.interactionId),L=Math.max(L,t.interactionId),S=L?(L-E)/7+1:0)};let M;const x=()=>M?S:performance.interactionCount??0;let k=0;class F{u=[];l=new Map;m;p;v(){k=x(),this.u.length=0,this.l.clear()}L(){const e=Math.min(this.u.length-1,Math.floor((x()-k)/50));return this.u[e]}h(e){if(this.m?.(e),!e.interactionId&&"first-input"!==e.entryType)return;const t=this.u.at(-1);let n=this.l.get(e.interactionId);if(n||this.u.length<10||e.duration>t.P){if(n?e.duration>n.P?(n.entries=[e],n.P=e.duration):e.duration===n.P&&e.startTime===n.entries[0].startTime&&n.entries.push(e):(n={id:e.interactionId,entries:[e],P:e.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((e,t)=>t.P-e.P),this.u.length>10){const e=this.u.splice(10);for(const t of e)this.l.delete(t.id)}this.p?.(n)}}}const R=e=>{const t=globalThis.requestIdleCallback||setTimeout;"hidden"===document.visibilityState?e():(e=m(e),addEventListener("visibilitychange",e,{once:!0,capture:!0}),t(()=>{e(),removeEventListener("visibilitychange",e,{capture:!0})}))},O=[200,500],H=(e,t={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const n=T();P(()=>{"interactionCount"in performance||M||(M=h("event",I,{type:"event",buffered:!0,durationThreshold:0}));let i,r=c("INP");const s=f(t,F),l=e=>{R(()=>{for(const t of e)s.h(t);const t=s.L();t&&t.P!==r.value&&(r.value=t.P,r.entries=t.entries,i())})},u=h("event",l,{durationThreshold:t.durationThreshold??40});i=a(e,r,O,t.reportAllChanges),u&&(u.observe({type:"first-input",buffered:!0}),n.onHidden(()=>{l(u.takeRecords()),i(!0)}),o(()=>{s.v(),r=c("INP"),i=a(e,r,O,t.reportAllChanges)}))})};class B{m;h(e){this.m?.(e)}}const j=[2500,4e3],q=[800,1800],N=e=>{document.prerendering?P(()=>N(e)):"complete"!==document.readyState?addEventListener("load",()=>N(e),!0):setTimeout(e)};function D(e){var t,n=(null===(t=e.entries[0])||void 0===t?void 0:t.startTime)||0;return performance.timeOrigin+n}function U(e){return{value:e.value,rating:e.rating,delta:e.delta,navigationType:e.navigationType,id:e.id,timestamp:Math.floor(D(e)),navigationStart:Math.floor(performance.timeOrigin)}}var V=function(){var e,r=null,d=(e="ampIntegrationContext","undefined"!=typeof globalThis&&void 0!==globalThis[e]?globalThis[e]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0),v=null==d?void 0:d.document,g=null==d?void 0:d.location;return{name:"web-vitals-browser",type:"enrichment",setup:function(e,d){return t(void 0,void 0,void 0,function(){var t,y;return n(this,function(n){return void 0===v||(t=i((null==g?void 0:g.href)||"",e.loggerProvider),y={"[Amplitude] Page Domain":(null==g?void 0:g.hostname)||"","[Amplitude] Page Location":t,"[Amplitude] Page Path":i((null==g?void 0:g.pathname)||"",e.loggerProvider),"[Amplitude] Page Title":"undefined"!=typeof document&&document.title||"","[Amplitude] Page URL":i(t.split("?")[0],e.loggerProvider)},((e,t={})=>{P(()=>{const n=T();let i,r=c("LCP");const l=f(t,B),d=e=>{t.reportAllChanges||(e=e.slice(-1));for(const t of e)l.h(t),t.startTime<n.firstHiddenTime&&(r.value=Math.max(t.startTime-u(),0),r.entries=[t],i())},p=h("largest-contentful-paint",d);if(p){i=a(e,r,j,t.reportAllChanges);const n=m(()=>{d(p.takeRecords()),p.disconnect(),i(!0)}),l=e=>{e.isTrusted&&(R(n),removeEventListener(e.type,l,{capture:!0}))};for(const e of["keydown","click","visibilitychange"])addEventListener(e,l,{capture:!0});o(n=>{r=c("LCP"),i=a(e,r,j,t.reportAllChanges),s(()=>{r.value=performance.now()-n.timeStamp,i(!0)})})}})})(function(e){y["[Amplitude] LCP"]=U(e)}),A(function(e){y["[Amplitude] FCP"]=U(e)}),H(function(e){y["[Amplitude] INP"]=U(e)}),((e,t={})=>{const n=T();A(m(()=>{let i,r=c("CLS",0);const l=f(t,p),u=e=>{for(const t of e)l.h(t);l.i>r.value&&(r.value=l.i,r.entries=l.o,i())},d=h("layout-shift",u);d&&(i=a(e,r,C,t.reportAllChanges),n.onHidden(()=>{u(d.takeRecords()),i(!0)}),o(()=>{l.i=0,r=c("CLS",0),i=a(e,r,C,t.reportAllChanges),s(()=>i())}),setTimeout(i))}))})(function(e){y["[Amplitude] CLS"]=U(e)}),((e,t={})=>{let n=c("TTFB"),i=a(e,n,q,t.reportAllChanges);N(()=>{const r=l();r&&(n.value=Math.max(r.responseStart-u(),0),n.entries=[r],i(!0),o(()=>{n=c("TTFB",0),i=a(e,n,q,t.reportAllChanges),i(!0)}))})})(function(e){y["[Amplitude] TTFB"]=U(e)}),r=function(){"hidden"===v.visibilityState&&r&&(d.track("[Amplitude] Web Vitals",y),v.removeEventListener("visibilitychange",r),r=null)},v.addEventListener("visibilitychange",r)),[2]})})},execute:function(e){return t(void 0,void 0,void 0,function(){return n(this,function(t){return[2,e]})})},teardown:function(){return t(void 0,void 0,void 0,function(){return n(this,function(e){return r&&(null==v||v.removeEventListener("visibilitychange",r)),[2]})})}}};e.VERSION="0.1.0-SR-1975.0",e.plugin=V,e.webVitalsPlugin=V,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAChD,eAAO,MAAM,qBAAqB,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BrowserClient, BrowserConfig, EnrichmentPlugin } from '@amplitude/analytics-core';
|
|
2
|
+
export type BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;
|
|
3
|
+
export declare const webVitalsPlugin: () => BrowserEnrichmentPlugin;
|
|
4
|
+
//# sourceMappingURL=web-vitals-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-vitals-plugin.d.ts","sourceRoot":"","sources":["../../src/web-vitals-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAGjB,MAAM,2BAA2B,CAAC;AAInC,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AA2CrF,eAAO,MAAM,eAAe,QAAO,uBAkElC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amplitude/plugin-web-vitals-browser",
|
|
3
|
+
"version": "0.1.0-SR-1975.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "Amplitude Inc",
|
|
6
|
+
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "lib/cjs/index.js",
|
|
9
|
+
"module": "lib/esm/index.js",
|
|
10
|
+
"types": "lib/esm/index.d.ts",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"tag": "alpha"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "yarn bundle && yarn build:es5 && yarn build:esm",
|
|
22
|
+
"bundle": "rollup --config rollup.config.js",
|
|
23
|
+
"build:es5": "tsc -p ./tsconfig.es5.json",
|
|
24
|
+
"build:esm": "tsc -p ./tsconfig.esm.json",
|
|
25
|
+
"watch": "tsc -p ./tsconfig.esm.json --watch",
|
|
26
|
+
"clean": "rimraf node_modules lib coverage",
|
|
27
|
+
"fix": "yarn fix:eslint & yarn fix:prettier",
|
|
28
|
+
"fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
|
|
29
|
+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
|
|
30
|
+
"lint": "yarn lint:eslint & yarn lint:prettier",
|
|
31
|
+
"lint:eslint": "eslint '{src,test}/**/*.ts'",
|
|
32
|
+
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"typecheck": "tsc -p ./tsconfig.json",
|
|
35
|
+
"version": "yarn version-file && yarn build",
|
|
36
|
+
"version-file": "node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@amplitude/analytics-core": "^2.31.1-SR-1975.0",
|
|
43
|
+
"rxjs": "^7.8.1",
|
|
44
|
+
"tslib": "^2.4.1",
|
|
45
|
+
"web-vitals": "^5.0.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@rollup/plugin-commonjs": "^23.0.4",
|
|
49
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
50
|
+
"@rollup/plugin-typescript": "^10.0.1",
|
|
51
|
+
"css.escape": "^1.5.1",
|
|
52
|
+
"rollup": "^2.79.1",
|
|
53
|
+
"rollup-plugin-execute": "^1.1.1",
|
|
54
|
+
"rollup-plugin-gzip": "^3.1.0",
|
|
55
|
+
"rollup-plugin-terser": "^7.0.2"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"lib"
|
|
59
|
+
],
|
|
60
|
+
"gitHead": "2b9bd1f0f41095bb68f153d5930329f77017272a"
|
|
61
|
+
}
|