@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.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.js +23 -3
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/boot/rumPublicApi.js +49 -13
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/boot/startRecording.js +1 -1
- package/cjs/boot/startRecording.js.map +1 -1
- package/cjs/domain/assembly.js +6 -5
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/configuration.js +1 -3
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/contexts/displayContext.js +12 -18
- package/cjs/domain/contexts/displayContext.js.map +1 -1
- package/cjs/domain/performanceCollection.js +16 -10
- package/cjs/domain/performanceCollection.js.map +1 -1
- package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
- package/cjs/domain/replay/record/mutationObserver.js +5 -5
- package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
- package/cjs/domain/replay/record/privacy.js +0 -1
- package/cjs/domain/replay/record/privacy.js.map +1 -1
- package/cjs/domain/replay/record/serializationUtils.js +14 -19
- package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
- package/cjs/domain/replay/record/serialize.js +12 -13
- package/cjs/domain/replay/record/serialize.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +10 -33
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js +2 -8
- package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +33 -18
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js +11 -25
- package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +45 -2
- package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
- package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +22 -29
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +12 -9
- package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -0
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +18 -27
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +66 -11
- package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +11 -6
- package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js +55 -24
- package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +34 -12
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +17 -14
- package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/cjs/domain/trackEventCounts.js +4 -4
- package/cjs/domain/trackEventCounts.js.map +1 -1
- package/cjs/transport/startRumBatch.js +1 -1
- package/cjs/transport/startRumBatch.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.js +23 -3
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rumPublicApi.js +50 -14
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/boot/startRecording.js +1 -1
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/domain/assembly.js +6 -5
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +1 -3
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/contexts/displayContext.js +11 -16
- package/esm/domain/contexts/displayContext.js.map +1 -1
- package/esm/domain/performanceCollection.js +17 -10
- package/esm/domain/performanceCollection.js.map +1 -1
- package/esm/domain/replay/deflate/deflateWorker.js +1 -1
- package/esm/domain/replay/record/mutationObserver.js +6 -6
- package/esm/domain/replay/record/mutationObserver.js.map +1 -1
- package/esm/domain/replay/record/privacy.js +0 -1
- package/esm/domain/replay/record/privacy.js.map +1 -1
- package/esm/domain/replay/record/serializationUtils.js +15 -19
- package/esm/domain/replay/record/serializationUtils.js.map +1 -1
- package/esm/domain/replay/record/serialize.js +13 -14
- package/esm/domain/replay/record/serialize.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +10 -33
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js +3 -9
- package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +34 -19
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +13 -27
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +47 -3
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +22 -28
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +13 -9
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -0
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +19 -28
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +65 -12
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +12 -6
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js +55 -25
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +33 -12
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/viewCollection.js +18 -15
- package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/esm/domain/trackEventCounts.js +4 -4
- package/esm/domain/trackEventCounts.js.map +1 -1
- package/esm/transport/startRumBatch.js +1 -1
- package/esm/transport/startRumBatch.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/rum.js +27 -3
- package/src/boot/rumPublicApi.js +63 -16
- package/src/boot/startRecording.js +1 -0
- package/src/domain/assembly.js +6 -4
- package/src/domain/configuration.js +1 -3
- package/src/domain/contexts/displayContext.js +11 -20
- package/src/domain/performanceCollection.js +21 -10
- package/src/domain/replay/record/mutationObserver.js +7 -10
- package/src/domain/replay/record/privacy.js +1 -5
- package/src/domain/replay/record/serializationUtils.js +23 -19
- package/src/domain/replay/record/serialize.js +13 -16
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +7 -35
- package/src/domain/rumEventsCollection/resource/matchRequestTiming.js +4 -13
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +67 -21
- package/src/domain/rumEventsCollection/view/trackCommonViewMetrics.js +18 -35
- package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +59 -3
- package/src/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
- package/src/domain/rumEventsCollection/view/trackFirstHidden.js +27 -32
- package/src/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +25 -8
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +24 -28
- package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +79 -15
- package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +21 -6
- package/src/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
- package/src/domain/rumEventsCollection/view/trackScrollMetrics.js +79 -35
- package/src/domain/rumEventsCollection/view/trackViews.js +39 -16
- package/src/domain/rumEventsCollection/view/viewCollection.js +47 -18
- package/src/domain/trackEventCounts.js +4 -4
- package/src/transport/startRumBatch.js +3 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstInputTimings.js.map +0 -1
- package/esm/domain/rumEventsCollection/view/trackFirstInputTimings.js.map +0 -1
|
@@ -1,72 +1,68 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ONE_MINUTE } from '@cloudcare/browser-core'
|
|
2
2
|
import { trackFirstContentfulPaint } from './trackFirstContentfulPaint'
|
|
3
|
-
import {
|
|
3
|
+
import { trackFirstInput } from './trackFirstInput'
|
|
4
4
|
import { trackNavigationTimings } from './trackNavigationTimings'
|
|
5
5
|
import { trackLargestContentfulPaint } from './trackLargestContentfulPaint'
|
|
6
|
-
import {
|
|
6
|
+
import { trackFirstHidden } from './trackFirstHidden'
|
|
7
7
|
|
|
8
8
|
export var KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE
|
|
9
9
|
export function trackInitialViewMetrics(
|
|
10
10
|
lifeCycle,
|
|
11
|
+
configuration,
|
|
11
12
|
setLoadEvent,
|
|
12
13
|
scheduleViewUpdate
|
|
13
14
|
) {
|
|
14
15
|
var initialViewMetrics = {}
|
|
15
|
-
function setMetrics(newMetrics) {
|
|
16
|
-
assign(initialViewMetrics, newMetrics)
|
|
17
|
-
scheduleViewUpdate()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
16
|
var _trackNavigationTimings = trackNavigationTimings(
|
|
21
17
|
lifeCycle,
|
|
22
18
|
function (navigationTimings) {
|
|
23
19
|
setLoadEvent(navigationTimings.loadEvent)
|
|
24
|
-
|
|
20
|
+
initialViewMetrics.navigationTimings = navigationTimings
|
|
21
|
+
scheduleViewUpdate()
|
|
25
22
|
}
|
|
26
23
|
)
|
|
24
|
+
var firstHidden = trackFirstHidden()
|
|
27
25
|
var stopNavigationTracking = _trackNavigationTimings.stop
|
|
28
26
|
var _trackFirstContentfulPaint = trackFirstContentfulPaint(
|
|
29
27
|
lifeCycle,
|
|
28
|
+
firstHidden,
|
|
30
29
|
function (firstContentfulPaint) {
|
|
31
|
-
|
|
30
|
+
initialViewMetrics.firstContentfulPaint = firstContentfulPaint
|
|
31
|
+
scheduleViewUpdate()
|
|
32
32
|
}
|
|
33
33
|
)
|
|
34
34
|
var stopFCPTracking = _trackFirstContentfulPaint.stop
|
|
35
35
|
var _trackLargestContentfulPaint = trackLargestContentfulPaint(
|
|
36
36
|
lifeCycle,
|
|
37
|
+
configuration,
|
|
38
|
+
firstHidden,
|
|
37
39
|
window,
|
|
38
|
-
function (largestContentfulPaint
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
largestContentfulPaintElement: lcpElement
|
|
42
|
-
? getSelectorFromElement(lcpElement)
|
|
43
|
-
: undefined
|
|
44
|
-
})
|
|
40
|
+
function (largestContentfulPaint) {
|
|
41
|
+
initialViewMetrics.largestContentfulPaint = largestContentfulPaint
|
|
42
|
+
scheduleViewUpdate()
|
|
45
43
|
}
|
|
46
44
|
)
|
|
47
45
|
var stopLCPTracking = _trackLargestContentfulPaint.stop
|
|
48
|
-
var
|
|
46
|
+
var _trackFirstInput = trackFirstInput(
|
|
49
47
|
lifeCycle,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
configuration,
|
|
49
|
+
firstHidden,
|
|
50
|
+
function (firstInput) {
|
|
51
|
+
initialViewMetrics.firstInput = firstInput
|
|
52
|
+
scheduleViewUpdate()
|
|
55
53
|
}
|
|
56
54
|
)
|
|
57
|
-
var stopFIDTracking =
|
|
55
|
+
var stopFIDTracking = _trackFirstInput.stop
|
|
58
56
|
function stop() {
|
|
59
57
|
stopNavigationTracking()
|
|
60
58
|
stopFCPTracking()
|
|
61
59
|
stopLCPTracking()
|
|
62
60
|
stopFIDTracking()
|
|
61
|
+
firstHidden.stop()
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
return {
|
|
66
65
|
stop: stop,
|
|
67
|
-
initialViewMetrics: initialViewMetrics
|
|
68
|
-
scheduleStop: function () {
|
|
69
|
-
setTimeout(stop, KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY)
|
|
70
|
-
}
|
|
66
|
+
initialViewMetrics: initialViewMetrics
|
|
71
67
|
}
|
|
72
68
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
noop,
|
|
3
3
|
LifeCycleEventType,
|
|
4
|
-
ViewLoadingType
|
|
4
|
+
ViewLoadingType,
|
|
5
|
+
addTelemetryDebug,
|
|
6
|
+
ONE_MINUTE,
|
|
7
|
+
elapsed,
|
|
8
|
+
isElementNode
|
|
5
9
|
} from '@cloudcare/browser-core'
|
|
6
10
|
import { supportPerformanceTimingEvent } from '../../performanceCollection'
|
|
7
|
-
|
|
11
|
+
import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
|
|
8
12
|
import {
|
|
9
13
|
getInteractionCount,
|
|
10
14
|
initInteractionCountPolyfill
|
|
@@ -13,18 +17,26 @@ import {
|
|
|
13
17
|
// Arbitrary value to prevent unnecessary memory usage on views with lots of interactions.
|
|
14
18
|
var MAX_INTERACTION_ENTRIES = 10
|
|
15
19
|
|
|
20
|
+
export var MAX_INP_VALUE = 1 * ONE_MINUTE
|
|
21
|
+
|
|
16
22
|
/**
|
|
17
23
|
* Track the interaction to next paint (INP).
|
|
18
24
|
* To avoid outliers, return the p98 worst interaction of the view.
|
|
19
25
|
* Documentation: https://web.dev/inp/
|
|
20
26
|
* Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/main/src/onINP.ts
|
|
21
27
|
*/
|
|
22
|
-
export function trackInteractionToNextPaint(
|
|
28
|
+
export function trackInteractionToNextPaint(
|
|
29
|
+
configuration,
|
|
30
|
+
viewStart,
|
|
31
|
+
viewLoadingType,
|
|
32
|
+
lifeCycle
|
|
33
|
+
) {
|
|
23
34
|
if (!isInteractionToNextPaintSupported()) {
|
|
24
35
|
return {
|
|
25
36
|
getInteractionToNextPaint: function () {
|
|
26
37
|
return undefined
|
|
27
38
|
},
|
|
39
|
+
setViewEnd: noop,
|
|
28
40
|
stop: noop
|
|
29
41
|
}
|
|
30
42
|
}
|
|
@@ -32,24 +44,55 @@ export function trackInteractionToNextPaint(viewLoadingType, lifeCycle) {
|
|
|
32
44
|
var _trackViewInteractionCount = trackViewInteractionCount(viewLoadingType)
|
|
33
45
|
var getViewInteractionCount =
|
|
34
46
|
_trackViewInteractionCount.getViewInteractionCount
|
|
35
|
-
var
|
|
36
|
-
|
|
47
|
+
var stopViewInteractionCount =
|
|
48
|
+
_trackViewInteractionCount.stopViewInteractionCount
|
|
37
49
|
|
|
50
|
+
let viewEnd = Infinity
|
|
51
|
+
var longestInteractions = trackLongestInteractions(getViewInteractionCount)
|
|
52
|
+
var interactionToNextPaint = -1
|
|
53
|
+
var interactionToNextPaintTargetSelector
|
|
54
|
+
var telemetryCollected = false
|
|
38
55
|
var subscribe = lifeCycle.subscribe(
|
|
39
56
|
LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
|
|
40
57
|
function (entries) {
|
|
41
58
|
for (var entry of entries) {
|
|
42
59
|
if (
|
|
43
60
|
(entry.entryType === 'event' || entry.entryType === 'first-input') &&
|
|
44
|
-
entry.interactionId
|
|
61
|
+
entry.interactionId &&
|
|
62
|
+
entry.startTime >= viewStart &&
|
|
63
|
+
entry.startTime <= viewEnd
|
|
45
64
|
) {
|
|
46
65
|
longestInteractions.process(entry)
|
|
47
66
|
}
|
|
48
67
|
}
|
|
49
68
|
|
|
50
|
-
var
|
|
51
|
-
if (
|
|
52
|
-
|
|
69
|
+
var newInteraction = longestInteractions.estimateP98Duration()
|
|
70
|
+
if (newInteraction) {
|
|
71
|
+
interactionToNextPaint = newInteraction.duration
|
|
72
|
+
if (interactionToNextPaint > 10 * ONE_MINUTE && !telemetryCollected) {
|
|
73
|
+
telemetryCollected = true
|
|
74
|
+
addTelemetryDebug('INP outlier', {
|
|
75
|
+
inp: interactionToNextPaint,
|
|
76
|
+
interaction: {
|
|
77
|
+
timeFromViewStart: elapsed(viewStart, newInteraction.startTime),
|
|
78
|
+
duration: newInteraction.duration,
|
|
79
|
+
startTime: newInteraction.startTime,
|
|
80
|
+
processingStart: newInteraction.processingStart,
|
|
81
|
+
processingEnd: newInteraction.processingEnd,
|
|
82
|
+
interactionId: newInteraction.interactionId,
|
|
83
|
+
name: newInteraction.name,
|
|
84
|
+
targetNodeName: newInteraction.target?.nodeName
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
if (newInteraction.target && isElementNode(newInteraction.target)) {
|
|
89
|
+
interactionToNextPaintTargetSelector = getSelectorFromElement(
|
|
90
|
+
newInteraction.target,
|
|
91
|
+
configuration.actionNameAttribute
|
|
92
|
+
)
|
|
93
|
+
} else {
|
|
94
|
+
interactionToNextPaintTargetSelector = undefined
|
|
95
|
+
}
|
|
53
96
|
}
|
|
54
97
|
}
|
|
55
98
|
)
|
|
@@ -58,12 +101,21 @@ export function trackInteractionToNextPaint(viewLoadingType, lifeCycle) {
|
|
|
58
101
|
getInteractionToNextPaint: function () {
|
|
59
102
|
// If no INP duration where captured because of the performanceObserver 40ms threshold
|
|
60
103
|
// but the view interaction count > 0 then report 0
|
|
61
|
-
if (
|
|
62
|
-
return
|
|
104
|
+
if (interactionToNextPaint >= 0) {
|
|
105
|
+
return {
|
|
106
|
+
value: Math.min(interactionToNextPaint, MAX_INP_VALUE),
|
|
107
|
+
targetSelector: interactionToNextPaintTargetSelector
|
|
108
|
+
}
|
|
63
109
|
} else if (getViewInteractionCount()) {
|
|
64
|
-
return
|
|
110
|
+
return {
|
|
111
|
+
value: 0
|
|
112
|
+
}
|
|
65
113
|
}
|
|
66
114
|
},
|
|
115
|
+
setViewEnd: function (viewEndTime) {
|
|
116
|
+
viewEnd = viewEndTime
|
|
117
|
+
stopViewInteractionCount()
|
|
118
|
+
},
|
|
67
119
|
stop: subscribe.unsubscribe
|
|
68
120
|
}
|
|
69
121
|
}
|
|
@@ -118,8 +170,6 @@ function trackLongestInteractions(getViewInteractionCount) {
|
|
|
118
170
|
Math.floor(getViewInteractionCount() / 50)
|
|
119
171
|
)
|
|
120
172
|
return longestInteractions[interactionIndex]
|
|
121
|
-
? longestInteractions[interactionIndex].duration
|
|
122
|
-
: undefined
|
|
123
173
|
}
|
|
124
174
|
}
|
|
125
175
|
}
|
|
@@ -128,9 +178,23 @@ export function trackViewInteractionCount(viewLoadingType) {
|
|
|
128
178
|
initInteractionCountPolyfill()
|
|
129
179
|
var previousInteractionCount =
|
|
130
180
|
viewLoadingType === ViewLoadingType.INITIAL_LOAD ? 0 : getInteractionCount()
|
|
181
|
+
var state = { stopped: false }
|
|
182
|
+
|
|
183
|
+
function computeViewInteractionCount() {
|
|
184
|
+
return getInteractionCount() - previousInteractionCount
|
|
185
|
+
}
|
|
131
186
|
return {
|
|
132
187
|
getViewInteractionCount: function () {
|
|
133
|
-
|
|
188
|
+
if (state.stopped) {
|
|
189
|
+
return state.interactionCount
|
|
190
|
+
}
|
|
191
|
+
return computeViewInteractionCount()
|
|
192
|
+
},
|
|
193
|
+
stopViewInteractionCount: function () {
|
|
194
|
+
state = {
|
|
195
|
+
stopped: true,
|
|
196
|
+
interactionCount: computeViewInteractionCount()
|
|
197
|
+
}
|
|
134
198
|
}
|
|
135
199
|
}
|
|
136
200
|
}
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
LifeCycleEventType,
|
|
6
6
|
ONE_MINUTE
|
|
7
7
|
} from '@cloudcare/browser-core'
|
|
8
|
-
import {
|
|
8
|
+
import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
11
|
* Track the largest contentful paint (LCP) occurring during the initial View. This can yield
|
|
11
12
|
* multiple values, only the most recent one should be used.
|
|
@@ -14,9 +15,13 @@ import { trackFirstHidden } from './trackFirstHidden'
|
|
|
14
15
|
*/
|
|
15
16
|
// It happens in some cases like sleep mode or some browser implementations
|
|
16
17
|
export var LCP_MAXIMUM_DELAY = 10 * ONE_MINUTE
|
|
17
|
-
export function trackLargestContentfulPaint(
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
export function trackLargestContentfulPaint(
|
|
19
|
+
lifeCycle,
|
|
20
|
+
configuration,
|
|
21
|
+
firstHidden,
|
|
22
|
+
eventTarget,
|
|
23
|
+
callback
|
|
24
|
+
) {
|
|
20
25
|
// Ignore entries that come after the first user interaction. According to the documentation, the
|
|
21
26
|
// browser should not send largest-contentful-paint entries after a user interact with the page,
|
|
22
27
|
// but the web-vitals reference implementation uses this as a safeguard.
|
|
@@ -37,12 +42,22 @@ export function trackLargestContentfulPaint(lifeCycle, eventTarget, callback) {
|
|
|
37
42
|
return (
|
|
38
43
|
entry.entryType === 'largest-contentful-paint' &&
|
|
39
44
|
entry.startTime < firstInteractionTimestamp &&
|
|
40
|
-
entry.startTime < firstHidden.
|
|
45
|
+
entry.startTime < firstHidden.geTimeStamp() &&
|
|
41
46
|
entry.startTime < LCP_MAXIMUM_DELAY
|
|
42
47
|
)
|
|
43
48
|
})
|
|
44
49
|
if (lcpEntry) {
|
|
45
|
-
|
|
50
|
+
var lcpTargetSelector
|
|
51
|
+
if (lcpEntry.element) {
|
|
52
|
+
lcpTargetSelector = getSelectorFromElement(
|
|
53
|
+
lcpEntry.element,
|
|
54
|
+
configuration.actionNameAttribute
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
callback({
|
|
58
|
+
value: lcpEntry.startTime,
|
|
59
|
+
targetSelector: lcpTargetSelector
|
|
60
|
+
})
|
|
46
61
|
}
|
|
47
62
|
}
|
|
48
63
|
)
|
|
@@ -21,7 +21,11 @@ export function trackLoadingTime(
|
|
|
21
21
|
callback(Math.max.apply(Math, loadingTimeCandidates))
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
function stopEndCallback() {
|
|
25
|
+
if (loadingTimeCandidates.length > 0) {
|
|
26
|
+
callback(Math.max.apply(Math, loadingTimeCandidates))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
25
29
|
var _waitPageActivityEnd = waitPageActivityEnd(
|
|
26
30
|
lifeCycle,
|
|
27
31
|
domMutationObservable,
|
|
@@ -36,6 +40,7 @@ export function trackLoadingTime(
|
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
)
|
|
43
|
+
|
|
39
44
|
var stop = _waitPageActivityEnd.stop
|
|
40
45
|
return {
|
|
41
46
|
setLoadEvent: function (loadEvent) {
|
|
@@ -45,6 +50,9 @@ export function trackLoadingTime(
|
|
|
45
50
|
invokeCallbackIfAllCandidatesAreReceived()
|
|
46
51
|
}
|
|
47
52
|
},
|
|
48
|
-
stop:
|
|
53
|
+
stop: function () {
|
|
54
|
+
stop()
|
|
55
|
+
stopEndCallback()
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
}
|
|
@@ -5,53 +5,58 @@ import {
|
|
|
5
5
|
throttle,
|
|
6
6
|
addEventListener,
|
|
7
7
|
DOM_EVENT,
|
|
8
|
-
getScrollY
|
|
8
|
+
getScrollY,
|
|
9
|
+
monitor,
|
|
10
|
+
Observable
|
|
9
11
|
} from '@cloudcare/browser-core'
|
|
10
12
|
import { getViewportDimension } from '../../initViewportObservable'
|
|
11
13
|
|
|
12
14
|
/** Arbitrary scroll throttle duration */
|
|
13
15
|
export var THROTTLE_SCROLL_DURATION = ONE_SECOND
|
|
14
16
|
|
|
15
|
-
export function trackScrollMetrics(
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
export function trackScrollMetrics(
|
|
18
|
+
configuration,
|
|
19
|
+
viewStart,
|
|
20
|
+
callback,
|
|
21
|
+
scrollValues
|
|
22
|
+
) {
|
|
23
|
+
if (scrollValues === undefined) {
|
|
24
|
+
scrollValues = createScrollValuesObservable(configuration)
|
|
18
25
|
}
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var now = relativeNow()
|
|
28
|
-
var maxDepthTime = elapsed(viewStart.relative, now)
|
|
29
|
-
maxDepth = scrollDepth
|
|
30
|
-
callback({
|
|
31
|
-
maxDepth: maxDepth,
|
|
32
|
-
maxDepthScrollHeight: scrollHeight,
|
|
33
|
-
maxDepthTime: maxDepthTime,
|
|
34
|
-
maxDepthScrollTop: scrollTop
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
THROTTLE_SCROLL_DURATION,
|
|
39
|
-
{ leading: false, trailing: true }
|
|
40
|
-
)
|
|
26
|
+
var maxScrollDepth = 0
|
|
27
|
+
var maxScrollHeight = 0
|
|
28
|
+
var maxScrollHeightTime = 0
|
|
29
|
+
var subscription = scrollValues.subscribe(function (data) {
|
|
30
|
+
var scrollDepth = data.scrollDepth
|
|
31
|
+
var scrollTop = data.scrollTop
|
|
32
|
+
var scrollHeight = data.scrollHeight
|
|
33
|
+
var shouldUpdate = false
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
handleScrollEvent.throttled,
|
|
46
|
-
{
|
|
47
|
-
passive: true
|
|
35
|
+
if (scrollDepth > maxScrollDepth) {
|
|
36
|
+
maxScrollDepth = scrollDepth
|
|
37
|
+
shouldUpdate = true
|
|
48
38
|
}
|
|
49
|
-
|
|
39
|
+
|
|
40
|
+
if (scrollHeight > maxScrollHeight) {
|
|
41
|
+
maxScrollHeight = scrollHeight
|
|
42
|
+
var now = relativeNow()
|
|
43
|
+
maxScrollHeightTime = elapsed(viewStart.relative, now)
|
|
44
|
+
shouldUpdate = true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (shouldUpdate) {
|
|
48
|
+
callback({
|
|
49
|
+
maxDepth: Math.min(maxScrollDepth, maxScrollHeight),
|
|
50
|
+
maxDepthScrollTop: scrollTop,
|
|
51
|
+
maxScrollHeight: maxScrollHeight,
|
|
52
|
+
maxScrollHeightTime: maxScrollHeightTime
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
})
|
|
50
56
|
|
|
51
57
|
return {
|
|
52
58
|
stop: function () {
|
|
53
|
-
|
|
54
|
-
_addEventListener.stop()
|
|
59
|
+
return subscription.unsubscribe()
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
}
|
|
@@ -72,3 +77,42 @@ export function computeScrollValues() {
|
|
|
72
77
|
scrollTop: scrollTop
|
|
73
78
|
}
|
|
74
79
|
}
|
|
80
|
+
export function createScrollValuesObservable(configuration, throttleDuration) {
|
|
81
|
+
if (throttleDuration === undefined) {
|
|
82
|
+
throttleDuration = THROTTLE_SCROLL_DURATION
|
|
83
|
+
}
|
|
84
|
+
var observable = new Observable(function () {
|
|
85
|
+
function notify() {
|
|
86
|
+
observable.notify(computeScrollValues())
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (window.ResizeObserver) {
|
|
90
|
+
var throttledNotify = throttle(notify, throttleDuration, {
|
|
91
|
+
leading: false,
|
|
92
|
+
trailing: true
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
var observerTarget = document.scrollingElement || document.documentElement
|
|
96
|
+
var resizeObserver = new ResizeObserver(
|
|
97
|
+
monitor(throttledNotify.throttled)
|
|
98
|
+
)
|
|
99
|
+
resizeObserver.observe(observerTarget)
|
|
100
|
+
var eventListener = addEventListener(
|
|
101
|
+
window,
|
|
102
|
+
DOM_EVENT.SCROLL,
|
|
103
|
+
throttledNotify.throttled,
|
|
104
|
+
{
|
|
105
|
+
passive: true
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
return function () {
|
|
110
|
+
throttledNotify.cancel()
|
|
111
|
+
resizeObserver.unobserve(observerTarget)
|
|
112
|
+
eventListener.stop()
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
return observable
|
|
118
|
+
}
|
|
@@ -15,7 +15,9 @@ import {
|
|
|
15
15
|
getPathFromHash,
|
|
16
16
|
noop,
|
|
17
17
|
setInterval,
|
|
18
|
+
Observable,
|
|
18
19
|
clearInterval,
|
|
20
|
+
setTimeout,
|
|
19
21
|
isNullUndefinedDefaultValue
|
|
20
22
|
} from '@cloudcare/browser-core'
|
|
21
23
|
|
|
@@ -24,7 +26,7 @@ import { trackCommonViewMetrics } from './trackCommonViewMetrics'
|
|
|
24
26
|
import { trackViewEventCounts } from './trackViewEventCounts'
|
|
25
27
|
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000
|
|
26
28
|
export var SESSION_KEEP_ALIVE_INTERVAL = 5 * ONE_MINUTE
|
|
27
|
-
|
|
29
|
+
export var KEEP_TRACKING_AFTER_VIEW_DELAY = 5 * ONE_MINUTE
|
|
28
30
|
export function trackViews(
|
|
29
31
|
location,
|
|
30
32
|
lifeCycle,
|
|
@@ -34,8 +36,9 @@ export function trackViews(
|
|
|
34
36
|
areViewsTrackedAutomatically,
|
|
35
37
|
initialViewOptions
|
|
36
38
|
) {
|
|
39
|
+
var activeViews = new Set()
|
|
37
40
|
function startNewView(loadingType, startClocks, viewOptions) {
|
|
38
|
-
|
|
41
|
+
var newlyCreatedView = newView(
|
|
39
42
|
lifeCycle,
|
|
40
43
|
domMutationObservable,
|
|
41
44
|
configuration,
|
|
@@ -44,6 +47,11 @@ export function trackViews(
|
|
|
44
47
|
startClocks,
|
|
45
48
|
viewOptions
|
|
46
49
|
)
|
|
50
|
+
activeViews.add(newlyCreatedView)
|
|
51
|
+
newlyCreatedView.stopObservable.subscribe(function () {
|
|
52
|
+
activeViews.delete(newlyCreatedView)
|
|
53
|
+
})
|
|
54
|
+
return newlyCreatedView
|
|
47
55
|
}
|
|
48
56
|
var currentView = startNewView(
|
|
49
57
|
ViewLoadingType.INITIAL_LOAD,
|
|
@@ -59,7 +67,7 @@ export function trackViews(
|
|
|
59
67
|
}
|
|
60
68
|
function startViewLifeCycle() {
|
|
61
69
|
lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
|
|
62
|
-
startNewView(ViewLoadingType.ROUTE_CHANGE, undefined, {
|
|
70
|
+
currentView = startNewView(ViewLoadingType.ROUTE_CHANGE, undefined, {
|
|
63
71
|
name: currentView.name,
|
|
64
72
|
service: currentView.service,
|
|
65
73
|
version: currentView.version
|
|
@@ -115,6 +123,9 @@ export function trackViews(
|
|
|
115
123
|
locationChangeSubscription.unsubscribe()
|
|
116
124
|
}
|
|
117
125
|
currentView.end()
|
|
126
|
+
activeViews.forEach(function (view) {
|
|
127
|
+
view.stop()
|
|
128
|
+
})
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
131
|
}
|
|
@@ -133,6 +144,7 @@ function newView(
|
|
|
133
144
|
startClocks = clocksNow()
|
|
134
145
|
}
|
|
135
146
|
var id = UUID()
|
|
147
|
+
var stopObservable = new Observable()
|
|
136
148
|
var customTimings = {}
|
|
137
149
|
var documentVersion = 0
|
|
138
150
|
var endClocks
|
|
@@ -178,23 +190,28 @@ function newView(
|
|
|
178
190
|
var setLoadEvent = _trackCommonViewMetrics.setLoadEvent
|
|
179
191
|
var stopCommonViewMetricsTracking = _trackCommonViewMetrics.stop
|
|
180
192
|
var getCommonViewMetrics = _trackCommonViewMetrics.getCommonViewMetrics
|
|
181
|
-
|
|
193
|
+
var stopINPTracking = _trackCommonViewMetrics.stopINPTracking
|
|
194
|
+
var setViewEnd = _trackCommonViewMetrics.setViewEnd
|
|
182
195
|
var _trackInitialViewTimings =
|
|
183
196
|
loadingType === ViewLoadingType.INITIAL_LOAD
|
|
184
|
-
? trackInitialViewMetrics(
|
|
197
|
+
? trackInitialViewMetrics(
|
|
198
|
+
lifeCycle,
|
|
199
|
+
configuration,
|
|
200
|
+
setLoadEvent,
|
|
201
|
+
scheduleViewUpdate
|
|
202
|
+
)
|
|
185
203
|
: {
|
|
186
|
-
|
|
204
|
+
stop: noop,
|
|
187
205
|
initialViewMetrics: {}
|
|
188
206
|
}
|
|
189
|
-
var
|
|
190
|
-
_trackInitialViewTimings.scheduleStop
|
|
207
|
+
var stopInitialViewMetricsTracking = _trackInitialViewTimings.stop
|
|
191
208
|
var initialViewMetrics = _trackInitialViewTimings.initialViewMetrics
|
|
192
209
|
var _trackViewEventCounts = trackViewEventCounts(
|
|
193
210
|
lifeCycle,
|
|
194
211
|
id,
|
|
195
212
|
scheduleViewUpdate
|
|
196
213
|
)
|
|
197
|
-
var
|
|
214
|
+
var stopEventCountsTracking = _trackViewEventCounts.scheduleStop
|
|
198
215
|
var eventCounts = _trackViewEventCounts.eventCounts
|
|
199
216
|
|
|
200
217
|
// Session keep alive
|
|
@@ -202,7 +219,6 @@ function newView(
|
|
|
202
219
|
triggerViewUpdate,
|
|
203
220
|
SESSION_KEEP_ALIVE_INTERVAL
|
|
204
221
|
)
|
|
205
|
-
// Initial view update
|
|
206
222
|
triggerViewUpdate()
|
|
207
223
|
|
|
208
224
|
function triggerViewUpdate() {
|
|
@@ -229,12 +245,11 @@ function newView(
|
|
|
229
245
|
eventCounts: eventCounts
|
|
230
246
|
})
|
|
231
247
|
}
|
|
232
|
-
|
|
233
|
-
return {
|
|
248
|
+
var result = {
|
|
234
249
|
name: name,
|
|
235
250
|
service: service,
|
|
236
251
|
version: version,
|
|
237
|
-
|
|
252
|
+
stopObservable: stopObservable,
|
|
238
253
|
end: function (options) {
|
|
239
254
|
if (endClocks) {
|
|
240
255
|
// view already ended
|
|
@@ -250,12 +265,19 @@ function newView(
|
|
|
250
265
|
)
|
|
251
266
|
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: endClocks })
|
|
252
267
|
clearInterval(keepAliveIntervalId)
|
|
268
|
+
setViewEnd(endClocks.relative)
|
|
253
269
|
stopCommonViewMetricsTracking()
|
|
254
|
-
scheduleStopInitialViewMetricsTracking()
|
|
255
|
-
scheduleStopEventCountsTracking()
|
|
256
270
|
triggerViewUpdate()
|
|
271
|
+
setTimeout(function () {
|
|
272
|
+
result.stop()
|
|
273
|
+
}, KEEP_TRACKING_AFTER_VIEW_DELAY)
|
|
274
|
+
},
|
|
275
|
+
stop: function () {
|
|
276
|
+
stopInitialViewMetricsTracking()
|
|
277
|
+
stopEventCountsTracking()
|
|
278
|
+
stopINPTracking()
|
|
279
|
+
stopObservable.notify()
|
|
257
280
|
},
|
|
258
|
-
|
|
259
281
|
addTiming: function (name, time) {
|
|
260
282
|
if (endClocks) {
|
|
261
283
|
return
|
|
@@ -267,6 +289,7 @@ function newView(
|
|
|
267
289
|
scheduleViewUpdate()
|
|
268
290
|
}
|
|
269
291
|
}
|
|
292
|
+
return result
|
|
270
293
|
}
|
|
271
294
|
|
|
272
295
|
/**
|