clarity-js 0.8.41 → 0.8.42

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 (113) hide show
  1. package/README.md +26 -26
  2. package/build/clarity.extended.js +1 -1
  3. package/build/clarity.insight.js +1 -1
  4. package/build/clarity.js +6027 -6027
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +6027 -6027
  7. package/build/clarity.performance.js +1 -1
  8. package/package.json +70 -70
  9. package/rollup.config.ts +161 -161
  10. package/src/clarity.ts +65 -65
  11. package/src/core/api.ts +8 -8
  12. package/src/core/config.ts +29 -29
  13. package/src/core/copy.ts +3 -3
  14. package/src/core/event.ts +53 -53
  15. package/src/core/hash.ts +19 -19
  16. package/src/core/history.ts +71 -71
  17. package/src/core/index.ts +81 -81
  18. package/src/core/measure.ts +19 -19
  19. package/src/core/report.ts +28 -28
  20. package/src/core/scrub.ts +202 -202
  21. package/src/core/task.ts +181 -181
  22. package/src/core/throttle.ts +46 -46
  23. package/src/core/time.ts +26 -26
  24. package/src/core/timeout.ts +10 -10
  25. package/src/core/version.ts +2 -2
  26. package/src/data/baseline.ts +162 -162
  27. package/src/data/compress.ts +31 -31
  28. package/src/data/consent.ts +77 -77
  29. package/src/data/custom.ts +23 -23
  30. package/src/data/dimension.ts +53 -53
  31. package/src/data/encode.ts +155 -155
  32. package/src/data/envelope.ts +53 -53
  33. package/src/data/extract.ts +211 -211
  34. package/src/data/index.ts +50 -50
  35. package/src/data/limit.ts +44 -44
  36. package/src/data/metadata.ts +408 -408
  37. package/src/data/metric.ts +51 -51
  38. package/src/data/ping.ts +36 -36
  39. package/src/data/signal.ts +30 -30
  40. package/src/data/summary.ts +34 -34
  41. package/src/data/token.ts +39 -39
  42. package/src/data/upgrade.ts +44 -44
  43. package/src/data/upload.ts +333 -333
  44. package/src/data/variable.ts +83 -83
  45. package/src/diagnostic/encode.ts +40 -40
  46. package/src/diagnostic/fraud.ts +36 -36
  47. package/src/diagnostic/index.ts +13 -13
  48. package/src/diagnostic/internal.ts +28 -28
  49. package/src/diagnostic/script.ts +35 -35
  50. package/src/dynamic/agent/blank.ts +2 -2
  51. package/src/dynamic/agent/crisp.ts +40 -40
  52. package/src/dynamic/agent/encode.ts +25 -25
  53. package/src/dynamic/agent/index.ts +8 -8
  54. package/src/dynamic/agent/livechat.ts +58 -58
  55. package/src/dynamic/agent/tidio.ts +44 -44
  56. package/src/global.ts +6 -6
  57. package/src/index.ts +9 -9
  58. package/src/insight/blank.ts +14 -14
  59. package/src/insight/encode.ts +60 -60
  60. package/src/insight/snapshot.ts +114 -114
  61. package/src/interaction/change.ts +38 -38
  62. package/src/interaction/click.ts +173 -173
  63. package/src/interaction/clipboard.ts +32 -32
  64. package/src/interaction/encode.ts +210 -210
  65. package/src/interaction/index.ts +60 -60
  66. package/src/interaction/input.ts +57 -57
  67. package/src/interaction/pointer.ts +137 -137
  68. package/src/interaction/resize.ts +50 -50
  69. package/src/interaction/scroll.ts +129 -129
  70. package/src/interaction/selection.ts +66 -66
  71. package/src/interaction/submit.ts +30 -30
  72. package/src/interaction/timeline.ts +69 -69
  73. package/src/interaction/unload.ts +26 -26
  74. package/src/interaction/visibility.ts +27 -27
  75. package/src/layout/animation.ts +133 -133
  76. package/src/layout/custom.ts +42 -42
  77. package/src/layout/discover.ts +31 -31
  78. package/src/layout/document.ts +46 -46
  79. package/src/layout/dom.ts +439 -439
  80. package/src/layout/encode.ts +154 -154
  81. package/src/layout/index.ts +42 -42
  82. package/src/layout/mutation.ts +411 -411
  83. package/src/layout/node.ts +294 -294
  84. package/src/layout/offset.ts +19 -19
  85. package/src/layout/region.ts +151 -151
  86. package/src/layout/schema.ts +63 -63
  87. package/src/layout/selector.ts +82 -82
  88. package/src/layout/style.ts +159 -159
  89. package/src/layout/target.ts +32 -32
  90. package/src/layout/traverse.ts +27 -27
  91. package/src/performance/blank.ts +9 -9
  92. package/src/performance/encode.ts +31 -31
  93. package/src/performance/index.ts +12 -12
  94. package/src/performance/interaction.ts +125 -125
  95. package/src/performance/navigation.ts +31 -31
  96. package/src/performance/observer.ts +112 -112
  97. package/src/queue.ts +33 -33
  98. package/test/core.test.ts +139 -139
  99. package/test/helper.ts +162 -162
  100. package/test/html/core.html +27 -27
  101. package/test/stub.test.ts +7 -7
  102. package/test/tsconfig.test.json +5 -5
  103. package/tsconfig.json +21 -21
  104. package/tslint.json +32 -32
  105. package/types/agent.d.ts +39 -39
  106. package/types/core.d.ts +150 -150
  107. package/types/data.d.ts +571 -571
  108. package/types/diagnostic.d.ts +24 -24
  109. package/types/global.d.ts +30 -30
  110. package/types/index.d.ts +40 -40
  111. package/types/interaction.d.ts +177 -177
  112. package/types/layout.d.ts +276 -276
  113. package/types/performance.d.ts +31 -31
@@ -1,53 +1,53 @@
1
- import { Check, Event, Dimension, DimensionData, Setting } from "@clarity-types/data";
2
- import * as limit from "@src/data/limit";
3
- import encode from "./encode";
4
-
5
- export let data: DimensionData = null;
6
- export let updates: DimensionData = null;
7
- let limited = false;
8
-
9
- export function start(): void {
10
- data = {};
11
- updates = {};
12
- limited = false;
13
- }
14
-
15
- export function stop(): void {
16
- data = {};
17
- updates = {};
18
- limited = false;
19
- }
20
-
21
- export function log(dimension: Dimension, value: string): void {
22
- // Check valid value before moving ahead
23
- if (value) {
24
- // Ensure received value is casted into a string if it wasn't a string to begin with
25
- value = `${value}`;
26
- if (!(dimension in data)) { data[dimension] = []; }
27
- if (data[dimension].indexOf(value) < 0) {
28
- // Limit check to ensure we have a cap on number of dimensions we can collect
29
- if (data[dimension].length > Setting.CollectionLimit) {
30
- if (!limited) {
31
- limited = true;
32
- limit.trigger(Check.Collection);
33
- }
34
- return;
35
- }
36
-
37
- data[dimension].push(value);
38
- // If this is a new value, track it as part of updates object
39
- // This allows us to only send back new values in subsequent payloads
40
- if (!(dimension in updates)) { updates[dimension] = []; }
41
- updates[dimension].push(value);
42
- }
43
- }
44
- }
45
-
46
- export function compute(): void {
47
- encode(Event.Dimension);
48
- }
49
-
50
- export function reset(): void {
51
- updates = {};
52
- limited = false;
53
- }
1
+ import { Check, Event, Dimension, DimensionData, Setting } from "@clarity-types/data";
2
+ import * as limit from "@src/data/limit";
3
+ import encode from "./encode";
4
+
5
+ export let data: DimensionData = null;
6
+ export let updates: DimensionData = null;
7
+ let limited = false;
8
+
9
+ export function start(): void {
10
+ data = {};
11
+ updates = {};
12
+ limited = false;
13
+ }
14
+
15
+ export function stop(): void {
16
+ data = {};
17
+ updates = {};
18
+ limited = false;
19
+ }
20
+
21
+ export function log(dimension: Dimension, value: string): void {
22
+ // Check valid value before moving ahead
23
+ if (value) {
24
+ // Ensure received value is casted into a string if it wasn't a string to begin with
25
+ value = `${value}`;
26
+ if (!(dimension in data)) { data[dimension] = []; }
27
+ if (data[dimension].indexOf(value) < 0) {
28
+ // Limit check to ensure we have a cap on number of dimensions we can collect
29
+ if (data[dimension].length > Setting.CollectionLimit) {
30
+ if (!limited) {
31
+ limited = true;
32
+ limit.trigger(Check.Collection);
33
+ }
34
+ return;
35
+ }
36
+
37
+ data[dimension].push(value);
38
+ // If this is a new value, track it as part of updates object
39
+ // This allows us to only send back new values in subsequent payloads
40
+ if (!(dimension in updates)) { updates[dimension] = []; }
41
+ updates[dimension].push(value);
42
+ }
43
+ }
44
+ }
45
+
46
+ export function compute(): void {
47
+ encode(Event.Dimension);
48
+ }
49
+
50
+ export function reset(): void {
51
+ updates = {};
52
+ limited = false;
53
+ }
@@ -1,155 +1,155 @@
1
- import { Event, Token } from "@clarity-types/data";
2
- import { time } from "@src/core/time";
3
- import * as baseline from "@src/data/baseline";
4
- import * as consent from "@src/data/consent";
5
- import * as custom from "@src/data/custom";
6
- import * as dimension from "@src/data/dimension";
7
- import * as limit from "@src/data/limit";
8
- import * as metric from "@src/data/metric";
9
- import * as ping from "@src/data/ping";
10
- import * as summary from "@src/data/summary";
11
- import * as upgrade from "@src/data/upgrade";
12
- import * as variable from "@src/data/variable";
13
- import * as extract from "@src/data/extract";
14
- import { queue, track } from "./upload";
15
-
16
- export default function(event: Event): void {
17
- const t = time();
18
- let tokens: Token[] = [t, event];
19
- switch (event) {
20
- case Event.Baseline: {
21
- const b = baseline.state;
22
- if (b && b.data) {
23
- tokens = [b.time, b.event];
24
- tokens.push(b.data.visible);
25
- tokens.push(b.data.docWidth);
26
- tokens.push(b.data.docHeight);
27
- tokens.push(b.data.screenWidth);
28
- tokens.push(b.data.screenHeight);
29
- tokens.push(b.data.scrollX);
30
- tokens.push(b.data.scrollY);
31
- tokens.push(b.data.pointerX);
32
- tokens.push(b.data.pointerY);
33
- tokens.push(b.data.activityTime);
34
- tokens.push(b.data.scrollTime);
35
- tokens.push(b.data.pointerTime);
36
- tokens.push(b.data.moveX);
37
- tokens.push(b.data.moveY);
38
- tokens.push(b.data.moveTime);
39
- tokens.push(b.data.downX);
40
- tokens.push(b.data.downY);
41
- tokens.push(b.data.downTime);
42
- tokens.push(b.data.upX);
43
- tokens.push(b.data.upY);
44
- tokens.push(b.data.upTime);
45
- tokens.push(b.data.pointerPrevX);
46
- tokens.push(b.data.pointerPrevY);
47
- tokens.push(b.data.pointerPrevTime);
48
- tokens.push(b.data.modules);
49
- queue(tokens, false);
50
- }
51
- baseline.reset();
52
- break;
53
- }
54
- case Event.Ping:
55
- tokens.push(ping.data.gap);
56
- queue(tokens);
57
- break;
58
- case Event.Limit:
59
- tokens.push(limit.data.check);
60
- queue(tokens, false);
61
- break;
62
- case Event.Upgrade:
63
- tokens.push(upgrade.data.key);
64
- queue(tokens);
65
- break;
66
- case Event.Upload:
67
- tokens.push(track.sequence);
68
- tokens.push(track.attempts);
69
- tokens.push(track.status);
70
- queue(tokens, false);
71
- break;
72
- case Event.Custom:
73
- // not all custom events have a key - if it wasn't passed server handles just value
74
- custom.data.key && tokens.push(custom.data.key);
75
- tokens.push(custom.data.value);
76
- queue(tokens);
77
- break;
78
- case Event.Variable: {
79
- const variableKeys = Object.keys(variable.data);
80
- if (variableKeys.length > 0) {
81
- for (const v of variableKeys) {
82
- tokens.push(v);
83
- tokens.push(variable.data[v]);
84
- }
85
- variable.reset();
86
- queue(tokens, false);
87
- }
88
- break;
89
- }
90
- case Event.Metric: {
91
- const metricKeys = Object.keys(metric.updates);
92
- if (metricKeys.length > 0) {
93
- for (const m of metricKeys) {
94
- const key = parseInt(m, 10);
95
- tokens.push(key);
96
- // For computation, we need microseconds precision that performance.now() API offers
97
- // However, for data over the wire, we round it off to milliseconds precision.
98
- tokens.push(Math.round(metric.updates[m]));
99
- }
100
- metric.reset();
101
- queue(tokens, false);
102
- }
103
- break;
104
- }
105
- case Event.Dimension: {
106
- const dimensionKeys = Object.keys(dimension.updates);
107
- if (dimensionKeys.length > 0) {
108
- for (const d of dimensionKeys) {
109
- const key = parseInt(d, 10);
110
- tokens.push(key);
111
- tokens.push(dimension.updates[d]);
112
- }
113
- dimension.reset();
114
- queue(tokens, false);
115
- }
116
- break;
117
- }
118
- case Event.Summary: {
119
- const eventKeys = Object.keys(summary.data);
120
- if (eventKeys.length > 0) {
121
- for (const e of eventKeys) {
122
- const key = parseInt(e, 10);
123
- tokens.push(key);
124
- tokens.push([].concat(...summary.data[e]));
125
- }
126
- summary.reset();
127
- queue(tokens, false);
128
- }
129
- break;
130
- }
131
- case Event.Extract: {
132
- const extractKeys = extract.keys;
133
- extractKeys.forEach(e => {
134
- tokens.push(e);
135
- const token = []
136
- for (const d in extract.data[e]) {
137
- const key = parseInt(d, 10);
138
- token.push(key);
139
- token.push(extract.data[e][d]);
140
- }
141
- tokens.push(token);
142
- });
143
-
144
- extract.reset();
145
- queue(tokens, false);
146
- break;
147
- }
148
- case Event.Consent:
149
- tokens.push(consent.data.source);
150
- tokens.push(consent.data.ad_Storage);
151
- tokens.push(consent.data.analytics_Storage);
152
- queue(tokens, false);
153
- break;
154
- }
155
- }
1
+ import { Event, Token } from "@clarity-types/data";
2
+ import { time } from "@src/core/time";
3
+ import * as baseline from "@src/data/baseline";
4
+ import * as consent from "@src/data/consent";
5
+ import * as custom from "@src/data/custom";
6
+ import * as dimension from "@src/data/dimension";
7
+ import * as limit from "@src/data/limit";
8
+ import * as metric from "@src/data/metric";
9
+ import * as ping from "@src/data/ping";
10
+ import * as summary from "@src/data/summary";
11
+ import * as upgrade from "@src/data/upgrade";
12
+ import * as variable from "@src/data/variable";
13
+ import * as extract from "@src/data/extract";
14
+ import { queue, track } from "./upload";
15
+
16
+ export default function(event: Event): void {
17
+ const t = time();
18
+ let tokens: Token[] = [t, event];
19
+ switch (event) {
20
+ case Event.Baseline: {
21
+ const b = baseline.state;
22
+ if (b && b.data) {
23
+ tokens = [b.time, b.event];
24
+ tokens.push(b.data.visible);
25
+ tokens.push(b.data.docWidth);
26
+ tokens.push(b.data.docHeight);
27
+ tokens.push(b.data.screenWidth);
28
+ tokens.push(b.data.screenHeight);
29
+ tokens.push(b.data.scrollX);
30
+ tokens.push(b.data.scrollY);
31
+ tokens.push(b.data.pointerX);
32
+ tokens.push(b.data.pointerY);
33
+ tokens.push(b.data.activityTime);
34
+ tokens.push(b.data.scrollTime);
35
+ tokens.push(b.data.pointerTime);
36
+ tokens.push(b.data.moveX);
37
+ tokens.push(b.data.moveY);
38
+ tokens.push(b.data.moveTime);
39
+ tokens.push(b.data.downX);
40
+ tokens.push(b.data.downY);
41
+ tokens.push(b.data.downTime);
42
+ tokens.push(b.data.upX);
43
+ tokens.push(b.data.upY);
44
+ tokens.push(b.data.upTime);
45
+ tokens.push(b.data.pointerPrevX);
46
+ tokens.push(b.data.pointerPrevY);
47
+ tokens.push(b.data.pointerPrevTime);
48
+ tokens.push(b.data.modules);
49
+ queue(tokens, false);
50
+ }
51
+ baseline.reset();
52
+ break;
53
+ }
54
+ case Event.Ping:
55
+ tokens.push(ping.data.gap);
56
+ queue(tokens);
57
+ break;
58
+ case Event.Limit:
59
+ tokens.push(limit.data.check);
60
+ queue(tokens, false);
61
+ break;
62
+ case Event.Upgrade:
63
+ tokens.push(upgrade.data.key);
64
+ queue(tokens);
65
+ break;
66
+ case Event.Upload:
67
+ tokens.push(track.sequence);
68
+ tokens.push(track.attempts);
69
+ tokens.push(track.status);
70
+ queue(tokens, false);
71
+ break;
72
+ case Event.Custom:
73
+ // not all custom events have a key - if it wasn't passed server handles just value
74
+ custom.data.key && tokens.push(custom.data.key);
75
+ tokens.push(custom.data.value);
76
+ queue(tokens);
77
+ break;
78
+ case Event.Variable: {
79
+ const variableKeys = Object.keys(variable.data);
80
+ if (variableKeys.length > 0) {
81
+ for (const v of variableKeys) {
82
+ tokens.push(v);
83
+ tokens.push(variable.data[v]);
84
+ }
85
+ variable.reset();
86
+ queue(tokens, false);
87
+ }
88
+ break;
89
+ }
90
+ case Event.Metric: {
91
+ const metricKeys = Object.keys(metric.updates);
92
+ if (metricKeys.length > 0) {
93
+ for (const m of metricKeys) {
94
+ const key = parseInt(m, 10);
95
+ tokens.push(key);
96
+ // For computation, we need microseconds precision that performance.now() API offers
97
+ // However, for data over the wire, we round it off to milliseconds precision.
98
+ tokens.push(Math.round(metric.updates[m]));
99
+ }
100
+ metric.reset();
101
+ queue(tokens, false);
102
+ }
103
+ break;
104
+ }
105
+ case Event.Dimension: {
106
+ const dimensionKeys = Object.keys(dimension.updates);
107
+ if (dimensionKeys.length > 0) {
108
+ for (const d of dimensionKeys) {
109
+ const key = parseInt(d, 10);
110
+ tokens.push(key);
111
+ tokens.push(dimension.updates[d]);
112
+ }
113
+ dimension.reset();
114
+ queue(tokens, false);
115
+ }
116
+ break;
117
+ }
118
+ case Event.Summary: {
119
+ const eventKeys = Object.keys(summary.data);
120
+ if (eventKeys.length > 0) {
121
+ for (const e of eventKeys) {
122
+ const key = parseInt(e, 10);
123
+ tokens.push(key);
124
+ tokens.push([].concat(...summary.data[e]));
125
+ }
126
+ summary.reset();
127
+ queue(tokens, false);
128
+ }
129
+ break;
130
+ }
131
+ case Event.Extract: {
132
+ const extractKeys = extract.keys;
133
+ extractKeys.forEach(e => {
134
+ tokens.push(e);
135
+ const token = []
136
+ for (const d in extract.data[e]) {
137
+ const key = parseInt(d, 10);
138
+ token.push(key);
139
+ token.push(extract.data[e][d]);
140
+ }
141
+ tokens.push(token);
142
+ });
143
+
144
+ extract.reset();
145
+ queue(tokens, false);
146
+ break;
147
+ }
148
+ case Event.Consent:
149
+ tokens.push(consent.data.source);
150
+ tokens.push(consent.data.ad_Storage);
151
+ tokens.push(consent.data.analytics_Storage);
152
+ queue(tokens, false);
153
+ break;
154
+ }
155
+ }
@@ -1,53 +1,53 @@
1
- import { BooleanFlag, Token, Upload, Envelope, ApplicationPlatform } from "@clarity-types/data";
2
- import { time } from "@src/core/time";
3
- import version from "@src/core/version";
4
- import * as metadata from "@src/data/metadata";
5
- import * as scrub from "@src/core/scrub";
6
-
7
- export let data: Envelope = null;
8
-
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
- };
25
- }
26
-
27
- export function stop(): void {
28
- data = null;
29
- }
30
-
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
- ];
53
- }
1
+ import { BooleanFlag, Token, Upload, Envelope, ApplicationPlatform } from "@clarity-types/data";
2
+ import { time } from "@src/core/time";
3
+ import version from "@src/core/version";
4
+ import * as metadata from "@src/data/metadata";
5
+ import * as scrub from "@src/core/scrub";
6
+
7
+ export let data: Envelope = null;
8
+
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
+ };
25
+ }
26
+
27
+ export function stop(): void {
28
+ data = null;
29
+ }
30
+
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
+ ];
53
+ }