@cloudcare/browser-rum 2.1.5 → 2.2.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.
- package/README.md +1 -2
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.js +57 -48
- package/cjs/boot/rumPublicApi.js +169 -134
- package/cjs/domain/assembly.js +58 -44
- package/cjs/domain/configuration.js +67 -0
- package/cjs/domain/contexts/internalContext.js +45 -0
- package/cjs/domain/contexts/urlContexts.js +68 -0
- package/cjs/domain/contexts/viewContexts.js +43 -0
- package/cjs/domain/domMutationCollection.js +44 -31
- package/cjs/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +25 -25
- package/cjs/domain/performanceCollection.js +55 -24
- package/cjs/domain/requestCollection.js +117 -0
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +22 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +82 -0
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +78 -0
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +163 -0
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +74 -0
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +263 -0
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +33 -53
- package/cjs/domain/rumEventsCollection/error/trackConsoleError.js +26 -0
- package/cjs/domain/rumEventsCollection/error/trackReportError.js +26 -0
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +46 -17
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +49 -9
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +7 -5
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +61 -24
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +91 -51
- package/cjs/domain/rumEventsCollection/view/trackViews.js +119 -86
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +41 -31
- package/cjs/domain/rumSessionManager.js +95 -0
- package/cjs/domain/tracing/tracer.js +9 -10
- package/cjs/domain/trackEventCounts.js +9 -6
- package/cjs/domain/usr/index.js +30 -0
- package/cjs/domain/waitPageActivityEnd.js +163 -0
- package/cjs/transport/startRumBatch.js +38 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.js +55 -48
- package/esm/boot/rumPublicApi.js +167 -135
- package/esm/domain/assembly.js +58 -44
- package/esm/domain/configuration.js +53 -0
- package/esm/domain/contexts/internalContext.js +38 -0
- package/esm/domain/contexts/urlContexts.js +58 -0
- package/esm/domain/contexts/viewContexts.js +32 -0
- package/esm/domain/domMutationCollection.js +43 -33
- package/esm/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +26 -24
- package/esm/domain/performanceCollection.js +56 -26
- package/esm/domain/requestCollection.js +102 -0
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +23 -5
- package/esm/domain/rumEventsCollection/actions/clickChain.js +69 -0
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +64 -0
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +139 -0
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +66 -0
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +244 -0
- package/esm/domain/rumEventsCollection/error/errorCollection.js +32 -54
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js +18 -0
- package/esm/domain/rumEventsCollection/error/trackReportError.js +18 -0
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +30 -18
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +31 -9
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +8 -6
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +43 -26
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +75 -51
- package/esm/domain/rumEventsCollection/view/trackViews.js +120 -85
- package/esm/domain/rumEventsCollection/view/viewCollection.js +42 -32
- package/esm/domain/rumSessionManager.js +80 -0
- package/esm/domain/tracing/skywalkingTracer.js +1 -1
- package/esm/domain/tracing/tracer.js +8 -9
- package/esm/domain/trackEventCounts.js +9 -6
- package/esm/domain/usr/index.js +17 -0
- package/esm/domain/waitPageActivityEnd.js +147 -0
- package/esm/transport/startRumBatch.js +30 -0
- package/package.json +3 -3
- package/src/boot/rum.js +79 -59
- package/src/boot/rumPublicApi.js +165 -171
- package/src/domain/.DS_Store +0 -0
- package/src/domain/assembly.js +77 -54
- package/src/domain/configuration.js +69 -0
- package/src/domain/contexts/internalContext.js +39 -0
- package/src/domain/contexts/urlContexts.js +76 -0
- package/src/domain/contexts/viewContexts.js +37 -0
- package/src/domain/domMutationCollection.js +48 -32
- package/src/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +28 -28
- package/src/domain/performanceCollection.js +62 -45
- package/src/domain/requestCollection.js +103 -0
- package/src/domain/rumEventsCollection/actions/actionCollection.js +34 -11
- package/src/domain/rumEventsCollection/actions/clickChain.js +90 -0
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +84 -0
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +73 -62
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +157 -0
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +85 -0
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +326 -0
- package/src/domain/rumEventsCollection/error/errorCollection.js +53 -69
- package/src/domain/rumEventsCollection/error/trackConsoleError.js +21 -0
- package/src/domain/rumEventsCollection/error/trackReportError.js +22 -0
- package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +29 -18
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +39 -23
- package/src/domain/rumEventsCollection/view/trackFirstHidden.js +9 -6
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +63 -42
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +80 -61
- package/src/domain/rumEventsCollection/view/trackViews.js +171 -134
- package/src/domain/rumEventsCollection/view/viewCollection.js +69 -49
- package/src/domain/rumSessionManager.js +90 -0
- package/src/domain/tracing/jaegerTracer.js +5 -5
- package/src/domain/tracing/skywalkingTracer.js +3 -3
- package/src/domain/tracing/tracer.js +50 -38
- package/src/domain/tracing/w3cTraceParentTracer.js +5 -5
- package/src/domain/tracing/zipkinMultiTracer.js +5 -5
- package/src/domain/tracing/zipkinSingleTracer.js +5 -5
- package/src/domain/trackEventCounts.js +10 -6
- package/src/domain/usr/index.js +16 -0
- package/src/domain/waitPageActivityEnd.js +192 -0
- package/src/transport/startRumBatch.js +48 -0
- package/cjs/domain/internalContext.js +0 -34
- package/cjs/domain/parentContexts.js +0 -143
- package/cjs/domain/requestCollections.js +0 -131
- package/cjs/domain/rumEventsCollection/actions/trackActions.js +0 -114
- package/cjs/domain/rumSession.js +0 -82
- package/cjs/domain/trackPageActivities.js +0 -166
- package/cjs/transport/batch.js +0 -81
- package/esm/domain/internalContext.js +0 -27
- package/esm/domain/parentContexts.js +0 -130
- package/esm/domain/requestCollections.js +0 -118
- package/esm/domain/rumEventsCollection/actions/trackActions.js +0 -103
- package/esm/domain/rumSession.js +0 -70
- package/esm/domain/trackPageActivities.js +0 -149
- package/esm/transport/batch.js +0 -74
- package/src/domain/internalContext.js +0 -28
- package/src/domain/parentContexts.js +0 -171
- package/src/domain/requestCollections.js +0 -118
- package/src/domain/rumEventsCollection/actions/trackActions.js +0 -113
- package/src/domain/rumSession.js +0 -92
- package/src/domain/trackPageActivities.js +0 -170
- package/src/transport/batch.js +0 -85
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
includes,
|
|
7
7
|
each,
|
|
8
8
|
extend,
|
|
9
|
+
filter,
|
|
10
|
+
dateNow,
|
|
11
|
+
relativeNow,
|
|
9
12
|
DOM_EVENT,
|
|
10
13
|
LifeCycleEventType
|
|
11
14
|
} from '@cloudcare/browser-core'
|
|
@@ -26,28 +29,41 @@ export function supportPerformanceTimingEvent(entryType) {
|
|
|
26
29
|
}
|
|
27
30
|
export function startPerformanceCollection(lifeCycle, configuration) {
|
|
28
31
|
retrieveInitialDocumentResourceTiming(function (timing) {
|
|
29
|
-
|
|
32
|
+
handleRumPerformanceEntries(lifeCycle, configuration, [timing])
|
|
30
33
|
})
|
|
31
34
|
|
|
32
35
|
if (supportPerformanceObject()) {
|
|
33
|
-
|
|
36
|
+
var performanceEntries = performance.getEntries()
|
|
37
|
+
// Because the performance entry list can be quite large
|
|
38
|
+
// delay the computation to prevent the SDK from blocking the main thread on init
|
|
39
|
+
setTimeout(function() {
|
|
40
|
+
handleRumPerformanceEntries(lifeCycle, configuration, performanceEntries)
|
|
41
|
+
})
|
|
34
42
|
}
|
|
35
43
|
if (window.PerformanceObserver) {
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
var handlePerformanceEntryList = function(entries) {
|
|
45
|
+
handleRumPerformanceEntries(lifeCycle, configuration, entries.getEntries())
|
|
46
|
+
}
|
|
47
|
+
var mainEntries = ['resource', 'navigation', 'longtask', 'paint']
|
|
48
|
+
var experimentalEntries = ['largest-contentful-paint', 'first-input', 'layout-shift']
|
|
49
|
+
try {
|
|
50
|
+
// Experimental entries are not retrieved by performance.getEntries()
|
|
51
|
+
// use a single PerformanceObserver with buffered flag by type
|
|
52
|
+
// to get values that could happen before SDK init
|
|
53
|
+
each(experimentalEntries, function(type) {
|
|
54
|
+
var observer = new PerformanceObserver(handlePerformanceEntryList)
|
|
55
|
+
observer.observe({ type:type, buffered: true })
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Some old browser versions (ex: chrome 67) don't support the PerformanceObserver type and buffered options
|
|
60
|
+
// In these cases, fallback to PerformanceObserver with entryTypes
|
|
61
|
+
each(experimentalEntries, function(type) {
|
|
62
|
+
mainEntries.push(type)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
var mainObserver = new PerformanceObserver(handlePerformanceEntryList)
|
|
66
|
+
mainObserver.observe({ entryTypes: mainEntries })
|
|
51
67
|
if (supportPerformanceObject() && 'addEventListener' in performance) {
|
|
52
68
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1559377
|
|
53
69
|
performance.addEventListener('resourcetimingbufferfull', function () {
|
|
@@ -57,12 +73,12 @@ export function startPerformanceCollection(lifeCycle, configuration) {
|
|
|
57
73
|
}
|
|
58
74
|
if (!supportPerformanceTimingEvent('navigation')) {
|
|
59
75
|
retrieveNavigationTiming(function (timing) {
|
|
60
|
-
|
|
76
|
+
handleRumPerformanceEntries(lifeCycle, configuration, [timing])
|
|
61
77
|
})
|
|
62
78
|
}
|
|
63
79
|
if (!supportPerformanceTimingEvent('first-input')) {
|
|
64
|
-
retrieveFirstInputTiming((timing)
|
|
65
|
-
|
|
80
|
+
retrieveFirstInputTiming(function(timing) {
|
|
81
|
+
return handleRumPerformanceEntries(lifeCycle, configuration, [timing])
|
|
66
82
|
})
|
|
67
83
|
}
|
|
68
84
|
}
|
|
@@ -117,7 +133,7 @@ function retrieveNavigationTiming(callback) {
|
|
|
117
133
|
* https://github.com/GoogleChrome/web-vitals/blob/master/src/lib/polyfills/firstInputPolyfill.ts
|
|
118
134
|
*/
|
|
119
135
|
function retrieveFirstInputTiming(callback) {
|
|
120
|
-
var startTimeStamp =
|
|
136
|
+
var startTimeStamp = dateNow()
|
|
121
137
|
var timingSent = false
|
|
122
138
|
|
|
123
139
|
var listeners = addEventListeners(
|
|
@@ -140,7 +156,7 @@ function retrieveFirstInputTiming(callback) {
|
|
|
140
156
|
// (e.g. performance.now()).
|
|
141
157
|
var timing = {
|
|
142
158
|
entryType: 'first-input',
|
|
143
|
-
processingStart:
|
|
159
|
+
processingStart: relativeNow(),
|
|
144
160
|
startTime: evt.timeStamp
|
|
145
161
|
}
|
|
146
162
|
|
|
@@ -183,7 +199,7 @@ function retrieveFirstInputTiming(callback) {
|
|
|
183
199
|
// - https://github.com/GoogleChromeLabs/first-input-delay/issues/6
|
|
184
200
|
// - https://github.com/GoogleChromeLabs/first-input-delay/issues/7
|
|
185
201
|
var delay = timing.processingStart - timing.startTime
|
|
186
|
-
if (delay >= 0 && delay <
|
|
202
|
+
if (delay >= 0 && delay < dateNow() - startTimeStamp) {
|
|
187
203
|
callback(timing)
|
|
188
204
|
}
|
|
189
205
|
}
|
|
@@ -216,32 +232,28 @@ function computeRelativePerformanceTiming() {
|
|
|
216
232
|
return result
|
|
217
233
|
}
|
|
218
234
|
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
entry.entryType === 'resource' ||
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
})
|
|
233
|
-
}
|
|
235
|
+
function handleRumPerformanceEntries(lifeCycle, configuration, entries) {
|
|
236
|
+
var rumPerformanceEntries = filter(entries,
|
|
237
|
+
function(entry){
|
|
238
|
+
return entry.entryType === 'resource' ||
|
|
239
|
+
entry.entryType === 'navigation' ||
|
|
240
|
+
entry.entryType === 'paint' ||
|
|
241
|
+
entry.entryType === 'longtask' ||
|
|
242
|
+
entry.entryType === 'largest-contentful-paint' ||
|
|
243
|
+
entry.entryType === 'first-input' ||
|
|
244
|
+
entry.entryType === 'layout-shift'
|
|
245
|
+
}
|
|
246
|
+
)
|
|
234
247
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
) {
|
|
240
|
-
return
|
|
248
|
+
var rumAllowedPerformanceEntries = filter(rumPerformanceEntries, function(entry) { return !isIncompleteNavigation(entry) && !isForbiddenResource(configuration, entry)})
|
|
249
|
+
|
|
250
|
+
if (rumAllowedPerformanceEntries.length) {
|
|
251
|
+
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, rumAllowedPerformanceEntries)
|
|
241
252
|
}
|
|
242
|
-
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, entry)
|
|
243
253
|
}
|
|
244
254
|
|
|
255
|
+
|
|
256
|
+
|
|
245
257
|
function isIncompleteNavigation(entry) {
|
|
246
258
|
return entry.entryType === 'navigation' && entry.loadEventEnd <= 0
|
|
247
259
|
}
|
|
@@ -252,3 +264,8 @@ function isForbiddenResource(configuration, entry) {
|
|
|
252
264
|
!isAllowedRequestUrl(configuration, entry.name)
|
|
253
265
|
)
|
|
254
266
|
}
|
|
267
|
+
export function supportPerformanceEntry() {
|
|
268
|
+
// Safari 10 doesn't support PerformanceEntry
|
|
269
|
+
return typeof PerformanceEntry === 'function'
|
|
270
|
+
}
|
|
271
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
2
|
+
import { RequestType, initFetchObservable, initXhrObservable, LifeCycleEventType } from '@cloudcare/browser-core'
|
|
3
|
+
import { isAllowedRequestUrl } from './rumEventsCollection/resource/resourceUtils'
|
|
4
|
+
import { startTracer } from './tracing/tracer'
|
|
5
|
+
|
|
6
|
+
let nextRequestIndex = 1
|
|
7
|
+
|
|
8
|
+
export function startRequestCollection(
|
|
9
|
+
lifeCycle,
|
|
10
|
+
configuration,
|
|
11
|
+
sessionManager
|
|
12
|
+
) {
|
|
13
|
+
var tracer = startTracer(configuration, sessionManager)
|
|
14
|
+
trackXhr(lifeCycle, configuration, tracer)
|
|
15
|
+
trackFetch(lifeCycle, configuration, tracer)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function trackXhr(lifeCycle, configuration, tracer) {
|
|
19
|
+
var subscription = initXhrObservable().subscribe(function(rawContext) {
|
|
20
|
+
var context = rawContext
|
|
21
|
+
if (!isAllowedRequestUrl(configuration, context.url)) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
switch (context.state) {
|
|
26
|
+
case 'start':
|
|
27
|
+
tracer.traceXhr(context, context.xhr)
|
|
28
|
+
context.requestIndex = getNextRequestIndex()
|
|
29
|
+
|
|
30
|
+
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, {
|
|
31
|
+
requestIndex: context.requestIndex,
|
|
32
|
+
url: context.url,
|
|
33
|
+
})
|
|
34
|
+
break
|
|
35
|
+
case 'complete':
|
|
36
|
+
tracer.clearTracingIfNeeded(context)
|
|
37
|
+
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
|
|
38
|
+
duration: context.duration,
|
|
39
|
+
method: context.method,
|
|
40
|
+
requestIndex: context.requestIndex,
|
|
41
|
+
spanId: context.spanId,
|
|
42
|
+
startClocks: context.startClocks,
|
|
43
|
+
status: context.status,
|
|
44
|
+
traceId: context.traceId,
|
|
45
|
+
traceSampled: context.traceSampled,
|
|
46
|
+
type: RequestType.XHR,
|
|
47
|
+
url: context.url,
|
|
48
|
+
xhr: context.xhr,
|
|
49
|
+
})
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return { stop: function() { return subscription.unsubscribe() } }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function trackFetch(lifeCycle, configuration, tracer) {
|
|
58
|
+
var subscription = initFetchObservable().subscribe(function(rawContext) {
|
|
59
|
+
var context = rawContext
|
|
60
|
+
if (!isAllowedRequestUrl(configuration, context.url)) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
switch (context.state) {
|
|
65
|
+
case 'start':
|
|
66
|
+
tracer.traceFetch(context)
|
|
67
|
+
context.requestIndex = getNextRequestIndex()
|
|
68
|
+
|
|
69
|
+
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, {
|
|
70
|
+
requestIndex: context.requestIndex,
|
|
71
|
+
url: context.url,
|
|
72
|
+
})
|
|
73
|
+
break
|
|
74
|
+
case 'complete':
|
|
75
|
+
tracer.clearTracingIfNeeded(context)
|
|
76
|
+
|
|
77
|
+
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
|
|
78
|
+
duration: context.duration,
|
|
79
|
+
method: context.method,
|
|
80
|
+
requestIndex: context.requestIndex,
|
|
81
|
+
responseType: context.responseType,
|
|
82
|
+
spanId: context.spanId,
|
|
83
|
+
startClocks: context.startClocks,
|
|
84
|
+
status: context.status,
|
|
85
|
+
traceId: context.traceId,
|
|
86
|
+
traceSampled: context.traceSampled,
|
|
87
|
+
type: RequestType.FETCH,
|
|
88
|
+
url: context.url,
|
|
89
|
+
response: context.response,
|
|
90
|
+
init: context.init,
|
|
91
|
+
input: context.input,
|
|
92
|
+
})
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
return { stop: function() { return subscription.unsubscribe() } }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getNextRequestIndex() {
|
|
100
|
+
var result = nextRequestIndex
|
|
101
|
+
nextRequestIndex += 1
|
|
102
|
+
return result
|
|
103
|
+
}
|
|
@@ -2,14 +2,18 @@ import {
|
|
|
2
2
|
toServerDuration,
|
|
3
3
|
extend,
|
|
4
4
|
extend2Lev,
|
|
5
|
-
preferredTimeStamp,
|
|
6
5
|
ActionType,
|
|
7
6
|
RumEventType,
|
|
8
|
-
LifeCycleEventType
|
|
7
|
+
LifeCycleEventType,
|
|
8
|
+
UUID,
|
|
9
|
+
noop
|
|
9
10
|
} from '@cloudcare/browser-core'
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import { trackClickActions } from './trackClickActions'
|
|
12
|
+
export function startActionCollection(
|
|
13
|
+
lifeCycle,
|
|
14
|
+
domMutationObservable,
|
|
15
|
+
configuration
|
|
16
|
+
) {
|
|
13
17
|
lifeCycle.subscribe(
|
|
14
18
|
LifeCycleEventType.AUTO_ACTION_COMPLETED,
|
|
15
19
|
function (action) {
|
|
@@ -19,11 +23,17 @@ export function startActionCollection(lifeCycle, configuration) {
|
|
|
19
23
|
)
|
|
20
24
|
}
|
|
21
25
|
)
|
|
26
|
+
|
|
27
|
+
var actionContexts = { findActionId: noop }
|
|
22
28
|
if (configuration.trackInteractions) {
|
|
23
|
-
|
|
29
|
+
actionContexts = trackClickActions(
|
|
30
|
+
lifeCycle,
|
|
31
|
+
domMutationObservable,
|
|
32
|
+
configuration
|
|
33
|
+
).actionContexts
|
|
24
34
|
}
|
|
25
|
-
|
|
26
35
|
return {
|
|
36
|
+
actionContexts: actionContexts,
|
|
27
37
|
addAction: function (action, savedCommonContext) {
|
|
28
38
|
lifeCycle.notify(
|
|
29
39
|
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
|
|
@@ -45,23 +55,33 @@ function processAction(action) {
|
|
|
45
55
|
},
|
|
46
56
|
id: action.id,
|
|
47
57
|
loadingTime: toServerDuration(action.duration),
|
|
58
|
+
frustration: {
|
|
59
|
+
type: action.frustrationTypes
|
|
60
|
+
},
|
|
48
61
|
long_task: {
|
|
49
62
|
count: action.counts.longTaskCount
|
|
50
63
|
},
|
|
51
64
|
resource: {
|
|
52
65
|
count: action.counts.resourceCount
|
|
53
66
|
}
|
|
67
|
+
},
|
|
68
|
+
_dd: {
|
|
69
|
+
action: {
|
|
70
|
+
target: action.target,
|
|
71
|
+
position: action.position
|
|
72
|
+
}
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
: {
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
action: {
|
|
77
|
+
loadingTime: 0
|
|
78
|
+
}
|
|
59
79
|
}
|
|
60
|
-
}
|
|
61
80
|
var customerContext = !isAutoAction(action) ? action.context : undefined
|
|
62
81
|
var actionEvent = extend2Lev(
|
|
63
82
|
{
|
|
64
83
|
action: {
|
|
84
|
+
id: UUID(),
|
|
65
85
|
target: {
|
|
66
86
|
name: action.name
|
|
67
87
|
},
|
|
@@ -75,7 +95,10 @@ function processAction(action) {
|
|
|
75
95
|
return {
|
|
76
96
|
customerContext: customerContext,
|
|
77
97
|
rawRumEvent: actionEvent,
|
|
78
|
-
startTime: action.startClocks.relative
|
|
98
|
+
startTime: action.startClocks.relative,
|
|
99
|
+
domainContext: isAutoAction(action)
|
|
100
|
+
? { event: action.event, events: action.events }
|
|
101
|
+
: {}
|
|
79
102
|
}
|
|
80
103
|
}
|
|
81
104
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ONE_SECOND, every } from '@cloudcare/browser-core'
|
|
2
|
+
|
|
3
|
+
export var MAX_DURATION_BETWEEN_CLICKS = ONE_SECOND
|
|
4
|
+
export var MAX_DISTANCE_BETWEEN_CLICKS = 100
|
|
5
|
+
|
|
6
|
+
var ClickChainStatus = {
|
|
7
|
+
WaitingForMoreClicks: 'WaitingForMoreClicks',
|
|
8
|
+
WaitingForClicksToStop: 'WaitingForClicksToStop',
|
|
9
|
+
Finalized: 'Finalized'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createClickChain(firstClick, onFinalize) {
|
|
13
|
+
var bufferedClicks = []
|
|
14
|
+
var status = ClickChainStatus.WaitingForMoreClicks
|
|
15
|
+
var maxDurationBetweenClicksTimeout
|
|
16
|
+
appendClick(firstClick)
|
|
17
|
+
|
|
18
|
+
function appendClick(click) {
|
|
19
|
+
click.stopObservable.subscribe(tryFinalize)
|
|
20
|
+
bufferedClicks.push(click)
|
|
21
|
+
clearTimeout(maxDurationBetweenClicksTimeout)
|
|
22
|
+
maxDurationBetweenClicksTimeout = setTimeout(
|
|
23
|
+
dontAcceptMoreClick,
|
|
24
|
+
MAX_DURATION_BETWEEN_CLICKS
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function tryFinalize() {
|
|
29
|
+
if (
|
|
30
|
+
status === ClickChainStatus.WaitingForClicksToStop &&
|
|
31
|
+
every(bufferedClicks, function (click) {
|
|
32
|
+
return click.isStopped()
|
|
33
|
+
})
|
|
34
|
+
) {
|
|
35
|
+
status = ClickChainStatus.Finalized
|
|
36
|
+
onFinalize(bufferedClicks)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function dontAcceptMoreClick() {
|
|
41
|
+
clearTimeout(maxDurationBetweenClicksTimeout)
|
|
42
|
+
if (status === ClickChainStatus.WaitingForMoreClicks) {
|
|
43
|
+
status = ClickChainStatus.WaitingForClicksToStop
|
|
44
|
+
tryFinalize()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
tryAppend: function (click) {
|
|
50
|
+
if (status !== ClickChainStatus.WaitingForMoreClicks) {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
bufferedClicks.length > 0 &&
|
|
56
|
+
!areEventsSimilar(
|
|
57
|
+
bufferedClicks[bufferedClicks.length - 1].event,
|
|
58
|
+
click.event
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
dontAcceptMoreClick()
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
appendClick(click)
|
|
66
|
+
return true
|
|
67
|
+
},
|
|
68
|
+
stop: function () {
|
|
69
|
+
dontAcceptMoreClick()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Checks whether two events are similar by comparing their target, position and timestamp
|
|
76
|
+
*/
|
|
77
|
+
function areEventsSimilar(first, second) {
|
|
78
|
+
return (
|
|
79
|
+
first.target === second.target &&
|
|
80
|
+
mouseEventDistance(first, second) <= MAX_DISTANCE_BETWEEN_CLICKS &&
|
|
81
|
+
first.timeStamp - second.timeStamp <= MAX_DURATION_BETWEEN_CLICKS
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function mouseEventDistance(origin, other) {
|
|
86
|
+
return Math.sqrt(
|
|
87
|
+
Math.pow(origin.clientX - other.clientX, 2) +
|
|
88
|
+
Math.pow(origin.clientY - other.clientY, 2)
|
|
89
|
+
)
|
|
90
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
elementMatches,
|
|
3
|
+
ONE_SECOND,
|
|
4
|
+
FrustrationType,
|
|
5
|
+
some,
|
|
6
|
+
each
|
|
7
|
+
} from '@cloudcare/browser-core'
|
|
8
|
+
|
|
9
|
+
var MIN_CLICKS_PER_SECOND_TO_CONSIDER_RAGE = 3
|
|
10
|
+
|
|
11
|
+
export function computeFrustration(clicks, rageClick) {
|
|
12
|
+
if (isRage(clicks)) {
|
|
13
|
+
rageClick.addFrustration(FrustrationType.RAGE_CLICK)
|
|
14
|
+
if (clicks.some(isDead)) {
|
|
15
|
+
rageClick.addFrustration(FrustrationType.DEAD_CLICK)
|
|
16
|
+
}
|
|
17
|
+
if (rageClick.hasError) {
|
|
18
|
+
rageClick.addFrustration(FrustrationType.ERROR_CLICK)
|
|
19
|
+
}
|
|
20
|
+
return { isRage: true }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var hasSelectionChanged = some(clicks, function (click) {
|
|
24
|
+
return click.getUserActivity().selection
|
|
25
|
+
})
|
|
26
|
+
each(clicks, function (click) {
|
|
27
|
+
if (click.hasError) {
|
|
28
|
+
click.addFrustration(FrustrationType.ERROR_CLICK)
|
|
29
|
+
}
|
|
30
|
+
if (
|
|
31
|
+
isDead(click) &&
|
|
32
|
+
// Avoid considering clicks part of a double-click or triple-click selections as dead clicks
|
|
33
|
+
!hasSelectionChanged
|
|
34
|
+
) {
|
|
35
|
+
click.addFrustration(FrustrationType.DEAD_CLICK)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return { isRage: false }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isRage(clicks) {
|
|
43
|
+
if (
|
|
44
|
+
some(clicks, function (click) {
|
|
45
|
+
return click.getUserActivity().selection
|
|
46
|
+
})
|
|
47
|
+
) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
for (
|
|
51
|
+
var i = 0;
|
|
52
|
+
i < clicks.length - (MIN_CLICKS_PER_SECOND_TO_CONSIDER_RAGE - 1);
|
|
53
|
+
i += 1
|
|
54
|
+
) {
|
|
55
|
+
if (
|
|
56
|
+
clicks[i + MIN_CLICKS_PER_SECOND_TO_CONSIDER_RAGE - 1].event.timeStamp -
|
|
57
|
+
clicks[i].event.timeStamp <=
|
|
58
|
+
ONE_SECOND
|
|
59
|
+
) {
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var DEAD_CLICK_EXCLUDE_SELECTOR =
|
|
67
|
+
// inputs that don't trigger a meaningful event like "input" when clicked, including textual
|
|
68
|
+
// inputs (using a negative selector is shorter here)
|
|
69
|
+
'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="range"]),' +
|
|
70
|
+
'textarea,' +
|
|
71
|
+
'select,' +
|
|
72
|
+
// canvas, as there is no good way to detect activity occurring on them
|
|
73
|
+
'canvas,' +
|
|
74
|
+
// links that are interactive (have an href attribute) or any of their descendants, as they can
|
|
75
|
+
// open a new tab or navigate to a hash without triggering a meaningful event
|
|
76
|
+
'a[href],' +
|
|
77
|
+
'a[href] *'
|
|
78
|
+
|
|
79
|
+
export function isDead(click) {
|
|
80
|
+
if (click.hasPageActivity || click.getUserActivity().input) {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
return !elementMatches(click.event.target, DEAD_CLICK_EXCLUDE_SELECTOR)
|
|
84
|
+
}
|