@cloudcare/browser-rum 2.2.15 → 3.0.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 (166) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +161 -0
  4. package/cjs/boot/rum.entry.js +6 -1
  5. package/cjs/boot/rum.js +15 -5
  6. package/cjs/boot/rumPublicApi.js +8 -4
  7. package/cjs/boot/startRecording.js +55 -0
  8. package/cjs/constants.js +52 -0
  9. package/cjs/domain/assembly.js +1 -7
  10. package/cjs/domain/configuration.js +3 -2
  11. package/cjs/domain/contexts/foregroundContexts.js +138 -0
  12. package/cjs/domain/contexts/internalContext.js +1 -1
  13. package/cjs/domain/contexts/urlContexts.js +9 -2
  14. package/cjs/domain/domMutationCollection.js +4 -5
  15. package/cjs/domain/initViewportObservable.js +52 -0
  16. package/cjs/domain/locationChangeObservable.js +12 -26
  17. package/cjs/domain/performanceCollection.js +2 -13
  18. package/cjs/domain/replay/record/elementsScrollPositions.js +27 -0
  19. package/cjs/domain/replay/record/index.js +41 -0
  20. package/cjs/domain/replay/record/mutationBatch.js +58 -0
  21. package/cjs/domain/replay/record/mutationObserver.js +383 -0
  22. package/cjs/domain/replay/record/observers.js +473 -0
  23. package/cjs/domain/replay/record/privacy.js +256 -0
  24. package/cjs/domain/replay/record/record.js +174 -0
  25. package/cjs/domain/replay/record/serializationUtils.js +137 -0
  26. package/cjs/domain/replay/record/serialize.js +488 -0
  27. package/cjs/domain/replay/record/shadowRootsController.js +61 -0
  28. package/cjs/domain/replay/record/utils.js +53 -0
  29. package/cjs/domain/replay/record/viewports.js +104 -0
  30. package/cjs/domain/replay/replayStats.js +83 -0
  31. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +43 -0
  32. package/cjs/domain/replay/segmentCollection/deflateWorker.js +4399 -0
  33. package/cjs/domain/replay/segmentCollection/index.js +33 -0
  34. package/cjs/domain/replay/segmentCollection/segment.js +101 -0
  35. package/cjs/domain/replay/segmentCollection/segmentCollection.js +179 -0
  36. package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +126 -0
  37. package/cjs/domain/requestCollection.js +35 -17
  38. package/cjs/domain/rumEventsCollection/actions/actionCollection.js +12 -4
  39. package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
  40. package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
  41. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +8 -6
  42. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +111 -75
  43. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
  44. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +94 -54
  45. package/cjs/domain/rumEventsCollection/error/errorCollection.js +13 -5
  46. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +45 -0
  47. package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
  48. package/cjs/domain/rumEventsCollection/view/trackViews.js +21 -18
  49. package/cjs/domain/rumEventsCollection/view/viewCollection.js +12 -9
  50. package/cjs/domain/rumSessionManager.js +6 -3
  51. package/cjs/domain/tracing/getDocumentTraceId.js +2 -10
  52. package/cjs/domain/trackEventCounts.js +10 -2
  53. package/cjs/domain/waitPageActivityEnd.js +5 -1
  54. package/cjs/transport/startRumBatch.js +5 -7
  55. package/cjs/types/index.js +18 -0
  56. package/cjs/types/sessionReplayConstants.js +56 -0
  57. package/esm/boot/buildEnv.js +1 -1
  58. package/esm/boot/recorderApi.js +149 -0
  59. package/esm/boot/rum.entry.js +4 -1
  60. package/esm/boot/rum.js +15 -6
  61. package/esm/boot/rumPublicApi.js +8 -4
  62. package/esm/boot/startRecording.js +44 -0
  63. package/esm/constants.js +31 -0
  64. package/esm/domain/assembly.js +1 -7
  65. package/esm/domain/configuration.js +4 -3
  66. package/esm/domain/contexts/foregroundContexts.js +122 -0
  67. package/esm/domain/contexts/internalContext.js +1 -1
  68. package/esm/domain/contexts/urlContexts.js +10 -3
  69. package/esm/domain/domMutationCollection.js +5 -6
  70. package/esm/domain/initViewportObservable.js +39 -0
  71. package/esm/domain/locationChangeObservable.js +13 -27
  72. package/esm/domain/performanceCollection.js +1 -12
  73. package/esm/domain/replay/record/elementsScrollPositions.js +20 -0
  74. package/esm/domain/replay/record/index.js +3 -0
  75. package/esm/domain/replay/record/mutationBatch.js +35 -0
  76. package/esm/domain/replay/record/mutationObserver.js +331 -0
  77. package/esm/domain/replay/record/observers.js +457 -0
  78. package/esm/domain/replay/record/privacy.js +233 -0
  79. package/esm/domain/replay/record/record.js +158 -0
  80. package/esm/domain/replay/record/serializationUtils.js +107 -0
  81. package/esm/domain/replay/record/serialize.js +461 -0
  82. package/esm/domain/replay/record/shadowRootsController.js +49 -0
  83. package/esm/domain/replay/record/utils.js +38 -0
  84. package/esm/domain/replay/record/viewports.js +87 -0
  85. package/esm/domain/replay/replayStats.js +64 -0
  86. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +31 -0
  87. package/esm/domain/replay/segmentCollection/deflateWorker.js +4390 -0
  88. package/esm/domain/replay/segmentCollection/index.js +3 -0
  89. package/esm/domain/replay/segmentCollection/segment.js +84 -0
  90. package/esm/domain/replay/segmentCollection/segmentCollection.js +158 -0
  91. package/esm/domain/replay/segmentCollection/startDeflateWorker.js +113 -0
  92. package/esm/domain/requestCollection.js +36 -18
  93. package/esm/domain/rumEventsCollection/actions/actionCollection.js +12 -4
  94. package/esm/domain/rumEventsCollection/actions/clickChain.js +3 -3
  95. package/esm/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
  96. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +6 -6
  97. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +105 -74
  98. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
  99. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +99 -59
  100. package/esm/domain/rumEventsCollection/error/errorCollection.js +13 -5
  101. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +33 -0
  102. package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +1 -18
  103. package/esm/domain/rumEventsCollection/view/trackViews.js +21 -19
  104. package/esm/domain/rumEventsCollection/view/viewCollection.js +12 -9
  105. package/esm/domain/rumSessionManager.js +6 -3
  106. package/esm/domain/tracing/getDocumentTraceId.js +1 -9
  107. package/esm/domain/trackEventCounts.js +10 -2
  108. package/esm/domain/waitPageActivityEnd.js +5 -1
  109. package/esm/transport/startRumBatch.js +5 -7
  110. package/esm/types/index.js +1 -0
  111. package/esm/types/sessionReplayConstants.js +45 -0
  112. package/package.json +3 -3
  113. package/src/boot/recorderApi.js +166 -0
  114. package/src/boot/rum.entry.js +4 -1
  115. package/src/boot/rum.js +38 -10
  116. package/src/boot/rumPublicApi.js +13 -3
  117. package/src/boot/startRecording.js +77 -0
  118. package/src/constants.js +37 -0
  119. package/src/domain/assembly.js +1 -6
  120. package/src/domain/configuration.js +10 -2
  121. package/src/domain/contexts/foregroundContexts.js +140 -0
  122. package/src/domain/contexts/internalContext.js +10 -4
  123. package/src/domain/contexts/urlContexts.js +29 -15
  124. package/src/domain/domMutationCollection.js +14 -6
  125. package/src/domain/initViewportObservable.js +46 -0
  126. package/src/domain/locationChangeObservable.js +17 -25
  127. package/src/domain/performanceCollection.js +42 -42
  128. package/src/domain/replay/record/elementsScrollPositions.js +22 -0
  129. package/src/domain/replay/record/index.js +7 -0
  130. package/src/domain/replay/record/mutationBatch.js +38 -0
  131. package/src/domain/replay/record/mutationObserver.js +393 -0
  132. package/src/domain/replay/record/observers.js +562 -0
  133. package/src/domain/replay/record/privacy.js +304 -0
  134. package/src/domain/replay/record/record.js +158 -0
  135. package/src/domain/replay/record/serializationUtils.js +134 -0
  136. package/src/domain/replay/record/serialize.js +497 -0
  137. package/src/domain/replay/record/shadowRootsController.js +58 -0
  138. package/src/domain/replay/record/utils.js +44 -0
  139. package/src/domain/replay/record/viewports.js +89 -0
  140. package/src/domain/replay/replayStats.js +67 -0
  141. package/src/domain/replay/segmentCollection/buildReplayPayload.js +34 -0
  142. package/src/domain/replay/segmentCollection/deflateWorker.js +4577 -0
  143. package/src/domain/replay/segmentCollection/index.js +6 -0
  144. package/src/domain/replay/segmentCollection/segment.js +87 -0
  145. package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
  146. package/src/domain/replay/segmentCollection/startDeflateWorker.js +101 -0
  147. package/src/domain/requestCollection.js +64 -28
  148. package/src/domain/rumEventsCollection/actions/actionCollection.js +11 -4
  149. package/src/domain/rumEventsCollection/actions/clickChain.js +3 -3
  150. package/src/domain/rumEventsCollection/actions/computeFrustration.js +7 -4
  151. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +9 -6
  152. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +130 -108
  153. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +26 -27
  154. package/src/domain/rumEventsCollection/actions/trackClickActions.js +162 -92
  155. package/src/domain/rumEventsCollection/error/errorCollection.js +11 -5
  156. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +38 -0
  157. package/src/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
  158. package/src/domain/rumEventsCollection/view/trackViews.js +98 -68
  159. package/src/domain/rumEventsCollection/view/viewCollection.js +15 -7
  160. package/src/domain/rumSessionManager.js +33 -19
  161. package/src/domain/tracing/getDocumentTraceId.js +6 -9
  162. package/src/domain/trackEventCounts.js +10 -4
  163. package/src/domain/waitPageActivityEnd.js +4 -1
  164. package/src/transport/startRumBatch.js +29 -24
  165. package/src/types/index.js +1 -0
  166. package/src/types/sessionReplayConstants.js +49 -0
@@ -13,10 +13,15 @@ import {
13
13
  map,
14
14
  LifeCycleEventType,
15
15
  ActionType,
16
- isNullUndefinedDefaultValue
16
+ isNullUndefinedDefaultValue,
17
+ isArray,
18
+ includes
17
19
  } from '@cloudcare/browser-core'
18
20
  import { trackEventCounts } from '../../trackEventCounts'
19
- import { waitPageActivityEnd } from '../../waitPageActivityEnd'
21
+ import {
22
+ waitPageActivityEnd,
23
+ PAGE_ACTIVITY_VALIDATION_DELAY
24
+ } from '../../waitPageActivityEnd'
20
25
  import { createClickChain } from './clickChain'
21
26
  import { getActionNameFromElement } from './getActionNameFromElement'
22
27
  // import { getSelectorsFromElement } from './getSelectorsFromElement'
@@ -39,23 +44,29 @@ export function trackClickActions(
39
44
  lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
40
45
  history.reset()
41
46
  })
42
- lifeCycle.subscribe(LifeCycleEventType.BEFORE_UNLOAD, stopClickChain)
43
47
  lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, stopClickChain)
44
48
  var _listenActionEvents = listenActionEvents({
45
49
  onPointerDown: function (pointerDownEvent) {
46
- return processPointerDown(configuration, pointerDownEvent)
50
+ return processPointerDown(
51
+ configuration,
52
+ lifeCycle,
53
+ domMutationObservable,
54
+ history,
55
+ pointerDownEvent
56
+ )
47
57
  },
48
- onClick: function (clickActionBase, clickEvent, getUserActivity) {
49
- return processClick(
58
+ onPointerUp: function (data, startEvent, getUserActivity) {
59
+ startClickAction(
50
60
  configuration,
51
61
  lifeCycle,
52
62
  domMutationObservable,
53
63
  history,
54
64
  stopObservable,
55
65
  appendClickToClickChain,
56
- clickActionBase,
57
- clickEvent,
58
- getUserActivity
66
+ data.clickActionBase,
67
+ startEvent,
68
+ getUserActivity,
69
+ data.hadActivityOnPointerDown
59
70
  )
60
71
  }
61
72
  })
@@ -90,86 +101,130 @@ export function trackClickActions(
90
101
  })
91
102
  }
92
103
  }
93
- function processPointerDown(configuration, pointerDownEvent) {
94
- var clickActionBase = computeClickActionBase(
95
- pointerDownEvent,
96
- configuration.actionNameAttribute
97
- )
98
- return clickActionBase
104
+ }
105
+ function processPointerDown(
106
+ configuration,
107
+ lifeCycle,
108
+ domMutationObservable,
109
+ history,
110
+ pointerDownEvent
111
+ ) {
112
+ if (!configuration.trackFrustrations && history.find()) {
113
+ // TODO: remove this in a future major version. To keep retrocompatibility, ignore any new
114
+ // action if another one is already occurring.
115
+ return
99
116
  }
100
- function processClick(
101
- configuration,
117
+
118
+ var clickActionBase = computeClickActionBase(
119
+ pointerDownEvent,
120
+ configuration.actionNameAttribute
121
+ )
122
+ if (!configuration.trackFrustrations && !clickActionBase.name) {
123
+ // TODO: remove this in a future major version. To keep retrocompatibility, ignore any action
124
+ // with a blank name
125
+ return
126
+ }
127
+
128
+ var hadActivityOnPointerDown = false
129
+
130
+ waitPageActivityEnd(
102
131
  lifeCycle,
103
132
  domMutationObservable,
133
+ configuration,
134
+ function (pageActivityEndEvent) {
135
+ hadActivityOnPointerDown = pageActivityEndEvent.hadActivity
136
+ },
137
+ // We don't care about the activity duration, we just want to know whether an activity did happen
138
+ // within the "validation delay" or not. Limit the duration so the callback is called sooner.
139
+ PAGE_ACTIVITY_VALIDATION_DELAY
140
+ )
141
+
142
+ return {
143
+ clickActionBase: clickActionBase,
144
+ hadActivityOnPointerDown: function () {
145
+ return hadActivityOnPointerDown
146
+ }
147
+ }
148
+ }
149
+ function startClickAction(
150
+ configuration,
151
+ lifeCycle,
152
+ domMutationObservable,
153
+ history,
154
+ stopObservable,
155
+ appendClickToClickChain,
156
+ clickActionBase,
157
+ startEvent,
158
+ getUserActivity,
159
+ hadActivityOnPointerDown
160
+ ) {
161
+ var click = newClick(
162
+ lifeCycle,
104
163
  history,
105
- stopObservable,
106
- appendClickToClickChain,
164
+ getUserActivity,
107
165
  clickActionBase,
108
- clickEvent,
109
- getUserActivity
110
- ) {
111
- var click = newClick(
112
- lifeCycle,
113
- history,
114
- getUserActivity,
115
- clickActionBase,
116
- clickEvent
117
- )
118
- if (configuration.trackFrustrations) {
119
- appendClickToClickChain(click)
120
- }
166
+ startEvent
167
+ )
121
168
 
122
- var _waitPageActivityEnd = waitPageActivityEnd(
123
- lifeCycle,
124
- domMutationObservable,
125
- configuration,
126
- function (pageActivityEndEvent) {
127
- if (
128
- pageActivityEndEvent.hadActivity &&
129
- pageActivityEndEvent.end < click.startClocks.timeStamp
130
- ) {
131
- // If the clock is looking weird, just discard the click
132
- click.discard()
133
- } else {
169
+ if (configuration.trackFrustrations) {
170
+ appendClickToClickChain(click)
171
+ }
172
+ var _waitPageActivityEnd = waitPageActivityEnd(
173
+ lifeCycle,
174
+ domMutationObservable,
175
+ configuration,
176
+ function (pageActivityEndEvent) {
177
+ if (
178
+ pageActivityEndEvent.hadActivity &&
179
+ pageActivityEndEvent.end < click.startClocks.timeStamp
180
+ ) {
181
+ // If the clock is looking weird, just discard the click
182
+ click.discard()
183
+ } else {
184
+ if (pageActivityEndEvent.hadActivity) {
185
+ click.stop(pageActivityEndEvent.end)
186
+ } else if (hadActivityOnPointerDown()) {
134
187
  click.stop(
135
- pageActivityEndEvent.hadActivity
136
- ? pageActivityEndEvent.end
137
- : undefined
188
+ // using the click start as activity end, so the click will have some activity but its
189
+ // duration will be 0 (as the activity started before the click start)
190
+ click.startClocks.timeStamp
138
191
  )
192
+ } else {
193
+ click.stop()
194
+ }
139
195
 
140
- // Validate or discard the click only if we don't track frustrations. It'll be done when
141
- // the click chain is finalized.
142
- if (!configuration.trackFrustrations) {
143
- if (!pageActivityEndEvent.hadActivity) {
144
- // If we are not tracking frustrations, we should discard the click to keep backward
145
- // compatibility.
146
- click.discard()
147
- } else {
148
- click.validate()
149
- }
196
+ // Validate or discard the click only if we don't track frustrations. It'll be done when
197
+ // the click chain is finalized.
198
+ if (!configuration.trackFrustrations) {
199
+ if (!pageActivityEndEvent.hadActivity) {
200
+ // If we are not tracking frustrations, we should discard the click to keep backward
201
+ // compatibility.
202
+ click.discard()
203
+ } else {
204
+ click.validate()
150
205
  }
151
206
  }
152
- },
153
- CLICK_ACTION_MAX_DURATION
154
- )
155
-
156
- var viewEndedSubscription = lifeCycle.subscribe(
157
- LifeCycleEventType.VIEW_ENDED,
158
- function (data) {
159
- click.stop(data.endClocks.timeStamp)
160
207
  }
161
- )
208
+ },
209
+ CLICK_ACTION_MAX_DURATION
210
+ )
211
+ var stopWaitPageActivityEnd = _waitPageActivityEnd.stop
212
+ var viewEndedSubscription = lifeCycle.subscribe(
213
+ LifeCycleEventType.VIEW_ENDED,
214
+ function (data) {
215
+ click.stop(data.endClocks.timeStamp)
216
+ }
217
+ )
162
218
 
163
- var stopSubscription = stopObservable.subscribe(function () {
164
- click.stop()
165
- })
219
+ var stopSubscription = stopObservable.subscribe(function () {
220
+ click.stop()
221
+ })
166
222
 
167
- click.stopObservable.subscribe(function () {
168
- viewEndedSubscription.unsubscribe()
169
- _waitPageActivityEnd.stop()
170
- stopSubscription.unsubscribe()
171
- })
172
- }
223
+ click.stopObservable.subscribe(function () {
224
+ viewEndedSubscription.unsubscribe()
225
+ stopWaitPageActivityEnd()
226
+ stopSubscription.unsubscribe()
227
+ })
173
228
  }
174
229
 
175
230
  function computeClickActionBase(event, actionNameAttribute) {
@@ -193,7 +248,7 @@ function computeClickActionBase(event, actionNameAttribute) {
193
248
  // }
194
249
 
195
250
  return {
196
- type: 'click',
251
+ type: ActionType.CLICK,
197
252
  target: target,
198
253
  position: position,
199
254
  name: getActionNameFromElement(event.target, actionNameAttribute)
@@ -202,11 +257,11 @@ function computeClickActionBase(event, actionNameAttribute) {
202
257
 
203
258
  var ClickStatus = {
204
259
  // Initial state, the click is still ongoing.
205
- ONGOING: 'ONGOING',
260
+ ONGOING: 0,
206
261
  // The click is no more ongoing but still needs to be validated or discarded.
207
- STOPPED: 'STOPPED',
262
+ STOPPED: 1,
208
263
  // Final state, the click has been stopped and validated or discarded.
209
- FINALIZED: 'FINALIZED'
264
+ FINALIZED: 2
210
265
  }
211
266
 
212
267
  function newClick(
@@ -214,12 +269,22 @@ function newClick(
214
269
  history,
215
270
  getUserActivity,
216
271
  clickActionBase,
217
- clickEvent
272
+ startEvent
218
273
  ) {
219
274
  var id = UUID()
220
275
  var startClocks = clocksNow()
221
276
  var historyEntry = history.add(id, startClocks.relative)
222
- var eventCountsSubscription = trackEventCounts(lifeCycle)
277
+ var eventCountsSubscription = trackEventCounts({
278
+ lifeCycle: lifeCycle,
279
+ isChildEvent: function (event) {
280
+ return (
281
+ event.action !== undefined &&
282
+ (isArray(event.action.id)
283
+ ? includes(event.action.id, id)
284
+ : event.action.id === id)
285
+ )
286
+ }
287
+ })
223
288
  var status = ClickStatus.ONGOING
224
289
  var activityEndTime
225
290
  var frustrationTypes = []
@@ -241,17 +306,20 @@ function newClick(
241
306
  }
242
307
 
243
308
  return {
244
- event: clickEvent,
309
+ event: startEvent,
245
310
  stop: stop,
246
- startClocks: startClocks,
247
311
  stopObservable: stopObservable,
248
- hasError: eventCountsSubscription.eventCounts.errorCount > 0,
249
- hasPageActivity: activityEndTime !== undefined,
312
+ hasError: function () {
313
+ return eventCountsSubscription.eventCounts.errorCount > 0
314
+ },
315
+ hasPageActivity: function () {
316
+ return activityEndTime !== undefined
317
+ },
250
318
  getUserActivity: getUserActivity,
251
319
  addFrustration: function (frustrationType) {
252
320
  frustrationTypes.push(frustrationType)
253
321
  },
254
-
322
+ startClocks: startClocks,
255
323
  isStopped: function () {
256
324
  return status === ClickStatus.STOPPED || status === ClickStatus.FINALIZED
257
325
  },
@@ -262,7 +330,7 @@ function newClick(
262
330
  history,
263
331
  getUserActivity,
264
332
  clickActionBase,
265
- clickEvent
333
+ startEvent
266
334
  )
267
335
  },
268
336
 
@@ -284,15 +352,16 @@ function newClick(
284
352
  id: id,
285
353
  frustrationTypes: frustrationTypes,
286
354
  counts: {
287
- resourceCount,
288
- errorCount,
289
- longTaskCount
355
+ resourceCount: resourceCount,
356
+ errorCount: errorCount,
357
+ longTaskCount: longTaskCount
290
358
  },
291
- events: isNullUndefinedDefaultValue(domEvents, [clickEvent]),
292
- event: clickEvent
359
+ events: isNullUndefinedDefaultValue(domEvents, [startEvent]),
360
+ event: startEvent
293
361
  },
294
362
  clickActionBase
295
363
  )
364
+
296
365
  lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, clickAction)
297
366
  status = ClickStatus.FINALIZED
298
367
  },
@@ -307,6 +376,7 @@ function newClick(
307
376
  export function finalizeClicks(clicks, rageClick) {
308
377
  var _computeFrustration = computeFrustration(clicks, rageClick)
309
378
  var isRage = _computeFrustration.isRage
379
+
310
380
  if (isRage) {
311
381
  each(clicks, function (click) {
312
382
  click.discard()
@@ -13,7 +13,7 @@ import {
13
13
  import { trackConsoleError } from './trackConsoleError'
14
14
  import { trackReportError } from './trackReportError'
15
15
 
16
- export function startErrorCollection(lifeCycle) {
16
+ export function startErrorCollection(lifeCycle, foregroundContexts) {
17
17
  var errorObservable = new Observable()
18
18
 
19
19
  trackConsoleError(errorObservable)
@@ -24,10 +24,10 @@ export function startErrorCollection(lifeCycle) {
24
24
  lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error })
25
25
  })
26
26
 
27
- return doStartErrorCollection(lifeCycle)
27
+ return doStartErrorCollection(lifeCycle, foregroundContexts)
28
28
  }
29
29
 
30
- export function doStartErrorCollection(lifeCycle) {
30
+ export function doStartErrorCollection(lifeCycle, foregroundContexts) {
31
31
  lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {
32
32
  lifeCycle.notify(
33
33
  LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
@@ -36,7 +36,7 @@ export function doStartErrorCollection(lifeCycle) {
36
36
  customerContext: error.customerContext,
37
37
  savedCommonContext: error.savedCommonContext
38
38
  },
39
- processError(error.error)
39
+ processError(error.error, foregroundContexts)
40
40
  )
41
41
  )
42
42
  })
@@ -64,7 +64,7 @@ export function doStartErrorCollection(lifeCycle) {
64
64
  }
65
65
  }
66
66
 
67
- function processError(error) {
67
+ function processError(error, foregroundContexts) {
68
68
  var rawRumEvent = {
69
69
  date: error.startClocks.timeStamp,
70
70
  error: {
@@ -80,6 +80,12 @@ function processError(error) {
80
80
  },
81
81
  type: RumEventType.ERROR
82
82
  }
83
+ var inForeground = foregroundContexts.isInForegroundAt(
84
+ error.startClocks.relative
85
+ )
86
+ if (inForeground) {
87
+ rawRumEvent.view = { in_foreground: inForeground }
88
+ }
83
89
  return {
84
90
  rawRumEvent: rawRumEvent,
85
91
  startTime: error.startClocks.relative,
@@ -0,0 +1,38 @@
1
+ import { ONE_MINUTE } from '@cloudcare/browser-core'
2
+ import { trackEventCounts } from '../../trackEventCounts'
3
+
4
+ // Some events are not being counted as they transcend views. To reduce the occurrence;
5
+ // an arbitrary delay is added for stopping event counting after the view ends.
6
+ //
7
+ // Ideally, we would not stop and keep counting events until the end of the session.
8
+ // But this might have a small performance impact if there are many many views:
9
+ // we would need to go through each event to see if the related view matches.
10
+ // So let's have a fairly short delay to avoid impacting performances too much.
11
+ //
12
+ // In the future, we could have views stored in a data structure similar to ContextHistory. Whenever
13
+ // a child event is collected, we could look into this history to find the matching view and
14
+ // increase the associated and increase its counter. Having a centralized data structure for it
15
+ // would allow us to look for views more efficiently.
16
+ //
17
+ // For now, having a small cleanup delay will already improve the situation in most cases.
18
+
19
+ export var KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE
20
+
21
+ export function trackViewEventCounts(lifeCycle, viewId, onChange) {
22
+ var _trackEventCounts = trackEventCounts({
23
+ lifeCycle: lifeCycle,
24
+ isChildEvent: function (event) {
25
+ return event.view.id === viewId
26
+ },
27
+ onChange: onChange
28
+ })
29
+ return {
30
+ scheduleStop: function () {
31
+ setTimeout(
32
+ _trackEventCounts.stop,
33
+ KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY
34
+ )
35
+ },
36
+ eventCounts: _trackEventCounts.eventCounts
37
+ }
38
+ }
@@ -7,7 +7,6 @@ import {
7
7
  ViewLoadingType
8
8
  } from '@cloudcare/browser-core'
9
9
  import { supportPerformanceTimingEvent } from '../../performanceCollection'
10
- import { trackEventCounts } from '../../trackEventCounts'
11
10
  import { waitPageActivityEnd } from '../../waitPageActivityEnd'
12
11
  export function trackViewMetrics(
13
12
  lifeCycle,
@@ -17,24 +16,8 @@ export function trackViewMetrics(
17
16
  loadingType,
18
17
  viewStart
19
18
  ) {
20
- var viewMetrics = {
21
- eventCounts: {
22
- errorCount: 0,
23
- longTaskCount: 0,
24
- resourceCount: 0,
25
- actionCount: 0,
26
- frustrationCount: 0
27
- }
28
- }
19
+ var viewMetrics = {}
29
20
 
30
- var _trackEventCounts = trackEventCounts(
31
- lifeCycle,
32
- function (newEventCounts) {
33
- viewMetrics.eventCounts = newEventCounts
34
- scheduleViewUpdate()
35
- }
36
- )
37
- var stopEventCountsTracking = _trackEventCounts.stop
38
21
  var _trackLoadingTime = trackLoadingTime(
39
22
  lifeCycle,
40
23
  domMutationObservable,
@@ -64,7 +47,6 @@ export function trackViewMetrics(
64
47
  }
65
48
  return {
66
49
  stop: function () {
67
- stopEventCountsTracking()
68
50
  stopLoadingTimeTracking()
69
51
  stopCLSTracking()
70
52
  },