@atlaskit/react-ufo 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/custom-cohort-data/package.json +15 -0
  3. package/dist/cjs/create-payload/critical-metrics-payload/index.js +5 -2
  4. package/dist/cjs/create-payload/critical-metrics-payload/root-metrics.js +13 -7
  5. package/dist/cjs/create-payload/critical-metrics-payload/segment-metrics/create-segment-metrics.js +25 -18
  6. package/dist/cjs/custom-cohort-data/index.js +37 -0
  7. package/dist/cjs/custom-cohort-data/types.js +1 -0
  8. package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +10 -13
  9. package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/{get-component-name-and-child-props.js → check-within-component-and-extract-child-props.js} +6 -39
  10. package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/find-react-fiber.js +16 -0
  11. package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/get-component-name.js +19 -0
  12. package/dist/es2019/create-payload/critical-metrics-payload/index.js +3 -2
  13. package/dist/es2019/create-payload/critical-metrics-payload/root-metrics.js +4 -0
  14. package/dist/es2019/create-payload/critical-metrics-payload/segment-metrics/create-segment-metrics.js +4 -0
  15. package/dist/es2019/custom-cohort-data/index.js +30 -0
  16. package/dist/es2019/custom-cohort-data/types.js +0 -0
  17. package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +7 -11
  18. package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/{get-component-name-and-child-props.js → check-within-component-and-extract-child-props.js} +4 -31
  19. package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/find-react-fiber.js +10 -0
  20. package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/get-component-name.js +11 -0
  21. package/dist/esm/create-payload/critical-metrics-payload/index.js +5 -2
  22. package/dist/esm/create-payload/critical-metrics-payload/root-metrics.js +13 -7
  23. package/dist/esm/create-payload/critical-metrics-payload/segment-metrics/create-segment-metrics.js +25 -18
  24. package/dist/esm/custom-cohort-data/index.js +29 -0
  25. package/dist/esm/custom-cohort-data/types.js +0 -0
  26. package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +10 -13
  27. package/dist/esm/vc/vc-observer-new/viewport-observer/utils/{get-component-name-and-child-props.js → check-within-component-and-extract-child-props.js} +4 -34
  28. package/dist/esm/vc/vc-observer-new/viewport-observer/utils/find-react-fiber.js +10 -0
  29. package/dist/esm/vc/vc-observer-new/viewport-observer/utils/get-component-name.js +12 -0
  30. package/dist/types/create-payload/critical-metrics-payload/root-metrics.d.ts +1 -1
  31. package/dist/types/custom-cohort-data/index.d.ts +4 -0
  32. package/dist/types/custom-cohort-data/types.d.ts +4 -0
  33. package/dist/types/vc/vc-observer-new/viewport-observer/utils/check-within-component-and-extract-child-props.d.ts +8 -0
  34. package/dist/types/vc/vc-observer-new/viewport-observer/utils/find-react-fiber.d.ts +1 -0
  35. package/dist/types/vc/vc-observer-new/viewport-observer/utils/get-component-name.d.ts +1 -0
  36. package/dist/types-ts4.5/create-payload/critical-metrics-payload/root-metrics.d.ts +1 -1
  37. package/dist/types-ts4.5/custom-cohort-data/index.d.ts +4 -0
  38. package/dist/types-ts4.5/custom-cohort-data/types.d.ts +4 -0
  39. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/check-within-component-and-extract-child-props.d.ts +8 -0
  40. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/find-react-fiber.d.ts +1 -0
  41. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/get-component-name.d.ts +1 -0
  42. package/package.json +5 -1
  43. package/dist/types/vc/vc-observer-new/viewport-observer/utils/get-component-name-and-child-props.d.ts +0 -15
  44. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/get-component-name-and-child-props.d.ts +0 -15
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/ufo-interaction-ignore
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#185569](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/185569)
8
+ [`1c7b682d3bd6a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1c7b682d3bd6a) -
9
+ Adds UFOCustomCohortData component and addUFOCustomCohortData function to separate cohorting data
10
+ (important for analytics) from general debugging data.
11
+
12
+ ## 4.0.3
13
+
14
+ ### Patch Changes
15
+
16
+ - [#186813](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/186813)
17
+ [`b0dd8177f1f10`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b0dd8177f1f10) -
18
+ HOT-119287 only produce critical metrics for root and successful interaction
19
+
3
20
  ## 4.0.2
4
21
 
5
22
  ### Patch Changes
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/react-ufo/custom-cohort-data",
3
+ "main": "../dist/cjs/custom-cohort-data/index.js",
4
+ "module": "../dist/esm/custom-cohort-data/index.js",
5
+ "module:es2019": "../dist/es2019/custom-cohort-data/index.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/custom-cohort-data/index.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <5.4": {
10
+ "*": [
11
+ "../dist/types-ts4.5/custom-cohort-data/index.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -9,6 +9,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _rootMetrics = require("./root-metrics");
13
14
  var _createSegmentMetrics = require("./segment-metrics/create-segment-metrics");
14
15
  function createCriticalMetricsPayloads(_x, _x2, _x3) {
@@ -21,13 +22,15 @@ function _createCriticalMetricsPayloads() {
21
22
  while (1) switch (_context.prev = _context.next) {
22
23
  case 0:
23
24
  _context.next = 2;
24
- return Promise.all([(0, _rootMetrics.createRootCriticalMetricsPayload)(interactionId, interaction, vcMetrics), (0, _createSegmentMetrics.createSegmentMetricsPayloads)(interactionId, interaction)]);
25
+ return Promise.all([(0, _rootMetrics.createRootCriticalMetricsPayload)(interactionId, interaction, vcMetrics), (0, _platformFeatureFlags.fg)('platform_ufo_segment_critical_metrics') ? (0, _createSegmentMetrics.createSegmentMetricsPayloads)(interactionId, interaction) : []]);
25
26
  case 2:
26
27
  _yield$Promise$all = _context.sent;
27
28
  _yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 2);
28
29
  rootPayload = _yield$Promise$all2[0];
29
30
  segmentPayloads = _yield$Promise$all2[1];
30
- return _context.abrupt("return", [rootPayload].concat((0, _toConsumableArray2.default)(segmentPayloads)));
31
+ return _context.abrupt("return", [rootPayload].concat((0, _toConsumableArray2.default)(segmentPayloads)).filter(function (v) {
32
+ return v != null;
33
+ }));
31
34
  case 7:
32
35
  case "end":
33
36
  return _context.stop();
@@ -57,11 +57,17 @@ function _createRootCriticalMetricsPayload() {
57
57
  pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
58
58
  pageVisibilityAtTTAI = (0, _getPageVisibilityUpToTtai.default)(interaction);
59
59
  interactionStatus = (0, _getInteractionStatus.default)(interaction);
60
+ if (!(interactionStatus.originalInteractionStatus !== 'SUCCEEDED')) {
61
+ _context.next = 9;
62
+ break;
63
+ }
64
+ return _context.abrupt("return", null);
65
+ case 9:
60
66
  newUFOName = (0, _utils.sanitizeUfoName)(ufoName); // Get performance metrics
61
67
  ttai = (0, _getTtai.default)(interaction);
62
- _context.next = 11;
68
+ _context.next = 13;
63
69
  return (0, _getPaintMetrics.default)(type, end);
64
- case 11:
70
+ case 13:
65
71
  paintMetrics = _context.sent;
66
72
  navigationMetrics = (0, _getNavigationMetrics.default)(type);
67
73
  ssrSuccess = (0, _getSsrSuccess.default)(type); // Calculate BM3 metrics (TTI and FMP) directly
@@ -74,14 +80,14 @@ function _createRootCriticalMetricsPayload() {
74
80
  }); // Use provided vcMetrics or calculate if not provided
75
81
  _context.t0 = vcMetrics;
76
82
  if (_context.t0) {
77
- _context.next = 23;
83
+ _context.next = 25;
78
84
  break;
79
85
  }
80
- _context.next = 22;
86
+ _context.next = 24;
81
87
  return (0, _getVcMetrics.default)(interaction);
82
- case 22:
88
+ case 24:
83
89
  _context.t0 = _context.sent;
84
- case 23:
90
+ case 25:
85
91
  finalVCMetrics = _context.t0;
86
92
  ttvc = (_finalVCMetrics$ufoV = finalVCMetrics['ufo:vc:rev']) === null || _finalVCMetrics$ufoV === void 0 ? void 0 : _finalVCMetrics$ufoV.map(function (revision) {
87
93
  if (revision['metric:vc90'] === null || revision.clean !== true) {
@@ -170,7 +176,7 @@ function _createRootCriticalMetricsPayload() {
170
176
  }
171
177
  };
172
178
  return _context.abrupt("return", payload);
173
- case 30:
179
+ case 32:
174
180
  case "end":
175
181
  return _context.stop();
176
182
  }
@@ -26,7 +26,7 @@ function createSegmentMetricsPayloads(_x, _x2) {
26
26
  function _createSegmentMetricsPayloads() {
27
27
  _createSegmentMetricsPayloads = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(interactionId, interaction) {
28
28
  var _interaction$cohortin;
29
- var config, browserMetadata, cohortingCustomData, pageVisibilityAtTTAI, knownSegments, reactProfilerTimings, rate, routeName, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, segmentsByName, _iterator, _step, _loop, _ret, payloads, _iterator2, _step2, _loop2;
29
+ var config, browserMetadata, cohortingCustomData, pageVisibilityAtTTAI, knownSegments, reactProfilerTimings, rate, routeName, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, segmentsByName, _iterator, _step, _loop, _ret, payloads, _iterator2, _step2, _loop2, _ret2;
30
30
  return _regenerator.default.wrap(function _callee$(_context3) {
31
31
  while (1) switch (_context3.prev = _context3.next) {
32
32
  case 0:
@@ -148,13 +148,19 @@ function _createSegmentMetricsPayloads() {
148
148
  _context2.next = 8;
149
149
  break;
150
150
  }
151
- return _context2.abrupt("return", 1);
151
+ return _context2.abrupt("return", 0);
152
152
  case 8:
153
153
  lastTiming = segmentProfilerTimings[segmentProfilerTimings.length - 1];
154
154
  startTime = isRootSegment ? interaction.start : firstMountTiming.startTime;
155
155
  endTime = lastTiming.commitTime;
156
156
  ttai = Math.round(endTime - startTime);
157
157
  _getSegmentStatus = (0, _getSegmentStatus2.default)(interaction, segment), status = _getSegmentStatus.status, segmentAbortReason = _getSegmentStatus.abortReason;
158
+ if (!(status !== 'SUCCEEDED')) {
159
+ _context2.next = 15;
160
+ break;
161
+ }
162
+ return _context2.abrupt("return", 0);
163
+ case 15:
158
164
  properties = _objectSpread({
159
165
  // Basic metadata
160
166
  'event:hostname': ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || 'unknown',
@@ -206,7 +212,7 @@ function _createSegmentMetricsPayloads() {
206
212
  }
207
213
  };
208
214
  payloads.push(payload);
209
- case 16:
215
+ case 18:
210
216
  case "end":
211
217
  return _context2.stop();
212
218
  }
@@ -215,37 +221,38 @@ function _createSegmentMetricsPayloads() {
215
221
  _iterator2.s();
216
222
  case 32:
217
223
  if ((_step2 = _iterator2.n()).done) {
218
- _context3.next = 38;
224
+ _context3.next = 39;
219
225
  break;
220
226
  }
221
227
  return _context3.delegateYield(_loop2(), "t2", 34);
222
228
  case 34:
223
- if (!_context3.t2) {
224
- _context3.next = 36;
229
+ _ret2 = _context3.t2;
230
+ if (!(_ret2 === 0)) {
231
+ _context3.next = 37;
225
232
  break;
226
233
  }
227
- return _context3.abrupt("continue", 36);
228
- case 36:
234
+ return _context3.abrupt("continue", 37);
235
+ case 37:
229
236
  _context3.next = 32;
230
237
  break;
231
- case 38:
232
- _context3.next = 43;
238
+ case 39:
239
+ _context3.next = 44;
233
240
  break;
234
- case 40:
235
- _context3.prev = 40;
241
+ case 41:
242
+ _context3.prev = 41;
236
243
  _context3.t3 = _context3["catch"](29);
237
244
  _iterator2.e(_context3.t3);
238
- case 43:
239
- _context3.prev = 43;
245
+ case 44:
246
+ _context3.prev = 44;
240
247
  _iterator2.f();
241
- return _context3.finish(43);
242
- case 46:
243
- return _context3.abrupt("return", payloads);
248
+ return _context3.finish(44);
244
249
  case 47:
250
+ return _context3.abrupt("return", payloads);
251
+ case 48:
245
252
  case "end":
246
253
  return _context3.stop();
247
254
  }
248
- }, _callee, null, [[9, 21, 24, 27], [29, 40, 43, 46]]);
255
+ }, _callee, null, [[9, 21, 24, 27], [29, 41, 44, 47]]);
249
256
  }));
250
257
  return _createSegmentMetricsPayloads.apply(this, arguments);
251
258
  }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.addUFOCustomCohortData = addUFOCustomCohortData;
8
+ exports.default = UFOCustomCohortData;
9
+ var _react = require("react");
10
+ var _interactionContext = _interopRequireDefault(require("../interaction-context"));
11
+ var _interactionIdContext = require("../interaction-id-context");
12
+ var _interactionMetrics = require("../interaction-metrics");
13
+ function UFOCustomCohortData(_ref) {
14
+ var dataKey = _ref.dataKey,
15
+ value = _ref.value;
16
+ var interactionContext = (0, _react.useContext)(_interactionContext.default);
17
+ (0, _react.useMemo)(function () {
18
+ if (!interactionContext) {
19
+ return;
20
+ }
21
+ var interactionId = (0, _interactionIdContext.getInteractionId)();
22
+ var currentInteractionId = interactionId.current;
23
+ if (!currentInteractionId) {
24
+ return;
25
+ }
26
+ (0, _interactionMetrics.addCohortingCustomData)(currentInteractionId, dataKey, value);
27
+ }, [dataKey, value, interactionContext]);
28
+ return null;
29
+ }
30
+ function addUFOCustomCohortData(key, value) {
31
+ var interactionId = (0, _interactionIdContext.getInteractionId)();
32
+ var currentInteractionId = interactionId.current;
33
+ if (!currentInteractionId) {
34
+ return;
35
+ }
36
+ (0, _interactionMetrics.addCohortingCustomData)(currentInteractionId, key, value);
37
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -17,7 +17,7 @@ var _rllPlaceholders = require("../../vc-observer/observers/rll-placeholders");
17
17
  var _intersectionObserver = require("./intersection-observer");
18
18
  var _mutationObserver = _interopRequireDefault(require("./mutation-observer"));
19
19
  var _performanceObserver = _interopRequireDefault(require("./performance-observer"));
20
- var _getComponentNameAndChildProps = require("./utils/get-component-name-and-child-props");
20
+ var _checkWithinComponentAndExtractChildProps = _interopRequireDefault(require("./utils/check-within-component-and-extract-child-props"));
21
21
  var _isInVcIgnoreIfNoLayoutShiftMarker = _interopRequireDefault(require("./utils/is-in-vc-ignore-if-no-layout-shift-marker"));
22
22
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
23
23
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -125,7 +125,7 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
125
125
  _context2.prev = 4;
126
126
  _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
127
127
  var _this$intersectionObs8;
128
- var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, result, _this$intersectionObs3, _result, _this$intersectionObs4, sameDeletedNode, isInIgnoreLsMarker, isNoLsMarkerEnabled, _this$intersectionObs5, _this$intersectionObs6, _checkThirdPartySegme, isWithinThirdPartySegment, ignoredReason, _this$intersectionObs7, assignedReason;
128
+ var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, result, _this$intersectionObs3, _result, _this$intersectionObs4, sameDeletedNode, isInIgnoreLsMarker, isNoLsMarkerEnabled, _this$intersectionObs5, _this$intersectionObs6, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs7;
129
129
  return _regenerator.default.wrap(function _loop$(_context) {
130
130
  while (1) switch (_context.prev = _context.next) {
131
131
  case 0:
@@ -235,17 +235,16 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
235
235
  (_this$intersectionObs6 = _this.intersectionObserver) === null || _this$intersectionObs6 === void 0 || _this$intersectionObs6.watchAndTag(addedNode, 'mutation:media');
236
236
  return _context.abrupt("return", 0);
237
237
  case 45:
238
- _checkThirdPartySegme = (0, _getComponentNameAndChildProps.checkThirdPartySegmentWithIgnoreReason)(addedNode), isWithinThirdPartySegment = _checkThirdPartySegme.isWithinThirdPartySegment, ignoredReason = _checkThirdPartySegme.ignoredReason;
238
+ _checkWithinComponent = (0, _checkWithinComponentAndExtractChildProps.default)(addedNode, 'UFOThirdPartySegment'), isWithinThirdPartySegment = _checkWithinComponent.isWithin;
239
239
  if (!isWithinThirdPartySegment) {
240
- _context.next = 50;
240
+ _context.next = 49;
241
241
  break;
242
242
  }
243
- assignedReason = (0, _getComponentNameAndChildProps.createMutationTypeWithIgnoredReason)(ignoredReason || 'third-party-element');
244
- (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(addedNode, assignedReason);
243
+ (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(addedNode, 'mutation:third-party-element');
245
244
  return _context.abrupt("return", 0);
246
- case 50:
245
+ case 49:
247
246
  (_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
248
- case 51:
247
+ case 50:
249
248
  case "end":
250
249
  return _context.stop();
251
250
  }
@@ -333,13 +332,11 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
333
332
  }
334
333
  };
335
334
  }
336
- var _checkThirdPartySegme2 = (0, _getComponentNameAndChildProps.checkThirdPartySegmentWithIgnoreReason)(target),
337
- isWithinThirdPartySegment = _checkThirdPartySegme2.isWithinThirdPartySegment,
338
- ignoredReason = _checkThirdPartySegme2.ignoredReason;
335
+ var _checkWithinComponent2 = (0, _checkWithinComponentAndExtractChildProps.default)(target, 'UFOThirdPartySegment'),
336
+ isWithinThirdPartySegment = _checkWithinComponent2.isWithin;
339
337
  if (isWithinThirdPartySegment) {
340
- var assignedReason = (0, _getComponentNameAndChildProps.createMutationTypeWithIgnoredReason)(ignoredReason || 'third-party-element');
341
338
  return {
342
- type: assignedReason,
339
+ type: 'mutation:third-party-element',
343
340
  mutationData: {
344
341
  attributeName: attributeName,
345
342
  oldValue: oldValue,
@@ -4,22 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.checkThirdPartySegmentWithIgnoreReason = checkThirdPartySegmentWithIgnoreReason;
8
- exports.checkWithinComponentAndExtractChildProps = checkWithinComponentAndExtractChildProps;
9
- exports.createMutationTypeWithIgnoredReason = createMutationTypeWithIgnoredReason;
7
+ exports.default = checkWithinComponentAndExtractChildProps;
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
12
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
+ var _findReactFiber = _interopRequireDefault(require("./find-react-fiber"));
11
+ var _getComponentName = _interopRequireDefault(require("./get-component-name"));
13
12
  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; }
14
13
  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) { (0, _defineProperty2.default)(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; }
15
- // Helper function to find React fiber on an element
16
- var findReactFiber = function findReactFiber(element) {
17
- var key = Object.keys(element).find(function (key) {
18
- return key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$');
19
- });
20
- return key ? element[key] : null;
21
- };
22
-
23
14
  // Using the React Fiber tree to traverse up the DOM and check if a node is within a specific component
24
15
  // and extract child component props if needed.
25
16
  function checkWithinComponentAndExtractChildProps(node, targetComponentName, childComponentConfig) {
@@ -28,13 +19,13 @@ function checkWithinComponentAndExtractChildProps(node, targetComponentName, chi
28
19
  // Walk up the DOM tree to find React fiber (handles non-React-rendered elements)
29
20
  var currentElement = node;
30
21
  while (currentElement && !fiber) {
31
- fiber = findReactFiber(currentElement);
22
+ fiber = (0, _findReactFiber.default)(currentElement);
32
23
  if (!fiber) {
33
24
  currentElement = currentElement.parentElement;
34
25
  }
35
26
  }
36
27
  } else {
37
- fiber = findReactFiber(node);
28
+ fiber = (0, _findReactFiber.default)(node);
38
29
  }
39
30
 
40
31
  // If no React fiber found, return false
@@ -48,14 +39,7 @@ function checkWithinComponentAndExtractChildProps(node, targetComponentName, chi
48
39
  var currentFiber = fiber;
49
40
  var childProp;
50
41
  while (currentFiber) {
51
- var componentName = void 0;
52
- if (currentFiber.type) {
53
- if (typeof currentFiber.type === 'function') {
54
- componentName = currentFiber.type.displayName || currentFiber.type.name;
55
- } else if ((0, _typeof2.default)(currentFiber.type) === 'object' && (currentFiber.type.displayName || currentFiber.type.name)) {
56
- componentName = currentFiber.type.displayName || currentFiber.type.name;
57
- }
58
- }
42
+ var componentName = (0, _getComponentName.default)(currentFiber);
59
43
 
60
44
  // Check if this is a child component we're looking for
61
45
  if (childComponentConfig && componentName === childComponentConfig.componentName) {
@@ -79,21 +63,4 @@ function checkWithinComponentAndExtractChildProps(node, targetComponentName, chi
79
63
  return {
80
64
  isWithin: false
81
65
  };
82
- }
83
-
84
- // Check if the node is within a UFOThirdPartySegment and extract any UFOIgnoreHolds reason
85
- function checkThirdPartySegmentWithIgnoreReason(node) {
86
- var result = checkWithinComponentAndExtractChildProps(node, 'UFOThirdPartySegment', {
87
- componentName: 'UFOIgnoreHolds',
88
- propName: 'reason'
89
- });
90
- return {
91
- isWithinThirdPartySegment: result.isWithin,
92
- ignoredReason: result.childProp
93
- };
94
- }
95
-
96
- // Helper function to create mutation type from UFOIgnoreHoldsReason
97
- function createMutationTypeWithIgnoredReason(reason) {
98
- return "mutation:".concat(reason);
99
66
  }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = findReactFiber;
7
+ // Helper function to find React fiber on an element
8
+ function findReactFiber(element) {
9
+ // Use for...in loop instead of Object.keys().find() to avoid creating an array
10
+ for (var key in element) {
11
+ if (key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$')) {
12
+ return element[key];
13
+ }
14
+ }
15
+ return null;
16
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = getComponentName;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ // Helper function to extract component name from fiber
10
+ function getComponentName(fiber) {
11
+ var type = fiber === null || fiber === void 0 ? void 0 : fiber.type;
12
+ if (!type) {
13
+ return undefined;
14
+ }
15
+ if (typeof type === 'function' || (0, _typeof2.default)(type) === 'object') {
16
+ return type.displayName || type.name;
17
+ }
18
+ return undefined;
19
+ }
@@ -1,6 +1,7 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
1
2
  import { createRootCriticalMetricsPayload } from './root-metrics';
2
3
  import { createSegmentMetricsPayloads } from './segment-metrics/create-segment-metrics';
3
4
  export async function createCriticalMetricsPayloads(interactionId, interaction, vcMetrics) {
4
- const [rootPayload, segmentPayloads] = await Promise.all([createRootCriticalMetricsPayload(interactionId, interaction, vcMetrics), createSegmentMetricsPayloads(interactionId, interaction)]);
5
- return [rootPayload, ...segmentPayloads];
5
+ const [rootPayload, segmentPayloads] = await Promise.all([createRootCriticalMetricsPayload(interactionId, interaction, vcMetrics), fg('platform_ufo_segment_critical_metrics') ? createSegmentMetricsPayloads(interactionId, interaction) : []]);
6
+ return [rootPayload, ...segmentPayloads].filter(v => v != null);
6
7
  }
@@ -50,6 +50,10 @@ export async function createRootCriticalMetricsPayload(interactionId, interactio
50
50
  const pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
51
51
  const pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
52
52
  const interactionStatus = getInteractionStatus(interaction);
53
+ if (interactionStatus.originalInteractionStatus !== 'SUCCEEDED') {
54
+ // To reduce payload sent from the client, we don't send critical perf metrics for non-success interactions
55
+ return null;
56
+ }
53
57
  const newUFOName = sanitizeUfoName(ufoName);
54
58
 
55
59
  // Get performance metrics
@@ -97,6 +97,10 @@ export async function createSegmentMetricsPayloads(interactionId, interaction) {
97
97
  status,
98
98
  abortReason: segmentAbortReason
99
99
  } = getSegmentStatus(interaction, segment);
100
+ if (status !== 'SUCCEEDED') {
101
+ // To reduce payload sent from the client, we don't send critical perf metrics for non-success interactions
102
+ continue;
103
+ }
100
104
  const properties = {
101
105
  // Basic metadata
102
106
  'event:hostname': ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || 'unknown',
@@ -0,0 +1,30 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import UFOInteractionContext from '../interaction-context';
3
+ import { getInteractionId } from '../interaction-id-context';
4
+ import { addCohortingCustomData } from '../interaction-metrics';
5
+ export default function UFOCustomCohortData({
6
+ dataKey,
7
+ value
8
+ }) {
9
+ const interactionContext = useContext(UFOInteractionContext);
10
+ useMemo(() => {
11
+ if (!interactionContext) {
12
+ return;
13
+ }
14
+ const interactionId = getInteractionId();
15
+ const currentInteractionId = interactionId.current;
16
+ if (!currentInteractionId) {
17
+ return;
18
+ }
19
+ addCohortingCustomData(currentInteractionId, dataKey, value);
20
+ }, [dataKey, value, interactionContext]);
21
+ return null;
22
+ }
23
+ export function addUFOCustomCohortData(key, value) {
24
+ const interactionId = getInteractionId();
25
+ const currentInteractionId = interactionId.current;
26
+ if (!currentInteractionId) {
27
+ return;
28
+ }
29
+ addCohortingCustomData(currentInteractionId, key, value);
30
+ }
File without changes
@@ -6,7 +6,7 @@ import { RLLPlaceholderHandlers } from '../../vc-observer/observers/rll-placehol
6
6
  import { createIntersectionObserver } from './intersection-observer';
7
7
  import createMutationObserver from './mutation-observer';
8
8
  import createPerformanceObserver from './performance-observer';
9
- import { checkThirdPartySegmentWithIgnoreReason, createMutationTypeWithIgnoredReason } from './utils/get-component-name-and-child-props';
9
+ import checkWithinComponentAndExtractChildProps from './utils/check-within-component-and-extract-child-props';
10
10
  import isInVCIgnoreIfNoLayoutShiftMarker from './utils/is-in-vc-ignore-if-no-layout-shift-marker';
11
11
  function isElementVisible(element) {
12
12
  if (!(element instanceof HTMLElement)) {
@@ -186,13 +186,11 @@ export default class ViewportObserver {
186
186
  continue;
187
187
  }
188
188
  const {
189
- isWithinThirdPartySegment,
190
- ignoredReason
191
- } = checkThirdPartySegmentWithIgnoreReason(addedNode);
189
+ isWithin: isWithinThirdPartySegment
190
+ } = checkWithinComponentAndExtractChildProps(addedNode, 'UFOThirdPartySegment');
192
191
  if (isWithinThirdPartySegment) {
193
192
  var _this$intersectionObs7;
194
- const assignedReason = createMutationTypeWithIgnoredReason(ignoredReason || 'third-party-element');
195
- (_this$intersectionObs7 = this.intersectionObserver) === null || _this$intersectionObs7 === void 0 ? void 0 : _this$intersectionObs7.watchAndTag(addedNode, assignedReason);
193
+ (_this$intersectionObs7 = this.intersectionObserver) === null || _this$intersectionObs7 === void 0 ? void 0 : _this$intersectionObs7.watchAndTag(addedNode, 'mutation:third-party-element');
196
194
  continue;
197
195
  }
198
196
  (_this$intersectionObs8 = this.intersectionObserver) === null || _this$intersectionObs8 === void 0 ? void 0 : _this$intersectionObs8.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
@@ -245,13 +243,11 @@ export default class ViewportObserver {
245
243
  };
246
244
  }
247
245
  const {
248
- isWithinThirdPartySegment,
249
- ignoredReason
250
- } = checkThirdPartySegmentWithIgnoreReason(target);
246
+ isWithin: isWithinThirdPartySegment
247
+ } = checkWithinComponentAndExtractChildProps(target, 'UFOThirdPartySegment');
251
248
  if (isWithinThirdPartySegment) {
252
- const assignedReason = createMutationTypeWithIgnoredReason(ignoredReason || 'third-party-element');
253
249
  return {
254
- type: assignedReason,
250
+ type: 'mutation:third-party-element',
255
251
  mutationData: {
256
252
  attributeName,
257
253
  oldValue,
@@ -1,13 +1,10 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
- // Helper function to find React fiber on an element
3
- const findReactFiber = element => {
4
- const key = Object.keys(element).find(key => key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$'));
5
- return key ? element[key] : null;
6
- };
2
+ import findReactFiber from './find-react-fiber';
3
+ import getComponentName from './get-component-name';
7
4
 
8
5
  // Using the React Fiber tree to traverse up the DOM and check if a node is within a specific component
9
6
  // and extract child component props if needed.
10
- export function checkWithinComponentAndExtractChildProps(node, targetComponentName, childComponentConfig) {
7
+ export default function checkWithinComponentAndExtractChildProps(node, targetComponentName, childComponentConfig) {
11
8
  let fiber = null;
12
9
  if (fg('platform_ufo_handle_non_react_element_for_3p')) {
13
10
  // Walk up the DOM tree to find React fiber (handles non-React-rendered elements)
@@ -33,14 +30,7 @@ export function checkWithinComponentAndExtractChildProps(node, targetComponentNa
33
30
  let currentFiber = fiber;
34
31
  let childProp;
35
32
  while (currentFiber) {
36
- let componentName;
37
- if (currentFiber.type) {
38
- if (typeof currentFiber.type === 'function') {
39
- componentName = currentFiber.type.displayName || currentFiber.type.name;
40
- } else if (typeof currentFiber.type === 'object' && (currentFiber.type.displayName || currentFiber.type.name)) {
41
- componentName = currentFiber.type.displayName || currentFiber.type.name;
42
- }
43
- }
33
+ const componentName = getComponentName(currentFiber);
44
34
 
45
35
  // Check if this is a child component we're looking for
46
36
  if (childComponentConfig && componentName === childComponentConfig.componentName) {
@@ -65,21 +55,4 @@ export function checkWithinComponentAndExtractChildProps(node, targetComponentNa
65
55
  return {
66
56
  isWithin: false
67
57
  };
68
- }
69
-
70
- // Check if the node is within a UFOThirdPartySegment and extract any UFOIgnoreHolds reason
71
- export function checkThirdPartySegmentWithIgnoreReason(node) {
72
- const result = checkWithinComponentAndExtractChildProps(node, 'UFOThirdPartySegment', {
73
- componentName: 'UFOIgnoreHolds',
74
- propName: 'reason'
75
- });
76
- return {
77
- isWithinThirdPartySegment: result.isWithin,
78
- ignoredReason: result.childProp
79
- };
80
- }
81
-
82
- // Helper function to create mutation type from UFOIgnoreHoldsReason
83
- export function createMutationTypeWithIgnoredReason(reason) {
84
- return `mutation:${reason}`;
85
58
  }
@@ -0,0 +1,10 @@
1
+ // Helper function to find React fiber on an element
2
+ export default function findReactFiber(element) {
3
+ // Use for...in loop instead of Object.keys().find() to avoid creating an array
4
+ for (const key in element) {
5
+ if (key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$')) {
6
+ return element[key];
7
+ }
8
+ }
9
+ return null;
10
+ }
@@ -0,0 +1,11 @@
1
+ // Helper function to extract component name from fiber
2
+ export default function getComponentName(fiber) {
3
+ const type = fiber === null || fiber === void 0 ? void 0 : fiber.type;
4
+ if (!type) {
5
+ return undefined;
6
+ }
7
+ if (typeof type === 'function' || typeof type === 'object') {
8
+ return type.displayName || type.name;
9
+ }
10
+ return undefined;
11
+ }
@@ -2,6 +2,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { createRootCriticalMetricsPayload } from './root-metrics';
6
7
  import { createSegmentMetricsPayloads } from './segment-metrics/create-segment-metrics';
7
8
  export function createCriticalMetricsPayloads(_x, _x2, _x3) {
@@ -14,13 +15,15 @@ function _createCriticalMetricsPayloads() {
14
15
  while (1) switch (_context.prev = _context.next) {
15
16
  case 0:
16
17
  _context.next = 2;
17
- return Promise.all([createRootCriticalMetricsPayload(interactionId, interaction, vcMetrics), createSegmentMetricsPayloads(interactionId, interaction)]);
18
+ return Promise.all([createRootCriticalMetricsPayload(interactionId, interaction, vcMetrics), fg('platform_ufo_segment_critical_metrics') ? createSegmentMetricsPayloads(interactionId, interaction) : []]);
18
19
  case 2:
19
20
  _yield$Promise$all = _context.sent;
20
21
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
21
22
  rootPayload = _yield$Promise$all2[0];
22
23
  segmentPayloads = _yield$Promise$all2[1];
23
- return _context.abrupt("return", [rootPayload].concat(_toConsumableArray(segmentPayloads)));
24
+ return _context.abrupt("return", [rootPayload].concat(_toConsumableArray(segmentPayloads)).filter(function (v) {
25
+ return v != null;
26
+ }));
24
27
  case 7:
25
28
  case "end":
26
29
  return _context.stop();
@@ -51,11 +51,17 @@ function _createRootCriticalMetricsPayload() {
51
51
  pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
52
52
  pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
53
53
  interactionStatus = getInteractionStatus(interaction);
54
+ if (!(interactionStatus.originalInteractionStatus !== 'SUCCEEDED')) {
55
+ _context.next = 9;
56
+ break;
57
+ }
58
+ return _context.abrupt("return", null);
59
+ case 9:
54
60
  newUFOName = sanitizeUfoName(ufoName); // Get performance metrics
55
61
  ttai = getTTAI(interaction);
56
- _context.next = 11;
62
+ _context.next = 13;
57
63
  return getPaintMetrics(type, end);
58
- case 11:
64
+ case 13:
59
65
  paintMetrics = _context.sent;
60
66
  navigationMetrics = getNavigationMetrics(type);
61
67
  ssrSuccess = getSSRSuccess(type); // Calculate BM3 metrics (TTI and FMP) directly
@@ -68,14 +74,14 @@ function _createRootCriticalMetricsPayload() {
68
74
  }); // Use provided vcMetrics or calculate if not provided
69
75
  _context.t0 = vcMetrics;
70
76
  if (_context.t0) {
71
- _context.next = 23;
77
+ _context.next = 25;
72
78
  break;
73
79
  }
74
- _context.next = 22;
80
+ _context.next = 24;
75
81
  return getVCMetrics(interaction);
76
- case 22:
82
+ case 24:
77
83
  _context.t0 = _context.sent;
78
- case 23:
84
+ case 25:
79
85
  finalVCMetrics = _context.t0;
80
86
  ttvc = (_finalVCMetrics$ufoV = finalVCMetrics['ufo:vc:rev']) === null || _finalVCMetrics$ufoV === void 0 ? void 0 : _finalVCMetrics$ufoV.map(function (revision) {
81
87
  if (revision['metric:vc90'] === null || revision.clean !== true) {
@@ -164,7 +170,7 @@ function _createRootCriticalMetricsPayload() {
164
170
  }
165
171
  };
166
172
  return _context.abrupt("return", payload);
167
- case 30:
173
+ case 32:
168
174
  case "end":
169
175
  return _context.stop();
170
176
  }
@@ -19,7 +19,7 @@ export function createSegmentMetricsPayloads(_x, _x2) {
19
19
  function _createSegmentMetricsPayloads() {
20
20
  _createSegmentMetricsPayloads = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(interactionId, interaction) {
21
21
  var _interaction$cohortin;
22
- var config, browserMetadata, cohortingCustomData, pageVisibilityAtTTAI, knownSegments, reactProfilerTimings, rate, routeName, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, segmentsByName, _iterator, _step, _loop, _ret, payloads, _iterator2, _step2, _loop2;
22
+ var config, browserMetadata, cohortingCustomData, pageVisibilityAtTTAI, knownSegments, reactProfilerTimings, rate, routeName, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, segmentsByName, _iterator, _step, _loop, _ret, payloads, _iterator2, _step2, _loop2, _ret2;
23
23
  return _regeneratorRuntime.wrap(function _callee$(_context3) {
24
24
  while (1) switch (_context3.prev = _context3.next) {
25
25
  case 0:
@@ -141,13 +141,19 @@ function _createSegmentMetricsPayloads() {
141
141
  _context2.next = 8;
142
142
  break;
143
143
  }
144
- return _context2.abrupt("return", 1);
144
+ return _context2.abrupt("return", 0);
145
145
  case 8:
146
146
  lastTiming = segmentProfilerTimings[segmentProfilerTimings.length - 1];
147
147
  startTime = isRootSegment ? interaction.start : firstMountTiming.startTime;
148
148
  endTime = lastTiming.commitTime;
149
149
  ttai = Math.round(endTime - startTime);
150
150
  _getSegmentStatus = getSegmentStatus(interaction, segment), status = _getSegmentStatus.status, segmentAbortReason = _getSegmentStatus.abortReason;
151
+ if (!(status !== 'SUCCEEDED')) {
152
+ _context2.next = 15;
153
+ break;
154
+ }
155
+ return _context2.abrupt("return", 0);
156
+ case 15:
151
157
  properties = _objectSpread({
152
158
  // Basic metadata
153
159
  'event:hostname': ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || 'unknown',
@@ -199,7 +205,7 @@ function _createSegmentMetricsPayloads() {
199
205
  }
200
206
  };
201
207
  payloads.push(payload);
202
- case 16:
208
+ case 18:
203
209
  case "end":
204
210
  return _context2.stop();
205
211
  }
@@ -208,37 +214,38 @@ function _createSegmentMetricsPayloads() {
208
214
  _iterator2.s();
209
215
  case 32:
210
216
  if ((_step2 = _iterator2.n()).done) {
211
- _context3.next = 38;
217
+ _context3.next = 39;
212
218
  break;
213
219
  }
214
220
  return _context3.delegateYield(_loop2(), "t2", 34);
215
221
  case 34:
216
- if (!_context3.t2) {
217
- _context3.next = 36;
222
+ _ret2 = _context3.t2;
223
+ if (!(_ret2 === 0)) {
224
+ _context3.next = 37;
218
225
  break;
219
226
  }
220
- return _context3.abrupt("continue", 36);
221
- case 36:
227
+ return _context3.abrupt("continue", 37);
228
+ case 37:
222
229
  _context3.next = 32;
223
230
  break;
224
- case 38:
225
- _context3.next = 43;
231
+ case 39:
232
+ _context3.next = 44;
226
233
  break;
227
- case 40:
228
- _context3.prev = 40;
234
+ case 41:
235
+ _context3.prev = 41;
229
236
  _context3.t3 = _context3["catch"](29);
230
237
  _iterator2.e(_context3.t3);
231
- case 43:
232
- _context3.prev = 43;
238
+ case 44:
239
+ _context3.prev = 44;
233
240
  _iterator2.f();
234
- return _context3.finish(43);
235
- case 46:
236
- return _context3.abrupt("return", payloads);
241
+ return _context3.finish(44);
237
242
  case 47:
243
+ return _context3.abrupt("return", payloads);
244
+ case 48:
238
245
  case "end":
239
246
  return _context3.stop();
240
247
  }
241
- }, _callee, null, [[9, 21, 24, 27], [29, 40, 43, 46]]);
248
+ }, _callee, null, [[9, 21, 24, 27], [29, 41, 44, 47]]);
242
249
  }));
243
250
  return _createSegmentMetricsPayloads.apply(this, arguments);
244
251
  }
@@ -0,0 +1,29 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import UFOInteractionContext from '../interaction-context';
3
+ import { getInteractionId } from '../interaction-id-context';
4
+ import { addCohortingCustomData } from '../interaction-metrics';
5
+ export default function UFOCustomCohortData(_ref) {
6
+ var dataKey = _ref.dataKey,
7
+ value = _ref.value;
8
+ var interactionContext = useContext(UFOInteractionContext);
9
+ useMemo(function () {
10
+ if (!interactionContext) {
11
+ return;
12
+ }
13
+ var interactionId = getInteractionId();
14
+ var currentInteractionId = interactionId.current;
15
+ if (!currentInteractionId) {
16
+ return;
17
+ }
18
+ addCohortingCustomData(currentInteractionId, dataKey, value);
19
+ }, [dataKey, value, interactionContext]);
20
+ return null;
21
+ }
22
+ export function addUFOCustomCohortData(key, value) {
23
+ var interactionId = getInteractionId();
24
+ var currentInteractionId = interactionId.current;
25
+ if (!currentInteractionId) {
26
+ return;
27
+ }
28
+ addCohortingCustomData(currentInteractionId, key, value);
29
+ }
File without changes
@@ -13,7 +13,7 @@ import { RLLPlaceholderHandlers } from '../../vc-observer/observers/rll-placehol
13
13
  import { createIntersectionObserver } from './intersection-observer';
14
14
  import createMutationObserver from './mutation-observer';
15
15
  import createPerformanceObserver from './performance-observer';
16
- import { checkThirdPartySegmentWithIgnoreReason, createMutationTypeWithIgnoredReason } from './utils/get-component-name-and-child-props';
16
+ import checkWithinComponentAndExtractChildProps from './utils/check-within-component-and-extract-child-props';
17
17
  import isInVCIgnoreIfNoLayoutShiftMarker from './utils/is-in-vc-ignore-if-no-layout-shift-marker';
18
18
  function isElementVisible(element) {
19
19
  if (!(element instanceof HTMLElement)) {
@@ -118,7 +118,7 @@ var ViewportObserver = /*#__PURE__*/function () {
118
118
  _context2.prev = 4;
119
119
  _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
120
120
  var _this$intersectionObs8;
121
- var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, result, _this$intersectionObs3, _result, _this$intersectionObs4, sameDeletedNode, isInIgnoreLsMarker, isNoLsMarkerEnabled, _this$intersectionObs5, _this$intersectionObs6, _checkThirdPartySegme, isWithinThirdPartySegment, ignoredReason, _this$intersectionObs7, assignedReason;
121
+ var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, result, _this$intersectionObs3, _result, _this$intersectionObs4, sameDeletedNode, isInIgnoreLsMarker, isNoLsMarkerEnabled, _this$intersectionObs5, _this$intersectionObs6, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs7;
122
122
  return _regeneratorRuntime.wrap(function _loop$(_context) {
123
123
  while (1) switch (_context.prev = _context.next) {
124
124
  case 0:
@@ -228,17 +228,16 @@ var ViewportObserver = /*#__PURE__*/function () {
228
228
  (_this$intersectionObs6 = _this.intersectionObserver) === null || _this$intersectionObs6 === void 0 || _this$intersectionObs6.watchAndTag(addedNode, 'mutation:media');
229
229
  return _context.abrupt("return", 0);
230
230
  case 45:
231
- _checkThirdPartySegme = checkThirdPartySegmentWithIgnoreReason(addedNode), isWithinThirdPartySegment = _checkThirdPartySegme.isWithinThirdPartySegment, ignoredReason = _checkThirdPartySegme.ignoredReason;
231
+ _checkWithinComponent = checkWithinComponentAndExtractChildProps(addedNode, 'UFOThirdPartySegment'), isWithinThirdPartySegment = _checkWithinComponent.isWithin;
232
232
  if (!isWithinThirdPartySegment) {
233
- _context.next = 50;
233
+ _context.next = 49;
234
234
  break;
235
235
  }
236
- assignedReason = createMutationTypeWithIgnoredReason(ignoredReason || 'third-party-element');
237
- (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(addedNode, assignedReason);
236
+ (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(addedNode, 'mutation:third-party-element');
238
237
  return _context.abrupt("return", 0);
239
- case 50:
238
+ case 49:
240
239
  (_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
241
- case 51:
240
+ case 50:
242
241
  case "end":
243
242
  return _context.stop();
244
243
  }
@@ -326,13 +325,11 @@ var ViewportObserver = /*#__PURE__*/function () {
326
325
  }
327
326
  };
328
327
  }
329
- var _checkThirdPartySegme2 = checkThirdPartySegmentWithIgnoreReason(target),
330
- isWithinThirdPartySegment = _checkThirdPartySegme2.isWithinThirdPartySegment,
331
- ignoredReason = _checkThirdPartySegme2.ignoredReason;
328
+ var _checkWithinComponent2 = checkWithinComponentAndExtractChildProps(target, 'UFOThirdPartySegment'),
329
+ isWithinThirdPartySegment = _checkWithinComponent2.isWithin;
332
330
  if (isWithinThirdPartySegment) {
333
- var assignedReason = createMutationTypeWithIgnoredReason(ignoredReason || 'third-party-element');
334
331
  return {
335
- type: assignedReason,
332
+ type: 'mutation:third-party-element',
336
333
  mutationData: {
337
334
  attributeName: attributeName,
338
335
  oldValue: oldValue,
@@ -1,19 +1,13 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _typeof from "@babel/runtime/helpers/typeof";
3
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; }
4
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; }
5
4
  import { fg } from '@atlaskit/platform-feature-flags';
6
- // Helper function to find React fiber on an element
7
- var findReactFiber = function findReactFiber(element) {
8
- var key = Object.keys(element).find(function (key) {
9
- return key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$');
10
- });
11
- return key ? element[key] : null;
12
- };
5
+ import findReactFiber from './find-react-fiber';
6
+ import getComponentName from './get-component-name';
13
7
 
14
8
  // Using the React Fiber tree to traverse up the DOM and check if a node is within a specific component
15
9
  // and extract child component props if needed.
16
- export function checkWithinComponentAndExtractChildProps(node, targetComponentName, childComponentConfig) {
10
+ export default function checkWithinComponentAndExtractChildProps(node, targetComponentName, childComponentConfig) {
17
11
  var fiber = null;
18
12
  if (fg('platform_ufo_handle_non_react_element_for_3p')) {
19
13
  // Walk up the DOM tree to find React fiber (handles non-React-rendered elements)
@@ -39,14 +33,7 @@ export function checkWithinComponentAndExtractChildProps(node, targetComponentNa
39
33
  var currentFiber = fiber;
40
34
  var childProp;
41
35
  while (currentFiber) {
42
- var componentName = void 0;
43
- if (currentFiber.type) {
44
- if (typeof currentFiber.type === 'function') {
45
- componentName = currentFiber.type.displayName || currentFiber.type.name;
46
- } else if (_typeof(currentFiber.type) === 'object' && (currentFiber.type.displayName || currentFiber.type.name)) {
47
- componentName = currentFiber.type.displayName || currentFiber.type.name;
48
- }
49
- }
36
+ var componentName = getComponentName(currentFiber);
50
37
 
51
38
  // Check if this is a child component we're looking for
52
39
  if (childComponentConfig && componentName === childComponentConfig.componentName) {
@@ -70,21 +57,4 @@ export function checkWithinComponentAndExtractChildProps(node, targetComponentNa
70
57
  return {
71
58
  isWithin: false
72
59
  };
73
- }
74
-
75
- // Check if the node is within a UFOThirdPartySegment and extract any UFOIgnoreHolds reason
76
- export function checkThirdPartySegmentWithIgnoreReason(node) {
77
- var result = checkWithinComponentAndExtractChildProps(node, 'UFOThirdPartySegment', {
78
- componentName: 'UFOIgnoreHolds',
79
- propName: 'reason'
80
- });
81
- return {
82
- isWithinThirdPartySegment: result.isWithin,
83
- ignoredReason: result.childProp
84
- };
85
- }
86
-
87
- // Helper function to create mutation type from UFOIgnoreHoldsReason
88
- export function createMutationTypeWithIgnoredReason(reason) {
89
- return "mutation:".concat(reason);
90
60
  }
@@ -0,0 +1,10 @@
1
+ // Helper function to find React fiber on an element
2
+ export default function findReactFiber(element) {
3
+ // Use for...in loop instead of Object.keys().find() to avoid creating an array
4
+ for (var key in element) {
5
+ if (key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$')) {
6
+ return element[key];
7
+ }
8
+ }
9
+ return null;
10
+ }
@@ -0,0 +1,12 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ // Helper function to extract component name from fiber
3
+ export default function getComponentName(fiber) {
4
+ var type = fiber === null || fiber === void 0 ? void 0 : fiber.type;
5
+ if (!type) {
6
+ return undefined;
7
+ }
8
+ if (typeof type === 'function' || _typeof(type) === 'object') {
9
+ return type.displayName || type.name;
10
+ }
11
+ return undefined;
12
+ }
@@ -4,4 +4,4 @@ import type { CriticalMetricsPayload } from './types';
4
4
  export type { CriticalMetricsPayload, CriticalMetricsPayloadProperties } from './types';
5
5
  export declare function createRootCriticalMetricsPayload(interactionId: string, interaction: InteractionMetrics, vcMetrics?: VCResult & {
6
6
  'metric:vc90'?: number | null;
7
- }): Promise<CriticalMetricsPayload>;
7
+ }): Promise<CriticalMetricsPayload | null>;
@@ -0,0 +1,4 @@
1
+ import type { UFOCustomCohortDataProps } from './types';
2
+ export type { UFOCustomCohortDataProps } from './types';
3
+ export default function UFOCustomCohortData({ dataKey, value }: UFOCustomCohortDataProps): null;
4
+ export declare function addUFOCustomCohortData(key: string, value: number | boolean | string | null | undefined): void;
@@ -0,0 +1,4 @@
1
+ export type UFOCustomCohortDataProps = {
2
+ dataKey: string;
3
+ value: number | boolean | string | null | undefined;
4
+ };
@@ -0,0 +1,8 @@
1
+ export default function checkWithinComponentAndExtractChildProps<T = string>(node: HTMLElement, targetComponentName: string, childComponentConfig?: {
2
+ componentName: string;
3
+ propName: string;
4
+ extractValue?: (props: any) => T;
5
+ }): {
6
+ isWithin: boolean;
7
+ childProp?: T;
8
+ };
@@ -0,0 +1 @@
1
+ export default function findReactFiber(element: HTMLElement): any;
@@ -0,0 +1 @@
1
+ export default function getComponentName(fiber: any): string | undefined;
@@ -4,4 +4,4 @@ import type { CriticalMetricsPayload } from './types';
4
4
  export type { CriticalMetricsPayload, CriticalMetricsPayloadProperties } from './types';
5
5
  export declare function createRootCriticalMetricsPayload(interactionId: string, interaction: InteractionMetrics, vcMetrics?: VCResult & {
6
6
  'metric:vc90'?: number | null;
7
- }): Promise<CriticalMetricsPayload>;
7
+ }): Promise<CriticalMetricsPayload | null>;
@@ -0,0 +1,4 @@
1
+ import type { UFOCustomCohortDataProps } from './types';
2
+ export type { UFOCustomCohortDataProps } from './types';
3
+ export default function UFOCustomCohortData({ dataKey, value }: UFOCustomCohortDataProps): null;
4
+ export declare function addUFOCustomCohortData(key: string, value: number | boolean | string | null | undefined): void;
@@ -0,0 +1,4 @@
1
+ export type UFOCustomCohortDataProps = {
2
+ dataKey: string;
3
+ value: number | boolean | string | null | undefined;
4
+ };
@@ -0,0 +1,8 @@
1
+ export default function checkWithinComponentAndExtractChildProps<T = string>(node: HTMLElement, targetComponentName: string, childComponentConfig?: {
2
+ componentName: string;
3
+ propName: string;
4
+ extractValue?: (props: any) => T;
5
+ }): {
6
+ isWithin: boolean;
7
+ childProp?: T;
8
+ };
@@ -0,0 +1 @@
1
+ export default function findReactFiber(element: HTMLElement): any;
@@ -0,0 +1 @@
1
+ export default function getComponentName(fiber: any): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/react-ufo",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "description": "Parts of React UFO that are publicly available",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,6 +35,7 @@
35
35
  "./create-payload": "./src/create-payload/index.ts",
36
36
  "./create-post-interaction-log-payload": "./src/create-post-interaction-log-payload/index.ts",
37
37
  "./custom-data": "./src/custom-data/index.ts",
38
+ "./custom-cohort-data": "./src/custom-cohort-data/index.ts",
38
39
  "./custom-mark": "./src/custom-mark/index.ts",
39
40
  "./custom-spans": "./src/custom-spans/index.ts",
40
41
  "./custom-timings": "./src/custom-timings/index.ts",
@@ -214,6 +215,9 @@
214
215
  },
215
216
  "platform_ufo_handle_non_react_element_for_3p": {
216
217
  "type": "boolean"
218
+ },
219
+ "platform_ufo_segment_critical_metrics": {
220
+ "type": "boolean"
217
221
  }
218
222
  }
219
223
  }
@@ -1,15 +0,0 @@
1
- import type { UFOIgnoreHoldsReason } from '../../../../ignore-holds';
2
- import type { VCObserverEntryType } from '../../types';
3
- export declare function checkWithinComponentAndExtractChildProps<T = string>(node: HTMLElement, targetComponentName: string, childComponentConfig?: {
4
- componentName: string;
5
- propName: string;
6
- extractValue?: (props: any) => T;
7
- }): {
8
- isWithin: boolean;
9
- childProp?: T;
10
- };
11
- export declare function checkThirdPartySegmentWithIgnoreReason(node: HTMLElement): {
12
- isWithinThirdPartySegment: boolean;
13
- ignoredReason?: UFOIgnoreHoldsReason;
14
- };
15
- export declare function createMutationTypeWithIgnoredReason(reason: UFOIgnoreHoldsReason): VCObserverEntryType;
@@ -1,15 +0,0 @@
1
- import type { UFOIgnoreHoldsReason } from '../../../../ignore-holds';
2
- import type { VCObserverEntryType } from '../../types';
3
- export declare function checkWithinComponentAndExtractChildProps<T = string>(node: HTMLElement, targetComponentName: string, childComponentConfig?: {
4
- componentName: string;
5
- propName: string;
6
- extractValue?: (props: any) => T;
7
- }): {
8
- isWithin: boolean;
9
- childProp?: T;
10
- };
11
- export declare function checkThirdPartySegmentWithIgnoreReason(node: HTMLElement): {
12
- isWithinThirdPartySegment: boolean;
13
- ignoredReason?: UFOIgnoreHoldsReason;
14
- };
15
- export declare function createMutationTypeWithIgnoredReason(reason: UFOIgnoreHoldsReason): VCObserverEntryType;