clarity-js 0.8.1 → 0.8.3
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 +5537 -5537
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +5537 -5537
- 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 +53 -53
- 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 +155 -155
- 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 +140 -140
- package/src/data/envelope.ts +53 -53
- package/src/data/extract.ts +211 -211
- 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 -162
- package/src/interaction/clipboard.ts +34 -34
- package/src/interaction/encode.ts +193 -193
- 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 +437 -437
- package/src/layout/encode.ts +147 -147
- package/src/layout/index.ts +41 -41
- package/src/layout/mutation.ts +409 -409
- package/src/layout/node.ts +292 -292
- 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 -150
- 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 +153 -153
- package/types/data.d.ts +510 -510
- package/types/diagnostic.d.ts +24 -24
- package/types/index.d.ts +39 -39
- package/types/interaction.d.ts +165 -165
- package/types/layout.d.ts +272 -272
- package/types/performance.d.ts +64 -64
package/src/data/baseline.ts
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import { Event, BooleanFlag } from "@clarity-types/data";
|
|
2
|
-
import { BaselineData, BaselineState } from "@clarity-types/data";
|
|
3
|
-
import { time } from "@src/core/time";
|
|
4
|
-
import encode from "@src/data/encode";
|
|
5
|
-
|
|
6
|
-
export let state: BaselineState = null;
|
|
7
|
-
let buffer: BaselineData = null;
|
|
8
|
-
let update: boolean = false;
|
|
9
|
-
|
|
10
|
-
export function start(): void {
|
|
11
|
-
update = false;
|
|
12
|
-
reset();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function reset(): void {
|
|
16
|
-
// Baseline state holds the previous values - if it is updated in the current payload,
|
|
17
|
-
// reset the state to current value after sending the previous state
|
|
18
|
-
if (update) {
|
|
19
|
-
state = { time: time(), event: Event.Baseline, data: {
|
|
20
|
-
visible: buffer.visible,
|
|
21
|
-
docWidth: buffer.docWidth,
|
|
22
|
-
docHeight: buffer.docHeight,
|
|
23
|
-
screenWidth: buffer.screenWidth,
|
|
24
|
-
screenHeight: buffer.screenHeight,
|
|
25
|
-
scrollX: buffer.scrollX,
|
|
26
|
-
scrollY: buffer.scrollY,
|
|
27
|
-
pointerX: buffer.pointerX,
|
|
28
|
-
pointerY: buffer.pointerY,
|
|
29
|
-
activityTime: buffer.activityTime,
|
|
30
|
-
scrollTime: buffer.scrollTime,
|
|
31
|
-
pointerTime: buffer.pointerTime,
|
|
32
|
-
moveX: buffer.moveX,
|
|
33
|
-
moveY: buffer.moveY,
|
|
34
|
-
moveTime: buffer.moveTime,
|
|
35
|
-
downX: buffer.downX,
|
|
36
|
-
downY: buffer.downY,
|
|
37
|
-
downTime: buffer.downTime,
|
|
38
|
-
upX: buffer.upX,
|
|
39
|
-
upY: buffer.upY,
|
|
40
|
-
upTime: buffer.upTime,
|
|
41
|
-
pointerPrevX: buffer.pointerPrevX,
|
|
42
|
-
pointerPrevY: buffer.pointerPrevY,
|
|
43
|
-
pointerPrevTime: buffer.pointerPrevTime,
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
buffer = buffer ? buffer : {
|
|
48
|
-
visible: BooleanFlag.True,
|
|
49
|
-
docWidth: 0,
|
|
50
|
-
docHeight: 0,
|
|
51
|
-
screenWidth: 0,
|
|
52
|
-
screenHeight: 0,
|
|
53
|
-
scrollX: 0,
|
|
54
|
-
scrollY: 0,
|
|
55
|
-
pointerX: 0,
|
|
56
|
-
pointerY: 0,
|
|
57
|
-
activityTime: 0,
|
|
58
|
-
scrollTime: 0,
|
|
59
|
-
pointerTime: undefined,
|
|
60
|
-
moveX: undefined,
|
|
61
|
-
moveY: undefined,
|
|
62
|
-
moveTime: undefined,
|
|
63
|
-
downX: undefined,
|
|
64
|
-
downY: undefined,
|
|
65
|
-
downTime: undefined,
|
|
66
|
-
upX: undefined,
|
|
67
|
-
upY: undefined,
|
|
68
|
-
upTime: undefined,
|
|
69
|
-
pointerPrevX: undefined,
|
|
70
|
-
pointerPrevY: undefined,
|
|
71
|
-
pointerPrevTime: undefined,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function track(event: Event, x: number, y: number, time?: number): void {
|
|
76
|
-
switch (event) {
|
|
77
|
-
case Event.Document:
|
|
78
|
-
buffer.docWidth = x;
|
|
79
|
-
buffer.docHeight = y;
|
|
80
|
-
break;
|
|
81
|
-
case Event.Resize:
|
|
82
|
-
buffer.screenWidth = x;
|
|
83
|
-
buffer.screenHeight = y;
|
|
84
|
-
break;
|
|
85
|
-
case Event.Scroll:
|
|
86
|
-
buffer.scrollX = x;
|
|
87
|
-
buffer.scrollY = y;
|
|
88
|
-
buffer.scrollTime = time;
|
|
89
|
-
break;
|
|
90
|
-
case Event.MouseMove:
|
|
91
|
-
buffer.moveX = x;
|
|
92
|
-
buffer.moveY = y;
|
|
93
|
-
buffer.moveTime = time;
|
|
94
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
95
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
96
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
97
|
-
buffer.pointerX = x;
|
|
98
|
-
buffer.pointerY = y;
|
|
99
|
-
buffer.pointerTime = time;
|
|
100
|
-
break;
|
|
101
|
-
case Event.MouseDown:
|
|
102
|
-
buffer.downX = x;
|
|
103
|
-
buffer.downY = y;
|
|
104
|
-
buffer.downTime = time;
|
|
105
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
106
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
107
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
108
|
-
buffer.pointerX = x;
|
|
109
|
-
buffer.pointerY = y;
|
|
110
|
-
buffer.pointerTime = time;
|
|
111
|
-
break;
|
|
112
|
-
case Event.MouseUp:
|
|
113
|
-
buffer.upX = x;
|
|
114
|
-
buffer.upY = y;
|
|
115
|
-
buffer.upTime = time;
|
|
116
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
117
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
118
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
119
|
-
buffer.pointerX = x;
|
|
120
|
-
buffer.pointerY = y;
|
|
121
|
-
buffer.pointerTime = time;
|
|
122
|
-
break;
|
|
123
|
-
default:
|
|
124
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
125
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
126
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
127
|
-
buffer.pointerX = x;
|
|
128
|
-
buffer.pointerY = y;
|
|
129
|
-
buffer.pointerTime = time;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
update = true;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function activity(t: number): void {
|
|
136
|
-
buffer.activityTime = t;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function visibility(t: number, visible: string): void {
|
|
140
|
-
buffer.visible = visible === "visible" ? BooleanFlag.True : BooleanFlag.False;
|
|
141
|
-
if (!buffer.visible) {
|
|
142
|
-
activity(t);
|
|
143
|
-
}
|
|
144
|
-
update = true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function compute(): void {
|
|
148
|
-
if (update) {
|
|
149
|
-
encode(Event.Baseline);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function stop(): void {
|
|
154
|
-
reset();
|
|
155
|
-
}
|
|
1
|
+
import { Event, BooleanFlag } from "@clarity-types/data";
|
|
2
|
+
import { BaselineData, BaselineState } from "@clarity-types/data";
|
|
3
|
+
import { time } from "@src/core/time";
|
|
4
|
+
import encode from "@src/data/encode";
|
|
5
|
+
|
|
6
|
+
export let state: BaselineState = null;
|
|
7
|
+
let buffer: BaselineData = null;
|
|
8
|
+
let update: boolean = false;
|
|
9
|
+
|
|
10
|
+
export function start(): void {
|
|
11
|
+
update = false;
|
|
12
|
+
reset();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function reset(): void {
|
|
16
|
+
// Baseline state holds the previous values - if it is updated in the current payload,
|
|
17
|
+
// reset the state to current value after sending the previous state
|
|
18
|
+
if (update) {
|
|
19
|
+
state = { time: time(), event: Event.Baseline, data: {
|
|
20
|
+
visible: buffer.visible,
|
|
21
|
+
docWidth: buffer.docWidth,
|
|
22
|
+
docHeight: buffer.docHeight,
|
|
23
|
+
screenWidth: buffer.screenWidth,
|
|
24
|
+
screenHeight: buffer.screenHeight,
|
|
25
|
+
scrollX: buffer.scrollX,
|
|
26
|
+
scrollY: buffer.scrollY,
|
|
27
|
+
pointerX: buffer.pointerX,
|
|
28
|
+
pointerY: buffer.pointerY,
|
|
29
|
+
activityTime: buffer.activityTime,
|
|
30
|
+
scrollTime: buffer.scrollTime,
|
|
31
|
+
pointerTime: buffer.pointerTime,
|
|
32
|
+
moveX: buffer.moveX,
|
|
33
|
+
moveY: buffer.moveY,
|
|
34
|
+
moveTime: buffer.moveTime,
|
|
35
|
+
downX: buffer.downX,
|
|
36
|
+
downY: buffer.downY,
|
|
37
|
+
downTime: buffer.downTime,
|
|
38
|
+
upX: buffer.upX,
|
|
39
|
+
upY: buffer.upY,
|
|
40
|
+
upTime: buffer.upTime,
|
|
41
|
+
pointerPrevX: buffer.pointerPrevX,
|
|
42
|
+
pointerPrevY: buffer.pointerPrevY,
|
|
43
|
+
pointerPrevTime: buffer.pointerPrevTime,
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
buffer = buffer ? buffer : {
|
|
48
|
+
visible: BooleanFlag.True,
|
|
49
|
+
docWidth: 0,
|
|
50
|
+
docHeight: 0,
|
|
51
|
+
screenWidth: 0,
|
|
52
|
+
screenHeight: 0,
|
|
53
|
+
scrollX: 0,
|
|
54
|
+
scrollY: 0,
|
|
55
|
+
pointerX: 0,
|
|
56
|
+
pointerY: 0,
|
|
57
|
+
activityTime: 0,
|
|
58
|
+
scrollTime: 0,
|
|
59
|
+
pointerTime: undefined,
|
|
60
|
+
moveX: undefined,
|
|
61
|
+
moveY: undefined,
|
|
62
|
+
moveTime: undefined,
|
|
63
|
+
downX: undefined,
|
|
64
|
+
downY: undefined,
|
|
65
|
+
downTime: undefined,
|
|
66
|
+
upX: undefined,
|
|
67
|
+
upY: undefined,
|
|
68
|
+
upTime: undefined,
|
|
69
|
+
pointerPrevX: undefined,
|
|
70
|
+
pointerPrevY: undefined,
|
|
71
|
+
pointerPrevTime: undefined,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function track(event: Event, x: number, y: number, time?: number): void {
|
|
76
|
+
switch (event) {
|
|
77
|
+
case Event.Document:
|
|
78
|
+
buffer.docWidth = x;
|
|
79
|
+
buffer.docHeight = y;
|
|
80
|
+
break;
|
|
81
|
+
case Event.Resize:
|
|
82
|
+
buffer.screenWidth = x;
|
|
83
|
+
buffer.screenHeight = y;
|
|
84
|
+
break;
|
|
85
|
+
case Event.Scroll:
|
|
86
|
+
buffer.scrollX = x;
|
|
87
|
+
buffer.scrollY = y;
|
|
88
|
+
buffer.scrollTime = time;
|
|
89
|
+
break;
|
|
90
|
+
case Event.MouseMove:
|
|
91
|
+
buffer.moveX = x;
|
|
92
|
+
buffer.moveY = y;
|
|
93
|
+
buffer.moveTime = time;
|
|
94
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
95
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
96
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
97
|
+
buffer.pointerX = x;
|
|
98
|
+
buffer.pointerY = y;
|
|
99
|
+
buffer.pointerTime = time;
|
|
100
|
+
break;
|
|
101
|
+
case Event.MouseDown:
|
|
102
|
+
buffer.downX = x;
|
|
103
|
+
buffer.downY = y;
|
|
104
|
+
buffer.downTime = time;
|
|
105
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
106
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
107
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
108
|
+
buffer.pointerX = x;
|
|
109
|
+
buffer.pointerY = y;
|
|
110
|
+
buffer.pointerTime = time;
|
|
111
|
+
break;
|
|
112
|
+
case Event.MouseUp:
|
|
113
|
+
buffer.upX = x;
|
|
114
|
+
buffer.upY = y;
|
|
115
|
+
buffer.upTime = time;
|
|
116
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
117
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
118
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
119
|
+
buffer.pointerX = x;
|
|
120
|
+
buffer.pointerY = y;
|
|
121
|
+
buffer.pointerTime = time;
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
125
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
126
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
127
|
+
buffer.pointerX = x;
|
|
128
|
+
buffer.pointerY = y;
|
|
129
|
+
buffer.pointerTime = time;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
update = true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function activity(t: number): void {
|
|
136
|
+
buffer.activityTime = t;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function visibility(t: number, visible: string): void {
|
|
140
|
+
buffer.visible = visible === "visible" ? BooleanFlag.True : BooleanFlag.False;
|
|
141
|
+
if (!buffer.visible) {
|
|
142
|
+
activity(t);
|
|
143
|
+
}
|
|
144
|
+
update = true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function compute(): void {
|
|
148
|
+
if (update) {
|
|
149
|
+
encode(Event.Baseline);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function stop(): void {
|
|
154
|
+
reset();
|
|
155
|
+
}
|
package/src/data/compress.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { Constant } from "@clarity-types/data";
|
|
2
|
-
|
|
3
|
-
const supported = Constant.CompressionStream in window;
|
|
4
|
-
|
|
5
|
-
export default async function(input: string): Promise<Uint8Array> {
|
|
6
|
-
try {
|
|
7
|
-
if (supported) {
|
|
8
|
-
// Create a readable stream from given input string and
|
|
9
|
-
// pipe it through text encoder and compression stream to gzip it
|
|
10
|
-
const stream = new ReadableStream({async start(controller) {
|
|
11
|
-
controller.enqueue(input);
|
|
12
|
-
controller.close();
|
|
13
|
-
}}).pipeThrough(new TextEncoderStream()).pipeThrough(new window[Constant.CompressionStream]("gzip"));
|
|
14
|
-
return new Uint8Array(await read(stream));
|
|
15
|
-
}
|
|
16
|
-
} catch { /* do nothing */ }
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function read(stream: ReadableStream): Promise<number[]> {
|
|
21
|
-
const reader = stream.getReader();
|
|
22
|
-
const chunks:number[] = [];
|
|
23
|
-
let done = false;
|
|
24
|
-
let value: number[] = [];
|
|
25
|
-
while (!done) {
|
|
26
|
-
({ done, value } = await reader.read());
|
|
27
|
-
if (done) { return chunks; }
|
|
28
|
-
chunks.push(...value);
|
|
29
|
-
}
|
|
30
|
-
return chunks;
|
|
31
|
-
}
|
|
1
|
+
import { Constant } from "@clarity-types/data";
|
|
2
|
+
|
|
3
|
+
const supported = Constant.CompressionStream in window;
|
|
4
|
+
|
|
5
|
+
export default async function(input: string): Promise<Uint8Array> {
|
|
6
|
+
try {
|
|
7
|
+
if (supported) {
|
|
8
|
+
// Create a readable stream from given input string and
|
|
9
|
+
// pipe it through text encoder and compression stream to gzip it
|
|
10
|
+
const stream = new ReadableStream({async start(controller) {
|
|
11
|
+
controller.enqueue(input);
|
|
12
|
+
controller.close();
|
|
13
|
+
}}).pipeThrough(new TextEncoderStream()).pipeThrough(new window[Constant.CompressionStream]("gzip"));
|
|
14
|
+
return new Uint8Array(await read(stream));
|
|
15
|
+
}
|
|
16
|
+
} catch { /* do nothing */ }
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function read(stream: ReadableStream): Promise<number[]> {
|
|
21
|
+
const reader = stream.getReader();
|
|
22
|
+
const chunks:number[] = [];
|
|
23
|
+
let done = false;
|
|
24
|
+
let value: number[] = [];
|
|
25
|
+
while (!done) {
|
|
26
|
+
({ done, value } = await reader.read());
|
|
27
|
+
if (done) { return chunks; }
|
|
28
|
+
chunks.push(...value);
|
|
29
|
+
}
|
|
30
|
+
return chunks;
|
|
31
|
+
}
|
package/src/data/consent.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { Dimension } from "@clarity-types/data";
|
|
2
|
-
import * as dimension from "@src/data/dimension";
|
|
3
|
-
|
|
4
|
-
const enum ConsentType {
|
|
5
|
-
None = 0,
|
|
6
|
-
Implicit = 1,
|
|
7
|
-
General = 2
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function config(track: boolean): void {
|
|
11
|
-
trackConsent(track ? ConsentType.Implicit : ConsentType.None);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// When we get consent signal as false, we restart the service and track config as false.
|
|
15
|
-
export function consent(): void {
|
|
16
|
-
trackConsent(ConsentType.General);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function trackConsent(consent: ConsentType): void {
|
|
20
|
-
dimension.log(Dimension.Consent, consent.toString());
|
|
1
|
+
import { Dimension } from "@clarity-types/data";
|
|
2
|
+
import * as dimension from "@src/data/dimension";
|
|
3
|
+
|
|
4
|
+
const enum ConsentType {
|
|
5
|
+
None = 0,
|
|
6
|
+
Implicit = 1,
|
|
7
|
+
General = 2
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function config(track: boolean): void {
|
|
11
|
+
trackConsent(track ? ConsentType.Implicit : ConsentType.None);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// When we get consent signal as false, we restart the service and track config as false.
|
|
15
|
+
export function consent(): void {
|
|
16
|
+
trackConsent(ConsentType.General);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function trackConsent(consent: ConsentType): void {
|
|
20
|
+
dimension.log(Dimension.Consent, consent.toString());
|
|
21
21
|
}
|
package/src/data/custom.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Constant, CustomData, Event } from "@clarity-types/data";
|
|
2
|
-
import * as core from "@src/core";
|
|
3
|
-
import encode from "./encode";
|
|
4
|
-
|
|
5
|
-
export let data: CustomData = null;
|
|
6
|
-
|
|
7
|
-
// custom events allow 2 parameters or 1 parameter to be passed. If 2 are passed we
|
|
8
|
-
// consider it a key value pair. If only 1 is passed we only consider the event to have a value.
|
|
9
|
-
export function event(a: string, b: string): void {
|
|
10
|
-
if (core.active() &&
|
|
11
|
-
a &&
|
|
12
|
-
typeof a === Constant.String &&
|
|
13
|
-
a.length < 255
|
|
14
|
-
) {
|
|
15
|
-
if (b && typeof b === Constant.String && b.length < 255) {
|
|
16
|
-
data = { key: a, value: b};
|
|
17
|
-
} else {
|
|
18
|
-
data = { value: a }
|
|
19
|
-
}
|
|
20
|
-
encode(Event.Custom);
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
import { Constant, CustomData, Event } from "@clarity-types/data";
|
|
2
|
+
import * as core from "@src/core";
|
|
3
|
+
import encode from "./encode";
|
|
4
|
+
|
|
5
|
+
export let data: CustomData = null;
|
|
6
|
+
|
|
7
|
+
// custom events allow 2 parameters or 1 parameter to be passed. If 2 are passed we
|
|
8
|
+
// consider it a key value pair. If only 1 is passed we only consider the event to have a value.
|
|
9
|
+
export function event(a: string, b: string): void {
|
|
10
|
+
if (core.active() &&
|
|
11
|
+
a &&
|
|
12
|
+
typeof a === Constant.String &&
|
|
13
|
+
a.length < 255
|
|
14
|
+
) {
|
|
15
|
+
if (b && typeof b === Constant.String && b.length < 255) {
|
|
16
|
+
data = { key: a, value: b};
|
|
17
|
+
} else {
|
|
18
|
+
data = { value: a }
|
|
19
|
+
}
|
|
20
|
+
encode(Event.Custom);
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/data/dimension.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { Check, Event, Dimension, DimensionData, Setting } from "@clarity-types/data";
|
|
2
|
-
import * as limit from "@src/data/limit";
|
|
3
|
-
import encode from "./encode";
|
|
4
|
-
|
|
5
|
-
export let data: DimensionData = null;
|
|
6
|
-
export let updates: DimensionData = null;
|
|
7
|
-
let limited = false;
|
|
8
|
-
|
|
9
|
-
export function start(): void {
|
|
10
|
-
data = {};
|
|
11
|
-
updates = {};
|
|
12
|
-
limited = false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function stop(): void {
|
|
16
|
-
data = {};
|
|
17
|
-
updates = {};
|
|
18
|
-
limited = false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function log(dimension: Dimension, value: string): void {
|
|
22
|
-
// Check valid value before moving ahead
|
|
23
|
-
if (value) {
|
|
24
|
-
// Ensure received value is casted into a string if it wasn't a string to begin with
|
|
25
|
-
value = `${value}`;
|
|
26
|
-
if (!(dimension in data)) { data[dimension] = []; }
|
|
27
|
-
if (data[dimension].indexOf(value) < 0) {
|
|
28
|
-
// Limit check to ensure we have a cap on number of dimensions we can collect
|
|
29
|
-
if (data[dimension].length > Setting.CollectionLimit) {
|
|
30
|
-
if (!limited) {
|
|
31
|
-
limited = true;
|
|
32
|
-
limit.trigger(Check.Collection);
|
|
33
|
-
}
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
data[dimension].push(value);
|
|
38
|
-
// If this is a new value, track it as part of updates object
|
|
39
|
-
// This allows us to only send back new values in subsequent payloads
|
|
40
|
-
if (!(dimension in updates)) { updates[dimension] = []; }
|
|
41
|
-
updates[dimension].push(value);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function compute(): void {
|
|
47
|
-
encode(Event.Dimension);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function reset(): void {
|
|
51
|
-
updates = {};
|
|
52
|
-
limited = false;
|
|
53
|
-
}
|
|
1
|
+
import { Check, Event, Dimension, DimensionData, Setting } from "@clarity-types/data";
|
|
2
|
+
import * as limit from "@src/data/limit";
|
|
3
|
+
import encode from "./encode";
|
|
4
|
+
|
|
5
|
+
export let data: DimensionData = null;
|
|
6
|
+
export let updates: DimensionData = null;
|
|
7
|
+
let limited = false;
|
|
8
|
+
|
|
9
|
+
export function start(): void {
|
|
10
|
+
data = {};
|
|
11
|
+
updates = {};
|
|
12
|
+
limited = false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function stop(): void {
|
|
16
|
+
data = {};
|
|
17
|
+
updates = {};
|
|
18
|
+
limited = false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function log(dimension: Dimension, value: string): void {
|
|
22
|
+
// Check valid value before moving ahead
|
|
23
|
+
if (value) {
|
|
24
|
+
// Ensure received value is casted into a string if it wasn't a string to begin with
|
|
25
|
+
value = `${value}`;
|
|
26
|
+
if (!(dimension in data)) { data[dimension] = []; }
|
|
27
|
+
if (data[dimension].indexOf(value) < 0) {
|
|
28
|
+
// Limit check to ensure we have a cap on number of dimensions we can collect
|
|
29
|
+
if (data[dimension].length > Setting.CollectionLimit) {
|
|
30
|
+
if (!limited) {
|
|
31
|
+
limited = true;
|
|
32
|
+
limit.trigger(Check.Collection);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
data[dimension].push(value);
|
|
38
|
+
// If this is a new value, track it as part of updates object
|
|
39
|
+
// This allows us to only send back new values in subsequent payloads
|
|
40
|
+
if (!(dimension in updates)) { updates[dimension] = []; }
|
|
41
|
+
updates[dimension].push(value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function compute(): void {
|
|
47
|
+
encode(Event.Dimension);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function reset(): void {
|
|
51
|
+
updates = {};
|
|
52
|
+
limited = false;
|
|
53
|
+
}
|