@atlaskit/react-ufo 2.3.3 → 2.4.1
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/CHANGELOG.md +16 -0
- package/dist/cjs/common/constants.js +2 -1
- package/dist/cjs/create-payload/common/utils/index.js +61 -2
- package/dist/cjs/create-payload/index.js +68 -50
- package/dist/cjs/global-error-handler/index.js +7 -1
- package/dist/cjs/interaction-metrics-init/index.js +0 -7
- package/dist/es2019/common/constants.js +2 -1
- package/dist/es2019/create-payload/common/utils/index.js +53 -2
- package/dist/es2019/create-payload/index.js +49 -31
- package/dist/es2019/global-error-handler/index.js +4 -0
- package/dist/es2019/interaction-metrics-init/index.js +0 -7
- package/dist/esm/common/constants.js +2 -1
- package/dist/esm/create-payload/common/utils/index.js +57 -2
- package/dist/esm/create-payload/index.js +53 -35
- package/dist/esm/global-error-handler/index.js +6 -0
- package/dist/esm/interaction-metrics-init/index.js +0 -7
- package/dist/types/common/constants.d.ts +1 -1
- package/dist/types/create-payload/common/types.d.ts +1 -1
- package/dist/types/create-payload/common/utils/index.d.ts +15 -1
- package/dist/types/create-payload/index.d.ts +3217 -145
- package/dist/types/global-error-handler/index.d.ts +1 -0
- package/dist/types/interaction-context/index.d.ts +1 -1
- package/dist/types-ts4.5/common/constants.d.ts +1 -1
- package/dist/types-ts4.5/create-payload/common/types.d.ts +1 -1
- package/dist/types-ts4.5/create-payload/common/utils/index.d.ts +15 -1
- package/dist/types-ts4.5/create-payload/index.d.ts +3217 -145
- package/dist/types-ts4.5/global-error-handler/index.d.ts +1 -0
- package/dist/types-ts4.5/interaction-context/index.d.ts +1 -1
- package/package.json +7 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import Bowser from 'bowser-ultralight';
|
|
2
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
3
|
import { getLighthouseMetrics } from '../additional-payload';
|
|
3
4
|
import * as bundleEvalTiming from '../bundle-eval-timing';
|
|
4
5
|
import { REACT_UFO_VERSION } from '../common/constants';
|
|
5
6
|
import { getConfig, getUfoNameOverrides } from '../config';
|
|
6
7
|
import { getBm3Timings } from '../custom-timings';
|
|
8
|
+
import { getGlobalErrorCount } from '../global-error-handler';
|
|
7
9
|
import { getPageVisibilityState } from '../hidden-timing';
|
|
8
10
|
import * as initialPageLoadExtraTiming from '../initial-page-load-extra-timing';
|
|
9
11
|
import { interactionSpans as atlaskitInteractionSpans, postInteractionLog } from '../interaction-metrics';
|
|
@@ -11,7 +13,7 @@ import * as resourceTiming from '../resource-timing';
|
|
|
11
13
|
import { roundEpsilon } from '../round-number';
|
|
12
14
|
import * as ssr from '../ssr';
|
|
13
15
|
import { getVCObserver } from '../vc';
|
|
14
|
-
import {
|
|
16
|
+
import { buildSegmentTree, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
|
|
15
17
|
function getUfoNameOverride(interaction) {
|
|
16
18
|
const {
|
|
17
19
|
ufoName,
|
|
@@ -31,17 +33,6 @@ function getUfoNameOverride(interaction) {
|
|
|
31
33
|
return ufoName;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
function stringifyLabelStackFully(labelStack) {
|
|
35
|
-
return labelStack.map(l => {
|
|
36
|
-
if (isSegmentLabel(l)) {
|
|
37
|
-
return `${l.name}:${l.segmentId}`;
|
|
38
|
-
}
|
|
39
|
-
return l.name;
|
|
40
|
-
}).join('/');
|
|
41
|
-
}
|
|
42
|
-
function labelStackStartWith(labelStack, startWith) {
|
|
43
|
-
return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
|
|
44
|
-
}
|
|
45
36
|
function getEarliestLegacyStopTime(interaction, labelStack) {
|
|
46
37
|
let earliestLegacyStopTime = null;
|
|
47
38
|
interaction.apdex.forEach(a => {
|
|
@@ -329,17 +320,6 @@ const getTracingContextData = interaction => {
|
|
|
329
320
|
}
|
|
330
321
|
return tracingContextData;
|
|
331
322
|
};
|
|
332
|
-
|
|
333
|
-
// interaction metric
|
|
334
|
-
|
|
335
|
-
function optimizeLabelStack(labelStack) {
|
|
336
|
-
return labelStack.map(ls => ({
|
|
337
|
-
n: ls.name,
|
|
338
|
-
...(ls.segmentId ? {
|
|
339
|
-
s: ls.segmentId
|
|
340
|
-
} : {})
|
|
341
|
-
}));
|
|
342
|
-
}
|
|
343
323
|
function optimizeCustomData(interaction) {
|
|
344
324
|
const {
|
|
345
325
|
customData,
|
|
@@ -520,7 +500,7 @@ function optimizeRequestInfo(requestInfo, interactionStart) {
|
|
|
520
500
|
return updatedRequestInfo;
|
|
521
501
|
}
|
|
522
502
|
function optimizeCustomTimings(customTimings, interactionStart) {
|
|
523
|
-
|
|
503
|
+
return customTimings.reduce((result, item) => {
|
|
524
504
|
Object.keys(item.data).forEach(key => {
|
|
525
505
|
if (item.data[key].startTime >= interactionStart) {
|
|
526
506
|
result.push({
|
|
@@ -534,7 +514,6 @@ function optimizeCustomTimings(customTimings, interactionStart) {
|
|
|
534
514
|
});
|
|
535
515
|
return result;
|
|
536
516
|
}, []);
|
|
537
|
-
return updatedCustomTimings;
|
|
538
517
|
}
|
|
539
518
|
function optimizeMarks(marks) {
|
|
540
519
|
return marks.map(({
|
|
@@ -560,8 +539,6 @@ function optimizeApdex(apdex) {
|
|
|
560
539
|
} : {})
|
|
561
540
|
}));
|
|
562
541
|
}
|
|
563
|
-
|
|
564
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
565
542
|
function objectToArray(obj = {}) {
|
|
566
543
|
return Object.keys(obj).reduce((result, key) => {
|
|
567
544
|
result.push({
|
|
@@ -569,9 +546,7 @@ function objectToArray(obj = {}) {
|
|
|
569
546
|
data: obj[key]
|
|
570
547
|
});
|
|
571
548
|
return result;
|
|
572
|
-
},
|
|
573
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
574
|
-
[]);
|
|
549
|
+
}, []);
|
|
575
550
|
}
|
|
576
551
|
function getBM3SubmetricsTimings(submetrics) {
|
|
577
552
|
if (!submetrics) {
|
|
@@ -626,6 +601,45 @@ function getSSRDoneTimeValue(config) {
|
|
|
626
601
|
function getPayloadSize(payload) {
|
|
627
602
|
return Math.round(new TextEncoder().encode(JSON.stringify(payload)).length / 1024);
|
|
628
603
|
}
|
|
604
|
+
function getStylesheetMetrics() {
|
|
605
|
+
if (!fg('ufo_capture_stylesheet_metrics')) {
|
|
606
|
+
return {};
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
const stylesheets = Array.from(document.styleSheets);
|
|
610
|
+
const stylesheetCount = stylesheets.length;
|
|
611
|
+
const cssrules = Array.from(document.styleSheets).reduce((acc, item) => {
|
|
612
|
+
// Other domain stylesheets throw a SecurityError
|
|
613
|
+
try {
|
|
614
|
+
return acc + item.cssRules.length;
|
|
615
|
+
} catch (e) {
|
|
616
|
+
return acc;
|
|
617
|
+
}
|
|
618
|
+
}, 0);
|
|
619
|
+
const styleElements = document.querySelectorAll('style').length;
|
|
620
|
+
const styleProps = document.querySelectorAll('[style]');
|
|
621
|
+
const styleDeclarations = Array.from(document.querySelectorAll('[style]')).reduce((acc, item) => {
|
|
622
|
+
try {
|
|
623
|
+
if ('style' in item) {
|
|
624
|
+
return acc + item.style.length;
|
|
625
|
+
} else {
|
|
626
|
+
return acc;
|
|
627
|
+
}
|
|
628
|
+
} catch (e) {
|
|
629
|
+
return acc;
|
|
630
|
+
}
|
|
631
|
+
}, 0);
|
|
632
|
+
return {
|
|
633
|
+
stylesheets: stylesheetCount,
|
|
634
|
+
styleElements,
|
|
635
|
+
styleProps: styleProps.length,
|
|
636
|
+
styleDeclarations,
|
|
637
|
+
cssrules: cssrules
|
|
638
|
+
};
|
|
639
|
+
} catch (e) {
|
|
640
|
+
return {};
|
|
641
|
+
}
|
|
642
|
+
}
|
|
629
643
|
function createInteractionMetricsPayload(interaction, interactionId) {
|
|
630
644
|
var _window$location, _config$additionalPay;
|
|
631
645
|
const interactionPayloadStart = performance.now();
|
|
@@ -650,6 +664,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
650
664
|
const pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
|
|
651
665
|
const pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
|
|
652
666
|
const segments = config.killswitchNestedSegments ? [] : knownSegments;
|
|
667
|
+
const segmentTree = buildSegmentTree(segments.map(segment => segment.labelStack));
|
|
653
668
|
const isDetailedPayload = pageVisibilityAtTTAI === 'visible';
|
|
654
669
|
const isPageLoad = type === 'page_load';
|
|
655
670
|
const calculatePageVisibilityFromTheStartOfPageLoad = config.enableBetterPageVisibilityApi && isPageLoad;
|
|
@@ -743,6 +758,8 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
743
758
|
...getVCMetrics(interaction),
|
|
744
759
|
...((_config$additionalPay = config.additionalPayloadData) === null || _config$additionalPay === void 0 ? void 0 : _config$additionalPay.call(config, interaction)),
|
|
745
760
|
...getTracingContextData(interaction),
|
|
761
|
+
...getStylesheetMetrics(),
|
|
762
|
+
errorCount: getGlobalErrorCount(),
|
|
746
763
|
interactionMetrics: {
|
|
747
764
|
namePrefix: config.namePrefix || '',
|
|
748
765
|
segmentPrefix: config.segmentPrefix || '',
|
|
@@ -764,7 +781,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
764
781
|
apdex: optimizeApdex(interaction.apdex),
|
|
765
782
|
end: Math.round(end),
|
|
766
783
|
start: Math.round(start),
|
|
767
|
-
segments: segments.map(({
|
|
784
|
+
segments: REACT_UFO_VERSION === '2.0.0' ? segmentTree : segments.map(({
|
|
768
785
|
labelStack,
|
|
769
786
|
...others
|
|
770
787
|
}) => ({
|
|
@@ -774,6 +791,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
774
791
|
marks: optimizeMarks(interaction.marks),
|
|
775
792
|
customData: optimizeCustomData(interaction),
|
|
776
793
|
reactProfilerTimings: optimizeReactProfilerTimings(interaction.reactProfilerTimings, start),
|
|
794
|
+
errorCount: interaction.errors.length,
|
|
777
795
|
...labelStack,
|
|
778
796
|
...getPageLoadInteractionMetrics(),
|
|
779
797
|
...getDetailedInteractionMetrics(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { bind } from 'bind-event-listener';
|
|
2
2
|
let shouldInitilizeGlobalErrorHandler = true;
|
|
3
|
+
let globalCount = 0;
|
|
3
4
|
const errors = [];
|
|
4
5
|
let push = (name, labelStack, errorType, errorMessage, errorStack) => {
|
|
5
6
|
errors.push({
|
|
@@ -17,8 +18,10 @@ export const sinkErrorHandler = sinkFunc => {
|
|
|
17
18
|
});
|
|
18
19
|
errors.length = 0;
|
|
19
20
|
};
|
|
21
|
+
export const getGlobalErrorCount = () => globalCount;
|
|
20
22
|
const handleError = e => {
|
|
21
23
|
var _e$error;
|
|
24
|
+
globalCount++;
|
|
22
25
|
if (((_e$error = e.error) === null || _e$error === void 0 ? void 0 : _e$error.UFOhasCaught) === undefined) {
|
|
23
26
|
try {
|
|
24
27
|
if (e.error instanceof Error) {
|
|
@@ -38,6 +41,7 @@ const handleError = e => {
|
|
|
38
41
|
}
|
|
39
42
|
};
|
|
40
43
|
const handlePromiseRejection = e => {
|
|
44
|
+
globalCount++;
|
|
41
45
|
if (e.reason instanceof Error) {
|
|
42
46
|
push('GlobalErrorHandler', null, e.reason.name, e.reason.message, e.reason.stack);
|
|
43
47
|
} else if (e.reason) {
|
|
@@ -30,13 +30,6 @@ export const init = (analyticsWebClientAsync, config) => {
|
|
|
30
30
|
if (initialized) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
try {
|
|
34
|
-
if (window !== undefined) {
|
|
35
|
-
window.__REACT_UFO_ENABLE_PERF_TRACING = Boolean(sessionStorage.getItem('additionalPerfMarks') === 'true');
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
/* do nothing */
|
|
39
|
-
}
|
|
40
33
|
setUFOConfig(config);
|
|
41
34
|
if ((_config$vc = config.vc) !== null && _config$vc !== void 0 && _config$vc.enabled) {
|
|
42
35
|
const vcOptions = {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
export var REACT_UFO_VERSION = fg('react-ufo-payload-segment-compressed') ? '2.0.0' : '1.0.1';
|
|
@@ -1,8 +1,63 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
|
5
|
+
import { REACT_UFO_VERSION } from '../../../common/constants';
|
|
1
6
|
export var sanitizeUfoName = function sanitizeUfoName(name) {
|
|
2
7
|
return name.replace(/_/g, '-');
|
|
3
8
|
};
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
9
|
export function isSegmentLabel(obj) {
|
|
7
10
|
return obj && typeof obj.name === 'string' && typeof obj.segmentId === 'string';
|
|
11
|
+
}
|
|
12
|
+
export function buildSegmentTree(labelStacks) {
|
|
13
|
+
var r = {
|
|
14
|
+
n: 'segment-tree-root',
|
|
15
|
+
c: {}
|
|
16
|
+
};
|
|
17
|
+
labelStacks.forEach(function (labelStack) {
|
|
18
|
+
var currentNode = r;
|
|
19
|
+
labelStack.forEach(function (label, index) {
|
|
20
|
+
var _currentNode$c;
|
|
21
|
+
var name = label.name;
|
|
22
|
+
var id = isSegmentLabel(label) ? label.segmentId : undefined;
|
|
23
|
+
var key = id !== undefined ? id.toString() : name;
|
|
24
|
+
if (currentNode.c && !currentNode.c[key]) {
|
|
25
|
+
currentNode.c[key] = {
|
|
26
|
+
n: name
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
currentNode = (_currentNode$c = currentNode.c) === null || _currentNode$c === void 0 ? void 0 : _currentNode$c[key];
|
|
30
|
+
if (index < labelStack.length - 1) {
|
|
31
|
+
currentNode.c = _objectSpread({}, currentNode.c || {});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
r: r
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function stringifyLabelStackFully(labelStack) {
|
|
40
|
+
return labelStack.map(function (l) {
|
|
41
|
+
if (isSegmentLabel(l)) {
|
|
42
|
+
return "".concat(l.name, ":").concat(l.segmentId);
|
|
43
|
+
}
|
|
44
|
+
return l.name;
|
|
45
|
+
}).join('/');
|
|
46
|
+
}
|
|
47
|
+
function getLabelStackReference(labelStack) {
|
|
48
|
+
return labelStack.map(function (l) {
|
|
49
|
+
return isSegmentLabel(l) ? l.segmentId : l.name;
|
|
50
|
+
}).join('/');
|
|
51
|
+
}
|
|
52
|
+
export function labelStackStartWith(labelStack, startWith) {
|
|
53
|
+
return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
|
|
54
|
+
}
|
|
55
|
+
export function optimizeLabelStack(labelStack) {
|
|
56
|
+
return REACT_UFO_VERSION === '2.0.0' ? getLabelStackReference(labelStack) : labelStack.map(function (ls) {
|
|
57
|
+
return _objectSpread({
|
|
58
|
+
n: ls.name
|
|
59
|
+
}, ls.segmentId ? {
|
|
60
|
+
s: ls.segmentId
|
|
61
|
+
} : {});
|
|
62
|
+
});
|
|
8
63
|
}
|
|
@@ -9,11 +9,13 @@ var _excluded = ["labelStack", "time"],
|
|
|
9
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
10
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
11
|
import Bowser from 'bowser-ultralight';
|
|
12
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
13
|
import { getLighthouseMetrics } from '../additional-payload';
|
|
13
14
|
import * as bundleEvalTiming from '../bundle-eval-timing';
|
|
14
15
|
import { REACT_UFO_VERSION } from '../common/constants';
|
|
15
16
|
import { getConfig, getUfoNameOverrides } from '../config';
|
|
16
17
|
import { getBm3Timings } from '../custom-timings';
|
|
18
|
+
import { getGlobalErrorCount } from '../global-error-handler';
|
|
17
19
|
import { getPageVisibilityState } from '../hidden-timing';
|
|
18
20
|
import * as initialPageLoadExtraTiming from '../initial-page-load-extra-timing';
|
|
19
21
|
import { interactionSpans as atlaskitInteractionSpans, postInteractionLog } from '../interaction-metrics';
|
|
@@ -21,7 +23,7 @@ import * as resourceTiming from '../resource-timing';
|
|
|
21
23
|
import { roundEpsilon } from '../round-number';
|
|
22
24
|
import * as ssr from '../ssr';
|
|
23
25
|
import { getVCObserver } from '../vc';
|
|
24
|
-
import {
|
|
26
|
+
import { buildSegmentTree, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
|
|
25
27
|
function getUfoNameOverride(interaction) {
|
|
26
28
|
var ufoName = interaction.ufoName,
|
|
27
29
|
apdex = interaction.apdex;
|
|
@@ -39,17 +41,6 @@ function getUfoNameOverride(interaction) {
|
|
|
39
41
|
return ufoName;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
function stringifyLabelStackFully(labelStack) {
|
|
43
|
-
return labelStack.map(function (l) {
|
|
44
|
-
if (isSegmentLabel(l)) {
|
|
45
|
-
return "".concat(l.name, ":").concat(l.segmentId);
|
|
46
|
-
}
|
|
47
|
-
return l.name;
|
|
48
|
-
}).join('/');
|
|
49
|
-
}
|
|
50
|
-
function labelStackStartWith(labelStack, startWith) {
|
|
51
|
-
return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
|
|
52
|
-
}
|
|
53
44
|
function getEarliestLegacyStopTime(interaction, labelStack) {
|
|
54
45
|
var earliestLegacyStopTime = null;
|
|
55
46
|
interaction.apdex.forEach(function (a) {
|
|
@@ -335,18 +326,6 @@ var getTracingContextData = function getTracingContextData(interaction) {
|
|
|
335
326
|
}
|
|
336
327
|
return tracingContextData;
|
|
337
328
|
};
|
|
338
|
-
|
|
339
|
-
// interaction metric
|
|
340
|
-
|
|
341
|
-
function optimizeLabelStack(labelStack) {
|
|
342
|
-
return labelStack.map(function (ls) {
|
|
343
|
-
return _objectSpread({
|
|
344
|
-
n: ls.name
|
|
345
|
-
}, ls.segmentId ? {
|
|
346
|
-
s: ls.segmentId
|
|
347
|
-
} : {});
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
329
|
function optimizeCustomData(interaction) {
|
|
351
330
|
var customData = interaction.customData,
|
|
352
331
|
legacyMetrics = interaction.legacyMetrics;
|
|
@@ -520,7 +499,7 @@ function optimizeRequestInfo(requestInfo, interactionStart) {
|
|
|
520
499
|
return updatedRequestInfo;
|
|
521
500
|
}
|
|
522
501
|
function optimizeCustomTimings(customTimings, interactionStart) {
|
|
523
|
-
|
|
502
|
+
return customTimings.reduce(function (result, item) {
|
|
524
503
|
Object.keys(item.data).forEach(function (key) {
|
|
525
504
|
if (item.data[key].startTime >= interactionStart) {
|
|
526
505
|
result.push({
|
|
@@ -534,7 +513,6 @@ function optimizeCustomTimings(customTimings, interactionStart) {
|
|
|
534
513
|
});
|
|
535
514
|
return result;
|
|
536
515
|
}, []);
|
|
537
|
-
return updatedCustomTimings;
|
|
538
516
|
}
|
|
539
517
|
function optimizeMarks(marks) {
|
|
540
518
|
return marks.map(function (_ref4) {
|
|
@@ -559,8 +537,6 @@ function optimizeApdex(apdex) {
|
|
|
559
537
|
} : {});
|
|
560
538
|
});
|
|
561
539
|
}
|
|
562
|
-
|
|
563
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
564
540
|
function objectToArray() {
|
|
565
541
|
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
566
542
|
return Object.keys(obj).reduce(function (result, key) {
|
|
@@ -569,9 +545,7 @@ function objectToArray() {
|
|
|
569
545
|
data: obj[key]
|
|
570
546
|
});
|
|
571
547
|
return result;
|
|
572
|
-
},
|
|
573
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
574
|
-
[]);
|
|
548
|
+
}, []);
|
|
575
549
|
}
|
|
576
550
|
function getBM3SubmetricsTimings(submetrics) {
|
|
577
551
|
if (!submetrics) {
|
|
@@ -625,6 +599,45 @@ function getSSRDoneTimeValue(config) {
|
|
|
625
599
|
function getPayloadSize(payload) {
|
|
626
600
|
return Math.round(new TextEncoder().encode(JSON.stringify(payload)).length / 1024);
|
|
627
601
|
}
|
|
602
|
+
function getStylesheetMetrics() {
|
|
603
|
+
if (!fg('ufo_capture_stylesheet_metrics')) {
|
|
604
|
+
return {};
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
var stylesheets = Array.from(document.styleSheets);
|
|
608
|
+
var stylesheetCount = stylesheets.length;
|
|
609
|
+
var cssrules = Array.from(document.styleSheets).reduce(function (acc, item) {
|
|
610
|
+
// Other domain stylesheets throw a SecurityError
|
|
611
|
+
try {
|
|
612
|
+
return acc + item.cssRules.length;
|
|
613
|
+
} catch (e) {
|
|
614
|
+
return acc;
|
|
615
|
+
}
|
|
616
|
+
}, 0);
|
|
617
|
+
var styleElements = document.querySelectorAll('style').length;
|
|
618
|
+
var styleProps = document.querySelectorAll('[style]');
|
|
619
|
+
var styleDeclarations = Array.from(document.querySelectorAll('[style]')).reduce(function (acc, item) {
|
|
620
|
+
try {
|
|
621
|
+
if ('style' in item) {
|
|
622
|
+
return acc + item.style.length;
|
|
623
|
+
} else {
|
|
624
|
+
return acc;
|
|
625
|
+
}
|
|
626
|
+
} catch (e) {
|
|
627
|
+
return acc;
|
|
628
|
+
}
|
|
629
|
+
}, 0);
|
|
630
|
+
return {
|
|
631
|
+
stylesheets: stylesheetCount,
|
|
632
|
+
styleElements: styleElements,
|
|
633
|
+
styleProps: styleProps.length,
|
|
634
|
+
styleDeclarations: styleDeclarations,
|
|
635
|
+
cssrules: cssrules
|
|
636
|
+
};
|
|
637
|
+
} catch (e) {
|
|
638
|
+
return {};
|
|
639
|
+
}
|
|
640
|
+
}
|
|
628
641
|
function createInteractionMetricsPayload(interaction, interactionId) {
|
|
629
642
|
var _window$location, _config$additionalPay;
|
|
630
643
|
var interactionPayloadStart = performance.now();
|
|
@@ -647,6 +660,9 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
647
660
|
var pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
|
|
648
661
|
var pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
|
|
649
662
|
var segments = config.killswitchNestedSegments ? [] : knownSegments;
|
|
663
|
+
var segmentTree = buildSegmentTree(segments.map(function (segment) {
|
|
664
|
+
return segment.labelStack;
|
|
665
|
+
}));
|
|
650
666
|
var isDetailedPayload = pageVisibilityAtTTAI === 'visible';
|
|
651
667
|
var isPageLoad = type === 'page_load';
|
|
652
668
|
var calculatePageVisibilityFromTheStartOfPageLoad = config.enableBetterPageVisibilityApi && isPageLoad;
|
|
@@ -716,7 +732,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
716
732
|
source: 'measured',
|
|
717
733
|
tags: ['observability'],
|
|
718
734
|
attributes: {
|
|
719
|
-
properties: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
735
|
+
properties: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
720
736
|
// basic
|
|
721
737
|
'event:hostname': ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || 'unknown',
|
|
722
738
|
'event:product': config.product,
|
|
@@ -730,7 +746,8 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
730
746
|
'event:region': config.region || 'unknown',
|
|
731
747
|
'experience:key': 'custom.interaction-metrics',
|
|
732
748
|
'experience:name': newUFOName
|
|
733
|
-
}, getBrowserMetadata()), getSSRProperties(type)), getPPSMetrics(interaction)), getPaintMetrics(type)), getNavigationMetrics(type)), getVCMetrics(interaction)), (_config$additionalPay = config.additionalPayloadData) === null || _config$additionalPay === void 0 ? void 0 : _config$additionalPay.call(config, interaction)), getTracingContextData(interaction)), {}, {
|
|
749
|
+
}, getBrowserMetadata()), getSSRProperties(type)), getPPSMetrics(interaction)), getPaintMetrics(type)), getNavigationMetrics(type)), getVCMetrics(interaction)), (_config$additionalPay = config.additionalPayloadData) === null || _config$additionalPay === void 0 ? void 0 : _config$additionalPay.call(config, interaction)), getTracingContextData(interaction)), getStylesheetMetrics()), {}, {
|
|
750
|
+
errorCount: getGlobalErrorCount(),
|
|
734
751
|
interactionMetrics: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
735
752
|
namePrefix: config.namePrefix || '',
|
|
736
753
|
segmentPrefix: config.segmentPrefix || '',
|
|
@@ -752,7 +769,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
752
769
|
apdex: optimizeApdex(interaction.apdex),
|
|
753
770
|
end: Math.round(end),
|
|
754
771
|
start: Math.round(start),
|
|
755
|
-
segments: segments.map(function (_ref7) {
|
|
772
|
+
segments: REACT_UFO_VERSION === '2.0.0' ? segmentTree : segments.map(function (_ref7) {
|
|
756
773
|
var labelStack = _ref7.labelStack,
|
|
757
774
|
others = _objectWithoutProperties(_ref7, _excluded4);
|
|
758
775
|
return _objectSpread(_objectSpread({}, others), {}, {
|
|
@@ -761,7 +778,8 @@ function createInteractionMetricsPayload(interaction, interactionId) {
|
|
|
761
778
|
}),
|
|
762
779
|
marks: optimizeMarks(interaction.marks),
|
|
763
780
|
customData: optimizeCustomData(interaction),
|
|
764
|
-
reactProfilerTimings: optimizeReactProfilerTimings(interaction.reactProfilerTimings, start)
|
|
781
|
+
reactProfilerTimings: optimizeReactProfilerTimings(interaction.reactProfilerTimings, start),
|
|
782
|
+
errorCount: interaction.errors.length
|
|
765
783
|
}, labelStack), getPageLoadInteractionMetrics()), getDetailedInteractionMetrics()), getPageLoadDetailedInteractionMetrics()), getBm3TrackerTimings(interaction)),
|
|
766
784
|
'ufo:payloadTime': roundEpsilon(performance.now() - interactionPayloadStart)
|
|
767
785
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
2
|
import { bind } from 'bind-event-listener';
|
|
3
3
|
var shouldInitilizeGlobalErrorHandler = true;
|
|
4
|
+
var globalCount = 0;
|
|
4
5
|
var errors = [];
|
|
5
6
|
var push = function push(name, labelStack, errorType, errorMessage, errorStack) {
|
|
6
7
|
errors.push({
|
|
@@ -18,8 +19,12 @@ export var sinkErrorHandler = function sinkErrorHandler(sinkFunc) {
|
|
|
18
19
|
});
|
|
19
20
|
errors.length = 0;
|
|
20
21
|
};
|
|
22
|
+
export var getGlobalErrorCount = function getGlobalErrorCount() {
|
|
23
|
+
return globalCount;
|
|
24
|
+
};
|
|
21
25
|
var handleError = function handleError(e) {
|
|
22
26
|
var _e$error;
|
|
27
|
+
globalCount++;
|
|
23
28
|
if (((_e$error = e.error) === null || _e$error === void 0 ? void 0 : _e$error.UFOhasCaught) === undefined) {
|
|
24
29
|
try {
|
|
25
30
|
if (e.error instanceof Error) {
|
|
@@ -39,6 +44,7 @@ var handleError = function handleError(e) {
|
|
|
39
44
|
}
|
|
40
45
|
};
|
|
41
46
|
var handlePromiseRejection = function handlePromiseRejection(e) {
|
|
47
|
+
globalCount++;
|
|
42
48
|
if (e.reason instanceof Error) {
|
|
43
49
|
push('GlobalErrorHandler', null, e.reason.name, e.reason.message, e.reason.stack);
|
|
44
50
|
} else if (e.reason) {
|
|
@@ -31,13 +31,6 @@ export var init = function init(analyticsWebClientAsync, config) {
|
|
|
31
31
|
if (initialized) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
try {
|
|
35
|
-
if (window !== undefined) {
|
|
36
|
-
window.__REACT_UFO_ENABLE_PERF_TRACING = Boolean(sessionStorage.getItem('additionalPerfMarks') === 'true');
|
|
37
|
-
}
|
|
38
|
-
} catch (err) {
|
|
39
|
-
/* do nothing */
|
|
40
|
-
}
|
|
41
34
|
setUFOConfig(config);
|
|
42
35
|
if ((_config$vc = config.vc) !== null && _config$vc !== void 0 && _config$vc.enabled) {
|
|
43
36
|
var vcOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const REACT_UFO_VERSION
|
|
1
|
+
export declare const REACT_UFO_VERSION: string;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LabelStack, SegmentLabel } from '../../../interaction-context';
|
|
2
|
+
export type SegmentItem = {
|
|
3
|
+
n: string;
|
|
4
|
+
c?: Record<string, SegmentItem>;
|
|
5
|
+
};
|
|
6
|
+
export type SegmentTree = {
|
|
7
|
+
r: SegmentItem;
|
|
8
|
+
};
|
|
2
9
|
export declare const sanitizeUfoName: (name: string) => string;
|
|
3
10
|
export declare function isSegmentLabel(obj: any): obj is SegmentLabel;
|
|
11
|
+
export declare function buildSegmentTree(labelStacks: LabelStack[]): SegmentTree;
|
|
12
|
+
export declare function stringifyLabelStackFully(labelStack: LabelStack): string;
|
|
13
|
+
export declare function labelStackStartWith(labelStack: LabelStack, startWith: LabelStack): boolean;
|
|
14
|
+
export declare function optimizeLabelStack(labelStack: LabelStack): string | {
|
|
15
|
+
s?: string | undefined;
|
|
16
|
+
n: string;
|
|
17
|
+
}[];
|