@gemx-dev/clarity-js 0.8.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +1 -0
  2. package/build/clarity.extended.js +1 -0
  3. package/build/clarity.insight.js +1 -0
  4. package/build/clarity.js +6433 -0
  5. package/build/clarity.livechat.js +1 -0
  6. package/build/clarity.min.js +1 -0
  7. package/build/clarity.module.js +6429 -0
  8. package/build/clarity.performance.js +1 -0
  9. package/build/dynamic/clarity.crisp.js +1 -0
  10. package/build/dynamic/clarity.tidio.js +1 -0
  11. package/package.json +55 -0
  12. package/rollup.config.ts +161 -0
  13. package/src/clarity.ts +71 -0
  14. package/src/core/api.ts +8 -0
  15. package/src/core/config.ts +29 -0
  16. package/src/core/copy.ts +3 -0
  17. package/src/core/dynamic.ts +57 -0
  18. package/src/core/event.ts +53 -0
  19. package/src/core/hash.ts +19 -0
  20. package/src/core/history.ts +71 -0
  21. package/src/core/index.ts +81 -0
  22. package/src/core/measure.ts +19 -0
  23. package/src/core/report.ts +35 -0
  24. package/src/core/scrub.ts +202 -0
  25. package/src/core/task.ts +181 -0
  26. package/src/core/throttle.ts +46 -0
  27. package/src/core/time.ts +26 -0
  28. package/src/core/timeout.ts +10 -0
  29. package/src/core/version.ts +2 -0
  30. package/src/data/baseline.ts +162 -0
  31. package/src/data/compress.ts +31 -0
  32. package/src/data/consent.ts +75 -0
  33. package/src/data/custom.ts +23 -0
  34. package/src/data/dimension.ts +53 -0
  35. package/src/data/encode.ts +155 -0
  36. package/src/data/envelope.ts +53 -0
  37. package/src/data/extract.ts +211 -0
  38. package/src/data/index.ts +50 -0
  39. package/src/data/limit.ts +44 -0
  40. package/src/data/metadata.ts +408 -0
  41. package/src/data/metric.ts +51 -0
  42. package/src/data/ping.ts +36 -0
  43. package/src/data/signal.ts +30 -0
  44. package/src/data/summary.ts +34 -0
  45. package/src/data/token.ts +39 -0
  46. package/src/data/upgrade.ts +44 -0
  47. package/src/data/upload.ts +333 -0
  48. package/src/data/variable.ts +84 -0
  49. package/src/diagnostic/encode.ts +40 -0
  50. package/src/diagnostic/fraud.ts +37 -0
  51. package/src/diagnostic/index.ts +13 -0
  52. package/src/diagnostic/internal.ts +28 -0
  53. package/src/diagnostic/script.ts +35 -0
  54. package/src/dynamic/agent/blank.ts +2 -0
  55. package/src/dynamic/agent/crisp.ts +40 -0
  56. package/src/dynamic/agent/encode.ts +25 -0
  57. package/src/dynamic/agent/index.ts +8 -0
  58. package/src/dynamic/agent/livechat.ts +58 -0
  59. package/src/dynamic/agent/tidio.ts +44 -0
  60. package/src/global.ts +6 -0
  61. package/src/index.ts +9 -0
  62. package/src/insight/blank.ts +14 -0
  63. package/src/insight/encode.ts +61 -0
  64. package/src/insight/snapshot.ts +115 -0
  65. package/src/interaction/change.ts +38 -0
  66. package/src/interaction/click.ts +163 -0
  67. package/src/interaction/clipboard.ts +32 -0
  68. package/src/interaction/encode.ts +207 -0
  69. package/src/interaction/focus.ts +25 -0
  70. package/src/interaction/index.ts +60 -0
  71. package/src/interaction/input.ts +58 -0
  72. package/src/interaction/pointer.ts +137 -0
  73. package/src/interaction/resize.ts +50 -0
  74. package/src/interaction/scroll.ts +129 -0
  75. package/src/interaction/selection.ts +66 -0
  76. package/src/interaction/submit.ts +30 -0
  77. package/src/interaction/timeline.ts +69 -0
  78. package/src/interaction/unload.ts +26 -0
  79. package/src/interaction/visibility.ts +28 -0
  80. package/src/layout/animation.ts +133 -0
  81. package/src/layout/custom.ts +43 -0
  82. package/src/layout/discover.ts +31 -0
  83. package/src/layout/document.ts +46 -0
  84. package/src/layout/dom.ts +439 -0
  85. package/src/layout/encode.ts +154 -0
  86. package/src/layout/index.ts +42 -0
  87. package/src/layout/mutation.ts +412 -0
  88. package/src/layout/node.ts +294 -0
  89. package/src/layout/offset.ts +19 -0
  90. package/src/layout/region.ts +151 -0
  91. package/src/layout/schema.ts +63 -0
  92. package/src/layout/selector.ts +82 -0
  93. package/src/layout/style.ts +160 -0
  94. package/src/layout/target.ts +32 -0
  95. package/src/layout/traverse.ts +28 -0
  96. package/src/performance/blank.ts +10 -0
  97. package/src/performance/encode.ts +31 -0
  98. package/src/performance/index.ts +12 -0
  99. package/src/performance/interaction.ts +125 -0
  100. package/src/performance/navigation.ts +31 -0
  101. package/src/performance/observer.ts +112 -0
  102. package/src/queue.ts +33 -0
  103. package/test/core.test.ts +139 -0
  104. package/test/helper.ts +167 -0
  105. package/test/html/core.html +34 -0
  106. package/test/stub.test.ts +7 -0
  107. package/test/tsconfig.test.json +6 -0
  108. package/tsconfig.json +21 -0
  109. package/tslint.json +33 -0
  110. package/types/agent.d.ts +39 -0
  111. package/types/core.d.ts +150 -0
  112. package/types/data.d.ts +568 -0
  113. package/types/diagnostic.d.ts +24 -0
  114. package/types/global.d.ts +30 -0
  115. package/types/index.d.ts +40 -0
  116. package/types/interaction.d.ts +174 -0
  117. package/types/layout.d.ts +277 -0
  118. package/types/performance.d.ts +31 -0
@@ -0,0 +1,66 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { SelectionData, Setting } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import { schedule } from "@src/core/task";
5
+ import { clearTimeout, setTimeout } from "@src/core/timeout";
6
+ import encode from "./encode";
7
+
8
+ export let data: SelectionData = null;
9
+ let previous: Selection = null;
10
+ let timeout: number = null;
11
+
12
+ export function start(): void {
13
+ reset();
14
+ }
15
+
16
+ export function observe(root: Node): void {
17
+ bind(root, "selectstart", recompute.bind(this, root), true);
18
+ bind(root, "selectionchange", recompute.bind(this, root), true);
19
+ }
20
+
21
+ function recompute(root: Node): void {
22
+ let doc = root.nodeType === Node.DOCUMENT_NODE ? root as Document : document;
23
+ let current = doc.getSelection();
24
+
25
+ // Bail out if we don't have a valid selection
26
+ if (current === null) { return; }
27
+
28
+ // Bail out if we got a valid selection but not valid nodes
29
+ // In Edge, selectionchange gets fired even on interactions like right clicks and
30
+ // can result in null anchorNode and focusNode if there was no previous selection on page
31
+ // Also, ignore any selections that start and end at the exact same point
32
+ if ((current.anchorNode === null && current.focusNode === null) ||
33
+ (current.anchorNode === current.focusNode && current.anchorOffset === current.focusOffset)) {
34
+ return;
35
+ }
36
+ let startNode = data.start ? data.start : null;
37
+ if (previous !== null && data.start !== null && startNode !== current.anchorNode) {
38
+ clearTimeout(timeout);
39
+ process(Event.Selection);
40
+ }
41
+
42
+ data = {
43
+ start: current.anchorNode,
44
+ startOffset: current.anchorOffset,
45
+ end: current.focusNode,
46
+ endOffset: current.focusOffset
47
+ };
48
+ previous = current;
49
+
50
+ clearTimeout(timeout);
51
+ timeout = setTimeout(process, Setting.LookAhead, Event.Selection);
52
+ }
53
+
54
+ function process(event: Event): void {
55
+ schedule(encode.bind(this, event));
56
+ }
57
+
58
+ export function reset(): void {
59
+ previous = null;
60
+ data = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
61
+ }
62
+
63
+ export function stop(): void {
64
+ reset();
65
+ clearTimeout(timeout);
66
+ }
@@ -0,0 +1,30 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { SubmitState } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import { schedule } from "@src/core/task";
5
+ import { time } from "@src/core/time";
6
+ import encode from "./encode";
7
+ import { target } from "@src/layout/target";
8
+
9
+ export let state: SubmitState[] = [];
10
+
11
+ export function start(): void {
12
+ reset();
13
+ }
14
+
15
+ export function observe(root: Node): void {
16
+ bind(root, "submit", recompute, true);
17
+ }
18
+
19
+ function recompute(evt: UIEvent): void {
20
+ state.push({ time: time(evt), event: Event.Submit, data: { target: target(evt) } });
21
+ schedule(encode.bind(this, Event.Submit));
22
+ }
23
+
24
+ export function reset(): void {
25
+ state = [];
26
+ }
27
+
28
+ export function stop(): void {
29
+ reset();
30
+ }
@@ -0,0 +1,69 @@
1
+ import { BooleanFlag, Event } from "@clarity-types/data";
2
+ import { BrowsingContext, Setting, TimelineState } from "@clarity-types/interaction";
3
+ import * as baseline from "@src/data/baseline";
4
+ import * as envelope from "@src/data/envelope";
5
+ import encode from "@src/interaction/encode";
6
+
7
+ let state: TimelineState[] = [];
8
+ export let updates: TimelineState[] = [];
9
+
10
+ export function start(): void {
11
+ state = [];
12
+ reset();
13
+ }
14
+
15
+ export function reset(): void {
16
+ updates = [];
17
+ }
18
+
19
+ export function track(time: number,
20
+ event: Event,
21
+ hash: string,
22
+ x: number,
23
+ y: number,
24
+ reaction: number = BooleanFlag.True,
25
+ context: number = BrowsingContext.Self): void {
26
+ state.push({
27
+ time,
28
+ event: Event.Timeline,
29
+ data: {
30
+ type: event,
31
+ hash,
32
+ x,
33
+ y,
34
+ reaction,
35
+ context
36
+ }
37
+ });
38
+
39
+ // Since timeline only keeps the data for configured time, we still want to continue tracking these values
40
+ // as part of the baseline. For instance, in a scenario where last scroll happened 5s ago.
41
+ // We would still need to capture the last scroll position as part of the baseline event, even when timeline will be empty.
42
+ baseline.track(event, x, y, time);
43
+ }
44
+
45
+ export function compute(): void {
46
+ if (!envelope.data) {
47
+ return;
48
+ }
49
+
50
+ const temp = [];
51
+ updates = [];
52
+ let max = (envelope.data.start || 0) + (envelope.data.duration || 0);
53
+ let min = Math.max(max - Setting.TimelineSpan, 0);
54
+
55
+ for (let s of state) {
56
+ if (s.time >= min) {
57
+ if (s.time <= max) { updates.push(s); }
58
+ temp.push(s);
59
+ }
60
+ }
61
+
62
+ state = temp; // Drop events less than the min time
63
+ encode(Event.Timeline);
64
+ }
65
+
66
+ export function stop(): void {
67
+ state = [];
68
+ reset();
69
+ }
@@ -0,0 +1,26 @@
1
+ import { BooleanFlag, Event } from "@clarity-types/data";
2
+ import { UnloadData } from "@clarity-types/interaction";
3
+ import * as clarity from "@src/clarity";
4
+ import { bind } from "@src/core/event";
5
+ import { time } from "@src/core/time";
6
+ import encode from "./encode";
7
+
8
+ export let data: UnloadData;
9
+
10
+ export function start(): void {
11
+ bind(window, "pagehide", recompute);
12
+ }
13
+
14
+ function recompute(evt: PageTransitionEvent): void {
15
+ data = { name: evt.type, persisted: evt.persisted ? BooleanFlag.True : BooleanFlag.False };
16
+ encode(Event.Unload, time(evt));
17
+ clarity.stop();
18
+ }
19
+
20
+ export function reset(): void {
21
+ data = null;
22
+ }
23
+
24
+ export function stop(): void {
25
+ reset();
26
+ }
@@ -0,0 +1,28 @@
1
+ import { BooleanFlag, Event } from "@clarity-types/data";
2
+ import { VisibilityData } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import { time } from "@src/core/time";
5
+ import encode from "./encode";
6
+
7
+ export let data: VisibilityData;
8
+
9
+ export function start(): void {
10
+ bind(document, "visibilitychange", recompute);
11
+ recompute();
12
+ }
13
+
14
+ function recompute(evt: UIEvent = null): void {
15
+ if ("visibilityState" in document) {
16
+ const visible = document.visibilityState === "visible" ? BooleanFlag.True : BooleanFlag.False;
17
+ data = { visible };
18
+ encode(Event.Visibility, time(evt));
19
+ }
20
+ }
21
+
22
+ export function reset(): void {
23
+ data = null;
24
+ }
25
+
26
+ export function stop(): void {
27
+ reset();
28
+ }
@@ -0,0 +1,133 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { AnimationOperation, AnimationState } from "@clarity-types/layout";
3
+ import { time } from "@src/core/time";
4
+ import { shortid } from "@src/data/metadata";
5
+ import encode from "@src/layout/encode";
6
+ import { getId } from "@src/layout/dom";
7
+ import * as core from "@src/core";
8
+
9
+ export let state: AnimationState[] = [];
10
+ let elementAnimate: (keyframes: Keyframe[] | PropertyIndexedKeyframes, options?: number | KeyframeAnimationOptions) => Animation = null;
11
+ let animationPlay: () => void = null;
12
+ let animationPause: () => void = null;
13
+ let animationCommitStyles: () => void = null;
14
+ let animationCancel: () => void = null;
15
+ let animationFinish: () => void = null;
16
+ const animationId = 'clarityAnimationId';
17
+ const operationCount = 'clarityOperationCount';
18
+ const maxOperations = 20;
19
+
20
+ export function start(): void {
21
+ if (
22
+ window["Animation"] &&
23
+ window["Animation"].prototype &&
24
+ window["KeyframeEffect"] &&
25
+ window["KeyframeEffect"].prototype &&
26
+ window["KeyframeEffect"].prototype.getKeyframes &&
27
+ window["KeyframeEffect"].prototype.getTiming
28
+ ) {
29
+ reset();
30
+ overrideAnimationHelper(animationPlay, "play");
31
+ overrideAnimationHelper(animationPause, "pause");
32
+ overrideAnimationHelper(animationCommitStyles, "commitStyles");
33
+ overrideAnimationHelper(animationCancel, "cancel");
34
+ overrideAnimationHelper(animationFinish, "finish");
35
+ if (elementAnimate === null) {
36
+ elementAnimate = Element.prototype.animate;
37
+ Element.prototype.animate = function(): Animation {
38
+ var createdAnimation = elementAnimate.apply(this, arguments);
39
+ trackAnimationOperation(createdAnimation, "play");
40
+ return createdAnimation;
41
+ }
42
+ }
43
+ if (document.getAnimations) {
44
+ for (var animation of document.getAnimations()) {
45
+ if (animation.playState === "finished") {
46
+ trackAnimationOperation(animation, "finish");
47
+ }
48
+ else if (animation.playState === "paused" || animation.playState === "idle") {
49
+ trackAnimationOperation(animation, "pause");
50
+ }
51
+ else if (animation.playState === "running") {
52
+ trackAnimationOperation(animation, "play");
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ export function reset(): void {
60
+ state = [];
61
+ }
62
+
63
+ function track(time: number, id: string, operation: AnimationOperation, keyFrames?: string, timing?: string, targetId?: number, timeline?: string): void {
64
+ state.push({
65
+ time,
66
+ event: Event.Animation,
67
+ data: {
68
+ id,
69
+ operation,
70
+ keyFrames,
71
+ timing,
72
+ targetId,
73
+ timeline
74
+ }
75
+ });
76
+
77
+ encode(Event.Animation);
78
+ }
79
+
80
+ export function stop(): void {
81
+ reset();
82
+ }
83
+
84
+ function overrideAnimationHelper(functionToOverride: () => void, name: string) {
85
+ if (functionToOverride === null) {
86
+ functionToOverride = Animation.prototype[name];
87
+ Animation.prototype[name] = function(): void {
88
+ trackAnimationOperation(this, name);
89
+ return functionToOverride.apply(this, arguments);
90
+ }
91
+ }
92
+ }
93
+
94
+ function trackAnimationOperation(animation: Animation, name: string) {
95
+ if (core.active()) {
96
+ let effect = <KeyframeEffect>animation.effect;
97
+ let target = effect?.target ? getId(effect.target) : null;
98
+ if (target !== null && effect.getKeyframes && effect.getTiming) {
99
+ if (!animation[animationId]) {
100
+ animation[animationId] = shortid();
101
+ animation[operationCount] = 0;
102
+
103
+ let keyframes = effect.getKeyframes();
104
+ let timing = effect.getTiming();
105
+ track(time(), animation[animationId], AnimationOperation.Create, JSON.stringify(keyframes), JSON.stringify(timing), target);
106
+ }
107
+
108
+ if (animation[operationCount]++ < maxOperations) {
109
+ let operation: AnimationOperation = null;
110
+ switch (name) {
111
+ case "play":
112
+ operation = AnimationOperation.Play;
113
+ break;
114
+ case "pause":
115
+ operation = AnimationOperation.Pause;
116
+ break;
117
+ case "cancel":
118
+ operation = AnimationOperation.Cancel;
119
+ break;
120
+ case "finish":
121
+ operation = AnimationOperation.Finish;
122
+ break;
123
+ case "commitStyles":
124
+ operation = AnimationOperation.CommitStyles;
125
+ break;
126
+ }
127
+ if (operation) {
128
+ track(time(), animation[animationId], operation);
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,43 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { active } from "@src/core";
3
+ import { schedule } from "@src/core/task";
4
+ import encode from "@src/layout/encode";
5
+
6
+ export const elements: string[] = [];
7
+
8
+ const definedElements = new Set<string>();
9
+ function register(tag: string) {
10
+ if (!definedElements.has(tag)) {
11
+ definedElements.add(tag);
12
+ elements.push(tag);
13
+ schedule(encode.bind(this, Event.CustomElement));
14
+ }
15
+ }
16
+
17
+ export function check(tag: string) {
18
+ if (window.customElements?.get && window.customElements.get(tag)) {
19
+ register(tag);
20
+ }
21
+ }
22
+
23
+ export function start() {
24
+ window.clarityOverrides = window.clarityOverrides || {};
25
+ if (window.customElements?.define && !window.clarityOverrides.define) {
26
+ window.clarityOverrides.define = window.customElements.define;
27
+ window.customElements.define = function () {
28
+ if (active()) {
29
+ register(arguments[0]);
30
+ }
31
+ return window.clarityOverrides.define.apply(this, arguments);
32
+ };
33
+ }
34
+ }
35
+
36
+ export function reset() {
37
+ elements.length = 0;
38
+ }
39
+
40
+ export function stop() {
41
+ reset();
42
+ definedElements.clear();
43
+ }
@@ -0,0 +1,31 @@
1
+ import { Priority, Timer } from "@clarity-types/core";
2
+ import { Event, Metric } from "@clarity-types/data";
3
+ import { Source } from "@clarity-types/layout";
4
+ import measure from "@src/core/measure";
5
+ import * as task from "@src/core/task";
6
+ import { time } from "@src/core/time";
7
+ import { id } from "@src/data/metadata";
8
+ import * as doc from "@src/layout/document";
9
+ import encode from "@src/layout/encode";
10
+ import * as region from "@src/layout/region";
11
+ import traverse from "@src/layout/traverse";
12
+ import { checkDocumentStyles } from "@src/layout/style";
13
+ import * as scroll from "@src/interaction/scroll";
14
+
15
+ export function start(): void {
16
+ task.schedule(discover, Priority.High).then((): void => {
17
+ measure(doc.compute)();
18
+ measure(region.compute)();
19
+ measure(scroll.compute)();
20
+ });
21
+ }
22
+
23
+ async function discover(): Promise<void> {
24
+ let ts = time();
25
+ let timer: Timer = { id: id(), cost: Metric.LayoutCost };
26
+ task.start(timer);
27
+ await traverse(document, timer, Source.Discover, ts);
28
+ checkDocumentStyles(document, ts);
29
+ await encode(Event.Discover, timer, ts);
30
+ task.stop(timer);
31
+ }
@@ -0,0 +1,46 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { DocumentData } from "@clarity-types/layout";
3
+ import encode from "@src/layout/encode";
4
+
5
+ export let data: DocumentData;
6
+
7
+ export function reset(): void {
8
+ data = null;
9
+ }
10
+
11
+ export function start(): void {
12
+ reset();
13
+ compute();
14
+ }
15
+
16
+ export function compute(): void {
17
+ let body = document.body;
18
+ let d = document.documentElement;
19
+ let bodyClientWidth = body ? body.clientWidth : null;
20
+ let bodyScrollWidth = body ? body.scrollWidth : null;
21
+ let bodyOffsetWidth = body ? body.offsetWidth : null;
22
+ let documentClientWidth = d ? d.clientWidth : null;
23
+ let documentScrollWidth = d ? d.scrollWidth : null;
24
+ let documentOffsetWidth = d ? d.offsetWidth : null;
25
+ let width = Math.max(bodyClientWidth, bodyScrollWidth, bodyOffsetWidth,
26
+ documentClientWidth, documentScrollWidth, documentOffsetWidth);
27
+
28
+ let bodyClientHeight = body ? body.clientHeight : null;
29
+ let bodyScrollHeight = body ? body.scrollHeight : null;
30
+ let bodyOffsetHeight = body ? body.offsetHeight : null;
31
+ let documentClientHeight = d ? d.clientHeight : null;
32
+ let documentScrollHeight = d ? d.scrollHeight : null;
33
+ let documentOffsetHeight = d ? d.offsetHeight : null;
34
+ let height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight,
35
+ documentClientHeight, documentScrollHeight, documentOffsetHeight);
36
+
37
+ // Check that width or height has changed from before, and also that width & height are not null values
38
+ if ((data === null || width !== data.width || height !== data.height) && width !== null && height !== null) {
39
+ data = { width, height };
40
+ encode(Event.Document);
41
+ }
42
+ }
43
+
44
+ export function stop(): void {
45
+ reset();
46
+ }