clarity-js 0.7.66 → 0.7.68
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.
- package/README.md +26 -26
- package/build/clarity.extended.js +1 -1
- package/build/clarity.insight.js +1 -1
- package/build/clarity.js +5422 -5372
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +5422 -5372
- package/build/clarity.performance.js +1 -1
- package/package.json +70 -70
- package/rollup.config.ts +98 -98
- package/src/clarity.ts +60 -60
- package/src/core/api.ts +8 -8
- package/src/core/config.ts +32 -32
- package/src/core/copy.ts +3 -3
- package/src/core/event.ts +30 -26
- package/src/core/hash.ts +19 -19
- package/src/core/history.ts +73 -73
- package/src/core/index.ts +83 -83
- package/src/core/measure.ts +19 -19
- package/src/core/report.ts +28 -28
- package/src/core/scrub.ts +196 -196
- package/src/core/task.ts +180 -180
- package/src/core/time.ts +19 -19
- package/src/core/timeout.ts +10 -10
- package/src/core/version.ts +2 -2
- package/src/data/baseline.ts +123 -92
- package/src/data/compress.ts +31 -31
- package/src/data/consent.ts +20 -20
- package/src/data/custom.ts +23 -23
- package/src/data/dimension.ts +53 -53
- package/src/data/encode.ts +134 -127
- package/src/data/envelope.ts +53 -53
- package/src/data/extract.ts +204 -204
- package/src/data/index.ts +46 -46
- package/src/data/limit.ts +44 -44
- package/src/data/metadata.ts +356 -356
- package/src/data/metric.ts +51 -51
- package/src/data/ping.ts +36 -36
- package/src/data/signal.ts +30 -30
- package/src/data/summary.ts +34 -34
- package/src/data/token.ts +39 -39
- package/src/data/upgrade.ts +37 -37
- package/src/data/upload.ts +283 -283
- package/src/data/variable.ts +83 -83
- package/src/diagnostic/encode.ts +40 -40
- package/src/diagnostic/fraud.ts +36 -36
- package/src/diagnostic/index.ts +15 -15
- package/src/diagnostic/internal.ts +28 -28
- package/src/diagnostic/script.ts +37 -37
- package/src/global.ts +6 -6
- package/src/index.ts +9 -9
- package/src/insight/blank.ts +14 -14
- package/src/insight/encode.ts +60 -60
- package/src/insight/snapshot.ts +114 -114
- package/src/interaction/change.ts +40 -40
- package/src/interaction/click.ts +162 -156
- package/src/interaction/clipboard.ts +34 -34
- package/src/interaction/encode.ts +193 -191
- package/src/interaction/index.ts +59 -59
- package/src/interaction/input.ts +59 -59
- package/src/interaction/pointer.ts +139 -139
- package/src/interaction/resize.ts +47 -47
- package/src/interaction/scroll.ts +124 -124
- package/src/interaction/selection.ts +68 -68
- package/src/interaction/submit.ts +32 -32
- package/src/interaction/timeline.ts +65 -65
- package/src/interaction/unload.ts +28 -28
- package/src/interaction/visibility.ts +26 -26
- package/src/layout/animation.ts +133 -133
- package/src/layout/discover.ts +31 -31
- package/src/layout/document.ts +48 -48
- package/src/layout/dom.ts +414 -414
- package/src/layout/encode.ts +145 -145
- package/src/layout/index.ts +41 -41
- package/src/layout/mutation.ts +340 -340
- package/src/layout/node.ts +264 -264
- package/src/layout/offset.ts +19 -19
- package/src/layout/region.ts +153 -153
- package/src/layout/schema.ts +63 -63
- package/src/layout/selector.ts +82 -82
- package/src/layout/style.ts +150 -149
- package/src/layout/target.ts +32 -32
- package/src/layout/traverse.ts +27 -27
- package/src/performance/blank.ts +7 -7
- package/src/performance/encode.ts +31 -31
- package/src/performance/index.ts +14 -14
- package/src/performance/interaction.ts +125 -125
- package/src/performance/navigation.ts +31 -31
- package/src/performance/observer.ts +108 -108
- package/src/queue.ts +33 -33
- package/test/core.test.ts +139 -139
- package/test/helper.ts +162 -162
- package/test/html/core.html +27 -27
- package/test/tsconfig.test.json +5 -5
- package/tsconfig.json +21 -21
- package/tslint.json +32 -32
- package/types/core.d.ts +154 -151
- package/types/data.d.ts +504 -497
- package/types/diagnostic.d.ts +24 -24
- package/types/index.d.ts +39 -39
- package/types/interaction.d.ts +165 -157
- package/types/layout.d.ts +273 -273
- package/types/performance.d.ts +64 -64
package/src/core/config.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { Config, Time } from "@clarity-types/core";
|
|
2
|
-
|
|
3
|
-
let config: Config = {
|
|
4
|
-
projectId: null,
|
|
5
|
-
delay: 1 * Time.Second,
|
|
6
|
-
lean: false,
|
|
7
|
-
track: true,
|
|
8
|
-
content: true,
|
|
9
|
-
drop: [],
|
|
10
|
-
mask: [],
|
|
11
|
-
unmask: [],
|
|
12
|
-
regions: [],
|
|
13
|
-
cookies: [],
|
|
14
|
-
fraud: true,
|
|
15
|
-
checksum: [],
|
|
16
|
-
report: null,
|
|
17
|
-
upload: null,
|
|
18
|
-
fallback: null,
|
|
19
|
-
upgrade: null,
|
|
20
|
-
action: null,
|
|
21
|
-
dob: null,
|
|
22
|
-
delayDom: false,
|
|
23
|
-
throttleDom: true,
|
|
24
|
-
conversions: false,
|
|
25
|
-
includeSubdomains: true,
|
|
26
|
-
throttleMutations: false,
|
|
27
|
-
dropMutations: false,
|
|
28
|
-
criticalMs: 200,
|
|
29
|
-
discard: [],
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default config;
|
|
1
|
+
import { Config, Time } from "@clarity-types/core";
|
|
2
|
+
|
|
3
|
+
let config: Config = {
|
|
4
|
+
projectId: null,
|
|
5
|
+
delay: 1 * Time.Second,
|
|
6
|
+
lean: false,
|
|
7
|
+
track: true,
|
|
8
|
+
content: true,
|
|
9
|
+
drop: [],
|
|
10
|
+
mask: [],
|
|
11
|
+
unmask: [],
|
|
12
|
+
regions: [],
|
|
13
|
+
cookies: [],
|
|
14
|
+
fraud: true,
|
|
15
|
+
checksum: [],
|
|
16
|
+
report: null,
|
|
17
|
+
upload: null,
|
|
18
|
+
fallback: null,
|
|
19
|
+
upgrade: null,
|
|
20
|
+
action: null,
|
|
21
|
+
dob: null,
|
|
22
|
+
delayDom: false,
|
|
23
|
+
throttleDom: true,
|
|
24
|
+
conversions: false,
|
|
25
|
+
includeSubdomains: true,
|
|
26
|
+
throttleMutations: false,
|
|
27
|
+
dropMutations: false,
|
|
28
|
+
criticalMs: 200,
|
|
29
|
+
discard: [],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default config;
|
package/src/core/copy.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default function<T>(input: T): T {
|
|
2
|
-
return JSON.parse(JSON.stringify(input));
|
|
3
|
-
}
|
|
1
|
+
export default function<T>(input: T): T {
|
|
2
|
+
return JSON.parse(JSON.stringify(input));
|
|
3
|
+
}
|
package/src/core/event.ts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import { BrowserEvent, Constant } from "@clarity-types/core";
|
|
2
|
-
import api from "./api";
|
|
3
|
-
import measure from "./measure";
|
|
4
|
-
|
|
5
|
-
let bindings: BrowserEvent[] = [];
|
|
6
|
-
|
|
7
|
-
export function bind(target: EventTarget, event: string, listener: EventListener, capture: boolean = false): void {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import { BrowserEvent, Constant } from "@clarity-types/core";
|
|
2
|
+
import api from "./api";
|
|
3
|
+
import measure from "./measure";
|
|
4
|
+
|
|
5
|
+
let bindings: BrowserEvent[] = [];
|
|
6
|
+
|
|
7
|
+
export function bind(target: EventTarget, event: string, listener: EventListener, capture: boolean = false, passive: boolean = true): void {
|
|
8
|
+
listener = measure(listener) as EventListener;
|
|
9
|
+
// Wrapping following lines inside try / catch to cover edge cases where we might try to access an inaccessible element.
|
|
10
|
+
// E.g. Iframe may start off as same-origin but later turn into cross-origin, and the following lines will throw an exception.
|
|
11
|
+
try {
|
|
12
|
+
target[api(Constant.AddEventListener)](event, listener, { capture, passive });
|
|
13
|
+
bindings.push({ event, target, listener, options: { capture, passive } });
|
|
14
|
+
} catch {
|
|
15
|
+
/* do nothing */
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function reset(): void {
|
|
20
|
+
// Walk through existing list of bindings and remove them all
|
|
21
|
+
for (let binding of bindings) {
|
|
22
|
+
// Wrapping inside try / catch to avoid situations where the element may be destroyed before we get a chance to unbind
|
|
23
|
+
try {
|
|
24
|
+
binding.target[api(Constant.RemoveEventListener)](binding.event, binding.listener, { capture: binding.options.capture, passive: binding.options.passive });
|
|
25
|
+
} catch {
|
|
26
|
+
/* do nothing */
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
bindings = [];
|
|
30
|
+
}
|
package/src/core/hash.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
// tslint:disable: no-bitwise
|
|
2
|
-
export default function(input: string, precision: number = null): string {
|
|
3
|
-
// Code inspired from C# GetHashCode: https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/string.cs
|
|
4
|
-
let hash = 0;
|
|
5
|
-
let hashOne = 5381;
|
|
6
|
-
let hashTwo = hashOne;
|
|
7
|
-
for (let i = 0; i < input.length; i += 2) {
|
|
8
|
-
let charOne = input.charCodeAt(i);
|
|
9
|
-
hashOne = ((hashOne << 5) + hashOne) ^ charOne;
|
|
10
|
-
if (i + 1 < input.length) {
|
|
11
|
-
let charTwo = input.charCodeAt(i + 1);
|
|
12
|
-
hashTwo = ((hashTwo << 5) + hashTwo) ^ charTwo;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
// Replace the magic number from C# implementation (1566083941) with a smaller prime number (11579)
|
|
16
|
-
// This ensures we don't hit integer overflow and prevent collisions
|
|
17
|
-
hash = Math.abs(hashOne + (hashTwo * 11579));
|
|
18
|
-
return (precision ? hash % Math.pow(2, precision) : hash).toString(36);
|
|
19
|
-
}
|
|
1
|
+
// tslint:disable: no-bitwise
|
|
2
|
+
export default function(input: string, precision: number = null): string {
|
|
3
|
+
// Code inspired from C# GetHashCode: https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/string.cs
|
|
4
|
+
let hash = 0;
|
|
5
|
+
let hashOne = 5381;
|
|
6
|
+
let hashTwo = hashOne;
|
|
7
|
+
for (let i = 0; i < input.length; i += 2) {
|
|
8
|
+
let charOne = input.charCodeAt(i);
|
|
9
|
+
hashOne = ((hashOne << 5) + hashOne) ^ charOne;
|
|
10
|
+
if (i + 1 < input.length) {
|
|
11
|
+
let charTwo = input.charCodeAt(i + 1);
|
|
12
|
+
hashTwo = ((hashTwo << 5) + hashTwo) ^ charTwo;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// Replace the magic number from C# implementation (1566083941) with a smaller prime number (11579)
|
|
16
|
+
// This ensures we don't hit integer overflow and prevent collisions
|
|
17
|
+
hash = Math.abs(hashOne + (hashTwo * 11579));
|
|
18
|
+
return (precision ? hash % Math.pow(2, precision) : hash).toString(36);
|
|
19
|
+
}
|
package/src/core/history.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { BooleanFlag, Code, Constant, Metric, Setting, Severity } from "@clarity-types/data";
|
|
2
|
-
import { FunctionNames } from "@clarity-types/performance";
|
|
3
|
-
import * as clarity from "@src/clarity";
|
|
4
|
-
import * as core from "@src/core"
|
|
5
|
-
import { bind } from "@src/core/event";
|
|
6
|
-
import * as internal from "@src/diagnostic/internal";
|
|
7
|
-
import * as metric from "@src/data/metric";
|
|
8
|
-
|
|
9
|
-
let pushState = null;
|
|
10
|
-
let replaceState = null;
|
|
11
|
-
let url = null;
|
|
12
|
-
let count = 0;
|
|
13
|
-
|
|
14
|
-
export function start(): void {
|
|
15
|
-
url = getCurrentUrl();
|
|
16
|
-
count = 0;
|
|
17
|
-
bind(window, "popstate", compute);
|
|
18
|
-
|
|
19
|
-
// Add a proxy to history.pushState function
|
|
20
|
-
if (pushState === null) {
|
|
21
|
-
pushState = history.pushState;
|
|
22
|
-
history.pushState = function(): void {
|
|
23
|
-
pushState.apply(this, arguments);
|
|
24
|
-
if (core.active() && check()) {
|
|
25
|
-
compute();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Add a proxy to history.replaceState function
|
|
31
|
-
if (replaceState === null)
|
|
32
|
-
{
|
|
33
|
-
replaceState = history.replaceState;
|
|
34
|
-
history.replaceState = function(): void {
|
|
35
|
-
replaceState.apply(this, arguments);
|
|
36
|
-
if (core.active() && check()) {
|
|
37
|
-
compute();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function check(): boolean {
|
|
44
|
-
if (count++ > Setting.CallStackDepth) {
|
|
45
|
-
internal.log(Code.CallStackDepth, Severity.Info);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function compute(): void {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
function restart(): void {
|
|
62
|
-
clarity.start();
|
|
63
|
-
metric.max(Metric.SinglePage, BooleanFlag.True);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getCurrentUrl(): string {
|
|
67
|
-
return location.href ? location.href.replace(location.hash, Constant.Empty) : location.href;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function stop(): void {
|
|
71
|
-
url = null;
|
|
72
|
-
count = 0;
|
|
73
|
-
}
|
|
1
|
+
import { BooleanFlag, Code, Constant, Metric, Setting, Severity } from "@clarity-types/data";
|
|
2
|
+
import { FunctionNames } from "@clarity-types/performance";
|
|
3
|
+
import * as clarity from "@src/clarity";
|
|
4
|
+
import * as core from "@src/core"
|
|
5
|
+
import { bind } from "@src/core/event";
|
|
6
|
+
import * as internal from "@src/diagnostic/internal";
|
|
7
|
+
import * as metric from "@src/data/metric";
|
|
8
|
+
|
|
9
|
+
let pushState = null;
|
|
10
|
+
let replaceState = null;
|
|
11
|
+
let url = null;
|
|
12
|
+
let count = 0;
|
|
13
|
+
|
|
14
|
+
export function start(): void {
|
|
15
|
+
url = getCurrentUrl();
|
|
16
|
+
count = 0;
|
|
17
|
+
bind(window, "popstate", compute);
|
|
18
|
+
|
|
19
|
+
// Add a proxy to history.pushState function
|
|
20
|
+
if (pushState === null) {
|
|
21
|
+
pushState = history.pushState;
|
|
22
|
+
history.pushState = function(): void {
|
|
23
|
+
pushState.apply(this, arguments);
|
|
24
|
+
if (core.active() && check()) {
|
|
25
|
+
compute();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Add a proxy to history.replaceState function
|
|
31
|
+
if (replaceState === null)
|
|
32
|
+
{
|
|
33
|
+
replaceState = history.replaceState;
|
|
34
|
+
history.replaceState = function(): void {
|
|
35
|
+
replaceState.apply(this, arguments);
|
|
36
|
+
if (core.active() && check()) {
|
|
37
|
+
compute();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function check(): boolean {
|
|
44
|
+
if (count++ > Setting.CallStackDepth) {
|
|
45
|
+
internal.log(Code.CallStackDepth, Severity.Info);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function compute(): void {
|
|
52
|
+
compute.dn = FunctionNames.HistoryCompute;
|
|
53
|
+
count = 0; // Reset the counter
|
|
54
|
+
if (url !== getCurrentUrl()) {
|
|
55
|
+
// If the url changed, start tracking it as a new page
|
|
56
|
+
clarity.stop();
|
|
57
|
+
window.setTimeout(restart, Setting.RestartDelay);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function restart(): void {
|
|
62
|
+
clarity.start();
|
|
63
|
+
metric.max(Metric.SinglePage, BooleanFlag.True);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getCurrentUrl(): string {
|
|
67
|
+
return location.href ? location.href.replace(location.hash, Constant.Empty) : location.href;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function stop(): void {
|
|
71
|
+
url = null;
|
|
72
|
+
count = 0;
|
|
73
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { Config } from "@clarity-types/core";
|
|
2
|
-
import { Constant } from "@clarity-types/data";
|
|
3
|
-
import { FunctionNames } from "@clarity-types/performance";
|
|
4
|
-
import configuration from "@src/core/config";
|
|
5
|
-
import * as event from "@src/core/event";
|
|
6
|
-
import * as history from "@src/core/history";
|
|
7
|
-
import * as report from "@src/core/report";
|
|
8
|
-
import * as task from "@src/core/task";
|
|
9
|
-
import * as time from "@src/core/time";
|
|
10
|
-
import * as clarity from "@src/clarity";
|
|
11
|
-
import * as custom from "@src/data/custom";
|
|
12
|
-
|
|
13
|
-
let status = false;
|
|
14
|
-
|
|
15
|
-
export function start(): void {
|
|
16
|
-
status = true;
|
|
17
|
-
time.start();
|
|
18
|
-
task.reset();
|
|
19
|
-
event.reset();
|
|
20
|
-
report.reset();
|
|
21
|
-
history.start();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function stop(): void {
|
|
25
|
-
history.stop();
|
|
26
|
-
report.reset();
|
|
27
|
-
event.reset();
|
|
28
|
-
task.reset();
|
|
29
|
-
time.stop();
|
|
30
|
-
status = false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function active(): boolean {
|
|
34
|
-
return status;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function check(): boolean {
|
|
38
|
-
try {
|
|
39
|
-
let globalPrivacyControlSet = navigator && "globalPrivacyControl" in navigator && navigator['globalPrivacyControl'] == true;
|
|
40
|
-
return status === false &&
|
|
41
|
-
typeof Promise !== "undefined" &&
|
|
42
|
-
window["MutationObserver"] &&
|
|
43
|
-
document["createTreeWalker"] &&
|
|
44
|
-
"now" in Date &&
|
|
45
|
-
"now" in performance &&
|
|
46
|
-
typeof WeakMap !== "undefined" &&
|
|
47
|
-
!globalPrivacyControlSet
|
|
48
|
-
} catch (ex) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function config(override: Config): boolean {
|
|
54
|
-
// Process custom configuration overrides, if available
|
|
55
|
-
if (override === null || status) { return false; }
|
|
56
|
-
for (let key in override) {
|
|
57
|
-
if (key in configuration) { configuration[key] = override[key]; }
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Suspend ends the current Clarity instance after a configured timeout period
|
|
63
|
-
// The way it differs from the "end" call is that it starts listening to
|
|
64
|
-
// user interaction events as soon as it terminates existing clarity instance.
|
|
65
|
-
// On the next interaction, it automatically starts another instance under a different page id
|
|
66
|
-
// E.g. if configured timeout is 10m, and user stays inactive for an hour.
|
|
67
|
-
// In this case, we will suspend clarity after 10m of inactivity and after another 50m when user interacts again
|
|
68
|
-
// Clarity will restart and start another instance seamlessly. Effectively not missing any active time, but also
|
|
69
|
-
// not holding the session during inactive time periods.
|
|
70
|
-
export function suspend(): void {
|
|
71
|
-
if (status) {
|
|
72
|
-
custom.event(Constant.Clarity, Constant.Suspend);
|
|
73
|
-
clarity.stop();
|
|
74
|
-
["mousemove", "touchstart"].forEach(x => event.bind(document, x, restart));
|
|
75
|
-
["resize", "scroll", "pageshow"].forEach(x => event.bind(window, x, restart));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function restart(): void {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
import { Config } from "@clarity-types/core";
|
|
2
|
+
import { Constant } from "@clarity-types/data";
|
|
3
|
+
import { FunctionNames } from "@clarity-types/performance";
|
|
4
|
+
import configuration from "@src/core/config";
|
|
5
|
+
import * as event from "@src/core/event";
|
|
6
|
+
import * as history from "@src/core/history";
|
|
7
|
+
import * as report from "@src/core/report";
|
|
8
|
+
import * as task from "@src/core/task";
|
|
9
|
+
import * as time from "@src/core/time";
|
|
10
|
+
import * as clarity from "@src/clarity";
|
|
11
|
+
import * as custom from "@src/data/custom";
|
|
12
|
+
|
|
13
|
+
let status = false;
|
|
14
|
+
|
|
15
|
+
export function start(): void {
|
|
16
|
+
status = true;
|
|
17
|
+
time.start();
|
|
18
|
+
task.reset();
|
|
19
|
+
event.reset();
|
|
20
|
+
report.reset();
|
|
21
|
+
history.start();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function stop(): void {
|
|
25
|
+
history.stop();
|
|
26
|
+
report.reset();
|
|
27
|
+
event.reset();
|
|
28
|
+
task.reset();
|
|
29
|
+
time.stop();
|
|
30
|
+
status = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function active(): boolean {
|
|
34
|
+
return status;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function check(): boolean {
|
|
38
|
+
try {
|
|
39
|
+
let globalPrivacyControlSet = navigator && "globalPrivacyControl" in navigator && navigator['globalPrivacyControl'] == true;
|
|
40
|
+
return status === false &&
|
|
41
|
+
typeof Promise !== "undefined" &&
|
|
42
|
+
window["MutationObserver"] &&
|
|
43
|
+
document["createTreeWalker"] &&
|
|
44
|
+
"now" in Date &&
|
|
45
|
+
"now" in performance &&
|
|
46
|
+
typeof WeakMap !== "undefined" &&
|
|
47
|
+
!globalPrivacyControlSet
|
|
48
|
+
} catch (ex) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function config(override: Config): boolean {
|
|
54
|
+
// Process custom configuration overrides, if available
|
|
55
|
+
if (override === null || status) { return false; }
|
|
56
|
+
for (let key in override) {
|
|
57
|
+
if (key in configuration) { configuration[key] = override[key]; }
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Suspend ends the current Clarity instance after a configured timeout period
|
|
63
|
+
// The way it differs from the "end" call is that it starts listening to
|
|
64
|
+
// user interaction events as soon as it terminates existing clarity instance.
|
|
65
|
+
// On the next interaction, it automatically starts another instance under a different page id
|
|
66
|
+
// E.g. if configured timeout is 10m, and user stays inactive for an hour.
|
|
67
|
+
// In this case, we will suspend clarity after 10m of inactivity and after another 50m when user interacts again
|
|
68
|
+
// Clarity will restart and start another instance seamlessly. Effectively not missing any active time, but also
|
|
69
|
+
// not holding the session during inactive time periods.
|
|
70
|
+
export function suspend(): void {
|
|
71
|
+
if (status) {
|
|
72
|
+
custom.event(Constant.Clarity, Constant.Suspend);
|
|
73
|
+
clarity.stop();
|
|
74
|
+
["mousemove", "touchstart"].forEach(x => event.bind(document, x, restart));
|
|
75
|
+
["resize", "scroll", "pageshow"].forEach(x => event.bind(window, x, restart));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function restart(): void {
|
|
80
|
+
restart.dn = FunctionNames.Restart;
|
|
81
|
+
clarity.start();
|
|
82
|
+
custom.event(Constant.Clarity, Constant.Restart);
|
|
83
|
+
}
|
package/src/core/measure.ts
CHANGED
|
@@ -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
|
-
internal.log(Code.FunctionExecutionTime, Severity.Info, `${method.dn || method.name}-${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
|
+
internal.log(Code.FunctionExecutionTime, Severity.Info, `${method.dn || method.name}-${duration}`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
package/src/core/report.ts
CHANGED
|
@@ -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) {
|
|
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) {
|
|
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
|
+
}
|