clarity-js 0.8.40 → 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,51 +1,51 @@
1
- import { Event, Metric, MetricData } from "@clarity-types/data";
2
- import encode from "./encode";
3
-
4
- export let data: MetricData = null;
5
- export let updates: MetricData = null;
6
-
7
- export function start(): void {
8
- data = {};
9
- updates = {};
10
- count(Metric.InvokeCount);
11
- }
12
-
13
- export function stop(): void {
14
- data = {};
15
- updates = {};
16
- }
17
-
18
- export function count(metric: Metric): void {
19
- if (!(metric in data)) { data[metric] = 0; }
20
- if (!(metric in updates)) { updates[metric] = 0; }
21
- data[metric]++;
22
- updates[metric]++;
23
- }
24
-
25
- export function sum(metric: Metric, value: number): void {
26
- if (value !== null) {
27
- if (!(metric in data)) { data[metric] = 0; }
28
- if (!(metric in updates)) { updates[metric] = 0; }
29
- data[metric] += value;
30
- updates[metric] += value;
31
- }
32
- }
33
-
34
- export function max(metric: Metric, value: number): void {
35
- // Ensure that we do not process null or NaN values
36
- if (value !== null && isNaN(value) === false) {
37
- if (!(metric in data)) { data[metric] = 0; }
38
- if (value > data[metric] || data[metric] === 0) {
39
- updates[metric] = value;
40
- data[metric] = value;
41
- }
42
- }
43
- }
44
-
45
- export function compute(): void {
46
- encode(Event.Metric);
47
- }
48
-
49
- export function reset(): void {
50
- updates = {};
51
- }
1
+ import { Event, Metric, MetricData } from "@clarity-types/data";
2
+ import encode from "./encode";
3
+
4
+ export let data: MetricData = null;
5
+ export let updates: MetricData = null;
6
+
7
+ export function start(): void {
8
+ data = {};
9
+ updates = {};
10
+ count(Metric.InvokeCount);
11
+ }
12
+
13
+ export function stop(): void {
14
+ data = {};
15
+ updates = {};
16
+ }
17
+
18
+ export function count(metric: Metric): void {
19
+ if (!(metric in data)) { data[metric] = 0; }
20
+ if (!(metric in updates)) { updates[metric] = 0; }
21
+ data[metric]++;
22
+ updates[metric]++;
23
+ }
24
+
25
+ export function sum(metric: Metric, value: number): void {
26
+ if (value !== null) {
27
+ if (!(metric in data)) { data[metric] = 0; }
28
+ if (!(metric in updates)) { updates[metric] = 0; }
29
+ data[metric] += value;
30
+ updates[metric] += value;
31
+ }
32
+ }
33
+
34
+ export function max(metric: Metric, value: number): void {
35
+ // Ensure that we do not process null or NaN values
36
+ if (value !== null && isNaN(value) === false) {
37
+ if (!(metric in data)) { data[metric] = 0; }
38
+ if (value > data[metric] || data[metric] === 0) {
39
+ updates[metric] = value;
40
+ data[metric] = value;
41
+ }
42
+ }
43
+ }
44
+
45
+ export function compute(): void {
46
+ encode(Event.Metric);
47
+ }
48
+
49
+ export function reset(): void {
50
+ updates = {};
51
+ }
package/src/data/ping.ts CHANGED
@@ -1,36 +1,36 @@
1
- import { Event, PingData, Setting } from "@clarity-types/data";
2
- import { suspend } from "@src/core";
3
- import { time } from "@src/core/time";
4
- import { clearTimeout, setTimeout } from "@src/core/timeout";
5
- import encode from "./encode";
6
-
7
- export let data: PingData;
8
- let last = 0;
9
- let interval = 0;
10
- let timeout: number = null;
11
-
12
- export function start(): void {
13
- interval = Setting.PingInterval;
14
- last = 0;
15
- }
16
-
17
- export function reset(): void {
18
- if (timeout) { clearTimeout(timeout); }
19
- timeout = setTimeout(ping, interval);
20
- last = time();
21
- }
22
-
23
- function ping(): void {
24
- let now = time();
25
- data = { gap: now - last };
26
- encode(Event.Ping);
27
- if (data.gap < Setting.PingTimeout) {
28
- timeout = setTimeout(ping, interval);
29
- } else { suspend(); }
30
- }
31
-
32
- export function stop(): void {
33
- clearTimeout(timeout);
34
- last = 0;
35
- interval = 0;
36
- }
1
+ import { Event, PingData, Setting } from "@clarity-types/data";
2
+ import { suspend } from "@src/core";
3
+ import { time } from "@src/core/time";
4
+ import { clearTimeout, setTimeout } from "@src/core/timeout";
5
+ import encode from "./encode";
6
+
7
+ export let data: PingData;
8
+ let last = 0;
9
+ let interval = 0;
10
+ let timeout: number = null;
11
+
12
+ export function start(): void {
13
+ interval = Setting.PingInterval;
14
+ last = 0;
15
+ }
16
+
17
+ export function reset(): void {
18
+ if (timeout) { clearTimeout(timeout); }
19
+ timeout = setTimeout(ping, interval);
20
+ last = time();
21
+ }
22
+
23
+ function ping(): void {
24
+ let now = time();
25
+ data = { gap: now - last };
26
+ encode(Event.Ping);
27
+ if (data.gap < Setting.PingTimeout) {
28
+ timeout = setTimeout(ping, interval);
29
+ } else { suspend(); }
30
+ }
31
+
32
+ export function stop(): void {
33
+ clearTimeout(timeout);
34
+ last = 0;
35
+ interval = 0;
36
+ }
@@ -1,30 +1,30 @@
1
- import { ClaritySignal, SignalCallback } from '@clarity-types/data';
2
-
3
- export let signalCallback: SignalCallback = null;
4
-
5
- export function signal(cb: SignalCallback): void {
6
- signalCallback = cb;
7
- }
8
-
9
- function parseSignals(signalsPayload: string): ClaritySignal[] {
10
- try{
11
- const parsedSignals: ClaritySignal[] = JSON.parse(signalsPayload);
12
- return parsedSignals;
13
- }catch{
14
- return []
15
- }
16
- }
17
-
18
- export function signalsEvent(signalsPayload: string) {
19
- try {
20
- if (!signalCallback) {
21
- return;
22
- }
23
- const signals = parseSignals(signalsPayload);
24
- signals.forEach((signal) => {
25
- signalCallback(signal);
26
- });
27
- } catch {
28
- //do nothing
29
- }
30
- }
1
+ import { ClaritySignal, SignalCallback } from '@clarity-types/data';
2
+
3
+ export let signalCallback: SignalCallback = null;
4
+
5
+ export function signal(cb: SignalCallback): void {
6
+ signalCallback = cb;
7
+ }
8
+
9
+ function parseSignals(signalsPayload: string): ClaritySignal[] {
10
+ try{
11
+ const parsedSignals: ClaritySignal[] = JSON.parse(signalsPayload);
12
+ return parsedSignals;
13
+ }catch{
14
+ return []
15
+ }
16
+ }
17
+
18
+ export function signalsEvent(signalsPayload: string) {
19
+ try {
20
+ if (!signalCallback) {
21
+ return;
22
+ }
23
+ const signals = parseSignals(signalsPayload);
24
+ signals.forEach((signal) => {
25
+ signalCallback(signal);
26
+ });
27
+ } catch {
28
+ //do nothing
29
+ }
30
+ }
@@ -1,34 +1,34 @@
1
- import { Event, SummaryData, Setting } from "@clarity-types/data";
2
- import encode from "./encode";
3
-
4
- export let data: SummaryData = null;
5
-
6
- export function start(): void {
7
- data = {};
8
- }
9
-
10
- export function stop(): void {
11
- data = {};
12
- }
13
-
14
- export function track(event: Event, time: number): void {
15
- if (!(event in data)) {
16
- data[event] = [[time, 0]];
17
- } else {
18
- let e = data[event];
19
- let last = e[e.length - 1];
20
- // Add a new entry only if the new event occurs after configured interval
21
- // Otherwise, extend the duration of the previous entry
22
- if (time - last[0] > Setting.SummaryInterval) {
23
- data[event].push([time, 0]);
24
- } else { last[1] = time - last[0]; }
25
- }
26
- }
27
-
28
- export function compute(): void {
29
- encode(Event.Summary);
30
- }
31
-
32
- export function reset(): void {
33
- data = {};
34
- }
1
+ import { Event, SummaryData, Setting } from "@clarity-types/data";
2
+ import encode from "./encode";
3
+
4
+ export let data: SummaryData = null;
5
+
6
+ export function start(): void {
7
+ data = {};
8
+ }
9
+
10
+ export function stop(): void {
11
+ data = {};
12
+ }
13
+
14
+ export function track(event: Event, time: number): void {
15
+ if (!(event in data)) {
16
+ data[event] = [[time, 0]];
17
+ } else {
18
+ let e = data[event];
19
+ let last = e[e.length - 1];
20
+ // Add a new entry only if the new event occurs after configured interval
21
+ // Otherwise, extend the duration of the previous entry
22
+ if (time - last[0] > Setting.SummaryInterval) {
23
+ data[event].push([time, 0]);
24
+ } else { last[1] = time - last[0]; }
25
+ }
26
+ }
27
+
28
+ export function compute(): void {
29
+ encode(Event.Summary);
30
+ }
31
+
32
+ export function reset(): void {
33
+ data = {};
34
+ }
package/src/data/token.ts CHANGED
@@ -1,39 +1,39 @@
1
- import {Constant, Token} from "@clarity-types/data";
2
-
3
- // Following code takes an array of tokens and transforms it to optimize for repeating tokens and make it efficient to send over the wire
4
- // The way it works is that it iterate over all tokens and checks if the current token was already seen in the tokens array so far
5
- // If so, it replaces the token with its reference (index). This helps us save bytes by not repeating the same value twice.
6
- // E.g. If tokens array is: ["hello", "world", "coding", "language", "world", "language", "example"]
7
- // Then the resulting tokens array after following code execution would be: ["hello", "world", "coding", "language", [1, 3], "example"]
8
- // Where [1,3] points to tokens[1] => "world" and tokens[3] => "language"
9
- export default function(tokens: Token[]): Token[] {
10
- let output: Token[] = [];
11
- let lookup: {[key: string]: number} = {};
12
- let pointer = 0;
13
- let reference = null;
14
- for (let i = 0; i < tokens.length; i++) {
15
- // Only optimize for string values
16
- if (typeof tokens[i] === Constant.String) {
17
- let token = tokens[i] as string;
18
- let index = lookup[token] || -1;
19
- if (index >= 0) {
20
- if (reference) { reference.push(index); } else {
21
- reference = [index];
22
- output.push(reference);
23
- pointer++;
24
- }
25
- } else {
26
- reference = null;
27
- output.push(token);
28
- lookup[token] = pointer++;
29
- }
30
- } else {
31
- // If the value is anything other than string, append it as it is to the output array
32
- // And, also increment the pointer to stay in sync with output array
33
- reference = null;
34
- output.push(tokens[i]);
35
- pointer++;
36
- }
37
- }
38
- return output;
39
- }
1
+ import {Constant, Token} from "@clarity-types/data";
2
+
3
+ // Following code takes an array of tokens and transforms it to optimize for repeating tokens and make it efficient to send over the wire
4
+ // The way it works is that it iterate over all tokens and checks if the current token was already seen in the tokens array so far
5
+ // If so, it replaces the token with its reference (index). This helps us save bytes by not repeating the same value twice.
6
+ // E.g. If tokens array is: ["hello", "world", "coding", "language", "world", "language", "example"]
7
+ // Then the resulting tokens array after following code execution would be: ["hello", "world", "coding", "language", [1, 3], "example"]
8
+ // Where [1,3] points to tokens[1] => "world" and tokens[3] => "language"
9
+ export default function(tokens: Token[]): Token[] {
10
+ let output: Token[] = [];
11
+ let lookup: {[key: string]: number} = {};
12
+ let pointer = 0;
13
+ let reference = null;
14
+ for (let i = 0; i < tokens.length; i++) {
15
+ // Only optimize for string values
16
+ if (typeof tokens[i] === Constant.String) {
17
+ let token = tokens[i] as string;
18
+ let index = lookup[token] || -1;
19
+ if (index >= 0) {
20
+ if (reference) { reference.push(index); } else {
21
+ reference = [index];
22
+ output.push(reference);
23
+ pointer++;
24
+ }
25
+ } else {
26
+ reference = null;
27
+ output.push(token);
28
+ lookup[token] = pointer++;
29
+ }
30
+ } else {
31
+ // If the value is anything other than string, append it as it is to the output array
32
+ // And, also increment the pointer to stay in sync with output array
33
+ reference = null;
34
+ output.push(tokens[i]);
35
+ pointer++;
36
+ }
37
+ }
38
+ return output;
39
+ }
@@ -1,44 +1,44 @@
1
- import { Constant, Event, UpgradeData } from "@clarity-types/data";
2
- import * as core from "@src/core";
3
- import config from "@src/core/config";
4
- import encode from "@src/data/encode";
5
- import * as metadata from "@src/data/metadata";
6
- import * as discover from "@src/layout/discover";
7
- import * as style from "@src/layout/style";
8
-
9
- export let data: UpgradeData = null;
10
-
11
- export function start(): void {
12
- if (!config.lean && config.upgrade) { config.upgrade(Constant.Config); }
13
- data = null;
14
- }
15
-
16
- // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
17
- // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
18
- // However, if there's a need for full fidelity playback, calling this function will disable lean mode
19
- // and send all backed up layout events to the server.
20
- export function upgrade(key: string): void {
21
- // Upgrade only if Clarity was successfully activated on the page
22
- if (core.active() && config.lean) {
23
- config.lean = false;
24
- data = { key };
25
-
26
- // Update metadata to track we have upgraded this session
27
- metadata.callback();
28
- metadata.save();
29
-
30
- // Callback upgrade handler, if configured
31
- if (config.upgrade) { config.upgrade(key); }
32
-
33
- encode(Event.Upgrade);
34
-
35
- if (config.lite) {
36
- discover.start();
37
- style.start();
38
- }
39
- }
40
- }
41
-
42
- export function stop(): void {
43
- data = null;
44
- }
1
+ import { Constant, Event, UpgradeData } from "@clarity-types/data";
2
+ import * as core from "@src/core";
3
+ import config from "@src/core/config";
4
+ import encode from "@src/data/encode";
5
+ import * as metadata from "@src/data/metadata";
6
+ import * as discover from "@src/layout/discover";
7
+ import * as style from "@src/layout/style";
8
+
9
+ export let data: UpgradeData = null;
10
+
11
+ export function start(): void {
12
+ if (!config.lean && config.upgrade) { config.upgrade(Constant.Config); }
13
+ data = null;
14
+ }
15
+
16
+ // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
17
+ // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
18
+ // However, if there's a need for full fidelity playback, calling this function will disable lean mode
19
+ // and send all backed up layout events to the server.
20
+ export function upgrade(key: string): void {
21
+ // Upgrade only if Clarity was successfully activated on the page
22
+ if (core.active() && config.lean) {
23
+ config.lean = false;
24
+ data = { key };
25
+
26
+ // Update metadata to track we have upgraded this session
27
+ metadata.callback();
28
+ metadata.save();
29
+
30
+ // Callback upgrade handler, if configured
31
+ if (config.upgrade) { config.upgrade(key); }
32
+
33
+ encode(Event.Upgrade);
34
+
35
+ if (config.lite) {
36
+ discover.start();
37
+ style.start();
38
+ }
39
+ }
40
+ }
41
+
42
+ export function stop(): void {
43
+ data = null;
44
+ }