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.
- package/README.md +26 -26
- package/build/clarity.extended.js +1 -1
- package/build/clarity.insight.js +1 -1
- package/build/clarity.js +6027 -6027
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +6027 -6027
- package/build/clarity.performance.js +1 -1
- package/package.json +70 -70
- package/rollup.config.ts +161 -161
- package/src/clarity.ts +65 -65
- package/src/core/api.ts +8 -8
- package/src/core/config.ts +29 -29
- package/src/core/copy.ts +3 -3
- package/src/core/event.ts +53 -53
- package/src/core/hash.ts +19 -19
- package/src/core/history.ts +71 -71
- package/src/core/index.ts +81 -81
- package/src/core/measure.ts +19 -19
- package/src/core/report.ts +28 -28
- package/src/core/scrub.ts +202 -202
- package/src/core/task.ts +181 -181
- package/src/core/throttle.ts +46 -46
- package/src/core/time.ts +26 -26
- package/src/core/timeout.ts +10 -10
- package/src/core/version.ts +2 -2
- package/src/data/baseline.ts +162 -162
- package/src/data/compress.ts +31 -31
- package/src/data/consent.ts +77 -77
- package/src/data/custom.ts +23 -23
- package/src/data/dimension.ts +53 -53
- package/src/data/encode.ts +155 -155
- package/src/data/envelope.ts +53 -53
- package/src/data/extract.ts +211 -211
- package/src/data/index.ts +50 -50
- package/src/data/limit.ts +44 -44
- package/src/data/metadata.ts +408 -408
- 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 +44 -44
- package/src/data/upload.ts +333 -333
- 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 +13 -13
- package/src/diagnostic/internal.ts +28 -28
- package/src/diagnostic/script.ts +35 -35
- package/src/dynamic/agent/blank.ts +2 -2
- package/src/dynamic/agent/crisp.ts +40 -40
- package/src/dynamic/agent/encode.ts +25 -25
- package/src/dynamic/agent/index.ts +8 -8
- package/src/dynamic/agent/livechat.ts +58 -58
- package/src/dynamic/agent/tidio.ts +44 -44
- 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 +38 -38
- package/src/interaction/click.ts +173 -173
- package/src/interaction/clipboard.ts +32 -32
- package/src/interaction/encode.ts +210 -210
- package/src/interaction/index.ts +60 -60
- package/src/interaction/input.ts +57 -57
- package/src/interaction/pointer.ts +137 -137
- package/src/interaction/resize.ts +50 -50
- package/src/interaction/scroll.ts +129 -129
- package/src/interaction/selection.ts +66 -66
- package/src/interaction/submit.ts +30 -30
- package/src/interaction/timeline.ts +69 -69
- package/src/interaction/unload.ts +26 -26
- package/src/interaction/visibility.ts +27 -27
- package/src/layout/animation.ts +133 -133
- package/src/layout/custom.ts +42 -42
- package/src/layout/discover.ts +31 -31
- package/src/layout/document.ts +46 -46
- package/src/layout/dom.ts +439 -439
- package/src/layout/encode.ts +154 -154
- package/src/layout/index.ts +42 -42
- package/src/layout/mutation.ts +411 -411
- package/src/layout/node.ts +294 -294
- package/src/layout/offset.ts +19 -19
- package/src/layout/region.ts +151 -151
- package/src/layout/schema.ts +63 -63
- package/src/layout/selector.ts +82 -82
- package/src/layout/style.ts +159 -159
- package/src/layout/target.ts +32 -32
- package/src/layout/traverse.ts +27 -27
- package/src/performance/blank.ts +9 -9
- package/src/performance/encode.ts +31 -31
- package/src/performance/index.ts +12 -12
- package/src/performance/interaction.ts +125 -125
- package/src/performance/navigation.ts +31 -31
- package/src/performance/observer.ts +112 -112
- 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/stub.test.ts +7 -7
- package/test/tsconfig.test.json +5 -5
- package/tsconfig.json +21 -21
- package/tslint.json +32 -32
- package/types/agent.d.ts +39 -39
- package/types/core.d.ts +150 -150
- package/types/data.d.ts +571 -571
- package/types/diagnostic.d.ts +24 -24
- package/types/global.d.ts +30 -30
- package/types/index.d.ts +40 -40
- package/types/interaction.d.ts +177 -177
- package/types/layout.d.ts +276 -276
- package/types/performance.d.ts +31 -31
package/src/data/variable.ts
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { Constant, Event, IdentityData, Setting, VariableData } from "@clarity-types/data";
|
|
2
|
-
import * as core from "@src/core";
|
|
3
|
-
import { scrub } from "@src/core/scrub";
|
|
4
|
-
import encode from "./encode";
|
|
5
|
-
|
|
6
|
-
export let data: VariableData = null;
|
|
7
|
-
|
|
8
|
-
export function start(): void {
|
|
9
|
-
reset();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function set(variable: string, value: string | string[]): void {
|
|
13
|
-
let values = typeof value === Constant.String ? [value as string] : value as string[];
|
|
14
|
-
log(variable, values);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function identify(userId: string, sessionId: string = null, pageId: string = null, userHint: string = null): Promise<IdentityData> {
|
|
18
|
-
let output: IdentityData = { userId: await sha256(userId), userHint: userHint || redact(userId) };
|
|
19
|
-
|
|
20
|
-
// By default, hash custom userId using SHA256 algorithm on the client to preserve privacy
|
|
21
|
-
log(Constant.UserId, [output.userId]);
|
|
22
|
-
|
|
23
|
-
// Optional non-identifying name for the user
|
|
24
|
-
// If name is not explicitly provided, we automatically generate a redacted version of the userId
|
|
25
|
-
log(Constant.UserHint, [output.userHint]);
|
|
26
|
-
log(Constant.UserType, [detect(userId)]);
|
|
27
|
-
|
|
28
|
-
// Log sessionId and pageId if provided
|
|
29
|
-
if (sessionId) {
|
|
30
|
-
log(Constant.SessionId, [sessionId]);
|
|
31
|
-
output.sessionId = sessionId;
|
|
32
|
-
}
|
|
33
|
-
if (pageId) {
|
|
34
|
-
log(Constant.PageId, [pageId]);
|
|
35
|
-
output.pageId = pageId;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return output;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function log(variable: string, value: string[]): void {
|
|
42
|
-
if (core.active() &&
|
|
43
|
-
variable &&
|
|
44
|
-
value &&
|
|
45
|
-
typeof variable === Constant.String &&
|
|
46
|
-
variable.length < 255) {
|
|
47
|
-
let validValues = variable in data ? data[variable] : [];
|
|
48
|
-
for (let i = 0; i < value.length; i++) {
|
|
49
|
-
if (typeof value[i] === Constant.String && value[i].length < 255) { validValues.push(value[i]); }
|
|
50
|
-
}
|
|
51
|
-
data[variable] = validValues;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function compute(): void {
|
|
56
|
-
encode(Event.Variable);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function reset(): void {
|
|
60
|
-
data = {};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function stop(): void {
|
|
64
|
-
reset();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function redact(input: string): string {
|
|
68
|
-
return input && input.length >= Setting.WordLength ?
|
|
69
|
-
`${input.substring(0,2)}${scrub(input.substring(2), Constant.Asterix, Constant.Asterix)}` : scrub(input, Constant.Asterix, Constant.Asterix);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function sha256(input: string): Promise<string> {
|
|
73
|
-
try {
|
|
74
|
-
if (crypto && input) {
|
|
75
|
-
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string
|
|
76
|
-
const buffer = await crypto.subtle.digest(Constant.SHA256, new TextEncoder().encode(input));
|
|
77
|
-
return Array.prototype.map.call(new Uint8Array(buffer), (x: any) =>(('00'+x.toString(16)).slice(-2))).join('');
|
|
78
|
-
} else { return Constant.Empty; }
|
|
79
|
-
} catch { return Constant.Empty; }
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function detect(input: string): string {
|
|
83
|
-
return input && input.indexOf(Constant.At) > 0 ? Constant.Email : Constant.String;
|
|
1
|
+
import { Constant, Event, IdentityData, Setting, VariableData } from "@clarity-types/data";
|
|
2
|
+
import * as core from "@src/core";
|
|
3
|
+
import { scrub } from "@src/core/scrub";
|
|
4
|
+
import encode from "./encode";
|
|
5
|
+
|
|
6
|
+
export let data: VariableData = null;
|
|
7
|
+
|
|
8
|
+
export function start(): void {
|
|
9
|
+
reset();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function set(variable: string, value: string | string[]): void {
|
|
13
|
+
let values = typeof value === Constant.String ? [value as string] : value as string[];
|
|
14
|
+
log(variable, values);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function identify(userId: string, sessionId: string = null, pageId: string = null, userHint: string = null): Promise<IdentityData> {
|
|
18
|
+
let output: IdentityData = { userId: await sha256(userId), userHint: userHint || redact(userId) };
|
|
19
|
+
|
|
20
|
+
// By default, hash custom userId using SHA256 algorithm on the client to preserve privacy
|
|
21
|
+
log(Constant.UserId, [output.userId]);
|
|
22
|
+
|
|
23
|
+
// Optional non-identifying name for the user
|
|
24
|
+
// If name is not explicitly provided, we automatically generate a redacted version of the userId
|
|
25
|
+
log(Constant.UserHint, [output.userHint]);
|
|
26
|
+
log(Constant.UserType, [detect(userId)]);
|
|
27
|
+
|
|
28
|
+
// Log sessionId and pageId if provided
|
|
29
|
+
if (sessionId) {
|
|
30
|
+
log(Constant.SessionId, [sessionId]);
|
|
31
|
+
output.sessionId = sessionId;
|
|
32
|
+
}
|
|
33
|
+
if (pageId) {
|
|
34
|
+
log(Constant.PageId, [pageId]);
|
|
35
|
+
output.pageId = pageId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return output;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function log(variable: string, value: string[]): void {
|
|
42
|
+
if (core.active() &&
|
|
43
|
+
variable &&
|
|
44
|
+
value &&
|
|
45
|
+
typeof variable === Constant.String &&
|
|
46
|
+
variable.length < 255) {
|
|
47
|
+
let validValues = variable in data ? data[variable] : [];
|
|
48
|
+
for (let i = 0; i < value.length; i++) {
|
|
49
|
+
if (typeof value[i] === Constant.String && value[i].length < 255) { validValues.push(value[i]); }
|
|
50
|
+
}
|
|
51
|
+
data[variable] = validValues;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function compute(): void {
|
|
56
|
+
encode(Event.Variable);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function reset(): void {
|
|
60
|
+
data = {};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function stop(): void {
|
|
64
|
+
reset();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function redact(input: string): string {
|
|
68
|
+
return input && input.length >= Setting.WordLength ?
|
|
69
|
+
`${input.substring(0,2)}${scrub(input.substring(2), Constant.Asterix, Constant.Asterix)}` : scrub(input, Constant.Asterix, Constant.Asterix);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function sha256(input: string): Promise<string> {
|
|
73
|
+
try {
|
|
74
|
+
if (crypto && input) {
|
|
75
|
+
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string
|
|
76
|
+
const buffer = await crypto.subtle.digest(Constant.SHA256, new TextEncoder().encode(input));
|
|
77
|
+
return Array.prototype.map.call(new Uint8Array(buffer), (x: any) =>(('00'+x.toString(16)).slice(-2))).join('');
|
|
78
|
+
} else { return Constant.Empty; }
|
|
79
|
+
} catch { return Constant.Empty; }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function detect(input: string): string {
|
|
83
|
+
return input && input.indexOf(Constant.At) > 0 ? Constant.Email : Constant.String;
|
|
84
84
|
}
|
package/src/diagnostic/encode.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { Event, Token } from "@clarity-types/data";
|
|
2
|
-
import * as scrub from "@src/core/scrub";
|
|
3
|
-
import { time } from "@src/core/time";
|
|
4
|
-
import { queue } from "@src/data/upload";
|
|
5
|
-
import * as fraud from "@src/diagnostic/fraud";
|
|
6
|
-
import * as internal from "@src/diagnostic/internal";
|
|
7
|
-
import * as script from "@src/diagnostic/script";
|
|
8
|
-
|
|
9
|
-
export default async function (type: Event): Promise<void> {
|
|
10
|
-
let tokens: Token[] = [time(), type];
|
|
11
|
-
|
|
12
|
-
switch (type) {
|
|
13
|
-
case Event.ScriptError:
|
|
14
|
-
tokens.push(script.data.message);
|
|
15
|
-
tokens.push(script.data.line);
|
|
16
|
-
tokens.push(script.data.column);
|
|
17
|
-
tokens.push(script.data.stack);
|
|
18
|
-
tokens.push(scrub.url(script.data.source));
|
|
19
|
-
queue(tokens);
|
|
20
|
-
break;
|
|
21
|
-
case Event.Log:
|
|
22
|
-
if (internal.data) {
|
|
23
|
-
tokens.push(internal.data.code);
|
|
24
|
-
tokens.push(internal.data.name);
|
|
25
|
-
tokens.push(internal.data.message);
|
|
26
|
-
tokens.push(internal.data.stack);
|
|
27
|
-
tokens.push(internal.data.severity);
|
|
28
|
-
queue(tokens, false);
|
|
29
|
-
}
|
|
30
|
-
break;
|
|
31
|
-
case Event.Fraud:
|
|
32
|
-
if (fraud.data) {
|
|
33
|
-
tokens.push(fraud.data.id);
|
|
34
|
-
tokens.push(fraud.data.target);
|
|
35
|
-
tokens.push(fraud.data.checksum);
|
|
36
|
-
queue(tokens, false);
|
|
37
|
-
}
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import { Event, Token } from "@clarity-types/data";
|
|
2
|
+
import * as scrub from "@src/core/scrub";
|
|
3
|
+
import { time } from "@src/core/time";
|
|
4
|
+
import { queue } from "@src/data/upload";
|
|
5
|
+
import * as fraud from "@src/diagnostic/fraud";
|
|
6
|
+
import * as internal from "@src/diagnostic/internal";
|
|
7
|
+
import * as script from "@src/diagnostic/script";
|
|
8
|
+
|
|
9
|
+
export default async function (type: Event): Promise<void> {
|
|
10
|
+
let tokens: Token[] = [time(), type];
|
|
11
|
+
|
|
12
|
+
switch (type) {
|
|
13
|
+
case Event.ScriptError:
|
|
14
|
+
tokens.push(script.data.message);
|
|
15
|
+
tokens.push(script.data.line);
|
|
16
|
+
tokens.push(script.data.column);
|
|
17
|
+
tokens.push(script.data.stack);
|
|
18
|
+
tokens.push(scrub.url(script.data.source));
|
|
19
|
+
queue(tokens);
|
|
20
|
+
break;
|
|
21
|
+
case Event.Log:
|
|
22
|
+
if (internal.data) {
|
|
23
|
+
tokens.push(internal.data.code);
|
|
24
|
+
tokens.push(internal.data.name);
|
|
25
|
+
tokens.push(internal.data.message);
|
|
26
|
+
tokens.push(internal.data.stack);
|
|
27
|
+
tokens.push(internal.data.severity);
|
|
28
|
+
queue(tokens, false);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
case Event.Fraud:
|
|
32
|
+
if (fraud.data) {
|
|
33
|
+
tokens.push(fraud.data.id);
|
|
34
|
+
tokens.push(fraud.data.target);
|
|
35
|
+
tokens.push(fraud.data.checksum);
|
|
36
|
+
queue(tokens, false);
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/diagnostic/fraud.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { BooleanFlag, Event, IframeStatus, Metric, Setting } from "@clarity-types/data";
|
|
2
|
-
import { FraudData } from "@clarity-types/diagnostic";
|
|
3
|
-
import config from "@src/core/config";
|
|
4
|
-
import hash from "@src/core/hash";
|
|
5
|
-
import * as metric from "@src/data/metric";
|
|
6
|
-
import encode from "./encode";
|
|
7
|
-
|
|
8
|
-
let history = [];
|
|
9
|
-
export let data: FraudData;
|
|
10
|
-
|
|
11
|
-
export function start(): void {
|
|
12
|
-
history = [];
|
|
13
|
-
metric.max(Metric.Automation, navigator.webdriver ? BooleanFlag.True : BooleanFlag.False);
|
|
14
|
-
try {
|
|
15
|
-
// some sites (unintentionally) overwrite the window.self property, so we also check for the main window object
|
|
16
|
-
metric.max(Metric.Iframed, window.top == window.self || window.top == window ? IframeStatus.TopFrame : IframeStatus.Iframe);
|
|
17
|
-
} catch (ex) {
|
|
18
|
-
metric.max(Metric.Iframed, IframeStatus.Unknown);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function check(id: number, target: number, input: string): void {
|
|
24
|
-
// Compute hash for fraud detection, if enabled. Hash is computed only if input meets the minimum length criteria
|
|
25
|
-
if (config.fraud && id !== null && input && input.length >= Setting.WordLength) {
|
|
26
|
-
data = { id, target, checksum: hash(input, Setting.ChecksumPrecision) };
|
|
27
|
-
// Only encode this event if we haven't already reported this hash
|
|
28
|
-
if (history.indexOf(data.checksum) < 0) {
|
|
29
|
-
history.push(data.checksum);
|
|
30
|
-
encode(Event.Fraud);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function stop(): void {
|
|
36
|
-
history = [];
|
|
1
|
+
import { BooleanFlag, Event, IframeStatus, Metric, Setting } from "@clarity-types/data";
|
|
2
|
+
import { FraudData } from "@clarity-types/diagnostic";
|
|
3
|
+
import config from "@src/core/config";
|
|
4
|
+
import hash from "@src/core/hash";
|
|
5
|
+
import * as metric from "@src/data/metric";
|
|
6
|
+
import encode from "./encode";
|
|
7
|
+
|
|
8
|
+
let history = [];
|
|
9
|
+
export let data: FraudData;
|
|
10
|
+
|
|
11
|
+
export function start(): void {
|
|
12
|
+
history = [];
|
|
13
|
+
metric.max(Metric.Automation, navigator.webdriver ? BooleanFlag.True : BooleanFlag.False);
|
|
14
|
+
try {
|
|
15
|
+
// some sites (unintentionally) overwrite the window.self property, so we also check for the main window object
|
|
16
|
+
metric.max(Metric.Iframed, window.top == window.self || window.top == window ? IframeStatus.TopFrame : IframeStatus.Iframe);
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
metric.max(Metric.Iframed, IframeStatus.Unknown);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function check(id: number, target: number, input: string): void {
|
|
24
|
+
// Compute hash for fraud detection, if enabled. Hash is computed only if input meets the minimum length criteria
|
|
25
|
+
if (config.fraud && id !== null && input && input.length >= Setting.WordLength) {
|
|
26
|
+
data = { id, target, checksum: hash(input, Setting.ChecksumPrecision) };
|
|
27
|
+
// Only encode this event if we haven't already reported this hash
|
|
28
|
+
if (history.indexOf(data.checksum) < 0) {
|
|
29
|
+
history.push(data.checksum);
|
|
30
|
+
encode(Event.Fraud);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function stop(): void {
|
|
36
|
+
history = [];
|
|
37
37
|
}
|
package/src/diagnostic/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as fraud from "@src/diagnostic/fraud";
|
|
2
|
-
import * as internal from "@src/diagnostic/internal";
|
|
3
|
-
import * as script from "@src/diagnostic/script";
|
|
4
|
-
|
|
5
|
-
export function start(): void {
|
|
6
|
-
fraud.start();
|
|
7
|
-
script.start();
|
|
8
|
-
internal.start();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function stop(): void {
|
|
12
|
-
internal.stop();
|
|
13
|
-
}
|
|
1
|
+
import * as fraud from "@src/diagnostic/fraud";
|
|
2
|
+
import * as internal from "@src/diagnostic/internal";
|
|
3
|
+
import * as script from "@src/diagnostic/script";
|
|
4
|
+
|
|
5
|
+
export function start(): void {
|
|
6
|
+
fraud.start();
|
|
7
|
+
script.start();
|
|
8
|
+
internal.start();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function stop(): void {
|
|
12
|
+
internal.stop();
|
|
13
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { Code, Event, Severity } from "@clarity-types/data";
|
|
2
|
-
import { LogData } from "@clarity-types/diagnostic";
|
|
3
|
-
import encode from "./encode";
|
|
4
|
-
|
|
5
|
-
let history: { [key: number]: string[] } = {};
|
|
6
|
-
export let data: LogData;
|
|
7
|
-
|
|
8
|
-
export function start(): void {
|
|
9
|
-
history = {};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function log(code: Code, severity: Severity, name: string = null, message: string = null, stack: string = null): void {
|
|
13
|
-
let key = name ? `${name}|${message}`: "";
|
|
14
|
-
// While rare, it's possible for code to fail repeatedly during the lifetime of the same page
|
|
15
|
-
// In those cases, we only want to log the failure once and not spam logs with redundant information.
|
|
16
|
-
if (code in history && history[code].indexOf(key) >= 0) { return; }
|
|
17
|
-
|
|
18
|
-
data = { code, name, message, stack, severity };
|
|
19
|
-
|
|
20
|
-
// Maintain history of errors in memory to avoid sending redundant information
|
|
21
|
-
if (code in history) { history[code].push(key); } else { history[code] = [key]; }
|
|
22
|
-
|
|
23
|
-
encode(Event.Log);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function stop(): void {
|
|
27
|
-
history = {};
|
|
28
|
-
}
|
|
1
|
+
import { Code, Event, Severity } from "@clarity-types/data";
|
|
2
|
+
import { LogData } from "@clarity-types/diagnostic";
|
|
3
|
+
import encode from "./encode";
|
|
4
|
+
|
|
5
|
+
let history: { [key: number]: string[] } = {};
|
|
6
|
+
export let data: LogData;
|
|
7
|
+
|
|
8
|
+
export function start(): void {
|
|
9
|
+
history = {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function log(code: Code, severity: Severity, name: string = null, message: string = null, stack: string = null): void {
|
|
13
|
+
let key = name ? `${name}|${message}`: "";
|
|
14
|
+
// While rare, it's possible for code to fail repeatedly during the lifetime of the same page
|
|
15
|
+
// In those cases, we only want to log the failure once and not spam logs with redundant information.
|
|
16
|
+
if (code in history && history[code].indexOf(key) >= 0) { return; }
|
|
17
|
+
|
|
18
|
+
data = { code, name, message, stack, severity };
|
|
19
|
+
|
|
20
|
+
// Maintain history of errors in memory to avoid sending redundant information
|
|
21
|
+
if (code in history) { history[code].push(key); } else { history[code] = [key]; }
|
|
22
|
+
|
|
23
|
+
encode(Event.Log);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function stop(): void {
|
|
27
|
+
history = {};
|
|
28
|
+
}
|
package/src/diagnostic/script.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Event, Setting } from "@clarity-types/data";
|
|
2
|
-
import { ScriptErrorData } from "@clarity-types/diagnostic";
|
|
3
|
-
import { bind } from "@src/core/event";
|
|
4
|
-
import encode from "./encode";
|
|
5
|
-
|
|
6
|
-
let history: { [key: string]: number } = {};
|
|
7
|
-
export let data: ScriptErrorData;
|
|
8
|
-
|
|
9
|
-
export function start(): void {
|
|
10
|
-
bind(window, "error", handler);
|
|
11
|
-
history = {};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function handler(error: ErrorEvent): boolean {
|
|
15
|
-
let e = error["error"] || error;
|
|
16
|
-
// While rare, it's possible for code to fail repeatedly during the lifetime of the same page
|
|
17
|
-
// In those cases, we only want to log the failure first few times and not spam logs with redundant information.
|
|
18
|
-
if (!(e.message in history)) { history[e.message] = 0; }
|
|
19
|
-
if (history[e.message]++ >= Setting.ScriptErrorLimit) { return true; }
|
|
20
|
-
|
|
21
|
-
// Send back information only if the handled error has valid information
|
|
22
|
-
if (e && e.message) {
|
|
23
|
-
data = {
|
|
24
|
-
message: e.message,
|
|
25
|
-
line: error["lineno"],
|
|
26
|
-
column: error["colno"],
|
|
27
|
-
stack: e.stack,
|
|
28
|
-
source: error["filename"]
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
encode(Event.ScriptError);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
1
|
+
import { Event, Setting } from "@clarity-types/data";
|
|
2
|
+
import { ScriptErrorData } from "@clarity-types/diagnostic";
|
|
3
|
+
import { bind } from "@src/core/event";
|
|
4
|
+
import encode from "./encode";
|
|
5
|
+
|
|
6
|
+
let history: { [key: string]: number } = {};
|
|
7
|
+
export let data: ScriptErrorData;
|
|
8
|
+
|
|
9
|
+
export function start(): void {
|
|
10
|
+
bind(window, "error", handler);
|
|
11
|
+
history = {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function handler(error: ErrorEvent): boolean {
|
|
15
|
+
let e = error["error"] || error;
|
|
16
|
+
// While rare, it's possible for code to fail repeatedly during the lifetime of the same page
|
|
17
|
+
// In those cases, we only want to log the failure first few times and not spam logs with redundant information.
|
|
18
|
+
if (!(e.message in history)) { history[e.message] = 0; }
|
|
19
|
+
if (history[e.message]++ >= Setting.ScriptErrorLimit) { return true; }
|
|
20
|
+
|
|
21
|
+
// Send back information only if the handled error has valid information
|
|
22
|
+
if (e && e.message) {
|
|
23
|
+
data = {
|
|
24
|
+
message: e.message,
|
|
25
|
+
line: error["lineno"],
|
|
26
|
+
column: error["colno"],
|
|
27
|
+
stack: e.stack,
|
|
28
|
+
source: error["filename"]
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
encode(Event.ScriptError);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function start(): void {}
|
|
2
|
-
export function stop(): void {}
|
|
1
|
+
export function start(): void {}
|
|
2
|
+
export function stop(): void {}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { Action } from "@clarity-types/agent";
|
|
2
|
-
import encode from "./encode";
|
|
3
|
-
|
|
4
|
-
function open() {
|
|
5
|
-
encode(Action.AgentMaximized);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function close() {
|
|
9
|
-
encode(Action.AgentMinimized);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function human() {
|
|
13
|
-
encode(Action.HumanMessage);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function agent() {
|
|
17
|
-
encode(Action.AgentMessage);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function start(): void {
|
|
21
|
-
if (window.$crisp) {
|
|
22
|
-
window.$crisp.push(["on", "chat:opened", open]);
|
|
23
|
-
window.$crisp.push(["on", "chat:closed", close]);
|
|
24
|
-
window.$crisp.push(["on", "message:sent", human]);
|
|
25
|
-
window.$crisp.push(["on", "message:received", agent]);
|
|
26
|
-
}
|
|
27
|
-
// Register stop callback with main Clarity
|
|
28
|
-
if (typeof window !== "undefined" && (window as any).clarity) {
|
|
29
|
-
(window as any).clarity("register", stop);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function stop(): void {
|
|
34
|
-
if (window.$crisp) {
|
|
35
|
-
window.$crisp.push(["off", "chat:opened", open]);
|
|
36
|
-
window.$crisp.push(["off", "chat:closed", close]);
|
|
37
|
-
window.$crisp.push(["off", "message:sent", human]);
|
|
38
|
-
window.$crisp.push(["off", "message:received", agent]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import { Action } from "@clarity-types/agent";
|
|
2
|
+
import encode from "./encode";
|
|
3
|
+
|
|
4
|
+
function open() {
|
|
5
|
+
encode(Action.AgentMaximized);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function close() {
|
|
9
|
+
encode(Action.AgentMinimized);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function human() {
|
|
13
|
+
encode(Action.HumanMessage);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function agent() {
|
|
17
|
+
encode(Action.AgentMessage);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function start(): void {
|
|
21
|
+
if (window.$crisp) {
|
|
22
|
+
window.$crisp.push(["on", "chat:opened", open]);
|
|
23
|
+
window.$crisp.push(["on", "chat:closed", close]);
|
|
24
|
+
window.$crisp.push(["on", "message:sent", human]);
|
|
25
|
+
window.$crisp.push(["on", "message:received", agent]);
|
|
26
|
+
}
|
|
27
|
+
// Register stop callback with main Clarity
|
|
28
|
+
if (typeof window !== "undefined" && (window as any).clarity) {
|
|
29
|
+
(window as any).clarity("register", stop);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function stop(): void {
|
|
34
|
+
if (window.$crisp) {
|
|
35
|
+
window.$crisp.push(["off", "chat:opened", open]);
|
|
36
|
+
window.$crisp.push(["off", "chat:closed", close]);
|
|
37
|
+
window.$crisp.push(["off", "message:sent", human]);
|
|
38
|
+
window.$crisp.push(["off", "message:received", agent]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { Event, Token } from "@clarity-types/data";
|
|
2
|
-
import { Action } from "@clarity-types/agent";
|
|
3
|
-
|
|
4
|
-
export default function (event: Action): void {
|
|
5
|
-
const t = (window as any).clarity("time");
|
|
6
|
-
let tokens: Token[] = [t, Event.Chat];
|
|
7
|
-
switch (event) {
|
|
8
|
-
case Action.AgentOnline:
|
|
9
|
-
case Action.AgentOffline:
|
|
10
|
-
case Action.AgentHidden:
|
|
11
|
-
case Action.AgentMaximized:
|
|
12
|
-
case Action.AgentMinimized:
|
|
13
|
-
case Action.AgentMessage:
|
|
14
|
-
case Action.HumanMessage:
|
|
15
|
-
tokens.push(event);
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
queueTokens(tokens);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function queueTokens(tokens: Token[]) {
|
|
22
|
-
if (typeof window !== "undefined" && (window as any).clarity) {
|
|
23
|
-
(window as any).clarity("queue", tokens);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import { Event, Token } from "@clarity-types/data";
|
|
2
|
+
import { Action } from "@clarity-types/agent";
|
|
3
|
+
|
|
4
|
+
export default function (event: Action): void {
|
|
5
|
+
const t = (window as any).clarity("time");
|
|
6
|
+
let tokens: Token[] = [t, Event.Chat];
|
|
7
|
+
switch (event) {
|
|
8
|
+
case Action.AgentOnline:
|
|
9
|
+
case Action.AgentOffline:
|
|
10
|
+
case Action.AgentHidden:
|
|
11
|
+
case Action.AgentMaximized:
|
|
12
|
+
case Action.AgentMinimized:
|
|
13
|
+
case Action.AgentMessage:
|
|
14
|
+
case Action.HumanMessage:
|
|
15
|
+
tokens.push(event);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
queueTokens(tokens);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function queueTokens(tokens: Token[]) {
|
|
22
|
+
if (typeof window !== "undefined" && (window as any).clarity) {
|
|
23
|
+
(window as any).clarity("queue", tokens);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as livechat from "@src/dynamic/agent/livechat";
|
|
2
|
-
import * as tidio from "@src/dynamic/agent/tidio";
|
|
3
|
-
import * as crisp from "@src/dynamic/agent/crisp";
|
|
4
|
-
(function () {
|
|
5
|
-
livechat.start();
|
|
6
|
-
tidio.start();
|
|
7
|
-
crisp.start();
|
|
8
|
-
})();
|
|
1
|
+
import * as livechat from "@src/dynamic/agent/livechat";
|
|
2
|
+
import * as tidio from "@src/dynamic/agent/tidio";
|
|
3
|
+
import * as crisp from "@src/dynamic/agent/crisp";
|
|
4
|
+
(function () {
|
|
5
|
+
livechat.start();
|
|
6
|
+
tidio.start();
|
|
7
|
+
crisp.start();
|
|
8
|
+
})();
|