clarity-js 0.8.42 → 0.8.43

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 (114) 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 +6043 -6030
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +6043 -6030
  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/dynamic.ts +13 -7
  15. package/src/core/event.ts +53 -53
  16. package/src/core/hash.ts +19 -19
  17. package/src/core/history.ts +71 -71
  18. package/src/core/index.ts +81 -81
  19. package/src/core/measure.ts +19 -19
  20. package/src/core/report.ts +28 -28
  21. package/src/core/scrub.ts +204 -202
  22. package/src/core/task.ts +181 -181
  23. package/src/core/throttle.ts +46 -46
  24. package/src/core/time.ts +26 -26
  25. package/src/core/timeout.ts +10 -10
  26. package/src/core/version.ts +2 -2
  27. package/src/data/baseline.ts +162 -162
  28. package/src/data/compress.ts +31 -31
  29. package/src/data/consent.ts +77 -77
  30. package/src/data/custom.ts +23 -23
  31. package/src/data/dimension.ts +53 -53
  32. package/src/data/encode.ts +155 -155
  33. package/src/data/envelope.ts +53 -53
  34. package/src/data/extract.ts +211 -211
  35. package/src/data/index.ts +50 -50
  36. package/src/data/limit.ts +44 -44
  37. package/src/data/metadata.ts +411 -408
  38. package/src/data/metric.ts +51 -51
  39. package/src/data/ping.ts +36 -36
  40. package/src/data/signal.ts +30 -30
  41. package/src/data/summary.ts +34 -34
  42. package/src/data/token.ts +39 -39
  43. package/src/data/upgrade.ts +44 -44
  44. package/src/data/upload.ts +333 -333
  45. package/src/data/variable.ts +83 -83
  46. package/src/diagnostic/encode.ts +40 -40
  47. package/src/diagnostic/fraud.ts +36 -36
  48. package/src/diagnostic/index.ts +13 -13
  49. package/src/diagnostic/internal.ts +28 -28
  50. package/src/diagnostic/script.ts +35 -35
  51. package/src/dynamic/agent/blank.ts +2 -2
  52. package/src/dynamic/agent/crisp.ts +40 -40
  53. package/src/dynamic/agent/encode.ts +25 -25
  54. package/src/dynamic/agent/index.ts +8 -8
  55. package/src/dynamic/agent/livechat.ts +58 -58
  56. package/src/dynamic/agent/tidio.ts +44 -44
  57. package/src/global.ts +6 -6
  58. package/src/index.ts +9 -9
  59. package/src/insight/blank.ts +14 -14
  60. package/src/insight/encode.ts +60 -60
  61. package/src/insight/snapshot.ts +114 -114
  62. package/src/interaction/change.ts +38 -38
  63. package/src/interaction/click.ts +173 -173
  64. package/src/interaction/clipboard.ts +32 -32
  65. package/src/interaction/encode.ts +210 -210
  66. package/src/interaction/index.ts +60 -60
  67. package/src/interaction/input.ts +57 -57
  68. package/src/interaction/pointer.ts +137 -137
  69. package/src/interaction/resize.ts +50 -50
  70. package/src/interaction/scroll.ts +129 -129
  71. package/src/interaction/selection.ts +66 -66
  72. package/src/interaction/submit.ts +30 -30
  73. package/src/interaction/timeline.ts +69 -69
  74. package/src/interaction/unload.ts +26 -26
  75. package/src/interaction/visibility.ts +27 -27
  76. package/src/layout/animation.ts +133 -133
  77. package/src/layout/custom.ts +42 -42
  78. package/src/layout/discover.ts +31 -31
  79. package/src/layout/document.ts +46 -46
  80. package/src/layout/dom.ts +439 -439
  81. package/src/layout/encode.ts +154 -154
  82. package/src/layout/index.ts +42 -42
  83. package/src/layout/mutation.ts +411 -411
  84. package/src/layout/node.ts +294 -294
  85. package/src/layout/offset.ts +19 -19
  86. package/src/layout/region.ts +151 -151
  87. package/src/layout/schema.ts +63 -63
  88. package/src/layout/selector.ts +82 -82
  89. package/src/layout/style.ts +159 -159
  90. package/src/layout/target.ts +32 -32
  91. package/src/layout/traverse.ts +27 -27
  92. package/src/performance/blank.ts +9 -9
  93. package/src/performance/encode.ts +31 -31
  94. package/src/performance/index.ts +12 -12
  95. package/src/performance/interaction.ts +125 -125
  96. package/src/performance/navigation.ts +31 -31
  97. package/src/performance/observer.ts +112 -112
  98. package/src/queue.ts +33 -33
  99. package/test/core.test.ts +139 -139
  100. package/test/helper.ts +162 -162
  101. package/test/html/core.html +27 -27
  102. package/test/stub.test.ts +7 -7
  103. package/test/tsconfig.test.json +5 -5
  104. package/tsconfig.json +21 -21
  105. package/tslint.json +32 -32
  106. package/types/agent.d.ts +39 -39
  107. package/types/core.d.ts +150 -150
  108. package/types/data.d.ts +572 -571
  109. package/types/diagnostic.d.ts +24 -24
  110. package/types/global.d.ts +30 -30
  111. package/types/index.d.ts +40 -40
  112. package/types/interaction.d.ts +177 -177
  113. package/types/layout.d.ts +276 -276
  114. package/types/performance.d.ts +31 -31
package/src/core/index.ts CHANGED
@@ -1,81 +1,81 @@
1
- import { Config } from "@clarity-types/core";
2
- import { Constant } from "@clarity-types/data";
3
- import configuration from "@src/core/config";
4
- import * as event from "@src/core/event";
5
- import * as history from "@src/core/history";
6
- import * as report from "@src/core/report";
7
- import * as task from "@src/core/task";
8
- import * as time from "@src/core/time";
9
- import * as clarity from "@src/clarity";
10
- import * as custom from "@src/data/custom";
11
-
12
- let status = false;
13
-
14
- export function start(): void {
15
- status = true;
16
- time.start();
17
- task.reset();
18
- event.reset();
19
- report.reset();
20
- history.start();
21
- }
22
-
23
- export function stop(): void {
24
- history.stop();
25
- report.reset();
26
- event.reset();
27
- task.reset();
28
- time.stop();
29
- status = false;
30
- }
31
-
32
- export function active(): boolean {
33
- return status;
34
- }
35
-
36
- export function check(): boolean {
37
- try {
38
- let globalPrivacyControlSet = navigator && "globalPrivacyControl" in navigator && navigator['globalPrivacyControl'] == true;
39
- return status === false &&
40
- typeof Promise !== "undefined" &&
41
- window["MutationObserver"] &&
42
- document["createTreeWalker"] &&
43
- "now" in Date &&
44
- "now" in performance &&
45
- typeof WeakMap !== "undefined" &&
46
- !globalPrivacyControlSet
47
- } catch (ex) {
48
- return false;
49
- }
50
- }
51
-
52
- export function config(override: Config): boolean {
53
- // Process custom configuration overrides, if available
54
- if (override === null || status) { return false; }
55
- for (let key in override) {
56
- if (key in configuration) { configuration[key] = override[key]; }
57
- }
58
- return true;
59
- }
60
-
61
- // Suspend ends the current Clarity instance after a configured timeout period
62
- // The way it differs from the "end" call is that it starts listening to
63
- // user interaction events as soon as it terminates existing clarity instance.
64
- // On the next interaction, it automatically starts another instance under a different page id
65
- // E.g. if configured timeout is 10m, and user stays inactive for an hour.
66
- // In this case, we will suspend clarity after 10m of inactivity and after another 50m when user interacts again
67
- // Clarity will restart and start another instance seamlessly. Effectively not missing any active time, but also
68
- // not holding the session during inactive time periods.
69
- export function suspend(): void {
70
- if (status) {
71
- custom.event(Constant.Clarity, Constant.Suspend);
72
- clarity.stop();
73
- ["mousemove", "touchstart"].forEach(x => event.bind(document, x, restart));
74
- ["resize", "scroll", "pageshow"].forEach(x => event.bind(window, x, restart));
75
- }
76
- }
77
-
78
- function restart(): void {
79
- clarity.start();
80
- custom.event(Constant.Clarity, Constant.Restart);
81
- }
1
+ import { Config } from "@clarity-types/core";
2
+ import { Constant } from "@clarity-types/data";
3
+ import configuration from "@src/core/config";
4
+ import * as event from "@src/core/event";
5
+ import * as history from "@src/core/history";
6
+ import * as report from "@src/core/report";
7
+ import * as task from "@src/core/task";
8
+ import * as time from "@src/core/time";
9
+ import * as clarity from "@src/clarity";
10
+ import * as custom from "@src/data/custom";
11
+
12
+ let status = false;
13
+
14
+ export function start(): void {
15
+ status = true;
16
+ time.start();
17
+ task.reset();
18
+ event.reset();
19
+ report.reset();
20
+ history.start();
21
+ }
22
+
23
+ export function stop(): void {
24
+ history.stop();
25
+ report.reset();
26
+ event.reset();
27
+ task.reset();
28
+ time.stop();
29
+ status = false;
30
+ }
31
+
32
+ export function active(): boolean {
33
+ return status;
34
+ }
35
+
36
+ export function check(): boolean {
37
+ try {
38
+ let globalPrivacyControlSet = navigator && "globalPrivacyControl" in navigator && navigator['globalPrivacyControl'] == true;
39
+ return status === false &&
40
+ typeof Promise !== "undefined" &&
41
+ window["MutationObserver"] &&
42
+ document["createTreeWalker"] &&
43
+ "now" in Date &&
44
+ "now" in performance &&
45
+ typeof WeakMap !== "undefined" &&
46
+ !globalPrivacyControlSet
47
+ } catch (ex) {
48
+ return false;
49
+ }
50
+ }
51
+
52
+ export function config(override: Config): boolean {
53
+ // Process custom configuration overrides, if available
54
+ if (override === null || status) { return false; }
55
+ for (let key in override) {
56
+ if (key in configuration) { configuration[key] = override[key]; }
57
+ }
58
+ return true;
59
+ }
60
+
61
+ // Suspend ends the current Clarity instance after a configured timeout period
62
+ // The way it differs from the "end" call is that it starts listening to
63
+ // user interaction events as soon as it terminates existing clarity instance.
64
+ // On the next interaction, it automatically starts another instance under a different page id
65
+ // E.g. if configured timeout is 10m, and user stays inactive for an hour.
66
+ // In this case, we will suspend clarity after 10m of inactivity and after another 50m when user interacts again
67
+ // Clarity will restart and start another instance seamlessly. Effectively not missing any active time, but also
68
+ // not holding the session during inactive time periods.
69
+ export function suspend(): void {
70
+ if (status) {
71
+ custom.event(Constant.Clarity, Constant.Suspend);
72
+ clarity.stop();
73
+ ["mousemove", "touchstart"].forEach(x => event.bind(document, x, restart));
74
+ ["resize", "scroll", "pageshow"].forEach(x => event.bind(window, x, restart));
75
+ }
76
+ }
77
+
78
+ function restart(): void {
79
+ clarity.start();
80
+ custom.event(Constant.Clarity, Constant.Restart);
81
+ }
@@ -1,19 +1,19 @@
1
- import { Code, Metric, Setting, Severity } from "@clarity-types/data";
2
- import { report } from "@src/core/report";
3
- import * as metric from "@src/data/metric";
4
- import * as internal from "@src/diagnostic/internal";
5
-
6
- // tslint:disable-next-line: ban-types
7
- export default function (method: Function): Function {
8
- return function (): void {
9
- let start = performance.now();
10
- try { method.apply(this, arguments); } catch (ex) { throw report(ex); }
11
- let duration = performance.now() - start;
12
- metric.sum(Metric.TotalCost, duration);
13
- if (duration > Setting.LongTask) {
14
- metric.count(Metric.LongTaskCount);
15
- metric.max(Metric.ThreadBlockedTime, duration);
16
- method.dn && internal.log(Code.FunctionExecutionTime, Severity.Info, `${method.dn}-${duration}`);
17
- }
18
- };
19
- }
1
+ import { Code, Metric, Setting, Severity } from "@clarity-types/data";
2
+ import { report } from "@src/core/report";
3
+ import * as metric from "@src/data/metric";
4
+ import * as internal from "@src/diagnostic/internal";
5
+
6
+ // tslint:disable-next-line: ban-types
7
+ export default function (method: Function): Function {
8
+ return function (): void {
9
+ let start = performance.now();
10
+ try { method.apply(this, arguments); } catch (ex) { throw report(ex); }
11
+ let duration = performance.now() - start;
12
+ metric.sum(Metric.TotalCost, duration);
13
+ if (duration > Setting.LongTask) {
14
+ metric.count(Metric.LongTaskCount);
15
+ metric.max(Metric.ThreadBlockedTime, duration);
16
+ method.dn && internal.log(Code.FunctionExecutionTime, Severity.Info, `${method.dn}-${duration}`);
17
+ }
18
+ };
19
+ }
@@ -1,28 +1,28 @@
1
- import { Report } from "@clarity-types/core";
2
- import config from "@src/core/config";
3
- import { data } from "@src/data/envelope";
4
-
5
- let history: string[];
6
-
7
- export function reset(): void {
8
- history = [];
9
- }
10
-
11
- export function report(e: Error): Error {
12
- // Do not report the same message twice for the same page
13
- if (history && history.indexOf(e.message) === -1) {
14
- const url = config.report;
15
- if (url && url.length > 0 && data) {
16
- let payload: Report = {v: data.version, p: data.projectId, u: data.userId, s: data.sessionId, n: data.pageNum};
17
- if (e.message) { payload.m = e.message; }
18
- if (e.stack) { payload.e = e.stack; }
19
- // Using POST request instead of a GET request (img-src) to not violate existing CSP rules
20
- // Since, Clarity already uses XHR to upload data, we stick with similar POST mechanism for reporting too
21
- let xhr = new XMLHttpRequest();
22
- xhr.open("POST", url, true);
23
- xhr.send(JSON.stringify(payload));
24
- history.push(e.message);
25
- }
26
- }
27
- return e;
28
- }
1
+ import { Report } from "@clarity-types/core";
2
+ import config from "@src/core/config";
3
+ import { data } from "@src/data/envelope";
4
+
5
+ let history: string[];
6
+
7
+ export function reset(): void {
8
+ history = [];
9
+ }
10
+
11
+ export function report(e: Error): Error {
12
+ // Do not report the same message twice for the same page
13
+ if (history && history.indexOf(e.message) === -1) {
14
+ const url = config.report;
15
+ if (url && url.length > 0 && data) {
16
+ let payload: Report = {v: data.version, p: data.projectId, u: data.userId, s: data.sessionId, n: data.pageNum};
17
+ if (e.message) { payload.m = e.message; }
18
+ if (e.stack) { payload.e = e.stack; }
19
+ // Using POST request instead of a GET request (img-src) to not violate existing CSP rules
20
+ // Since, Clarity already uses XHR to upload data, we stick with similar POST mechanism for reporting too
21
+ let xhr = new XMLHttpRequest();
22
+ xhr.open("POST", url, true);
23
+ xhr.send(JSON.stringify(payload));
24
+ history.push(e.message);
25
+ }
26
+ }
27
+ return e;
28
+ }