clarity-js 0.6.34 → 0.6.35
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/build/clarity.js +253 -324
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +253 -324
- package/package.json +1 -1
- package/src/core/config.ts +1 -0
- package/src/core/history.ts +10 -3
- package/src/core/version.ts +1 -1
- package/src/data/metadata.ts +1 -2
- package/src/data/metric.ts +3 -3
- package/src/diagnostic/encode.ts +9 -0
- package/src/diagnostic/fraud.ts +29 -0
- package/src/diagnostic/index.ts +2 -0
- package/src/diagnostic/script.ts +1 -11
- package/src/interaction/click.ts +2 -1
- package/src/interaction/encode.ts +4 -3
- package/src/interaction/input.ts +1 -8
- package/src/layout/dom.ts +70 -82
- package/src/layout/encode.ts +15 -15
- package/src/layout/index.ts +0 -3
- package/src/layout/target.ts +7 -4
- package/src/performance/observer.ts +10 -2
- package/types/core.d.ts +2 -0
- package/types/data.d.ts +11 -5
- package/types/diagnostic.d.ts +6 -0
- package/types/interaction.d.ts +1 -0
- package/types/layout.d.ts +7 -6
- package/types/performance.d.ts +0 -7
- package/src/layout/box.ts +0 -83
package/types/core.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ type TaskFunction = () => Promise<void>;
|
|
|
4
4
|
type TaskResolve = () => void;
|
|
5
5
|
type UploadCallback = (data: string) => void;
|
|
6
6
|
type Region = [number /* RegionId */, string /* Query Selector */];
|
|
7
|
+
type Fraud = [number /* FraudId */, string /* Query Selector */];
|
|
7
8
|
export type Extract = ExtractSource /* Extraction Source */ | number /* Extract Id */ | string | string[] /* Hash or Query Selector or String Token */;
|
|
8
9
|
|
|
9
10
|
/* Enum */
|
|
@@ -127,6 +128,7 @@ export interface Config {
|
|
|
127
128
|
regions?: Region[];
|
|
128
129
|
extract?: Extract[];
|
|
129
130
|
cookies?: string[];
|
|
131
|
+
fraud?: Fraud[];
|
|
130
132
|
report?: string;
|
|
131
133
|
upload?: string | UploadCallback;
|
|
132
134
|
fallback?: string;
|
package/types/data.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Time } from "@clarity-types/core";
|
|
2
|
-
import { callback } from "@src/data/metadata";
|
|
3
2
|
export type Target = (number | Node);
|
|
4
3
|
export type Token = (string | number | number[] | string[]);
|
|
5
4
|
export type DecodedToken = (any | any[]);
|
|
@@ -56,10 +55,14 @@ export const enum Event {
|
|
|
56
55
|
Variable = 34,
|
|
57
56
|
Limit = 35,
|
|
58
57
|
Summary = 36,
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated No longer support Box event
|
|
60
|
+
*/
|
|
59
61
|
Box = 37,
|
|
60
62
|
Clipboard = 38,
|
|
61
63
|
Submit = 39,
|
|
62
|
-
Extract = 40
|
|
64
|
+
Extract = 40,
|
|
65
|
+
Fraud = 41
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
export const enum Metric {
|
|
@@ -90,7 +93,10 @@ export const enum Metric {
|
|
|
90
93
|
CartTotal = 24,
|
|
91
94
|
EventCount = 25,
|
|
92
95
|
Automation = 26,
|
|
93
|
-
Mobile = 27
|
|
96
|
+
Mobile = 27,
|
|
97
|
+
UploadTime = 28,
|
|
98
|
+
SinglePage = 29,
|
|
99
|
+
UsedMemory = 30
|
|
94
100
|
}
|
|
95
101
|
|
|
96
102
|
export const enum Dimension {
|
|
@@ -181,7 +187,6 @@ export const enum Setting {
|
|
|
181
187
|
CollectionLimit = 128, // Number of unique entries for dimensions
|
|
182
188
|
ClickPrecision = 32767, // 2^15 - 1
|
|
183
189
|
BoxPrecision = 100, // Up to 2 decimal points (e.g. 34.56)
|
|
184
|
-
ResizeObserverThreshold = 15, // At least 15 characters before we attach a resize observer for the node
|
|
185
190
|
ScriptErrorLimit = 5, // Do not send the same script error more than 5 times per page
|
|
186
191
|
DimensionLimit = 256, // Do not extract dimensions which are over 256 characters
|
|
187
192
|
WordLength = 5, // Estimated average size of a word,
|
|
@@ -191,6 +196,7 @@ export const enum Setting {
|
|
|
191
196
|
ViewportIntersectionRatio = 0.05, // Ratio of intersection area in comparison to viewport area before it's marked visible
|
|
192
197
|
IntersectionRatio = 0.8, // Ratio of intersection area in comparison to element's area before it's marked visible
|
|
193
198
|
MaxFirstPayloadBytes = 1 * 1024 * 1024, // 1MB: Cap the very first payload to a maximum of 1MB
|
|
199
|
+
MegaByte = 1024 * 1024, // 1MB
|
|
194
200
|
UploadFactor = 3, // Slow down sequence by specified factor
|
|
195
201
|
MinUploadDelay = 100, // Minimum time before we are ready to flush events to the server
|
|
196
202
|
MaxUploadDelay = 30 * Time.Second, // Do flush out payload once every 30s,
|
|
@@ -216,6 +222,7 @@ export const enum Constant {
|
|
|
216
222
|
Pause = "pause",
|
|
217
223
|
Resume = "resume",
|
|
218
224
|
Report = "report",
|
|
225
|
+
Memory = "memory",
|
|
219
226
|
Empty = "",
|
|
220
227
|
Space = " ",
|
|
221
228
|
Expires = "expires=",
|
|
@@ -240,7 +247,6 @@ export const enum Constant {
|
|
|
240
247
|
UserId = "userId",
|
|
241
248
|
SessionId = "sessionId",
|
|
242
249
|
PageId = "pageId",
|
|
243
|
-
ResizeObserver = "ResizeObserver",
|
|
244
250
|
Mask = "•",
|
|
245
251
|
SessionStorage = "sessionStorage",
|
|
246
252
|
Cookie = "cookie",
|
package/types/diagnostic.d.ts
CHANGED
package/types/interaction.d.ts
CHANGED
package/types/layout.d.ts
CHANGED
|
@@ -28,6 +28,11 @@ export const enum RegionVisibility {
|
|
|
28
28
|
ScrolledToEnd = 13
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export const enum Mask {
|
|
32
|
+
Text = "password,secret,pass,social,ssn,name,code,dob,cell,mob,contact,hidden,account,cvv,ccv,email,tel,phone,address,addr,card,zip",
|
|
33
|
+
Disable = "radio,checkbox,range,button,reset,submit"
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
export const enum Constant {
|
|
32
37
|
Empty = "",
|
|
33
38
|
SvgPrefix = "svg:",
|
|
@@ -42,6 +47,7 @@ export const enum Constant {
|
|
|
42
47
|
Box = "#",
|
|
43
48
|
Bang = "!",
|
|
44
49
|
Period = ".",
|
|
50
|
+
Comma = ",",
|
|
45
51
|
MaskData = "data-clarity-mask",
|
|
46
52
|
UnmaskData = "data-clarity-unmask",
|
|
47
53
|
RegionData = "data-clarity-region",
|
|
@@ -162,6 +168,7 @@ export interface NodeMeta {
|
|
|
162
168
|
suspend: boolean;
|
|
163
169
|
privacy: Privacy;
|
|
164
170
|
position: number;
|
|
171
|
+
fraud: number;
|
|
165
172
|
size: number[];
|
|
166
173
|
}
|
|
167
174
|
|
|
@@ -198,12 +205,6 @@ export interface RegionData {
|
|
|
198
205
|
name: string;
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
export interface BoxData {
|
|
202
|
-
id: number;
|
|
203
|
-
width: number;
|
|
204
|
-
height: number;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
208
|
export interface TargetMetadata {
|
|
208
209
|
id: number;
|
|
209
210
|
hash: [string, string];
|
package/types/performance.d.ts
CHANGED
package/src/layout/box.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Event, Setting } from "@clarity-types/data";
|
|
2
|
-
import { BoxData } from "@clarity-types/layout";
|
|
3
|
-
import * as dom from "@src/layout/dom";
|
|
4
|
-
import encode from "@src/layout/encode";
|
|
5
|
-
|
|
6
|
-
export let data: BoxData[] = [];
|
|
7
|
-
let enabled = false;
|
|
8
|
-
let observer: ResizeObserver = null;
|
|
9
|
-
|
|
10
|
-
export function start(): void {
|
|
11
|
-
reset();
|
|
12
|
-
observer = null;
|
|
13
|
-
enabled = window["ResizeObserver"] ? true : false;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function compute(id: number): void {
|
|
17
|
-
if (enabled === false) { return; }
|
|
18
|
-
observer = observer === null ? new ResizeObserver(handler) : observer;
|
|
19
|
-
if (observer) {
|
|
20
|
-
let value = dom.getValue(id);
|
|
21
|
-
// If this is the first time computing size for this node, go ahead and wire up ResizeObserver
|
|
22
|
-
// In all other cases, value.metadata.size will be null or an array with two elements [width, height]
|
|
23
|
-
// And, in those cases, we will skip through the following section and not attach the observer
|
|
24
|
-
if (value && value.metadata.size !== null && value.metadata.size.length === 0) {
|
|
25
|
-
let node = dom.getNode(id);
|
|
26
|
-
if (node && node.nodeType === Node.ELEMENT_NODE) {
|
|
27
|
-
let e = node as HTMLElement;
|
|
28
|
-
let r = e.getBoundingClientRect();
|
|
29
|
-
value.metadata.size = [Math.floor(r.width * Setting.BoxPrecision), Math.floor(r.height * Setting.BoxPrecision)];
|
|
30
|
-
observer.observe(e);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function handler(entries: ResizeObserverEntry[]): void {
|
|
37
|
-
window.requestAnimationFrame(() => {
|
|
38
|
-
for (let entry of entries) {
|
|
39
|
-
let target = entry.target;
|
|
40
|
-
let id = target ? dom.getId(target) : null;
|
|
41
|
-
if (id) {
|
|
42
|
-
let v = dom.getValue(id);
|
|
43
|
-
let s = v.metadata.size;
|
|
44
|
-
let b = entry.borderBoxSize as any;
|
|
45
|
-
let w = null;
|
|
46
|
-
let h = null;
|
|
47
|
-
// Check if browser supports borderBoxSize property on ResizeObserverEntry object
|
|
48
|
-
// Otherwise, fall back to using getBoundingClientRect() to be cross browser compatible
|
|
49
|
-
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/borderBoxSize
|
|
50
|
-
if(b && b.length > 0) {
|
|
51
|
-
w = Math.floor(b[0].inlineSize * Setting.BoxPrecision);
|
|
52
|
-
h = Math.floor(b[0].blockSize * Setting.BoxPrecision);
|
|
53
|
-
} else {
|
|
54
|
-
let r = target.getBoundingClientRect();
|
|
55
|
-
w = Math.floor(r.width * Setting.BoxPrecision);
|
|
56
|
-
h = Math.floor(r.height * Setting.BoxPrecision);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Capture new width & height only if they are different from what we have in in-memory cache
|
|
60
|
-
if (w !== s[0] && h !== s[1]) {
|
|
61
|
-
s = [w,h];
|
|
62
|
-
data.push({ id, width: w, height: h });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Schedule encode only when we have at least one valid data entry
|
|
68
|
-
if (data.length > 0) { encode(Event.Box); }
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function reset(): void {
|
|
73
|
-
data = [];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function stop(): void {
|
|
77
|
-
reset();
|
|
78
|
-
if (observer) {
|
|
79
|
-
observer.disconnect();
|
|
80
|
-
observer = null;
|
|
81
|
-
}
|
|
82
|
-
enabled = false;
|
|
83
|
-
}
|