clarity-js 0.8.12 → 0.8.14

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 (92) hide show
  1. package/build/clarity.extended.js +1 -1
  2. package/build/clarity.insight.js +1 -1
  3. package/build/clarity.js +4609 -4762
  4. package/build/clarity.min.js +1 -1
  5. package/build/clarity.module.js +4609 -4762
  6. package/build/clarity.performance.js +1 -1
  7. package/package.json +69 -76
  8. package/rollup.config.ts +88 -84
  9. package/src/clarity.ts +29 -35
  10. package/src/core/api.ts +1 -8
  11. package/src/core/config.ts +2 -2
  12. package/src/core/event.ts +32 -36
  13. package/src/core/hash.ts +6 -5
  14. package/src/core/history.ts +11 -10
  15. package/src/core/index.ts +11 -21
  16. package/src/core/measure.ts +5 -9
  17. package/src/core/report.ts +6 -10
  18. package/src/core/scrub.ts +27 -30
  19. package/src/core/task.ts +45 -73
  20. package/src/core/time.ts +3 -3
  21. package/src/core/timeout.ts +2 -2
  22. package/src/core/version.ts +1 -1
  23. package/src/data/baseline.ts +55 -60
  24. package/src/data/consent.ts +22 -4
  25. package/src/data/custom.ts +13 -8
  26. package/src/data/dimension.ts +7 -11
  27. package/src/data/encode.ts +38 -36
  28. package/src/data/envelope.ts +38 -38
  29. package/src/data/extract.ts +77 -86
  30. package/src/data/index.ts +9 -11
  31. package/src/data/limit.ts +1 -1
  32. package/src/data/metadata.ts +319 -305
  33. package/src/data/metric.ts +8 -18
  34. package/src/data/ping.ts +4 -8
  35. package/src/data/signal.ts +18 -18
  36. package/src/data/summary.ts +4 -6
  37. package/src/data/token.ts +8 -10
  38. package/src/data/upgrade.ts +3 -7
  39. package/src/data/upload.ts +49 -100
  40. package/src/data/variable.ts +20 -27
  41. package/src/diagnostic/encode.ts +2 -2
  42. package/src/diagnostic/fraud.ts +4 -3
  43. package/src/diagnostic/internal.ts +5 -11
  44. package/src/diagnostic/script.ts +8 -12
  45. package/src/global.ts +1 -1
  46. package/src/insight/blank.ts +4 -4
  47. package/src/insight/encode.ts +17 -23
  48. package/src/insight/snapshot.ts +37 -57
  49. package/src/interaction/change.ts +6 -9
  50. package/src/interaction/click.ts +28 -34
  51. package/src/interaction/clipboard.ts +2 -2
  52. package/src/interaction/encode.ts +31 -35
  53. package/src/interaction/input.ts +9 -11
  54. package/src/interaction/pointer.ts +30 -41
  55. package/src/interaction/resize.ts +5 -5
  56. package/src/interaction/scroll.ts +17 -20
  57. package/src/interaction/selection.ts +8 -12
  58. package/src/interaction/submit.ts +2 -2
  59. package/src/interaction/timeline.ts +9 -13
  60. package/src/interaction/unload.ts +1 -1
  61. package/src/interaction/visibility.ts +2 -2
  62. package/src/layout/animation.ts +41 -47
  63. package/src/layout/discover.ts +5 -5
  64. package/src/layout/document.ts +19 -31
  65. package/src/layout/dom.ts +91 -141
  66. package/src/layout/encode.ts +37 -52
  67. package/src/layout/mutation.ts +318 -321
  68. package/src/layout/node.ts +81 -104
  69. package/src/layout/offset.ts +6 -7
  70. package/src/layout/region.ts +43 -66
  71. package/src/layout/schema.ts +8 -15
  72. package/src/layout/selector.ts +25 -47
  73. package/src/layout/style.ts +37 -45
  74. package/src/layout/target.ts +10 -14
  75. package/src/layout/traverse.ts +11 -17
  76. package/src/performance/blank.ts +1 -1
  77. package/src/performance/encode.ts +4 -4
  78. package/src/performance/interaction.ts +70 -58
  79. package/src/performance/navigation.ts +2 -2
  80. package/src/performance/observer.ts +26 -59
  81. package/src/queue.ts +9 -16
  82. package/tsconfig.json +1 -1
  83. package/tslint.json +32 -25
  84. package/types/core.d.ts +13 -13
  85. package/types/data.d.ts +48 -32
  86. package/types/diagnostic.d.ts +1 -1
  87. package/types/index.d.ts +1 -0
  88. package/types/interaction.d.ts +4 -5
  89. package/types/layout.d.ts +21 -36
  90. package/types/performance.d.ts +5 -6
  91. package/.lintstagedrc.yml +0 -3
  92. package/biome.json +0 -43
@@ -1,11 +1,11 @@
1
- import { BooleanFlag, Event } from "@clarity-types/data";
2
- import type { BaselineData, BaselineState } from "@clarity-types/data";
1
+ import { Event, BooleanFlag } from "@clarity-types/data";
2
+ import { BaselineData, BaselineState } from "@clarity-types/data";
3
3
  import { time } from "@src/core/time";
4
4
  import encode from "@src/data/encode";
5
5
 
6
6
  export let state: BaselineState = null;
7
7
  let buffer: BaselineData = null;
8
- let update = false;
8
+ let update: boolean = false;
9
9
 
10
10
  export function start(): void {
11
11
  update = false;
@@ -16,65 +16,60 @@ export function reset(): void {
16
16
  // Baseline state holds the previous values - if it is updated in the current payload,
17
17
  // reset the state to current value after sending the previous state
18
18
  if (update) {
19
- state = {
20
- time: time(),
21
- event: Event.Baseline,
22
- data: {
23
- visible: buffer.visible,
24
- docWidth: buffer.docWidth,
25
- docHeight: buffer.docHeight,
26
- screenWidth: buffer.screenWidth,
27
- screenHeight: buffer.screenHeight,
28
- scrollX: buffer.scrollX,
29
- scrollY: buffer.scrollY,
30
- pointerX: buffer.pointerX,
31
- pointerY: buffer.pointerY,
32
- activityTime: buffer.activityTime,
33
- scrollTime: buffer.scrollTime,
34
- pointerTime: buffer.pointerTime,
35
- moveX: buffer.moveX,
36
- moveY: buffer.moveY,
37
- moveTime: buffer.moveTime,
38
- downX: buffer.downX,
39
- downY: buffer.downY,
40
- downTime: buffer.downTime,
41
- upX: buffer.upX,
42
- upY: buffer.upY,
43
- upTime: buffer.upTime,
44
- pointerPrevX: buffer.pointerPrevX,
45
- pointerPrevY: buffer.pointerPrevY,
46
- pointerPrevTime: buffer.pointerPrevTime,
47
- },
19
+ state = { time: time(), event: Event.Baseline, data: {
20
+ visible: buffer.visible,
21
+ docWidth: buffer.docWidth,
22
+ docHeight: buffer.docHeight,
23
+ screenWidth: buffer.screenWidth,
24
+ screenHeight: buffer.screenHeight,
25
+ scrollX: buffer.scrollX,
26
+ scrollY: buffer.scrollY,
27
+ pointerX: buffer.pointerX,
28
+ pointerY: buffer.pointerY,
29
+ activityTime: buffer.activityTime,
30
+ scrollTime: buffer.scrollTime,
31
+ pointerTime: buffer.pointerTime,
32
+ moveX: buffer.moveX,
33
+ moveY: buffer.moveY,
34
+ moveTime: buffer.moveTime,
35
+ downX: buffer.downX,
36
+ downY: buffer.downY,
37
+ downTime: buffer.downTime,
38
+ upX: buffer.upX,
39
+ upY: buffer.upY,
40
+ upTime: buffer.upTime,
41
+ pointerPrevX: buffer.pointerPrevX,
42
+ pointerPrevY: buffer.pointerPrevY,
43
+ pointerPrevTime: buffer.pointerPrevTime,
44
+ }
48
45
  };
49
46
  }
50
- buffer = buffer
51
- ? buffer
52
- : {
53
- visible: BooleanFlag.True,
54
- docWidth: 0,
55
- docHeight: 0,
56
- screenWidth: 0,
57
- screenHeight: 0,
58
- scrollX: 0,
59
- scrollY: 0,
60
- pointerX: 0,
61
- pointerY: 0,
62
- activityTime: 0,
63
- scrollTime: 0,
64
- pointerTime: undefined,
65
- moveX: undefined,
66
- moveY: undefined,
67
- moveTime: undefined,
68
- downX: undefined,
69
- downY: undefined,
70
- downTime: undefined,
71
- upX: undefined,
72
- upY: undefined,
73
- upTime: undefined,
74
- pointerPrevX: undefined,
75
- pointerPrevY: undefined,
76
- pointerPrevTime: undefined,
77
- };
47
+ buffer = buffer ? buffer : {
48
+ visible: BooleanFlag.True,
49
+ docWidth: 0,
50
+ docHeight: 0,
51
+ screenWidth: 0,
52
+ screenHeight: 0,
53
+ scrollX: 0,
54
+ scrollY: 0,
55
+ pointerX: 0,
56
+ pointerY: 0,
57
+ activityTime: 0,
58
+ scrollTime: 0,
59
+ pointerTime: undefined,
60
+ moveX: undefined,
61
+ moveY: undefined,
62
+ moveTime: undefined,
63
+ downX: undefined,
64
+ downY: undefined,
65
+ downTime: undefined,
66
+ upX: undefined,
67
+ upY: undefined,
68
+ upTime: undefined,
69
+ pointerPrevX: undefined,
70
+ pointerPrevY: undefined,
71
+ pointerPrevTime: undefined,
72
+ };
78
73
  }
79
74
 
80
75
  export function track(event: Event, x: number, y: number, time?: number): void {
@@ -1,14 +1,19 @@
1
- import { Dimension } from "@clarity-types/data";
1
+ import { ConsentData, Dimension, Event } from "@clarity-types/data";
2
2
  import * as dimension from "@src/data/dimension";
3
+ import encode from "./encode";
4
+
5
+ export let data: ConsentData = null;
6
+ let updateConsent: boolean = true;
3
7
 
4
8
  const enum ConsentType {
5
9
  None = 0,
6
10
  Implicit = 1,
7
- General = 2,
11
+ General = 2
8
12
  }
9
13
 
10
- export function config(track: boolean): void {
11
- trackConsent(track ? ConsentType.Implicit : ConsentType.None);
14
+ export function config(consent: ConsentData): void {
15
+ trackConsent(consent.analytics_Storage ? ConsentType.Implicit : ConsentType.None);
16
+ data = consent;
12
17
  }
13
18
 
14
19
  // When we get consent signal as false, we restart the service and track config as false.
@@ -19,3 +24,16 @@ export function consent(): void {
19
24
  function trackConsent(consent: ConsentType): void {
20
25
  dimension.log(Dimension.Consent, consent.toString());
21
26
  }
27
+
28
+ export function consentv2(consent: ConsentData): void {
29
+ data = consent;
30
+ encode(Event.Consent);
31
+ }
32
+
33
+ // Compute function is called every upload, but we only want to send consent data once.
34
+ export function compute(): void {
35
+ if (updateConsent) {
36
+ encode(Event.Consent);
37
+ updateConsent = false;
38
+ }
39
+ }
@@ -1,4 +1,4 @@
1
- import { type CustomData, Event } from "@clarity-types/data";
1
+ import { Constant, CustomData, Event } from "@clarity-types/data";
2
2
  import * as core from "@src/core";
3
3
  import encode from "./encode";
4
4
 
@@ -7,12 +7,17 @@ export let data: CustomData = null;
7
7
  // custom events allow 2 parameters or 1 parameter to be passed. If 2 are passed we
8
8
  // consider it a key value pair. If only 1 is passed we only consider the event to have a value.
9
9
  export function event(a: string, b: string): void {
10
- if (core.active() && a && typeof a === "string" && a.length < 255) {
11
- if (b && typeof b === "string" && b.length < 255) {
12
- data = { key: a, value: b };
13
- } else {
14
- data = { value: a };
15
- }
16
- encode(Event.Custom);
10
+ if (core.active() &&
11
+ a &&
12
+ typeof a === Constant.String &&
13
+ a.length < 255
14
+ ) {
15
+ if (b && typeof b === Constant.String && b.length < 255) {
16
+ data = { key: a, value: b};
17
+ } else {
18
+ data = { value: a }
19
+ }
20
+ encode(Event.Custom);
21
+
17
22
  }
18
23
  }
@@ -1,4 +1,4 @@
1
- import { Check, type Dimension, type DimensionData, Event, Setting } from "@clarity-types/data";
1
+ import { Check, Event, Dimension, DimensionData, Setting } from "@clarity-types/data";
2
2
  import * as limit from "@src/data/limit";
3
3
  import encode from "./encode";
4
4
 
@@ -18,20 +18,18 @@ export function stop(): void {
18
18
  limited = false;
19
19
  }
20
20
 
21
- export function log(dimension: Dimension, inputValue: string): void {
21
+ export function log(dimension: Dimension, value: string): void {
22
22
  // Check valid value before moving ahead
23
- if (inputValue) {
23
+ if (value) {
24
24
  // Ensure received value is casted into a string if it wasn't a string to begin with
25
- const value = `${inputValue}`;
26
- if (!(dimension in data)) {
27
- data[dimension] = [];
28
- }
25
+ value = `${value}`;
26
+ if (!(dimension in data)) { data[dimension] = []; }
29
27
  if (data[dimension].indexOf(value) < 0) {
30
28
  // Limit check to ensure we have a cap on number of dimensions we can collect
31
29
  if (data[dimension].length > Setting.CollectionLimit) {
32
30
  if (!limited) {
33
31
  limited = true;
34
- limit.trigger(Check.Collection);
32
+ limit.trigger(Check.Collection);
35
33
  }
36
34
  return;
37
35
  }
@@ -39,9 +37,7 @@ export function log(dimension: Dimension, inputValue: string): void {
39
37
  data[dimension].push(value);
40
38
  // If this is a new value, track it as part of updates object
41
39
  // This allows us to only send back new values in subsequent payloads
42
- if (!(dimension in updates)) {
43
- updates[dimension] = [];
44
- }
40
+ if (!(dimension in updates)) { updates[dimension] = []; }
45
41
  updates[dimension].push(value);
46
42
  }
47
43
  }
@@ -1,23 +1,24 @@
1
- import { Event, type Token } from "@clarity-types/data";
1
+ import { Event, Token } from "@clarity-types/data";
2
2
  import { time } from "@src/core/time";
3
3
  import * as baseline from "@src/data/baseline";
4
+ import * as consent from "@src/data/consent";
4
5
  import * as custom from "@src/data/custom";
5
6
  import * as dimension from "@src/data/dimension";
6
- import * as extract from "@src/data/extract";
7
7
  import * as limit from "@src/data/limit";
8
8
  import * as metric from "@src/data/metric";
9
9
  import * as ping from "@src/data/ping";
10
10
  import * as summary from "@src/data/summary";
11
11
  import * as upgrade from "@src/data/upgrade";
12
12
  import * as variable from "@src/data/variable";
13
+ import * as extract from "@src/data/extract";
13
14
  import { queue, track } from "./upload";
14
15
 
15
- export default function (event: Event): void {
16
- const t = time();
17
- let tokens: Token[] = [t, event];
16
+ export default function(event: Event): void {
17
+ let t = time();
18
+ let tokens: Token[] = [t, event];
18
19
  switch (event) {
19
- case Event.Baseline: {
20
- const b = baseline.state;
20
+ case Event.Baseline:
21
+ let b = baseline.state;
21
22
  if (b) {
22
23
  tokens = [b.time, b.event];
23
24
  tokens.push(b.data.visible);
@@ -48,7 +49,6 @@ export default function (event: Event): void {
48
49
  }
49
50
  baseline.reset();
50
51
  break;
51
- }
52
52
  case Event.Ping:
53
53
  tokens.push(ping.data.gap);
54
54
  queue(tokens);
@@ -73,10 +73,10 @@ export default function (event: Event): void {
73
73
  tokens.push(custom.data.value);
74
74
  queue(tokens);
75
75
  break;
76
- case Event.Variable: {
77
- const variableKeys = Object.keys(variable.data);
76
+ case Event.Variable:
77
+ let variableKeys = Object.keys(variable.data);
78
78
  if (variableKeys.length > 0) {
79
- for (const v of variableKeys) {
79
+ for (let v of variableKeys) {
80
80
  tokens.push(v);
81
81
  tokens.push(variable.data[v]);
82
82
  }
@@ -84,12 +84,11 @@ export default function (event: Event): void {
84
84
  queue(tokens, false);
85
85
  }
86
86
  break;
87
- }
88
- case Event.Metric: {
89
- const metricKeys = Object.keys(metric.updates);
87
+ case Event.Metric:
88
+ let metricKeys = Object.keys(metric.updates);
90
89
  if (metricKeys.length > 0) {
91
- for (const m of metricKeys) {
92
- const key = Number.parseInt(m, 10);
90
+ for (let m of metricKeys) {
91
+ let key = parseInt(m, 10);
93
92
  tokens.push(key);
94
93
  // For computation, we need microseconds precision that performance.now() API offers
95
94
  // However, for data over the wire, we round it off to milliseconds precision.
@@ -99,12 +98,11 @@ export default function (event: Event): void {
99
98
  queue(tokens, false);
100
99
  }
101
100
  break;
102
- }
103
- case Event.Dimension: {
104
- const dimensionKeys = Object.keys(dimension.updates);
101
+ case Event.Dimension:
102
+ let dimensionKeys = Object.keys(dimension.updates);
105
103
  if (dimensionKeys.length > 0) {
106
- for (const d of dimensionKeys) {
107
- const key = Number.parseInt(d, 10);
104
+ for (let d of dimensionKeys) {
105
+ let key = parseInt(d, 10);
108
106
  tokens.push(key);
109
107
  tokens.push(dimension.updates[d]);
110
108
  }
@@ -112,12 +110,11 @@ export default function (event: Event): void {
112
110
  queue(tokens, false);
113
111
  }
114
112
  break;
115
- }
116
- case Event.Summary: {
117
- const eventKeys = Object.keys(summary.data);
113
+ case Event.Summary:
114
+ let eventKeys = Object.keys(summary.data);
118
115
  if (eventKeys.length > 0) {
119
- for (const e of eventKeys) {
120
- const key = Number.parseInt(e, 10);
116
+ for (let e of eventKeys) {
117
+ let key = parseInt(e, 10);
121
118
  tokens.push(key);
122
119
  tokens.push([].concat(...summary.data[e]));
123
120
  }
@@ -125,22 +122,27 @@ export default function (event: Event): void {
125
122
  queue(tokens, false);
126
123
  }
127
124
  break;
128
- }
129
- case Event.Extract: {
130
- const extractKeys = extract.keys;
131
- for (const e of Array.from(extractKeys)) {
125
+ case Event.Extract:
126
+ let extractKeys = extract.keys;
127
+ extractKeys.forEach((e => {
132
128
  tokens.push(e);
133
- const token = [];
134
- for (const d in extract.data[e]) {
135
- const key = Number.parseInt(d, 10);
129
+ let token = []
130
+ for (let d in extract.data[e]) {
131
+ let key = parseInt(d, 10);
136
132
  token.push(key);
137
133
  token.push(extract.data[e][d]);
138
134
  }
139
135
  tokens.push(token);
140
- }
141
-
136
+ }));
137
+
142
138
  extract.reset();
143
139
  queue(tokens, false);
144
- }
140
+
141
+ case Event.Consent:
142
+ tokens.push(consent.data.source);
143
+ tokens.push(consent.data.ad_Storage);
144
+ tokens.push(consent.data.analytics_Storage);
145
+ queue(tokens);
146
+ break;
145
147
  }
146
148
  }
@@ -1,27 +1,27 @@
1
- import { ApplicationPlatform, BooleanFlag, type Envelope, type Token, Upload } from "@clarity-types/data";
2
- import * as scrub from "@src/core/scrub";
1
+ import { BooleanFlag, Token, Upload, Envelope, ApplicationPlatform } from "@clarity-types/data";
3
2
  import { time } from "@src/core/time";
4
3
  import version from "@src/core/version";
5
4
  import * as metadata from "@src/data/metadata";
5
+ import * as scrub from "@src/core/scrub";
6
6
 
7
7
  export let data: Envelope = null;
8
8
 
9
9
  export function start(): void {
10
- const m = metadata.data;
11
- data = {
12
- version,
13
- sequence: 0,
14
- start: 0,
15
- duration: 0,
16
- projectId: m.projectId,
17
- userId: m.userId,
18
- sessionId: m.sessionId,
19
- pageNum: m.pageNum,
20
- upload: Upload.Async,
21
- end: BooleanFlag.False,
22
- applicationPlatform: ApplicationPlatform.WebApp,
23
- url: "",
24
- };
10
+ const m = metadata.data;
11
+ data = {
12
+ version,
13
+ sequence: 0,
14
+ start: 0,
15
+ duration: 0,
16
+ projectId: m.projectId,
17
+ userId: m.userId,
18
+ sessionId: m.sessionId,
19
+ pageNum: m.pageNum,
20
+ upload: Upload.Async,
21
+ end: BooleanFlag.False,
22
+ applicationPlatform: ApplicationPlatform.WebApp,
23
+ url: ''
24
+ };
25
25
  }
26
26
 
27
27
  export function stop(): void {
@@ -29,25 +29,25 @@ export function stop(): void {
29
29
  }
30
30
 
31
31
  export function envelope(last: boolean): Token[] {
32
- data.start = data.start + data.duration;
33
- data.duration = time() - data.start;
34
- data.sequence++;
35
- data.upload = last && "sendBeacon" in navigator ? Upload.Beacon : Upload.Async;
36
- data.end = last ? BooleanFlag.True : BooleanFlag.False;
37
- data.applicationPlatform = ApplicationPlatform.WebApp;
38
- data.url = scrub.url(location.href, false, true);
39
- return [
40
- data.version,
41
- data.sequence,
42
- data.start,
43
- data.duration,
44
- data.projectId,
45
- data.userId,
46
- data.sessionId,
47
- data.pageNum,
48
- data.upload,
49
- data.end,
50
- data.applicationPlatform,
51
- data.url,
52
- ];
32
+ data.start = data.start + data.duration;
33
+ data.duration = time() - data.start;
34
+ data.sequence++;
35
+ data.upload = last && "sendBeacon" in navigator ? Upload.Beacon : Upload.Async;
36
+ data.end = last ? BooleanFlag.True : BooleanFlag.False;
37
+ data.applicationPlatform = ApplicationPlatform.WebApp;
38
+ data.url = scrub.url(location.href, false, true);
39
+ return [
40
+ data.version,
41
+ data.sequence,
42
+ data.start,
43
+ data.duration,
44
+ data.projectId,
45
+ data.userId,
46
+ data.sessionId,
47
+ data.pageNum,
48
+ data.upload,
49
+ data.end,
50
+ data.applicationPlatform,
51
+ data.url
52
+ ];
53
53
  }