@atlaskit/react-ufo 4.11.2 → 4.11.4

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/create-interaction-extra-metrics-payload/index.js +58 -11
  3. package/dist/cjs/create-payload/utils/get-vc-metrics.js +1 -0
  4. package/dist/cjs/interaction-metrics/index.js +7 -6
  5. package/dist/cjs/interaction-metrics/interaction-extra-metrics.js +17 -10
  6. package/dist/cjs/interaction-metrics-init/index.js +2 -2
  7. package/dist/cjs/segment/segment.js +3 -19
  8. package/dist/cjs/vc/index.js +8 -4
  9. package/dist/cjs/vc/vc-observer-new/index.js +4 -2
  10. package/dist/cjs/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +46 -30
  11. package/dist/es2019/create-interaction-extra-metrics-payload/index.js +40 -5
  12. package/dist/es2019/create-payload/utils/get-vc-metrics.js +2 -1
  13. package/dist/es2019/interaction-metrics/index.js +7 -5
  14. package/dist/es2019/interaction-metrics/interaction-extra-metrics.js +14 -9
  15. package/dist/es2019/interaction-metrics-init/index.js +2 -2
  16. package/dist/es2019/segment/segment.js +2 -12
  17. package/dist/es2019/vc/index.js +7 -1
  18. package/dist/es2019/vc/vc-observer-new/index.js +3 -0
  19. package/dist/es2019/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +17 -3
  20. package/dist/esm/create-interaction-extra-metrics-payload/index.js +58 -11
  21. package/dist/esm/create-payload/utils/get-vc-metrics.js +2 -1
  22. package/dist/esm/interaction-metrics/index.js +7 -6
  23. package/dist/esm/interaction-metrics/interaction-extra-metrics.js +17 -10
  24. package/dist/esm/interaction-metrics-init/index.js +2 -2
  25. package/dist/esm/segment/segment.js +2 -16
  26. package/dist/esm/vc/index.js +8 -4
  27. package/dist/esm/vc/vc-observer-new/index.js +4 -2
  28. package/dist/esm/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +46 -30
  29. package/dist/types/common/vc/types.d.ts +5 -0
  30. package/dist/types/config/index.d.ts +4 -0
  31. package/dist/types/create-interaction-extra-metrics-payload/index.d.ts +9 -1
  32. package/dist/types/interaction-metrics/interaction-extra-metrics.d.ts +6 -3
  33. package/dist/types/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.d.ts +1 -1
  34. package/dist/types/vc/vc-observer-new/metric-calculator/types.d.ts +1 -0
  35. package/dist/types/vc/vc-observer-new/types.d.ts +1 -0
  36. package/dist/types-ts4.5/common/vc/types.d.ts +5 -0
  37. package/dist/types-ts4.5/config/index.d.ts +4 -0
  38. package/dist/types-ts4.5/create-interaction-extra-metrics-payload/index.d.ts +9 -1
  39. package/dist/types-ts4.5/interaction-metrics/interaction-extra-metrics.d.ts +6 -3
  40. package/dist/types-ts4.5/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.d.ts +1 -1
  41. package/dist/types-ts4.5/vc/vc-observer-new/metric-calculator/types.d.ts +1 -0
  42. package/dist/types-ts4.5/vc/vc-observer-new/types.d.ts +1 -0
  43. package/package.json +4 -1
  44. package/dist/cjs/segment/segment-highlight.js +0 -39
  45. package/dist/es2019/segment/segment-highlight.js +0 -27
  46. package/dist/esm/segment/segment-highlight.js +0 -30
  47. package/dist/types/segment/segment-highlight.d.ts +0 -6
  48. package/dist/types-ts4.5/segment/segment-highlight.d.ts +0 -6
@@ -16,8 +16,8 @@ import { optimizeReactProfilerTimings } from '../create-payload/utils/optimize-r
16
16
  import { optimizeRequestInfo } from '../create-payload/utils/optimize-request-info';
17
17
  import { optimizeSpans } from '../create-payload/utils/optimize-spans';
18
18
  import { interactionSpans as atlaskitInteractionSpans } from '../interaction-metrics';
19
- async function createInteractionExtraLogPayload(interactionId, interaction) {
20
- var _getTTAI, _window$location;
19
+ async function createInteractionExtraLogPayload(interactionId, interaction, lastInteractionFinish, lastInteractionFinishVCResult) {
20
+ var _getTTAI, _lastInteractionFinis, _getTTAI2, _window$location;
21
21
  const config = getConfig();
22
22
  if (!config) {
23
23
  throw Error('UFO Configuration not provided');
@@ -33,7 +33,8 @@ async function createInteractionExtraLogPayload(interactionId, interaction) {
33
33
  previousInteractionName,
34
34
  isPreviousInteractionAborted,
35
35
  abortedByInteractionName,
36
- knownSegments
36
+ knownSegments,
37
+ minorInteractions
37
38
  } = interaction;
38
39
  const sanitisedUfoName = sanitizeUfoName(ufoName);
39
40
  const configRate = getExtraInteractionRate(sanitisedUfoName, type);
@@ -42,7 +43,8 @@ async function createInteractionExtraLogPayload(interactionId, interaction) {
42
43
  }
43
44
  const pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
44
45
  const isPageLoad = type === 'page_load' || type === 'transition';
45
- if (!isPageLoad) {
46
+ if (!isPageLoad || minorInteractions !== undefined && minorInteractions.length > 0) {
47
+ // Not send if aborted by minor interaction for now
46
48
  // Only create payload for page load
47
49
  return null;
48
50
  }
@@ -61,6 +63,32 @@ async function createInteractionExtraLogPayload(interactionId, interaction) {
61
63
  return null;
62
64
  }
63
65
 
66
+ // Get normal TTAI & VC90 for last finished interaction (without 3p)
67
+ if (!lastInteractionFinish || lastInteractionFinish !== null && lastInteractionFinish !== void 0 && lastInteractionFinish.abortReason || lastInteractionFinish !== null && lastInteractionFinish !== void 0 && (_lastInteractionFinis = lastInteractionFinish.errors) !== null && _lastInteractionFinis !== void 0 && _lastInteractionFinis.length) {
68
+ return null;
69
+ }
70
+ const normalTTAI = (_getTTAI2 = getTTAI(lastInteractionFinish)) !== null && _getTTAI2 !== void 0 ? _getTTAI2 : undefined;
71
+ const lastInteractionFinishStart = typeof lastInteractionFinish.start === 'number' ? Math.round(lastInteractionFinish.start) : undefined;
72
+ const lastInteractionFinishEnd = typeof lastInteractionFinish.end === 'number' ? Math.round(lastInteractionFinish.end) : undefined;
73
+ let lastInteractionFinishVC90 = null;
74
+ let lastInteractionFinishVCClean = false;
75
+ if (lastInteractionFinishVCResult) {
76
+ const lastInteractionFinishVCRev = lastInteractionFinishVCResult['ufo:vc:rev'];
77
+ const lastInteractionFinishRevision = lastInteractionFinishVCRev === null || lastInteractionFinishVCRev === void 0 ? void 0 : lastInteractionFinishVCRev.find(({
78
+ revision
79
+ }) => revision === DEFAULT_TTVC_REVISION);
80
+ if (lastInteractionFinishRevision !== null && lastInteractionFinishRevision !== void 0 && lastInteractionFinishRevision.clean) {
81
+ lastInteractionFinishVCClean = true;
82
+ lastInteractionFinishVC90 = lastInteractionFinishRevision['metric:vc90'];
83
+ } else {
84
+ return null;
85
+ }
86
+ } else if (normalTTAI !== undefined && typeof normalTTAI === 'number' && normalTTAI === extraTTAI) {
87
+ // Because TTAI is equal between with and without 3p, we can assume VC90 is also equal
88
+ lastInteractionFinishVC90 = effectiveVCRevisionPayload === null || effectiveVCRevisionPayload === void 0 ? void 0 : effectiveVCRevisionPayload['metric:vc90'];
89
+ lastInteractionFinishVCClean = effectiveVCRevisionPayload === null || effectiveVCRevisionPayload === void 0 ? void 0 : effectiveVCRevisionPayload.clean;
90
+ }
91
+
64
92
  // Helper function to check if labelStack contains third-party type
65
93
  const isThirdParty = labelStack => {
66
94
  var _labelStack$some;
@@ -148,7 +176,14 @@ async function createInteractionExtraLogPayload(interactionId, interaction) {
148
176
  customData: filteredData.customData,
149
177
  ...getDetailedInteractionMetrics()
150
178
  },
151
- 'vc:effective:revision': DEFAULT_TTVC_REVISION
179
+ 'vc:effective:revision': DEFAULT_TTVC_REVISION,
180
+ lastInteractionFinish: {
181
+ start: lastInteractionFinishStart,
182
+ end: lastInteractionFinishEnd,
183
+ ttai: normalTTAI,
184
+ vc90: lastInteractionFinishVC90,
185
+ vcClean: lastInteractionFinishVCClean
186
+ }
152
187
  }
153
188
  }
154
189
  };
@@ -1,5 +1,5 @@
1
1
  import { getConfig, getMostRecentVCRevision } from '../../config';
2
- import { postInteractionLog } from '../../interaction-metrics';
2
+ import { interactionExtraMetrics, postInteractionLog } from '../../interaction-metrics';
3
3
  import getInteractionStatus from './get-interaction-status';
4
4
  import getPageVisibilityUpToTTAI from './get-page-visibility-up-to-ttai';
5
5
  import getSSRDoneTimeValue from './get-ssr-done-time-value';
@@ -50,6 +50,7 @@ async function getVCMetrics(interaction, include3p = false, excludeSmartAnswersI
50
50
  if (!include3p) {
51
51
  // For Post Interaction, last interaction should be without 3p
52
52
  postInteractionLog.setLastInteractionFinishVCResult(result);
53
+ interactionExtraMetrics.setLastInteractionFinishVCResult(result);
53
54
  }
54
55
  const mostRecentVCRevision = getMostRecentVCRevision(interaction.ufoName);
55
56
  const mostRecentVCRevisionPayload = result === null || result === void 0 ? void 0 : (_result$ufoVcRev = result['ufo:vc:rev']) === null || _result$ufoVcRev === void 0 ? void 0 : _result$ufoVcRev.find(({
@@ -652,7 +652,8 @@ function finishInteraction(id, data, endTime = performance.now()) {
652
652
  PreviousInteractionLog.isAborted = data.abortReason != null;
653
653
  if (data.ufoName) {
654
654
  if (fg('platform_ufo_enable_ttai_with_3p')) {
655
- if (interactionExtraMetrics.finishedInteractionId !== id) {
655
+ var _interactionExtraMetr;
656
+ if (((_interactionExtraMetr = interactionExtraMetrics.finishedInteraction) === null || _interactionExtraMetr === void 0 ? void 0 : _interactionExtraMetr.id) !== id) {
656
657
  // If this same interaction was not already handled, handle it
657
658
  handleInteraction(id, data);
658
659
  }
@@ -747,7 +748,8 @@ export function tryComplete(interactionId, endTime) {
747
748
  });
748
749
  }
749
750
  if (fg('platform_ufo_enable_ttai_with_3p')) {
750
- if (interactionExtraMetrics.finishedInteractionId !== interactionId) {
751
+ var _interactionExtraMetr2;
752
+ if (((_interactionExtraMetr2 = interactionExtraMetrics.finishedInteraction) === null || _interactionExtraMetr2 === void 0 ? void 0 : _interactionExtraMetr2.id) !== interactionId) {
751
753
  var _getConfig9, _getConfig9$experimen;
752
754
  // If interactionExtraMetrics is not waiting for measuring this interaction
753
755
  if ((_getConfig9 = getConfig()) !== null && _getConfig9 !== void 0 && (_getConfig9$experimen = _getConfig9.experimentalInteractionMetrics) !== null && _getConfig9$experimen !== void 0 && _getConfig9$experimen.enabled) {
@@ -763,15 +765,15 @@ export function tryComplete(interactionId, endTime) {
763
765
  activeSubmitted = false;
764
766
  };
765
767
  if (fg('platform_ufo_enable_ttai_with_3p')) {
766
- var _interaction$hold3pAc;
768
+ var _interaction$hold3pAc, _interactionExtraMetr3;
767
769
  const noMoreActive3pHolds = ((_interaction$hold3pAc = interaction.hold3pActive) === null || _interaction$hold3pAc === void 0 ? void 0 : _interaction$hold3pAc.size) === 0 || interaction.hold3pActive === undefined;
768
- if (noMoreActiveHolds && interactionExtraMetrics.finishedInteractionId !== interactionId) {
770
+ if (noMoreActiveHolds && ((_interactionExtraMetr3 = interactionExtraMetrics.finishedInteraction) === null || _interactionExtraMetr3 === void 0 ? void 0 : _interactionExtraMetr3.id) !== interactionId) {
769
771
  // If it's not waiting for extra metrics to complete, finish the interaction as normal
770
772
  if (!activeSubmitted) {
771
773
  var _getConfig1, _getConfig1$extraInte, _getConfig10, _getConfig10$extraSea, _getConfig11, _getConfig11$extraSea;
772
774
  finishInteraction(interactionId, interaction, endTime);
773
775
  if ((_getConfig1 = getConfig()) !== null && _getConfig1 !== void 0 && (_getConfig1$extraInte = _getConfig1.extraInteractionMetrics) !== null && _getConfig1$extraInte !== void 0 && _getConfig1$extraInte.enabled) {
774
- interactionExtraMetrics.updateFinishedInteractionId(interactionId);
776
+ interactionExtraMetrics.updateFinishedInteraction(interaction);
775
777
  }
776
778
  if ((_getConfig10 = getConfig()) !== null && _getConfig10 !== void 0 && (_getConfig10$extraSea = _getConfig10.extraSearchPageInteraction) !== null && _getConfig10$extraSea !== void 0 && _getConfig10$extraSea.enabled && interaction.ufoName === ((_getConfig11 = getConfig()) === null || _getConfig11 === void 0 ? void 0 : (_getConfig11$extraSea = _getConfig11.extraSearchPageInteraction) === null || _getConfig11$extraSea === void 0 ? void 0 : _getConfig11$extraSea.searchPageMetricName) && fg('react_ufo_unified_search_ignoring_sain_metric')) {
777
779
  onSearchPageInteractionComplete(interactionId, interaction);
@@ -4,8 +4,8 @@ import { interactions } from './common/constants';
4
4
  import { remove } from './index';
5
5
  export default class InteractionExtraMetrics {
6
6
  constructor() {
7
- // Store the finished interaction ID (as non-3p interaction)
8
- _defineProperty(this, "finishedInteractionId", null);
7
+ // Store the finished interaction (as non-3p interaction)
8
+ _defineProperty(this, "finishedInteraction", null);
9
9
  // independent VC observer, that observes until `custom.post-interaction-logs` event is sent
10
10
  _defineProperty(this, "vcObserver", null);
11
11
  _defineProperty(this, "sinkHandlerFn", () => {});
@@ -36,11 +36,14 @@ export default class InteractionExtraMetrics {
36
36
  const interaction = interactions.get(interactionId);
37
37
  return (interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'page_load' || (interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'transition';
38
38
  }
39
- updateFinishedInteractionId(interactionId) {
40
- if (this.eligibleToMeasure(interactionId)) {
41
- this.finishedInteractionId = interactionId;
39
+ updateFinishedInteraction(interaction) {
40
+ if ((interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'page_load' || (interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'transition') {
41
+ this.finishedInteraction = interaction;
42
42
  }
43
43
  }
44
+ setLastInteractionFinishVCResult(result) {
45
+ this.lastInteractionFinishVCResult = result;
46
+ }
44
47
  sinkHandler(fn) {
45
48
  this.sinkHandlerFn = fn;
46
49
  }
@@ -51,18 +54,20 @@ export default class InteractionExtraMetrics {
51
54
  ...data,
52
55
  vcObserver: (_this$vcObserver3 = this.vcObserver) !== null && _this$vcObserver3 !== void 0 ? _this$vcObserver3 : undefined
53
56
  };
54
- this.sinkHandlerFn(id, updatedData);
57
+ this.sinkHandlerFn(id, updatedData, this.finishedInteraction, this.lastInteractionFinishVCResult);
55
58
  }
56
59
  this.stopVCObserver();
57
60
  remove(id);
58
61
  this.reset();
59
62
  }
60
63
  reset() {
64
+ var _this$finishedInterac;
61
65
  this.stopVCObserver();
62
- if (this.finishedInteractionId) {
63
- remove(this.finishedInteractionId);
66
+ if ((_this$finishedInterac = this.finishedInteraction) !== null && _this$finishedInterac !== void 0 && _this$finishedInterac.id) {
67
+ remove(this.finishedInteraction.id);
64
68
  }
65
- this.finishedInteractionId = null;
69
+ this.finishedInteraction = null;
70
+ this.lastInteractionFinishVCResult = undefined;
66
71
  }
67
72
  stopAll(id) {
68
73
  remove(id);
@@ -70,9 +70,9 @@ function sinkPostInteractionLog(instance, createPostInteractionLogPayload) {
70
70
  });
71
71
  }
72
72
  function sinkInteractionExtraMetrics(instance, createInteractionExtraLogPayload) {
73
- interactionExtraMetrics.sinkHandler((interactionId, interaction) => {
73
+ interactionExtraMetrics.sinkHandler((interactionId, interaction, lastInteractionFinish, lastInteractionFinishVCResult) => {
74
74
  scheduleIdleCallback(async () => {
75
- const payload = await createInteractionExtraLogPayload(interactionId, interaction);
75
+ const payload = await createInteractionExtraLogPayload(interactionId, interaction, lastInteractionFinish, lastInteractionFinishVCResult);
76
76
  if (payload) {
77
77
  // NOTE: This API is used by the UFO DevTool Chrome Extension and also by Criterion
78
78
  // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
@@ -1,4 +1,4 @@
1
- import React, { lazy, Profiler, Suspense, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
1
+ import React, { Profiler, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
2
2
  import { unstable_NormalPriority as NormalPriority, unstable_scheduleCallback as scheduleCallback } from 'scheduler';
3
3
  import { v4 as createUUID } from 'uuid';
4
4
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -12,11 +12,7 @@ import UFORouteName from '../route-name-context';
12
12
  import generateId from '../short-id';
13
13
  import scheduleOnPaint from './schedule-on-paint';
14
14
  let tryCompleteHandle;
15
- const AsyncSegmentHighlight = /*#__PURE__*/lazy(() => import( /* webpackChunkName: "@atlaskit-internal_ufo-segment-highlight" */'./segment-highlight').then(module => ({
16
- default: module.SegmentHighlight
17
- })));
18
15
 
19
- // KARL TODO: finish self profiling
20
16
  /** A portion of the page we apply measurement to */
21
17
  export default function UFOSegment({
22
18
  name: segmentName,
@@ -24,7 +20,6 @@ export default function UFOSegment({
24
20
  mode = 'single',
25
21
  type = 'first-party'
26
22
  }) {
27
- var _getConfig2;
28
23
  const parentContext = useContext(UFOInteractionContext);
29
24
  const segmentIdMap = useMemo(() => {
30
25
  if (!(parentContext !== null && parentContext !== void 0 && parentContext.segmentIdMap)) {
@@ -260,16 +255,11 @@ export default function UFOSegment({
260
255
  };
261
256
  }, [interactionId, parentContext, interactionContext, labelStack]);
262
257
  const reactProfilerId = useMemo(() => labelStack.map(l => l.name).join('/'), [labelStack]);
263
- const enableSegmentHighlighting = (_getConfig2 = getConfig()) === null || _getConfig2 === void 0 ? void 0 : _getConfig2.enableSegmentHighlighting;
264
258
  return /*#__PURE__*/React.createElement(UFOInteractionContext.Provider, {
265
259
  value: interactionContext
266
260
  }, /*#__PURE__*/React.createElement(Profiler, {
267
261
  id: reactProfilerId,
268
262
  onRender: onRender
269
- }, children, enableSegmentHighlighting && /*#__PURE__*/React.createElement(Suspense, {
270
- fallback: null
271
- }, /*#__PURE__*/React.createElement(AsyncSegmentHighlight, {
272
- segmentName: segmentName
273
- }))));
263
+ }, children));
274
264
  }
275
265
  UFOSegment.displayName = 'UFOSegment';
@@ -96,7 +96,8 @@ export class VCObserverWrapper {
96
96
  const {
97
97
  experienceKey,
98
98
  include3p,
99
- excludeSmartAnswersInSearch
99
+ excludeSmartAnswersInSearch,
100
+ includeSSRRatio
100
101
  } = param;
101
102
  const v1v2Result = isVCRevisionEnabled('fy25.01', experienceKey) || isVCRevisionEnabled('fy25.02', experienceKey) ? await ((_this$oldVCObserver4 = this.oldVCObserver) === null || _this$oldVCObserver4 === void 0 ? void 0 : _this$oldVCObserver4.getVCResult(param)) : {};
102
103
  const v3Result = isVCRevisionEnabled('fy25.03', experienceKey) ? await ((_this$newVCObserver3 = this.newVCObserver) === null || _this$newVCObserver3 === void 0 ? void 0 : _this$newVCObserver3.getVCResult({
@@ -106,6 +107,7 @@ export class VCObserverWrapper {
106
107
  ssr: param.includeSSRInV3 ? param.ssr : undefined,
107
108
  include3p,
108
109
  excludeSmartAnswersInSearch,
110
+ includeSSRRatio,
109
111
  interactionType: param.interactionType,
110
112
  isPageVisible: param.isPageVisible,
111
113
  interactionAbortReason: param.interactionAbortReason
@@ -113,7 +115,11 @@ export class VCObserverWrapper {
113
115
  if (!v3Result) {
114
116
  return v1v2Result !== null && v1v2Result !== void 0 ? v1v2Result : {};
115
117
  }
118
+ const ssrRatio = v3Result[0].ssrRatio;
116
119
  return {
120
+ ...(includeSSRRatio && ssrRatio !== undefined ? {
121
+ 'ufo:vc:ssrRatio': ssrRatio
122
+ } : {}),
117
123
  ...v1v2Result,
118
124
  'ufo:vc:rev': [...((_ref = v1v2Result === null || v1v2Result === void 0 ? void 0 : v1v2Result['ufo:vc:rev']) !== null && _ref !== void 0 ? _ref : []), ...(v3Result !== null && v3Result !== void 0 ? v3Result : [])]
119
125
  };
@@ -200,6 +200,7 @@ export default class VCObserverNew {
200
200
  interactionAbortReason,
201
201
  isPageVisible,
202
202
  include3p,
203
+ includeSSRRatio,
203
204
  excludeSmartAnswersInSearch
204
205
  } = param;
205
206
  const results = [];
@@ -221,6 +222,7 @@ export default class VCObserverNew {
221
222
  isPostInteraction: this.isPostInteraction,
222
223
  include3p,
223
224
  excludeSmartAnswersInSearch,
225
+ includeSSRRatio,
224
226
  isPageVisible,
225
227
  interactionAbortReason
226
228
  });
@@ -239,6 +241,7 @@ export default class VCObserverNew {
239
241
  interactionType,
240
242
  isPostInteraction: this.isPostInteraction,
241
243
  include3p,
244
+ includeSSRRatio,
242
245
  isPageVisible,
243
246
  interactionAbortReason
244
247
  });
@@ -52,7 +52,7 @@ export default class AbstractVCCalculatorBase {
52
52
  }
53
53
  return labelStacks;
54
54
  }
55
- async calculateWithDebugInfo(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionType, isPageVisible, interactionId, dirtyReason, allEntries, include3p, excludeSmartAnswersInSearch, interactionAbortReason) {
55
+ async calculateWithDebugInfo(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionType, isPageVisible, interactionId, dirtyReason, allEntries, include3p, excludeSmartAnswersInSearch, interactionAbortReason, includeSSRRatio) {
56
56
  var _window, _window2, _window6, _window8;
57
57
  const percentiles = [25, 50, 75, 80, 85, 90, 95, 98, 99, 100];
58
58
  const viewportEntries = this.filterViewportEntries(filteredEntries);
@@ -68,6 +68,7 @@ export default class AbstractVCCalculatorBase {
68
68
  const vcDetails = {};
69
69
  let percentileIndex = 0;
70
70
  const entryDataBuffer = new Set();
71
+ let ssrRatio = -1;
71
72
  if (vcLogs) {
72
73
  for (const entry of vcLogs) {
73
74
  const {
@@ -75,6 +76,9 @@ export default class AbstractVCCalculatorBase {
75
76
  viewportPercentage,
76
77
  entries
77
78
  } = entry;
79
+ if (includeSSRRatio && ssrRatio === -1 && entries.some(e => e.elementName === 'SSR') && fg('platform_report_ssr_ratio_in_v3')) {
80
+ ssrRatio = viewportPercentage / 100;
81
+ }
78
82
 
79
83
  // Only process entries if we haven't reached all percentiles
80
84
  if (percentileIndex >= percentiles.length) {
@@ -247,7 +251,10 @@ export default class AbstractVCCalculatorBase {
247
251
  console.error('Error in 3pDebugData', e);
248
252
  }
249
253
  }
250
- return vcDetails;
254
+ return {
255
+ vcDetails,
256
+ ssrRatio
257
+ };
251
258
  }
252
259
  async calculate({
253
260
  startTime,
@@ -257,6 +264,7 @@ export default class AbstractVCCalculatorBase {
257
264
  isPostInteraction,
258
265
  include3p,
259
266
  excludeSmartAnswersInSearch,
267
+ includeSSRRatio,
260
268
  interactionType,
261
269
  isPageVisible,
262
270
  interactionAbortReason
@@ -279,7 +287,10 @@ export default class AbstractVCCalculatorBase {
279
287
  abortTimestamp: getVCCleanStatusResult.abortTimestamp
280
288
  };
281
289
  }
282
- const vcDetails = await this.calculateWithDebugInfo(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionType, isPageVisible, interactionId, dirtyReason, orderedEntries, include3p, excludeSmartAnswersInSearch, interactionAbortReason);
290
+ const {
291
+ vcDetails,
292
+ ssrRatio
293
+ } = await this.calculateWithDebugInfo(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionType, isPageVisible, interactionId, dirtyReason, orderedEntries, include3p, excludeSmartAnswersInSearch, interactionAbortReason, includeSSRRatio);
283
294
  const result = {
284
295
  revision: this.revisionNo,
285
296
  clean: true,
@@ -287,6 +298,9 @@ export default class AbstractVCCalculatorBase {
287
298
  vcDetails: vcDetails !== null && vcDetails !== void 0 ? vcDetails : undefined
288
299
  };
289
300
  result.ratios = this.calculateRatios(filteredEntries);
301
+ if (ssrRatio !== -1) {
302
+ result.ssrRatio = ssrRatio;
303
+ }
290
304
  if (isPostInteraction) {
291
305
  result.labelStacks = this.getLabelStacks(filteredEntries);
292
306
  }
@@ -24,13 +24,13 @@ import { optimizeReactProfilerTimings } from '../create-payload/utils/optimize-r
24
24
  import { optimizeRequestInfo } from '../create-payload/utils/optimize-request-info';
25
25
  import { optimizeSpans } from '../create-payload/utils/optimize-spans';
26
26
  import { interactionSpans as atlaskitInteractionSpans } from '../interaction-metrics';
27
- function createInteractionExtraLogPayload(_x, _x2) {
27
+ function createInteractionExtraLogPayload(_x, _x2, _x3, _x4) {
28
28
  return _createInteractionExtraLogPayload.apply(this, arguments);
29
29
  }
30
30
  function _createInteractionExtraLogPayload() {
31
- _createInteractionExtraLogPayload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(interactionId, interaction) {
32
- var _getTTAI, _window$location;
33
- var config, end, start, ufoName, rate, type, abortReason, routeName, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, knownSegments, sanitisedUfoName, configRate, pageVisibilityAtTTAI, isPageLoad, calculatePageVisibilityFromTheStartOfPageLoad, moreAccuratePageVisibilityAtTTAI, extraTTAI, newUFOName, finalVCMetrics, vcRevisionPayload, effectiveVCRevisionPayload, isThirdParty, filteredData, getDetailedInteractionMetrics, segments3p, segmentTree, payload;
31
+ _createInteractionExtraLogPayload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(interactionId, interaction, lastInteractionFinish, lastInteractionFinishVCResult) {
32
+ var _getTTAI, _lastInteractionFinis, _getTTAI2, _window$location;
33
+ var config, end, start, ufoName, rate, type, abortReason, routeName, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, knownSegments, minorInteractions, sanitisedUfoName, configRate, pageVisibilityAtTTAI, isPageLoad, calculatePageVisibilityFromTheStartOfPageLoad, moreAccuratePageVisibilityAtTTAI, extraTTAI, newUFOName, finalVCMetrics, vcRevisionPayload, effectiveVCRevisionPayload, normalTTAI, lastInteractionFinishStart, lastInteractionFinishEnd, lastInteractionFinishVC90, lastInteractionFinishVCClean, lastInteractionFinishVCRev, lastInteractionFinishRevision, isThirdParty, filteredData, getDetailedInteractionMetrics, segments3p, segmentTree, payload;
34
34
  return _regeneratorRuntime.wrap(function _callee$(_context) {
35
35
  while (1) switch (_context.prev = _context.next) {
36
36
  case 0:
@@ -41,7 +41,7 @@ function _createInteractionExtraLogPayload() {
41
41
  }
42
42
  throw Error('UFO Configuration not provided');
43
43
  case 3:
44
- end = interaction.end, start = interaction.start, ufoName = interaction.ufoName, rate = interaction.rate, type = interaction.type, abortReason = interaction.abortReason, routeName = interaction.routeName, previousInteractionName = interaction.previousInteractionName, isPreviousInteractionAborted = interaction.isPreviousInteractionAborted, abortedByInteractionName = interaction.abortedByInteractionName, knownSegments = interaction.knownSegments;
44
+ end = interaction.end, start = interaction.start, ufoName = interaction.ufoName, rate = interaction.rate, type = interaction.type, abortReason = interaction.abortReason, routeName = interaction.routeName, previousInteractionName = interaction.previousInteractionName, isPreviousInteractionAborted = interaction.isPreviousInteractionAborted, abortedByInteractionName = interaction.abortedByInteractionName, knownSegments = interaction.knownSegments, minorInteractions = interaction.minorInteractions;
45
45
  sanitisedUfoName = sanitizeUfoName(ufoName);
46
46
  configRate = getExtraInteractionRate(sanitisedUfoName, type);
47
47
  if (coinflip(configRate)) {
@@ -52,7 +52,7 @@ function _createInteractionExtraLogPayload() {
52
52
  case 8:
53
53
  pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
54
54
  isPageLoad = type === 'page_load' || type === 'transition';
55
- if (isPageLoad) {
55
+ if (!(!isPageLoad || minorInteractions !== undefined && minorInteractions.length > 0)) {
56
56
  _context.next = 12;
57
57
  break;
58
58
  }
@@ -78,6 +78,46 @@ function _createInteractionExtraLogPayload() {
78
78
  }
79
79
  return _context.abrupt("return", null);
80
80
  case 23:
81
+ if (!(!lastInteractionFinish || lastInteractionFinish !== null && lastInteractionFinish !== void 0 && lastInteractionFinish.abortReason || lastInteractionFinish !== null && lastInteractionFinish !== void 0 && (_lastInteractionFinis = lastInteractionFinish.errors) !== null && _lastInteractionFinis !== void 0 && _lastInteractionFinis.length)) {
82
+ _context.next = 25;
83
+ break;
84
+ }
85
+ return _context.abrupt("return", null);
86
+ case 25:
87
+ normalTTAI = (_getTTAI2 = getTTAI(lastInteractionFinish)) !== null && _getTTAI2 !== void 0 ? _getTTAI2 : undefined;
88
+ lastInteractionFinishStart = typeof lastInteractionFinish.start === 'number' ? Math.round(lastInteractionFinish.start) : undefined;
89
+ lastInteractionFinishEnd = typeof lastInteractionFinish.end === 'number' ? Math.round(lastInteractionFinish.end) : undefined;
90
+ lastInteractionFinishVC90 = null;
91
+ lastInteractionFinishVCClean = false;
92
+ if (!lastInteractionFinishVCResult) {
93
+ _context.next = 41;
94
+ break;
95
+ }
96
+ lastInteractionFinishVCRev = lastInteractionFinishVCResult['ufo:vc:rev'];
97
+ lastInteractionFinishRevision = lastInteractionFinishVCRev === null || lastInteractionFinishVCRev === void 0 ? void 0 : lastInteractionFinishVCRev.find(function (_ref2) {
98
+ var revision = _ref2.revision;
99
+ return revision === DEFAULT_TTVC_REVISION;
100
+ });
101
+ if (!(lastInteractionFinishRevision !== null && lastInteractionFinishRevision !== void 0 && lastInteractionFinishRevision.clean)) {
102
+ _context.next = 38;
103
+ break;
104
+ }
105
+ lastInteractionFinishVCClean = true;
106
+ lastInteractionFinishVC90 = lastInteractionFinishRevision['metric:vc90'];
107
+ _context.next = 39;
108
+ break;
109
+ case 38:
110
+ return _context.abrupt("return", null);
111
+ case 39:
112
+ _context.next = 42;
113
+ break;
114
+ case 41:
115
+ if (normalTTAI !== undefined && typeof normalTTAI === 'number' && normalTTAI === extraTTAI) {
116
+ // Because TTAI is equal between with and without 3p, we can assume VC90 is also equal
117
+ lastInteractionFinishVC90 = effectiveVCRevisionPayload === null || effectiveVCRevisionPayload === void 0 ? void 0 : effectiveVCRevisionPayload['metric:vc90'];
118
+ lastInteractionFinishVCClean = effectiveVCRevisionPayload === null || effectiveVCRevisionPayload === void 0 ? void 0 : effectiveVCRevisionPayload.clean;
119
+ }
120
+ case 42:
81
121
  // Helper function to check if labelStack contains third-party type
82
122
  isThirdParty = function isThirdParty(labelStack) {
83
123
  var _labelStack$some;
@@ -120,9 +160,9 @@ function _createInteractionExtraLogPayload() {
120
160
  getDetailedInteractionMetrics = function getDetailedInteractionMetrics() {
121
161
  var _interaction$hold3pIn;
122
162
  return {
123
- errors: filteredData.errors.map(function (_ref2) {
124
- var labelStack = _ref2.labelStack,
125
- others = _objectWithoutProperties(_ref2, _excluded);
163
+ errors: filteredData.errors.map(function (_ref3) {
164
+ var labelStack = _ref3.labelStack,
165
+ others = _objectWithoutProperties(_ref3, _excluded);
126
166
  return _objectSpread(_objectSpread({}, others), {}, {
127
167
  labelStack: labelStack && optimizeLabelStack(labelStack, getReactUFOPayloadVersion(interaction.type))
128
168
  });
@@ -183,13 +223,20 @@ function _createInteractionExtraLogPayload() {
183
223
  reactProfilerTimings: optimizeReactProfilerTimings(filteredData.reactProfilerTimings, start, getReactUFOPayloadVersion(interaction.type)),
184
224
  customData: filteredData.customData
185
225
  }, getDetailedInteractionMetrics()),
186
- 'vc:effective:revision': DEFAULT_TTVC_REVISION
226
+ 'vc:effective:revision': DEFAULT_TTVC_REVISION,
227
+ lastInteractionFinish: {
228
+ start: lastInteractionFinishStart,
229
+ end: lastInteractionFinishEnd,
230
+ ttai: normalTTAI,
231
+ vc90: lastInteractionFinishVC90,
232
+ vcClean: lastInteractionFinishVCClean
233
+ }
187
234
  }
188
235
  }
189
236
  };
190
237
  payload.attributes.properties['event:sizeInKb'] = getPayloadSize(payload.attributes.properties);
191
238
  return _context.abrupt("return", payload);
192
- case 32:
239
+ case 51:
193
240
  case "end":
194
241
  return _context.stop();
195
242
  }
@@ -4,7 +4,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  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; }
5
5
  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; }
6
6
  import { getConfig, getMostRecentVCRevision } from '../../config';
7
- import { postInteractionLog } from '../../interaction-metrics';
7
+ import { interactionExtraMetrics, postInteractionLog } from '../../interaction-metrics';
8
8
  import getInteractionStatus from './get-interaction-status';
9
9
  import getPageVisibilityUpToTTAI from './get-page-visibility-up-to-ttai';
10
10
  import getSSRDoneTimeValue from './get-ssr-done-time-value';
@@ -90,6 +90,7 @@ function _getVCMetrics() {
90
90
  if (!include3p) {
91
91
  // For Post Interaction, last interaction should be without 3p
92
92
  postInteractionLog.setLastInteractionFinishVCResult(result);
93
+ interactionExtraMetrics.setLastInteractionFinishVCResult(result);
93
94
  }
94
95
  mostRecentVCRevision = getMostRecentVCRevision(interaction.ufoName);
95
96
  mostRecentVCRevisionPayload = result === null || result === void 0 || (_result$ufoVcRev = result['ufo:vc:rev']) === null || _result$ufoVcRev === void 0 ? void 0 : _result$ufoVcRev.find(function (_ref) {
@@ -688,7 +688,8 @@ function finishInteraction(id, data) {
688
688
  PreviousInteractionLog.isAborted = data.abortReason != null;
689
689
  if (data.ufoName) {
690
690
  if (fg('platform_ufo_enable_ttai_with_3p')) {
691
- if (interactionExtraMetrics.finishedInteractionId !== id) {
691
+ var _interactionExtraMetr;
692
+ if (((_interactionExtraMetr = interactionExtraMetrics.finishedInteraction) === null || _interactionExtraMetr === void 0 ? void 0 : _interactionExtraMetr.id) !== id) {
692
693
  // If this same interaction was not already handled, handle it
693
694
  handleInteraction(id, data);
694
695
  }
@@ -773,7 +774,7 @@ export function tryComplete(interactionId, endTime) {
773
774
  var postInteraction = /*#__PURE__*/function () {
774
775
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
775
776
  var _getConfig7;
776
- var _getConfig8, experimentalVC90, experimentalTTAI, _yield$getExperimenta, start, end, _getConfig9, _getConfig0;
777
+ var _getConfig8, experimentalVC90, experimentalTTAI, _yield$getExperimenta, start, end, _interactionExtraMetr2, _getConfig9, _getConfig0;
777
778
  return _regeneratorRuntime.wrap(function _callee$(_context) {
778
779
  while (1) switch (_context.prev = _context.next) {
779
780
  case 0:
@@ -816,7 +817,7 @@ export function tryComplete(interactionId, endTime) {
816
817
  }));
817
818
  case 17:
818
819
  if (fg('platform_ufo_enable_ttai_with_3p')) {
819
- if (interactionExtraMetrics.finishedInteractionId !== interactionId) {
820
+ if (((_interactionExtraMetr2 = interactionExtraMetrics.finishedInteraction) === null || _interactionExtraMetr2 === void 0 ? void 0 : _interactionExtraMetr2.id) !== interactionId) {
820
821
  // If interactionExtraMetrics is not waiting for measuring this interaction
821
822
  if ((_getConfig9 = getConfig()) !== null && _getConfig9 !== void 0 && (_getConfig9 = _getConfig9.experimentalInteractionMetrics) !== null && _getConfig9 !== void 0 && _getConfig9.enabled) {
822
823
  remove(interactionId);
@@ -839,15 +840,15 @@ export function tryComplete(interactionId, endTime) {
839
840
  };
840
841
  }();
841
842
  if (fg('platform_ufo_enable_ttai_with_3p')) {
842
- var _interaction$hold3pAc;
843
+ var _interaction$hold3pAc, _interactionExtraMetr3;
843
844
  var noMoreActive3pHolds = ((_interaction$hold3pAc = interaction.hold3pActive) === null || _interaction$hold3pAc === void 0 ? void 0 : _interaction$hold3pAc.size) === 0 || interaction.hold3pActive === undefined;
844
- if (noMoreActiveHolds && interactionExtraMetrics.finishedInteractionId !== interactionId) {
845
+ if (noMoreActiveHolds && ((_interactionExtraMetr3 = interactionExtraMetrics.finishedInteraction) === null || _interactionExtraMetr3 === void 0 ? void 0 : _interactionExtraMetr3.id) !== interactionId) {
845
846
  // If it's not waiting for extra metrics to complete, finish the interaction as normal
846
847
  if (!activeSubmitted) {
847
848
  var _getConfig1, _getConfig10, _getConfig11;
848
849
  finishInteraction(interactionId, interaction, endTime);
849
850
  if ((_getConfig1 = getConfig()) !== null && _getConfig1 !== void 0 && (_getConfig1 = _getConfig1.extraInteractionMetrics) !== null && _getConfig1 !== void 0 && _getConfig1.enabled) {
850
- interactionExtraMetrics.updateFinishedInteractionId(interactionId);
851
+ interactionExtraMetrics.updateFinishedInteraction(interaction);
851
852
  }
852
853
  if ((_getConfig10 = getConfig()) !== null && _getConfig10 !== void 0 && (_getConfig10 = _getConfig10.extraSearchPageInteraction) !== null && _getConfig10 !== void 0 && _getConfig10.enabled && interaction.ufoName === ((_getConfig11 = getConfig()) === null || _getConfig11 === void 0 || (_getConfig11 = _getConfig11.extraSearchPageInteraction) === null || _getConfig11 === void 0 ? void 0 : _getConfig11.searchPageMetricName) && fg('react_ufo_unified_search_ignoring_sain_metric')) {
853
854
  onSearchPageInteractionComplete(interactionId, interaction);
@@ -9,8 +9,8 @@ import { remove } from './index';
9
9
  var InteractionExtraMetrics = /*#__PURE__*/function () {
10
10
  function InteractionExtraMetrics() {
11
11
  _classCallCheck(this, InteractionExtraMetrics);
12
- // Store the finished interaction ID (as non-3p interaction)
13
- _defineProperty(this, "finishedInteractionId", null);
12
+ // Store the finished interaction (as non-3p interaction)
13
+ _defineProperty(this, "finishedInteraction", null);
14
14
  // independent VC observer, that observes until `custom.post-interaction-logs` event is sent
15
15
  _defineProperty(this, "vcObserver", null);
16
16
  _defineProperty(this, "sinkHandlerFn", function () {});
@@ -48,12 +48,17 @@ var InteractionExtraMetrics = /*#__PURE__*/function () {
48
48
  return (interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'page_load' || (interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'transition';
49
49
  }
50
50
  }, {
51
- key: "updateFinishedInteractionId",
52
- value: function updateFinishedInteractionId(interactionId) {
53
- if (this.eligibleToMeasure(interactionId)) {
54
- this.finishedInteractionId = interactionId;
51
+ key: "updateFinishedInteraction",
52
+ value: function updateFinishedInteraction(interaction) {
53
+ if ((interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'page_load' || (interaction === null || interaction === void 0 ? void 0 : interaction.type) === 'transition') {
54
+ this.finishedInteraction = interaction;
55
55
  }
56
56
  }
57
+ }, {
58
+ key: "setLastInteractionFinishVCResult",
59
+ value: function setLastInteractionFinishVCResult(result) {
60
+ this.lastInteractionFinishVCResult = result;
61
+ }
57
62
  }, {
58
63
  key: "sinkHandler",
59
64
  value: function sinkHandler(fn) {
@@ -67,7 +72,7 @@ var InteractionExtraMetrics = /*#__PURE__*/function () {
67
72
  var updatedData = _objectSpread(_objectSpread({}, data), {}, {
68
73
  vcObserver: (_this$vcObserver3 = this.vcObserver) !== null && _this$vcObserver3 !== void 0 ? _this$vcObserver3 : undefined
69
74
  });
70
- this.sinkHandlerFn(id, updatedData);
75
+ this.sinkHandlerFn(id, updatedData, this.finishedInteraction, this.lastInteractionFinishVCResult);
71
76
  }
72
77
  this.stopVCObserver();
73
78
  remove(id);
@@ -76,11 +81,13 @@ var InteractionExtraMetrics = /*#__PURE__*/function () {
76
81
  }, {
77
82
  key: "reset",
78
83
  value: function reset() {
84
+ var _this$finishedInterac;
79
85
  this.stopVCObserver();
80
- if (this.finishedInteractionId) {
81
- remove(this.finishedInteractionId);
86
+ if ((_this$finishedInterac = this.finishedInteraction) !== null && _this$finishedInterac !== void 0 && _this$finishedInterac.id) {
87
+ remove(this.finishedInteraction.id);
82
88
  }
83
- this.finishedInteractionId = null;
89
+ this.finishedInteraction = null;
90
+ this.lastInteractionFinishVCResult = undefined;
84
91
  }
85
92
  }, {
86
93
  key: "stopAll",
@@ -73,14 +73,14 @@ function sinkPostInteractionLog(instance, createPostInteractionLogPayload) {
73
73
  });
74
74
  }
75
75
  function sinkInteractionExtraMetrics(instance, createInteractionExtraLogPayload) {
76
- interactionExtraMetrics.sinkHandler(function (interactionId, interaction) {
76
+ interactionExtraMetrics.sinkHandler(function (interactionId, interaction, lastInteractionFinish, lastInteractionFinishVCResult) {
77
77
  scheduleIdleCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
78
78
  var payload, devToolObserver;
79
79
  return _regeneratorRuntime.wrap(function _callee$(_context) {
80
80
  while (1) switch (_context.prev = _context.next) {
81
81
  case 0:
82
82
  _context.next = 2;
83
- return createInteractionExtraLogPayload(interactionId, interaction);
83
+ return createInteractionExtraLogPayload(interactionId, interaction, lastInteractionFinish, lastInteractionFinishVCResult);
84
84
  case 2:
85
85
  payload = _context.sent;
86
86
  if (payload) {