@cloudcare/browser-rum 3.1.1 → 3.1.3

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 (148) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/rum.js +23 -3
  4. package/cjs/boot/rum.js.map +1 -1
  5. package/cjs/boot/rumPublicApi.js +49 -13
  6. package/cjs/boot/rumPublicApi.js.map +1 -1
  7. package/cjs/boot/startRecording.js +1 -1
  8. package/cjs/boot/startRecording.js.map +1 -1
  9. package/cjs/domain/assembly.js +6 -5
  10. package/cjs/domain/assembly.js.map +1 -1
  11. package/cjs/domain/configuration.js +1 -3
  12. package/cjs/domain/configuration.js.map +1 -1
  13. package/cjs/domain/contexts/displayContext.js +12 -18
  14. package/cjs/domain/contexts/displayContext.js.map +1 -1
  15. package/cjs/domain/performanceCollection.js +16 -10
  16. package/cjs/domain/performanceCollection.js.map +1 -1
  17. package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
  18. package/cjs/domain/replay/record/mutationObserver.js +5 -5
  19. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  20. package/cjs/domain/replay/record/privacy.js +0 -1
  21. package/cjs/domain/replay/record/privacy.js.map +1 -1
  22. package/cjs/domain/replay/record/serializationUtils.js +14 -19
  23. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  24. package/cjs/domain/replay/record/serialize.js +12 -13
  25. package/cjs/domain/replay/record/serialize.js.map +1 -1
  26. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +10 -33
  27. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  28. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js +2 -8
  29. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  30. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +33 -18
  31. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  32. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js +11 -25
  33. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  34. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +45 -2
  35. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  36. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
  37. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  38. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +22 -29
  39. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  40. package/cjs/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +12 -9
  41. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -0
  42. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +18 -27
  43. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  44. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +66 -11
  45. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  46. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +11 -6
  47. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  48. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
  49. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  50. package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js +55 -24
  51. package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  52. package/cjs/domain/rumEventsCollection/view/trackViews.js +34 -12
  53. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  54. package/cjs/domain/rumEventsCollection/view/viewCollection.js +17 -14
  55. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  56. package/cjs/domain/trackEventCounts.js +4 -4
  57. package/cjs/domain/trackEventCounts.js.map +1 -1
  58. package/cjs/transport/startRumBatch.js +1 -1
  59. package/cjs/transport/startRumBatch.js.map +1 -1
  60. package/esm/boot/buildEnv.js +1 -1
  61. package/esm/boot/rum.js +23 -3
  62. package/esm/boot/rum.js.map +1 -1
  63. package/esm/boot/rumPublicApi.js +50 -14
  64. package/esm/boot/rumPublicApi.js.map +1 -1
  65. package/esm/boot/startRecording.js +1 -1
  66. package/esm/boot/startRecording.js.map +1 -1
  67. package/esm/domain/assembly.js +6 -5
  68. package/esm/domain/assembly.js.map +1 -1
  69. package/esm/domain/configuration.js +1 -3
  70. package/esm/domain/configuration.js.map +1 -1
  71. package/esm/domain/contexts/displayContext.js +11 -16
  72. package/esm/domain/contexts/displayContext.js.map +1 -1
  73. package/esm/domain/performanceCollection.js +17 -10
  74. package/esm/domain/performanceCollection.js.map +1 -1
  75. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  76. package/esm/domain/replay/record/mutationObserver.js +6 -6
  77. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  78. package/esm/domain/replay/record/privacy.js +0 -1
  79. package/esm/domain/replay/record/privacy.js.map +1 -1
  80. package/esm/domain/replay/record/serializationUtils.js +15 -19
  81. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  82. package/esm/domain/replay/record/serialize.js +13 -14
  83. package/esm/domain/replay/record/serialize.js.map +1 -1
  84. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +10 -33
  85. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  86. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js +3 -9
  87. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  88. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +34 -19
  89. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  90. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +13 -27
  91. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  92. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +47 -3
  93. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  94. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
  95. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  96. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +22 -28
  97. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  98. package/esm/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +13 -9
  99. package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -0
  100. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +19 -28
  101. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  102. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +65 -12
  103. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  104. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +12 -6
  105. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  106. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
  107. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  108. package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js +55 -25
  109. package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  110. package/esm/domain/rumEventsCollection/view/trackViews.js +33 -12
  111. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  112. package/esm/domain/rumEventsCollection/view/viewCollection.js +18 -15
  113. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  114. package/esm/domain/trackEventCounts.js +4 -4
  115. package/esm/domain/trackEventCounts.js.map +1 -1
  116. package/esm/transport/startRumBatch.js +1 -1
  117. package/esm/transport/startRumBatch.js.map +1 -1
  118. package/package.json +4 -4
  119. package/src/boot/rum.js +27 -3
  120. package/src/boot/rumPublicApi.js +63 -16
  121. package/src/boot/startRecording.js +1 -0
  122. package/src/domain/assembly.js +6 -4
  123. package/src/domain/configuration.js +1 -3
  124. package/src/domain/contexts/displayContext.js +11 -20
  125. package/src/domain/performanceCollection.js +21 -10
  126. package/src/domain/replay/record/mutationObserver.js +7 -10
  127. package/src/domain/replay/record/privacy.js +1 -5
  128. package/src/domain/replay/record/serializationUtils.js +23 -19
  129. package/src/domain/replay/record/serialize.js +13 -16
  130. package/src/domain/rumEventsCollection/actions/trackClickActions.js +7 -35
  131. package/src/domain/rumEventsCollection/resource/matchRequestTiming.js +4 -13
  132. package/src/domain/rumEventsCollection/resource/resourceCollection.js +67 -21
  133. package/src/domain/rumEventsCollection/view/trackCommonViewMetrics.js +18 -35
  134. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +59 -3
  135. package/src/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
  136. package/src/domain/rumEventsCollection/view/trackFirstHidden.js +27 -32
  137. package/src/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +25 -8
  138. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +24 -28
  139. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +79 -15
  140. package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +21 -6
  141. package/src/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
  142. package/src/domain/rumEventsCollection/view/trackScrollMetrics.js +79 -35
  143. package/src/domain/rumEventsCollection/view/trackViews.js +39 -16
  144. package/src/domain/rumEventsCollection/view/viewCollection.js +47 -18
  145. package/src/domain/trackEventCounts.js +4 -4
  146. package/src/transport/startRumBatch.js +3 -1
  147. package/cjs/domain/rumEventsCollection/view/trackFirstInputTimings.js.map +0 -1
  148. package/esm/domain/rumEventsCollection/view/trackFirstInputTimings.js.map +0 -1
@@ -52,7 +52,6 @@ export function trackClickActions(
52
52
  configuration,
53
53
  lifeCycle,
54
54
  domMutationObservable,
55
- history,
56
55
  pointerDownEvent
57
56
  )
58
57
  },
@@ -74,12 +73,14 @@ export function trackClickActions(
74
73
  var stopActionEventsListener = _listenActionEvents.stop
75
74
  var actionContexts = {
76
75
  findActionId: function (startTime) {
77
- return history.find(startTime)
76
+ const allIds = history.findAll(startTime)
77
+ if (allIds && allIds.length) {
78
+ return allIds[allIds.length - 1]
79
+ }
80
+ return undefined
78
81
  },
79
82
  findAllActionId: function (startTime) {
80
- return configuration.trackFrustrations
81
- ? history.findAll(startTime)
82
- : history.find(startTime)
83
+ return history.findAll(startTime)
83
84
  }
84
85
  }
85
86
 
@@ -110,24 +111,12 @@ function processPointerDown(
110
111
  configuration,
111
112
  lifeCycle,
112
113
  domMutationObservable,
113
- history,
114
114
  pointerDownEvent
115
115
  ) {
116
- if (!configuration.trackFrustrations && history.find()) {
117
- // TODO: remove this in a future major version. To keep retrocompatibility, ignore any new
118
- // action if another one is already occurring.
119
- return
120
- }
121
-
122
116
  var clickActionBase = computeClickActionBase(
123
117
  pointerDownEvent,
124
118
  configuration.actionNameAttribute
125
119
  )
126
- if (!configuration.trackFrustrations && !clickActionBase.name) {
127
- // TODO: remove this in a future major version. To keep retrocompatibility, ignore any action
128
- // with a blank name
129
- return
130
- }
131
120
 
132
121
  var hadActivityOnPointerDown = false
133
122
 
@@ -138,8 +127,6 @@ function processPointerDown(
138
127
  function (pageActivityEndEvent) {
139
128
  hadActivityOnPointerDown = pageActivityEndEvent.hadActivity
140
129
  },
141
- // We don't care about the activity duration, we just want to know whether an activity did happen
142
- // within the "validation delay" or not. Limit the duration so the callback is called sooner.
143
130
  PAGE_ACTIVITY_VALIDATION_DELAY
144
131
  )
145
132
 
@@ -169,10 +156,7 @@ function startClickAction(
169
156
  clickActionBase,
170
157
  startEvent
171
158
  )
172
-
173
- if (configuration.trackFrustrations) {
174
- appendClickToClickChain(click)
175
- }
159
+ appendClickToClickChain(click)
176
160
  var _waitPageActivityEnd = waitPageActivityEnd(
177
161
  lifeCycle,
178
162
  domMutationObservable,
@@ -196,18 +180,6 @@ function startClickAction(
196
180
  } else {
197
181
  click.stop()
198
182
  }
199
-
200
- // Validate or discard the click only if we don't track frustrations. It'll be done when
201
- // the click chain is finalized.
202
- if (!configuration.trackFrustrations) {
203
- if (!pageActivityEndEvent.hadActivity) {
204
- // If we are not tracking frustrations, we should discard the click to keep backward
205
- // compatibility.
206
- click.discard()
207
- } else {
208
- click.validate()
209
- }
210
- }
211
183
  }
212
184
  },
213
185
  CLICK_ACTION_MAX_DURATION
@@ -1,5 +1,5 @@
1
1
  import { toValidEntry } from './resourceUtils'
2
- import { map, filter } from '@cloudcare/browser-core'
2
+ import { map, filter, addDuration } from '@cloudcare/browser-core'
3
3
 
4
4
  /**
5
5
  * Look for corresponding timing in resource timing buffer
@@ -26,7 +26,7 @@ export function matchRequestTiming(request) {
26
26
  var candidates = map(sameNameEntries, function (entry) {
27
27
  return entry.toJSON()
28
28
  })
29
-
29
+
30
30
  candidates = filter(candidates, toValidEntry)
31
31
  candidates = filter(candidates, function (entry) {
32
32
  return isBetween(
@@ -42,20 +42,11 @@ export function matchRequestTiming(request) {
42
42
  if (candidates.length === 1) {
43
43
  return candidates[0]
44
44
  }
45
-
46
- if (candidates.length === 2 && firstCanBeOptionRequest(candidates)) {
47
- return candidates[1]
48
- }
49
-
50
45
  return
51
46
  }
52
47
 
53
- function firstCanBeOptionRequest(correspondingEntries) {
54
- return endTime(correspondingEntries[0]) <= correspondingEntries[1].startTime
55
- }
56
-
57
48
  function endTime(timing) {
58
- return timing.startTime + timing.duration
49
+ return addDuration(timing.startTime, timing.duration)
59
50
  }
60
51
 
61
52
  function isBetween(timing, start, end) {
@@ -63,6 +54,6 @@ function isBetween(timing, start, end) {
63
54
  var errorMargin = 1
64
55
  return (
65
56
  timing.startTime >= start - errorMargin &&
66
- endTime(timing) <= end + errorMargin
57
+ endTime(timing) <= addDuration(end, errorMargin)
67
58
  )
68
59
  }
@@ -11,7 +11,10 @@ import {
11
11
  RequestType,
12
12
  ResourceType,
13
13
  RumEventType,
14
- LifeCycleEventType
14
+ LifeCycleEventType,
15
+ toServerDuration,
16
+ some,
17
+ isNullUndefinedDefaultValue
15
18
  } from '@cloudcare/browser-core'
16
19
  import { matchRequestTiming } from './matchRequestTiming'
17
20
  import {
@@ -24,12 +27,17 @@ import {
24
27
  isCacheHit,
25
28
  isResourceUrlLimit
26
29
  } from './resourceUtils'
27
- import { supportPerformanceEntry } from '../../performanceCollection'
28
- export function startResourceCollection(lifeCycle, configuration) {
30
+ import { PageState } from '../../contexts/pageStateHistory.js'
31
+ export function startResourceCollection(
32
+ lifeCycle,
33
+ configuration,
34
+ sessionManager,
35
+ pageStateHistory
36
+ ) {
29
37
  lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {
30
38
  lifeCycle.notify(
31
39
  LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
32
- processRequest(request)
40
+ processRequest(request, sessionManager, pageStateHistory)
33
41
  )
34
42
  })
35
43
 
@@ -45,7 +53,7 @@ export function startResourceCollection(lifeCycle, configuration) {
45
53
  ) {
46
54
  lifeCycle.notify(
47
55
  LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
48
- processResourceEntry(entry)
56
+ processResourceEntry(entry, sessionManager, pageStateHistory)
49
57
  )
50
58
  }
51
59
  }
@@ -53,7 +61,7 @@ export function startResourceCollection(lifeCycle, configuration) {
53
61
  )
54
62
  }
55
63
 
56
- function processRequest(request) {
64
+ function processRequest(request, sessionManager, pageStateHistory) {
57
65
  var type =
58
66
  request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH
59
67
  var matchingTiming = matchRequestTiming(request)
@@ -64,6 +72,20 @@ function processRequest(request) {
64
72
  ? computePerformanceEntryMetrics(matchingTiming)
65
73
  : undefined
66
74
  var tracingInfo = computeRequestTracingInfo(request)
75
+
76
+ var duration = computeRequestDuration(
77
+ pageStateHistory,
78
+ startClocks,
79
+ request.duration
80
+ )
81
+ var pageStateInfo = computePageStateInfo(
82
+ pageStateHistory,
83
+ startClocks,
84
+ isNullUndefinedDefaultValue(
85
+ matchingTiming && matchingTiming.duration,
86
+ request.duration
87
+ )
88
+ )
67
89
  var urlObj = urlParse(request.url).getParse()
68
90
  var resourceEvent = extend2Lev(
69
91
  {
@@ -71,7 +93,7 @@ function processRequest(request) {
71
93
  resource: {
72
94
  id: UUID,
73
95
  type: type,
74
- duration: msToNs(request.duration),
96
+ duration: duration,
75
97
  method: request.method,
76
98
  status: request.status,
77
99
  statusGroup: getStatusGroup(request.status),
@@ -84,14 +106,14 @@ function processRequest(request) {
84
106
  type: RumEventType.RESOURCE
85
107
  },
86
108
  tracingInfo,
87
- correspondingTimingOverrides
109
+ correspondingTimingOverrides,
110
+ pageStateInfo
88
111
  )
89
112
  return {
90
113
  startTime: startClocks.relative,
91
114
  rawRumEvent: resourceEvent,
92
115
  domainContext: {
93
- performanceEntry:
94
- matchingTiming && toPerformanceEntryRepresentation(matchingTiming),
116
+ performanceEntry: matchingTiming,
95
117
  xhr: request.xhr,
96
118
  response: request.response,
97
119
  requestInput: request.input,
@@ -101,9 +123,11 @@ function processRequest(request) {
101
123
  }
102
124
  }
103
125
 
104
- function processResourceEntry(entry) {
126
+ function processResourceEntry(entry, sessionManager, pageStateHistory) {
105
127
  var type = computeResourceKind(entry)
106
128
  var entryMetrics = computePerformanceEntryMetrics(entry)
129
+ var startClocks = relativeToClocks(entry.startTime)
130
+
107
131
  var tracingInfo = computeEntryTracingInfo(entry)
108
132
  var urlObj = urlParse(entry.name).getParse()
109
133
  var statusCode = ''
@@ -112,7 +136,13 @@ function processResourceEntry(entry) {
112
136
  } else if (isCacheHit(entry)) {
113
137
  statusCode = 200
114
138
  }
115
- var startClocks = relativeToClocks(entry.startTime)
139
+
140
+ var pageStateInfo = computePageStateInfo(
141
+ pageStateHistory,
142
+ startClocks,
143
+ entry.duration
144
+ )
145
+
116
146
  var resourceEvent = extend2Lev(
117
147
  {
118
148
  date: startClocks.timeStamp,
@@ -131,13 +161,14 @@ function processResourceEntry(entry) {
131
161
  type: RumEventType.RESOURCE
132
162
  },
133
163
  tracingInfo,
134
- entryMetrics
164
+ entryMetrics,
165
+ pageStateInfo
135
166
  )
136
167
  return {
137
168
  startTime: startClocks.relative,
138
169
  rawRumEvent: resourceEvent,
139
170
  domainContext: {
140
- performanceEntry: toPerformanceEntryRepresentation(entry)
171
+ performanceEntry: entry
141
172
  }
142
173
  }
143
174
  }
@@ -154,12 +185,7 @@ function computePerformanceEntryMetrics(timing) {
154
185
  )
155
186
  }
156
187
  }
157
- function toPerformanceEntryRepresentation(entry) {
158
- if (supportPerformanceEntry() && entry instanceof PerformanceEntry) {
159
- entry.toJSON()
160
- }
161
- return entry
162
- }
188
+
163
189
  function computeRequestTracingInfo(request) {
164
190
  var hasBeenTraced = request.traceSampled && request.traceId && request.spanId
165
191
  if (!hasBeenTraced) {
@@ -173,7 +199,27 @@ function computeRequestTracingInfo(request) {
173
199
  resource: { id: UUID() }
174
200
  }
175
201
  }
176
-
202
+ function computePageStateInfo(pageStateHistory, startClocks, duration) {
203
+ return {
204
+ _gc: {
205
+ page_states: pageStateHistory.findAll(startClocks.relative, duration),
206
+ page_was_discarded: String(document.wasDiscarded)
207
+ }
208
+ }
209
+ }
210
+ function computeRequestDuration(pageStateHistory, startClocks, duration) {
211
+ const requestCrosseds = pageStateHistory.findAll(
212
+ startClocks.relative,
213
+ duration
214
+ )
215
+ var requestCrossedFrozenState
216
+ if (requestCrosseds) {
217
+ requestCrossedFrozenState = some(requestCrosseds, function (pageState) {
218
+ return pageState.state === PageState.FROZEN
219
+ })
220
+ }
221
+ return !requestCrossedFrozenState ? toServerDuration(duration) : undefined
222
+ }
177
223
  function computeEntryTracingInfo(entry) {
178
224
  return entry.traceId ? { _gc: { traceId: entry.traceId } } : undefined
179
225
  }
@@ -1,11 +1,6 @@
1
- import { noop } from '@cloudcare/browser-core'
2
-
3
- import { computeScrollValues, trackScrollMetrics } from './trackScrollMetrics'
1
+ import { trackScrollMetrics } from './trackScrollMetrics'
4
2
  import { trackLoadingTime } from './trackLoadingTime'
5
- import {
6
- isLayoutShiftSupported,
7
- trackCumulativeLayoutShift
8
- } from './trackCumulativeLayoutShift'
3
+ import { trackCumulativeLayoutShift } from './trackCumulativeLayoutShift'
9
4
  import { trackInteractionToNextPaint } from './trackInteractionToNextPaint'
10
5
 
11
6
  export function trackCommonViewMetrics(
@@ -25,60 +20,48 @@ export function trackCommonViewMetrics(
25
20
  viewStart,
26
21
  function (newLoadingTime) {
27
22
  commonViewMetrics.loadingTime = newLoadingTime
28
-
29
- // We compute scroll metrics at loading time to ensure we have scroll data when loading the view initially
30
- // This is to ensure that we have the depth data even if the user didn't scroll or if the view is not scrollable.
31
- var _computeScrollValues = computeScrollValues()
32
-
33
- commonViewMetrics.scroll = {
34
- maxDepth: _computeScrollValues.scrollDepth,
35
- maxDepthScrollHeight: _computeScrollValues.scrollHeight,
36
- maxDepthTime: newLoadingTime,
37
- maxDepthScrollTop: _computeScrollValues.scrollTop
38
- }
39
23
  scheduleViewUpdate()
40
24
  }
41
25
  )
42
26
  var stopLoadingTimeTracking = _trackLoadingTime.stop
43
27
  var setLoadEvent = _trackLoadingTime.setLoadEvent
44
28
  var _trackScrollMetrics = trackScrollMetrics(
29
+ configuration,
45
30
  viewStart,
46
31
  function (newScrollMetrics) {
47
32
  commonViewMetrics.scroll = newScrollMetrics
48
- },
49
- computeScrollValues
33
+ }
50
34
  )
51
35
  var stopScrollMetricsTracking = _trackScrollMetrics.stop
52
36
  var stopCLSTracking
53
- if (isLayoutShiftSupported()) {
54
- commonViewMetrics.cumulativeLayoutShift = 0
55
- var _trackCumulativeLayoutShift = trackCumulativeLayoutShift(
56
- lifeCycle,
57
- function (cumulativeLayoutShift) {
58
- commonViewMetrics.cumulativeLayoutShift = cumulativeLayoutShift
59
- scheduleViewUpdate()
60
- }
61
- )
62
- stopCLSTracking = _trackCumulativeLayoutShift.stop
63
- } else {
64
- stopCLSTracking = noop
65
- }
66
-
37
+ var _trackCumulativeLayoutShift = trackCumulativeLayoutShift(
38
+ lifeCycle,
39
+ configuration,
40
+ function (cumulativeLayoutShift) {
41
+ commonViewMetrics.cumulativeLayoutShift = cumulativeLayoutShift
42
+ scheduleViewUpdate()
43
+ }
44
+ )
45
+ var stopCLSTracking = _trackCumulativeLayoutShift.stop
67
46
  var _trackInteractionToNextPaint = trackInteractionToNextPaint(
47
+ configuration,
48
+ viewStart.relative,
68
49
  loadingType,
69
50
  lifeCycle
70
51
  )
71
52
  var stopINPTracking = _trackInteractionToNextPaint.stop
72
53
  var getInteractionToNextPaint =
73
54
  _trackInteractionToNextPaint.getInteractionToNextPaint
55
+ var setViewEnd = _trackInteractionToNextPaint.setViewEnd
74
56
  return {
75
57
  stop: function () {
76
58
  stopLoadingTimeTracking()
77
59
  stopCLSTracking()
78
60
  stopScrollMetricsTracking()
79
- stopINPTracking()
80
61
  },
62
+ stopINPTracking: stopINPTracking,
81
63
  setLoadEvent: setLoadEvent,
64
+ setViewEnd: setViewEnd,
82
65
  getCommonViewMetrics: function () {
83
66
  commonViewMetrics.interactionToNextPaint = getInteractionToNextPaint()
84
67
  return commonViewMetrics
@@ -1,5 +1,14 @@
1
- import { round, ONE_SECOND, LifeCycleEventType } from '@cloudcare/browser-core'
1
+ import {
2
+ find,
3
+ noop,
4
+ round,
5
+ ONE_SECOND,
6
+ LifeCycleEventType,
7
+ isElementNode
8
+ } from '@cloudcare/browser-core'
2
9
  import { supportPerformanceTimingEvent } from '../../performanceCollection'
10
+ import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
11
+
3
12
  /**
4
13
  * Track the cumulative layout shifts (CLS).
5
14
  * Layout shifts are grouped into session windows.
@@ -17,8 +26,16 @@ import { supportPerformanceTimingEvent } from '../../performanceCollection'
17
26
  * https://web.dev/evolving-cls/
18
27
  * Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getCLS.ts
19
28
  */
20
- export function trackCumulativeLayoutShift(lifeCycle, callback) {
29
+ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
30
+ if (!isLayoutShiftSupported()) {
31
+ return {
32
+ stop: noop
33
+ }
34
+ }
21
35
  var maxClsValue = 0
36
+ callback({
37
+ value: 0
38
+ })
22
39
  var window = slidingSessionWindow()
23
40
  var _subscribe = lifeCycle.subscribe(
24
41
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
@@ -29,7 +46,19 @@ export function trackCumulativeLayoutShift(lifeCycle, callback) {
29
46
  window.update(entry)
30
47
  if (window.value() > maxClsValue) {
31
48
  maxClsValue = window.value()
32
- callback(round(maxClsValue, 4))
49
+ var cls = round(maxClsValue, 4)
50
+ var clsTarget = window.largestLayoutShiftTarget()
51
+ var cslTargetSelector
52
+ if (clsTarget) {
53
+ cslTargetSelector = getSelectorFromElement(
54
+ clsTarget,
55
+ configuration.actionNameAttribute
56
+ )
57
+ }
58
+ callback({
59
+ value: cls,
60
+ targetSelector: cslTargetSelector
61
+ })
33
62
  }
34
63
  }
35
64
  }
@@ -45,6 +74,9 @@ function slidingSessionWindow() {
45
74
  var value = 0
46
75
  var startTime
47
76
  var endTime
77
+ var largestLayoutShift = 0
78
+ var largestLayoutShiftTarget
79
+ var largestLayoutShiftTime
48
80
  return {
49
81
  update: function (entry) {
50
82
  var shouldCreateNewWindow =
@@ -54,13 +86,37 @@ function slidingSessionWindow() {
54
86
  if (shouldCreateNewWindow) {
55
87
  startTime = endTime = entry.startTime
56
88
  value = entry.value
89
+ largestLayoutShift = 0
90
+ largestLayoutShiftTarget = undefined
57
91
  } else {
58
92
  value += entry.value
59
93
  endTime = entry.startTime
60
94
  }
95
+
96
+ if (entry.value > largestLayoutShift) {
97
+ largestLayoutShift = entry.value
98
+ largestLayoutShiftTime = entry.startTime
99
+
100
+ if (entry.sources && entry.sources.length) {
101
+ var findTarget = find(entry.sources, function (s) {
102
+ return !!s.node && isElementNode(s.node)
103
+ })
104
+ if (findTarget) {
105
+ largestLayoutShiftTarget = findTarget.node
106
+ }
107
+ } else {
108
+ largestLayoutShiftTarget = undefined
109
+ }
110
+ }
61
111
  },
62
112
  value: function () {
63
113
  return value
114
+ },
115
+ largestLayoutShiftTarget: function () {
116
+ return largestLayoutShiftTarget
117
+ },
118
+ largestLayoutShiftTime: function () {
119
+ return largestLayoutShiftTime
64
120
  }
65
121
  }
66
122
  }
@@ -1,8 +1,6 @@
1
1
  import { find, LifeCycleEventType, ONE_MINUTE } from '@cloudcare/browser-core'
2
- import { trackFirstHidden } from './trackFirstHidden'
3
2
  export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE
4
- export function trackFirstContentfulPaint(lifeCycle, callback) {
5
- var firstHidden = trackFirstHidden()
3
+ export function trackFirstContentfulPaint(lifeCycle, firstHidden, callback) {
6
4
  var subscribe = lifeCycle.subscribe(
7
5
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
8
6
  function (entries) {
@@ -10,7 +8,7 @@ export function trackFirstContentfulPaint(lifeCycle, callback) {
10
8
  return (
11
9
  entry.entryType === 'paint' &&
12
10
  entry.name === 'first-contentful-paint' &&
13
- entry.startTime < firstHidden.timeStamp &&
11
+ entry.startTime < firstHidden.geTimeStamp() &&
14
12
  entry.startTime < TIMING_MAXIMUM_DELAY
15
13
  )
16
14
  })
@@ -1,42 +1,37 @@
1
1
  import { DOM_EVENT, addEventListeners } from '@cloudcare/browser-core'
2
- var trackFirstHiddenSingleton
3
- var stopListeners
4
2
 
5
3
  export function trackFirstHidden(eventTarget) {
6
4
  if (typeof eventTarget === 'undefined') {
7
5
  eventTarget = window
8
6
  }
9
- if (!trackFirstHiddenSingleton) {
10
- if (document.visibilityState === 'hidden') {
11
- trackFirstHiddenSingleton = { timeStamp: 0 }
12
- } else {
13
- trackFirstHiddenSingleton = {
14
- timeStamp: Infinity
15
- }
16
- var listeners = addEventListeners(
17
- eventTarget,
18
- [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE],
19
- function (event) {
20
- if (
21
- event.type === 'pagehide' ||
22
- document.visibilityState === 'hidden'
23
- ) {
24
- trackFirstHiddenSingleton.timeStamp = event.timeStamp
25
- stopListeners()
26
- }
27
- },
28
- { capture: true }
29
- )
30
- var stopListeners = listeners.stop
31
- }
7
+ var timeStamp
8
+ var stopListeners
9
+ if (document.visibilityState === 'hidden') {
10
+ timeStamp = 0
11
+ } else {
12
+ timeStamp = Infinity
13
+ var stopListeners = addEventListeners(
14
+ eventTarget,
15
+ [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE],
16
+ function (event) {
17
+ if (
18
+ event.type === DOM_EVENT.PAGE_HIDE ||
19
+ document.visibilityState === 'hidden'
20
+ ) {
21
+ timeStamp = event.timeStamp
22
+ stopListeners()
23
+ }
24
+ },
25
+ { capture: true }
26
+ ).stop
32
27
  }
33
28
 
34
- return trackFirstHiddenSingleton
35
- }
36
-
37
- export function resetFirstHidden() {
38
- if (stopListeners) {
39
- stopListeners()
29
+ return {
30
+ geTimeStamp() {
31
+ return timeStamp
32
+ },
33
+ stop: function () {
34
+ stopListeners && stopListeners()
35
+ }
40
36
  }
41
- trackFirstHiddenSingleton = undefined
42
37
  }
@@ -1,5 +1,11 @@
1
- import { elapsed, find, LifeCycleEventType } from '@cloudcare/browser-core'
2
- import { trackFirstHidden } from './trackFirstHidden'
1
+ import {
2
+ elapsed,
3
+ find,
4
+ LifeCycleEventType,
5
+ isElementNode
6
+ } from '@cloudcare/browser-core'
7
+ import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
8
+
3
9
  /**
4
10
  * Track the first input occurring during the initial View to return:
5
11
  * - First Input Delay
@@ -8,15 +14,19 @@ import { trackFirstHidden } from './trackFirstHidden'
8
14
  * Documentation: https://web.dev/fid/
9
15
  * Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getFID.ts
10
16
  */
11
- export function trackFirstInputTimings(lifeCycle, callback) {
12
- var firstHidden = trackFirstHidden()
17
+ export function trackFirstInput(
18
+ lifeCycle,
19
+ configuration,
20
+ firstHidden,
21
+ callback
22
+ ) {
13
23
  var subscribe = lifeCycle.subscribe(
14
24
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
15
25
  function (entries) {
16
26
  var firstInputEntry = find(entries, function (entry) {
17
27
  return (
18
28
  entry.entryType === 'first-input' &&
19
- entry.startTime < firstHidden.timeStamp
29
+ entry.startTime < firstHidden.geTimeStamp()
20
30
  )
21
31
  })
22
32
  if (firstInputEntry) {
@@ -24,12 +34,19 @@ export function trackFirstInputTimings(lifeCycle, callback) {
24
34
  firstInputEntry.startTime,
25
35
  firstInputEntry.processingStart
26
36
  )
37
+ var firstInputTargetSelector
38
+ if (firstInputEntry.target && isElementNode(firstInputEntry.target)) {
39
+ firstInputTargetSelector = getSelectorFromElement(
40
+ firstInputEntry.target,
41
+ configuration.actionNameAttribute
42
+ )
43
+ }
27
44
  callback({
28
45
  // Ensure firstInputDelay to be positive, see
29
46
  // https://bugs.chromium.org/p/chromium/issues/detail?id=1185815
30
- firstInputDelay: firstInputDelay >= 0 ? firstInputDelay : 0,
31
- firstInputTime: firstInputEntry.startTime,
32
- firstInputTarget: firstInputEntry.target
47
+ delay: firstInputDelay >= 0 ? firstInputDelay : 0,
48
+ time: firstInputEntry.startTime,
49
+ targetSelector: firstInputTargetSelector
33
50
  })
34
51
  }
35
52
  }