@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.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/recorderApi.js +161 -0
- package/cjs/boot/rum.entry.js +6 -1
- package/cjs/boot/rum.js +15 -5
- package/cjs/boot/rumPublicApi.js +8 -4
- package/cjs/boot/startRecording.js +55 -0
- package/cjs/constants.js +52 -0
- package/cjs/domain/assembly.js +1 -7
- package/cjs/domain/configuration.js +3 -2
- package/cjs/domain/contexts/foregroundContexts.js +138 -0
- package/cjs/domain/contexts/internalContext.js +1 -1
- package/cjs/domain/contexts/urlContexts.js +9 -2
- package/cjs/domain/domMutationCollection.js +4 -5
- package/cjs/domain/initViewportObservable.js +52 -0
- package/cjs/domain/locationChangeObservable.js +12 -26
- package/cjs/domain/performanceCollection.js +2 -13
- package/cjs/domain/replay/record/elementsScrollPositions.js +27 -0
- package/cjs/domain/replay/record/index.js +41 -0
- package/cjs/domain/replay/record/mutationBatch.js +58 -0
- package/cjs/domain/replay/record/mutationObserver.js +383 -0
- package/cjs/domain/replay/record/observers.js +473 -0
- package/cjs/domain/replay/record/privacy.js +256 -0
- package/cjs/domain/replay/record/record.js +174 -0
- package/cjs/domain/replay/record/serializationUtils.js +137 -0
- package/cjs/domain/replay/record/serialize.js +488 -0
- package/cjs/domain/replay/record/shadowRootsController.js +61 -0
- package/cjs/domain/replay/record/utils.js +53 -0
- package/cjs/domain/replay/record/viewports.js +104 -0
- package/cjs/domain/replay/replayStats.js +83 -0
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +43 -0
- package/cjs/domain/replay/segmentCollection/deflateWorker.js +4399 -0
- package/cjs/domain/replay/segmentCollection/index.js +33 -0
- package/cjs/domain/replay/segmentCollection/segment.js +101 -0
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +179 -0
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +126 -0
- package/cjs/domain/requestCollection.js +35 -17
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +8 -6
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +111 -75
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +94 -54
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +45 -0
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/cjs/domain/rumEventsCollection/view/trackViews.js +21 -18
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/cjs/domain/rumSessionManager.js +6 -3
- package/cjs/domain/tracing/getDocumentTraceId.js +2 -10
- package/cjs/domain/trackEventCounts.js +10 -2
- package/cjs/domain/waitPageActivityEnd.js +5 -1
- package/cjs/transport/startRumBatch.js +5 -7
- package/cjs/types/index.js +18 -0
- package/cjs/types/sessionReplayConstants.js +56 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/recorderApi.js +149 -0
- package/esm/boot/rum.entry.js +4 -1
- package/esm/boot/rum.js +15 -6
- package/esm/boot/rumPublicApi.js +8 -4
- package/esm/boot/startRecording.js +44 -0
- package/esm/constants.js +31 -0
- package/esm/domain/assembly.js +1 -7
- package/esm/domain/configuration.js +4 -3
- package/esm/domain/contexts/foregroundContexts.js +122 -0
- package/esm/domain/contexts/internalContext.js +1 -1
- package/esm/domain/contexts/urlContexts.js +10 -3
- package/esm/domain/domMutationCollection.js +5 -6
- package/esm/domain/initViewportObservable.js +39 -0
- package/esm/domain/locationChangeObservable.js +13 -27
- package/esm/domain/performanceCollection.js +1 -12
- package/esm/domain/replay/record/elementsScrollPositions.js +20 -0
- package/esm/domain/replay/record/index.js +3 -0
- package/esm/domain/replay/record/mutationBatch.js +35 -0
- package/esm/domain/replay/record/mutationObserver.js +331 -0
- package/esm/domain/replay/record/observers.js +457 -0
- package/esm/domain/replay/record/privacy.js +233 -0
- package/esm/domain/replay/record/record.js +158 -0
- package/esm/domain/replay/record/serializationUtils.js +107 -0
- package/esm/domain/replay/record/serialize.js +461 -0
- package/esm/domain/replay/record/shadowRootsController.js +49 -0
- package/esm/domain/replay/record/utils.js +38 -0
- package/esm/domain/replay/record/viewports.js +87 -0
- package/esm/domain/replay/replayStats.js +64 -0
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +31 -0
- package/esm/domain/replay/segmentCollection/deflateWorker.js +4390 -0
- package/esm/domain/replay/segmentCollection/index.js +3 -0
- package/esm/domain/replay/segmentCollection/segment.js +84 -0
- package/esm/domain/replay/segmentCollection/segmentCollection.js +158 -0
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js +113 -0
- package/esm/domain/requestCollection.js +36 -18
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/esm/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +6 -6
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +105 -74
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +99 -59
- package/esm/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +33 -0
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +1 -18
- package/esm/domain/rumEventsCollection/view/trackViews.js +21 -19
- package/esm/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/esm/domain/rumSessionManager.js +6 -3
- package/esm/domain/tracing/getDocumentTraceId.js +1 -9
- package/esm/domain/trackEventCounts.js +10 -2
- package/esm/domain/waitPageActivityEnd.js +5 -1
- package/esm/transport/startRumBatch.js +5 -7
- package/esm/types/index.js +1 -0
- package/esm/types/sessionReplayConstants.js +45 -0
- package/package.json +3 -3
- package/src/boot/recorderApi.js +166 -0
- package/src/boot/rum.entry.js +4 -1
- package/src/boot/rum.js +38 -10
- package/src/boot/rumPublicApi.js +13 -3
- package/src/boot/startRecording.js +77 -0
- package/src/constants.js +37 -0
- package/src/domain/assembly.js +1 -6
- package/src/domain/configuration.js +10 -2
- package/src/domain/contexts/foregroundContexts.js +140 -0
- package/src/domain/contexts/internalContext.js +10 -4
- package/src/domain/contexts/urlContexts.js +29 -15
- package/src/domain/domMutationCollection.js +14 -6
- package/src/domain/initViewportObservable.js +46 -0
- package/src/domain/locationChangeObservable.js +17 -25
- package/src/domain/performanceCollection.js +42 -42
- package/src/domain/replay/record/elementsScrollPositions.js +22 -0
- package/src/domain/replay/record/index.js +7 -0
- package/src/domain/replay/record/mutationBatch.js +38 -0
- package/src/domain/replay/record/mutationObserver.js +393 -0
- package/src/domain/replay/record/observers.js +562 -0
- package/src/domain/replay/record/privacy.js +304 -0
- package/src/domain/replay/record/record.js +158 -0
- package/src/domain/replay/record/serializationUtils.js +134 -0
- package/src/domain/replay/record/serialize.js +497 -0
- package/src/domain/replay/record/shadowRootsController.js +58 -0
- package/src/domain/replay/record/utils.js +44 -0
- package/src/domain/replay/record/viewports.js +89 -0
- package/src/domain/replay/replayStats.js +67 -0
- package/src/domain/replay/segmentCollection/buildReplayPayload.js +34 -0
- package/src/domain/replay/segmentCollection/deflateWorker.js +4577 -0
- package/src/domain/replay/segmentCollection/index.js +6 -0
- package/src/domain/replay/segmentCollection/segment.js +87 -0
- package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
- package/src/domain/replay/segmentCollection/startDeflateWorker.js +101 -0
- package/src/domain/requestCollection.js +64 -28
- package/src/domain/rumEventsCollection/actions/actionCollection.js +11 -4
- package/src/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +7 -4
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +9 -6
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +130 -108
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +26 -27
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +162 -92
- package/src/domain/rumEventsCollection/error/errorCollection.js +11 -5
- package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +38 -0
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/src/domain/rumEventsCollection/view/trackViews.js +98 -68
- package/src/domain/rumEventsCollection/view/viewCollection.js +15 -7
- package/src/domain/rumSessionManager.js +33 -19
- package/src/domain/tracing/getDocumentTraceId.js +6 -9
- package/src/domain/trackEventCounts.js +10 -4
- package/src/domain/waitPageActivityEnd.js +4 -1
- package/src/transport/startRumBatch.js +29 -24
- package/src/types/index.js +1 -0
- package/src/types/sessionReplayConstants.js +49 -0
|
@@ -1,124 +1,134 @@
|
|
|
1
1
|
import { arrayFrom, cssEscape, elementMatches, map } from '@cloudcare/browser-core';
|
|
2
|
+
import { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './getActionNameFromElement';
|
|
2
3
|
/**
|
|
3
4
|
* Stable attributes are attributes that are commonly used to identify parts of a UI (ex:
|
|
4
5
|
* component). Those attribute values should not be generated randomly (hardcoded most of the time)
|
|
5
6
|
* and stay the same across deploys. They are not necessarily unique across the document.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
var STABLE_ATTRIBUTES = [
|
|
9
|
+
export var STABLE_ATTRIBUTES = [DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE, // Common test attributes (list provided by google recorder)
|
|
9
10
|
'data-testid', 'data-test', 'data-qa', 'data-cy', 'data-test-id', 'data-qa-id', 'data-testing', // FullStory decorator attributes:
|
|
10
|
-
'data-component', 'data-element', 'data-source-file'];
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
'data-component', 'data-element', 'data-source-file']; // Selectors to use if they target a single element on the whole document. Those selectors are
|
|
12
|
+
// considered as "stable" and uniquely identify an element regardless of the page state. If we find
|
|
13
|
+
// one, we should consider the selector "complete" and stop iterating over ancestors.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}].concat(attributeSelectors);
|
|
18
|
-
}
|
|
15
|
+
var GLOBALLY_UNIQUE_SELECTOR_GETTERS = [getStableAttributeSelector, getIDSelector]; // Selectors to use if they target a single element among an element descendants. Those selectors
|
|
16
|
+
// are more brittle than "globally unique" selectors and should be combined with ancestor selectors
|
|
17
|
+
// to improve specificity.
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
selector_with_stable_attributes: getSelectorFromElement(element, attributeSelectors.concat(getIDSelector), attributeSelectors.concat(getClassSelector)),
|
|
23
|
-
selector_without_classes: getSelectorFromElement(element, attributeSelectors.concat(getIDSelector), attributeSelectors)
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getSelectorFromElement(targetElement, globallyUniqueSelectorStrategies, uniqueAmongChildrenSelectorStrategies) {
|
|
19
|
+
var UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS = [getStableAttributeSelector, getClassSelector, getTagNameSelector];
|
|
20
|
+
export function getSelectorFromElement(targetElement, actionNameAttribute) {
|
|
28
21
|
var targetElementSelector = [];
|
|
29
22
|
var element = targetElement;
|
|
30
23
|
|
|
31
24
|
while (element && element.nodeName !== 'HTML') {
|
|
32
|
-
var globallyUniqueSelector = findSelector(element,
|
|
25
|
+
var globallyUniqueSelector = findSelector(element, GLOBALLY_UNIQUE_SELECTOR_GETTERS, isSelectorUniqueGlobally, actionNameAttribute, targetElementSelector);
|
|
33
26
|
|
|
34
27
|
if (globallyUniqueSelector) {
|
|
35
|
-
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var uniqueSelectorAmongChildren = findSelector(element, uniqueAmongChildrenSelectorStrategies, isSelectorUniqueAmongChildren);
|
|
40
|
-
|
|
41
|
-
if (uniqueSelectorAmongChildren) {
|
|
42
|
-
targetElementSelector.unshift(uniqueSelectorAmongChildren);
|
|
43
|
-
} else {
|
|
44
|
-
targetElementSelector.unshift(getPositionSelector(element));
|
|
28
|
+
return globallyUniqueSelector;
|
|
45
29
|
}
|
|
46
30
|
|
|
31
|
+
var uniqueSelectorAmongChildren = findSelector(element, UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS, isSelectorUniqueAmongSiblings, actionNameAttribute, targetElementSelector);
|
|
32
|
+
targetElementSelector = uniqueSelectorAmongChildren || combineSelector(getPositionSelector(element), targetElementSelector);
|
|
47
33
|
element = element.parentElement;
|
|
48
34
|
}
|
|
49
35
|
|
|
50
|
-
return targetElementSelector
|
|
36
|
+
return targetElementSelector;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isGeneratedValue(value) {
|
|
40
|
+
// To compute the "URL path group", the backend replaces every URL path parts as a question mark
|
|
41
|
+
// if it thinks the part is an identifier. The condition it uses is to checks whether a digit is
|
|
42
|
+
// present.
|
|
43
|
+
//
|
|
44
|
+
// Here, we use the same strategy: if a the value contains a digit, we consider it generated. This
|
|
45
|
+
// strategy might be a bit naive and fail in some cases, but there are many fallbacks to generate
|
|
46
|
+
// CSS selectors so it should be fine most of the time. We might want to allow customers to
|
|
47
|
+
// provide their own `isGeneratedValue` at some point.
|
|
48
|
+
return /[0-9]/.test(value);
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
function getIDSelector(element) {
|
|
54
|
-
if (element.id) {
|
|
52
|
+
if (element.id && !isGeneratedValue(element.id)) {
|
|
55
53
|
return '#' + cssEscape(element.id);
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
function getClassSelector(element) {
|
|
58
|
+
if (element.tagName === 'BODY') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
60
62
|
if (element.classList.length > 0) {
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
for (var i = 0; i < element.classList.length; i += 1) {
|
|
64
|
+
var className = element.classList[i];
|
|
65
|
+
|
|
66
|
+
if (isGeneratedValue(className)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return element.tagName + '.' + cssEscape(className);
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
|
|
68
|
-
|
|
75
|
+
function getTagNameSelector(element) {
|
|
76
|
+
return element.tagName;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getStableAttributeSelector(element, actionNameAttribute) {
|
|
80
|
+
if (actionNameAttribute) {
|
|
81
|
+
var selector = getAttributeSelector(actionNameAttribute);
|
|
69
82
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return function (element) {
|
|
74
|
-
return getAttributeSelector(attribute, element);
|
|
75
|
-
};
|
|
76
|
-
});
|
|
83
|
+
if (selector) {
|
|
84
|
+
return selector;
|
|
85
|
+
}
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
for (var i = 0; i < STABLE_ATTRIBUTES.length; i++) {
|
|
89
|
+
var attributeName = STABLE_ATTRIBUTES[i];
|
|
90
|
+
var selector = getAttributeSelector(attributeName);
|
|
91
|
+
|
|
92
|
+
if (selector) {
|
|
93
|
+
return selector;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
81
96
|
|
|
82
|
-
function getAttributeSelector(attributeName
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
function getAttributeSelector(attributeName) {
|
|
98
|
+
if (element.hasAttribute(attributeName)) {
|
|
99
|
+
return element.tagName + '[' + attributeName + '="' + cssEscape(element.getAttribute(attributeName)) + '"]';
|
|
100
|
+
}
|
|
85
101
|
}
|
|
86
102
|
}
|
|
87
103
|
|
|
88
104
|
function getPositionSelector(element) {
|
|
89
|
-
var
|
|
90
|
-
var
|
|
91
|
-
var currentIndex = 0;
|
|
92
|
-
var elementIndex;
|
|
105
|
+
var sibling = element.parentElement && element.parentElement.firstElementChild;
|
|
106
|
+
var elementIndex = 1;
|
|
93
107
|
|
|
94
|
-
while (sibling) {
|
|
108
|
+
while (sibling && sibling !== element) {
|
|
95
109
|
if (sibling.tagName === element.tagName) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (sibling === element) {
|
|
99
|
-
elementIndex = currentIndex;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (elementIndex !== undefined && currentIndex > 1) {
|
|
103
|
-
// Performance improvement: avoid iterating over all children, stop as soon as we are sure
|
|
104
|
-
// the element is not alone
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
110
|
+
elementIndex += 1;
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
sibling = sibling.nextElementSibling;
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
return
|
|
116
|
+
return element.tagName + ':nth-of-type(' + elementIndex + ')';
|
|
113
117
|
}
|
|
114
118
|
|
|
115
|
-
function findSelector(element, selectorGetters, predicate) {
|
|
119
|
+
function findSelector(element, selectorGetters, predicate, actionNameAttribute, childSelector) {
|
|
116
120
|
for (var i = 0; i < selectorGetters.length; i++) {
|
|
117
121
|
var selectorGetter = selectorGetters[i];
|
|
118
|
-
var
|
|
122
|
+
var elementSelector = selectorGetter(element, actionNameAttribute);
|
|
119
123
|
|
|
120
|
-
if (
|
|
121
|
-
|
|
124
|
+
if (!elementSelector) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var fullSelector = combineSelector(elementSelector, childSelector);
|
|
129
|
+
|
|
130
|
+
if (predicate(element, fullSelector)) {
|
|
131
|
+
return fullSelector;
|
|
122
132
|
}
|
|
123
133
|
}
|
|
124
134
|
}
|
|
@@ -126,15 +136,36 @@ function findSelector(element, selectorGetters, predicate) {
|
|
|
126
136
|
function isSelectorUniqueGlobally(element, selector) {
|
|
127
137
|
return element.ownerDocument.body.querySelectorAll(selector).length === 1;
|
|
128
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Check whether the selector is unique among the element siblings. In other words, it returns true
|
|
141
|
+
* if "ELEMENT_PARENT > SELECTOR" returns a single element.
|
|
142
|
+
*
|
|
143
|
+
* The result will be less accurate on browsers that don't support :scope (i. e. IE): it will check
|
|
144
|
+
* for any element matching the selector contained in the parent (in other words,
|
|
145
|
+
* "ELEMENT_PARENT SELECTOR" returns a single element), regardless of whether the selector is a
|
|
146
|
+
* direct descendent of the element parent. This should not impact results too much: if it
|
|
147
|
+
* inaccurately returns false, we'll just fall back to another strategy.
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
function isSelectorUniqueAmongSiblings(element, selector) {
|
|
152
|
+
return element.parentElement.querySelectorAll(supportScopeSelector() ? combineSelector(':scope', selector) : selector).length === 1;
|
|
153
|
+
}
|
|
129
154
|
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
function combineSelector(parent, child) {
|
|
156
|
+
return child ? parent + '>' + child : parent;
|
|
157
|
+
}
|
|
133
158
|
|
|
134
|
-
|
|
135
|
-
|
|
159
|
+
var supportScopeSelectorCache;
|
|
160
|
+
export function supportScopeSelector() {
|
|
161
|
+
if (supportScopeSelectorCache === undefined) {
|
|
162
|
+
try {
|
|
163
|
+
document.querySelector(':scope');
|
|
164
|
+
supportScopeSelectorCache = true;
|
|
165
|
+
} catch (_unused) {
|
|
166
|
+
supportScopeSelectorCache = false;
|
|
136
167
|
}
|
|
137
168
|
}
|
|
138
169
|
|
|
139
|
-
return
|
|
170
|
+
return supportScopeSelectorCache;
|
|
140
171
|
}
|
|
@@ -1,49 +1,41 @@
|
|
|
1
1
|
import { addEventListener, DOM_EVENT, each } from '@cloudcare/browser-core';
|
|
2
2
|
export function listenActionEvents(events) {
|
|
3
|
-
var onClick = events.onClick;
|
|
4
|
-
var onPointerDown = events.onPointerDown;
|
|
5
|
-
var hasSelectionChanged = false;
|
|
6
3
|
var selectionEmptyAtPointerDown;
|
|
7
|
-
var
|
|
4
|
+
var userActivity = {
|
|
5
|
+
selection: false,
|
|
6
|
+
input: false
|
|
7
|
+
};
|
|
8
8
|
var clickContext;
|
|
9
9
|
var listeners = [addEventListener(window, DOM_EVENT.POINTER_DOWN, function (event) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (isValidPointerEvent(event)) {
|
|
11
|
+
selectionEmptyAtPointerDown = isSelectionEmpty();
|
|
12
|
+
userActivity = {
|
|
13
|
+
selection: false,
|
|
14
|
+
input: false
|
|
15
|
+
};
|
|
16
|
+
clickContext = events.onPointerDown(event);
|
|
15
17
|
}
|
|
16
18
|
}, {
|
|
17
19
|
capture: true
|
|
18
20
|
}), addEventListener(window, DOM_EVENT.SELECTION_CHANGE, function () {
|
|
19
21
|
if (!selectionEmptyAtPointerDown || !isSelectionEmpty()) {
|
|
20
|
-
|
|
22
|
+
userActivity.selection = true;
|
|
21
23
|
}
|
|
22
24
|
}, {
|
|
23
25
|
capture: true
|
|
24
|
-
}), addEventListener(window, DOM_EVENT.
|
|
25
|
-
if (
|
|
26
|
+
}), addEventListener(window, DOM_EVENT.POINTER_UP, function (event) {
|
|
27
|
+
if (isValidPointerEvent(event) && clickContext) {
|
|
26
28
|
// Use a scoped variable to make sure the value is not changed by other clicks
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (!hasInputChanged) {
|
|
33
|
-
setTimeout(function () {
|
|
34
|
-
userActivity.input = hasInputChanged;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
onClick(clickContext, clickEvent, function () {
|
|
39
|
-
return userActivity;
|
|
29
|
+
var localUserActivity = userActivity;
|
|
30
|
+
events.onPointerUp(clickContext, event, function () {
|
|
31
|
+
return localUserActivity;
|
|
40
32
|
});
|
|
41
33
|
clickContext = undefined;
|
|
42
34
|
}
|
|
43
35
|
}, {
|
|
44
36
|
capture: true
|
|
45
37
|
}), addEventListener(window, DOM_EVENT.INPUT, function () {
|
|
46
|
-
|
|
38
|
+
userActivity.input = true;
|
|
47
39
|
}, {
|
|
48
40
|
capture: true
|
|
49
41
|
})];
|
|
@@ -61,6 +53,8 @@ function isSelectionEmpty() {
|
|
|
61
53
|
return !selection || selection.isCollapsed;
|
|
62
54
|
}
|
|
63
55
|
|
|
64
|
-
function
|
|
65
|
-
return event.target instanceof Element
|
|
56
|
+
function isValidPointerEvent(event) {
|
|
57
|
+
return event.target instanceof Element && // Only consider 'primary' pointer events for now. Multi-touch support could be implemented in
|
|
58
|
+
// the future.
|
|
59
|
+
event.isPrimary !== false;
|
|
66
60
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { timeStampNow, Observable, assign, getRelativeTime, ONE_MINUTE, ContextHistory, UUID, clocksNow, ONE_SECOND, elapsed, each, map, LifeCycleEventType, ActionType, isNullUndefinedDefaultValue } from '@cloudcare/browser-core';
|
|
1
|
+
import { timeStampNow, Observable, assign, getRelativeTime, ONE_MINUTE, ContextHistory, UUID, clocksNow, ONE_SECOND, elapsed, each, map, LifeCycleEventType, ActionType, isNullUndefinedDefaultValue, isArray, includes } from '@cloudcare/browser-core';
|
|
2
2
|
import { trackEventCounts } from '../../trackEventCounts';
|
|
3
|
-
import { waitPageActivityEnd } from '../../waitPageActivityEnd';
|
|
3
|
+
import { waitPageActivityEnd, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../waitPageActivityEnd';
|
|
4
4
|
import { createClickChain } from './clickChain';
|
|
5
5
|
import { getActionNameFromElement } from './getActionNameFromElement'; // import { getSelectorsFromElement } from './getSelectorsFromElement'
|
|
6
6
|
|
|
@@ -17,15 +17,14 @@ export function trackClickActions(lifeCycle, domMutationObservable, configuratio
|
|
|
17
17
|
lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
|
|
18
18
|
history.reset();
|
|
19
19
|
});
|
|
20
|
-
lifeCycle.subscribe(LifeCycleEventType.BEFORE_UNLOAD, stopClickChain);
|
|
21
20
|
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, stopClickChain);
|
|
22
21
|
|
|
23
22
|
var _listenActionEvents = listenActionEvents({
|
|
24
23
|
onPointerDown: function onPointerDown(pointerDownEvent) {
|
|
25
|
-
return processPointerDown(configuration, pointerDownEvent);
|
|
24
|
+
return processPointerDown(configuration, lifeCycle, domMutationObservable, history, pointerDownEvent);
|
|
26
25
|
},
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
onPointerUp: function onPointerUp(data, startEvent, getUserActivity) {
|
|
27
|
+
startClickAction(configuration, lifeCycle, domMutationObservable, history, stopObservable, appendClickToClickChain, data.clickActionBase, startEvent, getUserActivity, data.hadActivityOnPointerDown);
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
30
|
|
|
@@ -58,53 +57,85 @@ export function trackClickActions(lifeCycle, domMutationObservable, configuratio
|
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
}
|
|
60
|
+
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
function processPointerDown(configuration, lifeCycle, domMutationObservable, history, pointerDownEvent) {
|
|
63
|
+
if (!configuration.trackFrustrations && history.find()) {
|
|
64
|
+
// TODO: remove this in a future major version. To keep retrocompatibility, ignore any new
|
|
65
|
+
// action if another one is already occurring.
|
|
66
|
+
return;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
var clickActionBase = computeClickActionBase(pointerDownEvent, configuration.actionNameAttribute);
|
|
70
|
+
|
|
71
|
+
if (!configuration.trackFrustrations && !clickActionBase.name) {
|
|
72
|
+
// TODO: remove this in a future major version. To keep retrocompatibility, ignore any action
|
|
73
|
+
// with a blank name
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
var _hadActivityOnPointerDown = false;
|
|
78
|
+
waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, function (pageActivityEndEvent) {
|
|
79
|
+
_hadActivityOnPointerDown = pageActivityEndEvent.hadActivity;
|
|
80
|
+
}, // We don't care about the activity duration, we just want to know whether an activity did happen
|
|
81
|
+
// within the "validation delay" or not. Limit the duration so the callback is called sooner.
|
|
82
|
+
PAGE_ACTIVITY_VALIDATION_DELAY);
|
|
83
|
+
return {
|
|
84
|
+
clickActionBase: clickActionBase,
|
|
85
|
+
hadActivityOnPointerDown: function hadActivityOnPointerDown() {
|
|
86
|
+
return _hadActivityOnPointerDown;
|
|
72
87
|
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
73
90
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
function startClickAction(configuration, lifeCycle, domMutationObservable, history, stopObservable, appendClickToClickChain, clickActionBase, startEvent, getUserActivity, hadActivityOnPointerDown) {
|
|
92
|
+
var click = newClick(lifeCycle, history, getUserActivity, clickActionBase, startEvent);
|
|
93
|
+
|
|
94
|
+
if (configuration.trackFrustrations) {
|
|
95
|
+
appendClickToClickChain(click);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var _waitPageActivityEnd = waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, function (pageActivityEndEvent) {
|
|
99
|
+
if (pageActivityEndEvent.hadActivity && pageActivityEndEvent.end < click.startClocks.timeStamp) {
|
|
100
|
+
// If the clock is looking weird, just discard the click
|
|
101
|
+
click.discard();
|
|
102
|
+
} else {
|
|
103
|
+
if (pageActivityEndEvent.hadActivity) {
|
|
104
|
+
click.stop(pageActivityEndEvent.end);
|
|
105
|
+
} else if (hadActivityOnPointerDown()) {
|
|
106
|
+
click.stop( // using the click start as activity end, so the click will have some activity but its
|
|
107
|
+
// duration will be 0 (as the activity started before the click start)
|
|
108
|
+
click.startClocks.timeStamp);
|
|
78
109
|
} else {
|
|
79
|
-
click.stop(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (!configuration.trackFrustrations) {
|
|
83
|
-
if (!pageActivityEndEvent.hadActivity) {
|
|
84
|
-
// If we are not tracking frustrations, we should discard the click to keep backward
|
|
85
|
-
// compatibility.
|
|
86
|
-
click.discard();
|
|
87
|
-
} else {
|
|
88
|
-
click.validate();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}, CLICK_ACTION_MAX_DURATION);
|
|
110
|
+
click.stop();
|
|
111
|
+
} // Validate or discard the click only if we don't track frustrations. It'll be done when
|
|
112
|
+
// the click chain is finalized.
|
|
93
113
|
|
|
94
|
-
var viewEndedSubscription = lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function (data) {
|
|
95
|
-
click.stop(data.endClocks.timeStamp);
|
|
96
|
-
});
|
|
97
|
-
var stopSubscription = stopObservable.subscribe(function () {
|
|
98
|
-
click.stop();
|
|
99
|
-
});
|
|
100
|
-
click.stopObservable.subscribe(function () {
|
|
101
|
-
viewEndedSubscription.unsubscribe();
|
|
102
114
|
|
|
103
|
-
|
|
115
|
+
if (!configuration.trackFrustrations) {
|
|
116
|
+
if (!pageActivityEndEvent.hadActivity) {
|
|
117
|
+
// If we are not tracking frustrations, we should discard the click to keep backward
|
|
118
|
+
// compatibility.
|
|
119
|
+
click.discard();
|
|
120
|
+
} else {
|
|
121
|
+
click.validate();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, CLICK_ACTION_MAX_DURATION);
|
|
104
126
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
127
|
+
var stopWaitPageActivityEnd = _waitPageActivityEnd.stop;
|
|
128
|
+
var viewEndedSubscription = lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function (data) {
|
|
129
|
+
click.stop(data.endClocks.timeStamp);
|
|
130
|
+
});
|
|
131
|
+
var stopSubscription = stopObservable.subscribe(function () {
|
|
132
|
+
click.stop();
|
|
133
|
+
});
|
|
134
|
+
click.stopObservable.subscribe(function () {
|
|
135
|
+
viewEndedSubscription.unsubscribe();
|
|
136
|
+
stopWaitPageActivityEnd();
|
|
137
|
+
stopSubscription.unsubscribe();
|
|
138
|
+
});
|
|
108
139
|
}
|
|
109
140
|
|
|
110
141
|
function computeClickActionBase(event, actionNameAttribute) {
|
|
@@ -126,7 +157,7 @@ function computeClickActionBase(event, actionNameAttribute) {
|
|
|
126
157
|
// }
|
|
127
158
|
|
|
128
159
|
return {
|
|
129
|
-
type:
|
|
160
|
+
type: ActionType.CLICK,
|
|
130
161
|
target: target,
|
|
131
162
|
position: position,
|
|
132
163
|
name: getActionNameFromElement(event.target, actionNameAttribute)
|
|
@@ -135,18 +166,23 @@ function computeClickActionBase(event, actionNameAttribute) {
|
|
|
135
166
|
|
|
136
167
|
var ClickStatus = {
|
|
137
168
|
// Initial state, the click is still ongoing.
|
|
138
|
-
ONGOING:
|
|
169
|
+
ONGOING: 0,
|
|
139
170
|
// The click is no more ongoing but still needs to be validated or discarded.
|
|
140
|
-
STOPPED:
|
|
171
|
+
STOPPED: 1,
|
|
141
172
|
// Final state, the click has been stopped and validated or discarded.
|
|
142
|
-
FINALIZED:
|
|
173
|
+
FINALIZED: 2
|
|
143
174
|
};
|
|
144
175
|
|
|
145
|
-
function newClick(lifeCycle, history, getUserActivity, clickActionBase,
|
|
176
|
+
function newClick(lifeCycle, history, getUserActivity, clickActionBase, startEvent) {
|
|
146
177
|
var id = UUID();
|
|
147
178
|
var startClocks = clocksNow();
|
|
148
179
|
var historyEntry = history.add(id, startClocks.relative);
|
|
149
|
-
var eventCountsSubscription = trackEventCounts(
|
|
180
|
+
var eventCountsSubscription = trackEventCounts({
|
|
181
|
+
lifeCycle: lifeCycle,
|
|
182
|
+
isChildEvent: function isChildEvent(event) {
|
|
183
|
+
return event.action !== undefined && (isArray(event.action.id) ? includes(event.action.id, id) : event.action.id === id);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
150
186
|
var status = ClickStatus.ONGOING;
|
|
151
187
|
var activityEndTime;
|
|
152
188
|
var frustrationTypes = [];
|
|
@@ -171,21 +207,25 @@ function newClick(lifeCycle, history, getUserActivity, clickActionBase, clickEve
|
|
|
171
207
|
}
|
|
172
208
|
|
|
173
209
|
return {
|
|
174
|
-
event:
|
|
210
|
+
event: startEvent,
|
|
175
211
|
stop: stop,
|
|
176
|
-
startClocks: startClocks,
|
|
177
212
|
stopObservable: stopObservable,
|
|
178
|
-
hasError:
|
|
179
|
-
|
|
213
|
+
hasError: function hasError() {
|
|
214
|
+
return eventCountsSubscription.eventCounts.errorCount > 0;
|
|
215
|
+
},
|
|
216
|
+
hasPageActivity: function hasPageActivity() {
|
|
217
|
+
return activityEndTime !== undefined;
|
|
218
|
+
},
|
|
180
219
|
getUserActivity: getUserActivity,
|
|
181
220
|
addFrustration: function addFrustration(frustrationType) {
|
|
182
221
|
frustrationTypes.push(frustrationType);
|
|
183
222
|
},
|
|
223
|
+
startClocks: startClocks,
|
|
184
224
|
isStopped: function isStopped() {
|
|
185
225
|
return status === ClickStatus.STOPPED || status === ClickStatus.FINALIZED;
|
|
186
226
|
},
|
|
187
227
|
clone: function clone() {
|
|
188
|
-
return newClick(lifeCycle, history, getUserActivity, clickActionBase,
|
|
228
|
+
return newClick(lifeCycle, history, getUserActivity, clickActionBase, startEvent);
|
|
189
229
|
},
|
|
190
230
|
validate: function validate(domEvents) {
|
|
191
231
|
stop();
|
|
@@ -205,12 +245,12 @@ function newClick(lifeCycle, history, getUserActivity, clickActionBase, clickEve
|
|
|
205
245
|
id: id,
|
|
206
246
|
frustrationTypes: frustrationTypes,
|
|
207
247
|
counts: {
|
|
208
|
-
resourceCount,
|
|
209
|
-
errorCount,
|
|
210
|
-
longTaskCount
|
|
248
|
+
resourceCount: resourceCount,
|
|
249
|
+
errorCount: errorCount,
|
|
250
|
+
longTaskCount: longTaskCount
|
|
211
251
|
},
|
|
212
|
-
events: isNullUndefinedDefaultValue(domEvents, [
|
|
213
|
-
event:
|
|
252
|
+
events: isNullUndefinedDefaultValue(domEvents, [startEvent]),
|
|
253
|
+
event: startEvent
|
|
214
254
|
}, clickActionBase);
|
|
215
255
|
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, clickAction);
|
|
216
256
|
status = ClickStatus.FINALIZED;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assign, computeStackTrace, computeRawError, ErrorSource, UUID, ErrorHandling, Observable, trackRuntimeError, RumEventType, LifeCycleEventType } from '@cloudcare/browser-core';
|
|
2
2
|
import { trackConsoleError } from './trackConsoleError';
|
|
3
3
|
import { trackReportError } from './trackReportError';
|
|
4
|
-
export function startErrorCollection(lifeCycle) {
|
|
4
|
+
export function startErrorCollection(lifeCycle, foregroundContexts) {
|
|
5
5
|
var errorObservable = new Observable();
|
|
6
6
|
trackConsoleError(errorObservable);
|
|
7
7
|
trackRuntimeError(errorObservable);
|
|
@@ -11,14 +11,14 @@ export function startErrorCollection(lifeCycle) {
|
|
|
11
11
|
error: error
|
|
12
12
|
});
|
|
13
13
|
});
|
|
14
|
-
return doStartErrorCollection(lifeCycle);
|
|
14
|
+
return doStartErrorCollection(lifeCycle, foregroundContexts);
|
|
15
15
|
}
|
|
16
|
-
export function doStartErrorCollection(lifeCycle) {
|
|
16
|
+
export function doStartErrorCollection(lifeCycle, foregroundContexts) {
|
|
17
17
|
lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {
|
|
18
18
|
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, assign({
|
|
19
19
|
customerContext: error.customerContext,
|
|
20
20
|
savedCommonContext: error.savedCommonContext
|
|
21
|
-
}, processError(error.error)));
|
|
21
|
+
}, processError(error.error, foregroundContexts)));
|
|
22
22
|
});
|
|
23
23
|
return {
|
|
24
24
|
addError: function addError(providedError, savedCommonContext) {
|
|
@@ -42,7 +42,7 @@ export function doStartErrorCollection(lifeCycle) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function processError(error) {
|
|
45
|
+
function processError(error, foregroundContexts) {
|
|
46
46
|
var rawRumEvent = {
|
|
47
47
|
date: error.startClocks.timeStamp,
|
|
48
48
|
error: {
|
|
@@ -58,6 +58,14 @@ function processError(error) {
|
|
|
58
58
|
},
|
|
59
59
|
type: RumEventType.ERROR
|
|
60
60
|
};
|
|
61
|
+
var inForeground = foregroundContexts.isInForegroundAt(error.startClocks.relative);
|
|
62
|
+
|
|
63
|
+
if (inForeground) {
|
|
64
|
+
rawRumEvent.view = {
|
|
65
|
+
in_foreground: inForeground
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
return {
|
|
62
70
|
rawRumEvent: rawRumEvent,
|
|
63
71
|
startTime: error.startClocks.relative,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ONE_MINUTE } from '@cloudcare/browser-core';
|
|
2
|
+
import { trackEventCounts } from '../../trackEventCounts'; // Some events are not being counted as they transcend views. To reduce the occurrence;
|
|
3
|
+
// an arbitrary delay is added for stopping event counting after the view ends.
|
|
4
|
+
//
|
|
5
|
+
// Ideally, we would not stop and keep counting events until the end of the session.
|
|
6
|
+
// But this might have a small performance impact if there are many many views:
|
|
7
|
+
// we would need to go through each event to see if the related view matches.
|
|
8
|
+
// So let's have a fairly short delay to avoid impacting performances too much.
|
|
9
|
+
//
|
|
10
|
+
// In the future, we could have views stored in a data structure similar to ContextHistory. Whenever
|
|
11
|
+
// a child event is collected, we could look into this history to find the matching view and
|
|
12
|
+
// increase the associated and increase its counter. Having a centralized data structure for it
|
|
13
|
+
// would allow us to look for views more efficiently.
|
|
14
|
+
//
|
|
15
|
+
// For now, having a small cleanup delay will already improve the situation in most cases.
|
|
16
|
+
|
|
17
|
+
export var KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE;
|
|
18
|
+
export function trackViewEventCounts(lifeCycle, viewId, onChange) {
|
|
19
|
+
var _trackEventCounts = trackEventCounts({
|
|
20
|
+
lifeCycle: lifeCycle,
|
|
21
|
+
isChildEvent: function isChildEvent(event) {
|
|
22
|
+
return event.view.id === viewId;
|
|
23
|
+
},
|
|
24
|
+
onChange: onChange
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
scheduleStop: function scheduleStop() {
|
|
29
|
+
setTimeout(_trackEventCounts.stop, KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY);
|
|
30
|
+
},
|
|
31
|
+
eventCounts: _trackEventCounts.eventCounts
|
|
32
|
+
};
|
|
33
|
+
}
|