clarity-js 0.8.42 → 0.8.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -26
- package/build/clarity.extended.js +1 -1
- package/build/clarity.insight.js +1 -1
- package/build/clarity.js +6043 -6030
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +6043 -6030
- 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/dynamic.ts +13 -7
- 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 +204 -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 +411 -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 +572 -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/baseline.ts
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
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
|
-
modules: buffer.modules,
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
buffer = buffer ? buffer : {
|
|
49
|
-
visible: BooleanFlag.True,
|
|
50
|
-
docWidth: 0,
|
|
51
|
-
docHeight: 0,
|
|
52
|
-
screenWidth: 0,
|
|
53
|
-
screenHeight: 0,
|
|
54
|
-
scrollX: 0,
|
|
55
|
-
scrollY: 0,
|
|
56
|
-
pointerX: 0,
|
|
57
|
-
pointerY: 0,
|
|
58
|
-
activityTime: 0,
|
|
59
|
-
scrollTime: 0,
|
|
60
|
-
pointerTime: undefined,
|
|
61
|
-
moveX: undefined,
|
|
62
|
-
moveY: undefined,
|
|
63
|
-
moveTime: undefined,
|
|
64
|
-
downX: undefined,
|
|
65
|
-
downY: undefined,
|
|
66
|
-
downTime: undefined,
|
|
67
|
-
upX: undefined,
|
|
68
|
-
upY: undefined,
|
|
69
|
-
upTime: undefined,
|
|
70
|
-
pointerPrevX: undefined,
|
|
71
|
-
pointerPrevY: undefined,
|
|
72
|
-
pointerPrevTime: undefined,
|
|
73
|
-
modules: null,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function track(event: Event, x: number, y: number, time?: number): void {
|
|
78
|
-
switch (event) {
|
|
79
|
-
case Event.Document:
|
|
80
|
-
buffer.docWidth = x;
|
|
81
|
-
buffer.docHeight = y;
|
|
82
|
-
break;
|
|
83
|
-
case Event.Resize:
|
|
84
|
-
buffer.screenWidth = x;
|
|
85
|
-
buffer.screenHeight = y;
|
|
86
|
-
break;
|
|
87
|
-
case Event.Scroll:
|
|
88
|
-
buffer.scrollX = x;
|
|
89
|
-
buffer.scrollY = y;
|
|
90
|
-
buffer.scrollTime = time;
|
|
91
|
-
break;
|
|
92
|
-
case Event.MouseMove:
|
|
93
|
-
buffer.moveX = x;
|
|
94
|
-
buffer.moveY = y;
|
|
95
|
-
buffer.moveTime = time;
|
|
96
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
97
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
98
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
99
|
-
buffer.pointerX = x;
|
|
100
|
-
buffer.pointerY = y;
|
|
101
|
-
buffer.pointerTime = time;
|
|
102
|
-
break;
|
|
103
|
-
case Event.MouseDown:
|
|
104
|
-
buffer.downX = x;
|
|
105
|
-
buffer.downY = y;
|
|
106
|
-
buffer.downTime = time;
|
|
107
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
108
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
109
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
110
|
-
buffer.pointerX = x;
|
|
111
|
-
buffer.pointerY = y;
|
|
112
|
-
buffer.pointerTime = time;
|
|
113
|
-
break;
|
|
114
|
-
case Event.MouseUp:
|
|
115
|
-
buffer.upX = x;
|
|
116
|
-
buffer.upY = y;
|
|
117
|
-
buffer.upTime = time;
|
|
118
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
119
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
120
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
121
|
-
buffer.pointerX = x;
|
|
122
|
-
buffer.pointerY = y;
|
|
123
|
-
buffer.pointerTime = time;
|
|
124
|
-
break;
|
|
125
|
-
default:
|
|
126
|
-
buffer.pointerPrevX = buffer.pointerX;
|
|
127
|
-
buffer.pointerPrevY = buffer.pointerY;
|
|
128
|
-
buffer.pointerPrevTime = buffer.pointerTime;
|
|
129
|
-
buffer.pointerX = x;
|
|
130
|
-
buffer.pointerY = y;
|
|
131
|
-
buffer.pointerTime = time;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
update = true;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function activity(t: number): void {
|
|
138
|
-
buffer.activityTime = t;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function visibility(t: number, visible: BooleanFlag): void {
|
|
142
|
-
buffer.visible = visible;
|
|
143
|
-
if (!buffer.visible) {
|
|
144
|
-
activity(t);
|
|
145
|
-
}
|
|
146
|
-
update = true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function dynamic(modules: Set<number>): void {
|
|
150
|
-
buffer.modules = Array.from(modules);
|
|
151
|
-
update = true;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function compute(): void {
|
|
155
|
-
if (update) {
|
|
156
|
-
encode(Event.Baseline);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function stop(): void {
|
|
161
|
-
reset();
|
|
162
|
-
}
|
|
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
|
+
modules: buffer.modules,
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
buffer = buffer ? buffer : {
|
|
49
|
+
visible: BooleanFlag.True,
|
|
50
|
+
docWidth: 0,
|
|
51
|
+
docHeight: 0,
|
|
52
|
+
screenWidth: 0,
|
|
53
|
+
screenHeight: 0,
|
|
54
|
+
scrollX: 0,
|
|
55
|
+
scrollY: 0,
|
|
56
|
+
pointerX: 0,
|
|
57
|
+
pointerY: 0,
|
|
58
|
+
activityTime: 0,
|
|
59
|
+
scrollTime: 0,
|
|
60
|
+
pointerTime: undefined,
|
|
61
|
+
moveX: undefined,
|
|
62
|
+
moveY: undefined,
|
|
63
|
+
moveTime: undefined,
|
|
64
|
+
downX: undefined,
|
|
65
|
+
downY: undefined,
|
|
66
|
+
downTime: undefined,
|
|
67
|
+
upX: undefined,
|
|
68
|
+
upY: undefined,
|
|
69
|
+
upTime: undefined,
|
|
70
|
+
pointerPrevX: undefined,
|
|
71
|
+
pointerPrevY: undefined,
|
|
72
|
+
pointerPrevTime: undefined,
|
|
73
|
+
modules: null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function track(event: Event, x: number, y: number, time?: number): void {
|
|
78
|
+
switch (event) {
|
|
79
|
+
case Event.Document:
|
|
80
|
+
buffer.docWidth = x;
|
|
81
|
+
buffer.docHeight = y;
|
|
82
|
+
break;
|
|
83
|
+
case Event.Resize:
|
|
84
|
+
buffer.screenWidth = x;
|
|
85
|
+
buffer.screenHeight = y;
|
|
86
|
+
break;
|
|
87
|
+
case Event.Scroll:
|
|
88
|
+
buffer.scrollX = x;
|
|
89
|
+
buffer.scrollY = y;
|
|
90
|
+
buffer.scrollTime = time;
|
|
91
|
+
break;
|
|
92
|
+
case Event.MouseMove:
|
|
93
|
+
buffer.moveX = x;
|
|
94
|
+
buffer.moveY = y;
|
|
95
|
+
buffer.moveTime = time;
|
|
96
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
97
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
98
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
99
|
+
buffer.pointerX = x;
|
|
100
|
+
buffer.pointerY = y;
|
|
101
|
+
buffer.pointerTime = time;
|
|
102
|
+
break;
|
|
103
|
+
case Event.MouseDown:
|
|
104
|
+
buffer.downX = x;
|
|
105
|
+
buffer.downY = y;
|
|
106
|
+
buffer.downTime = time;
|
|
107
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
108
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
109
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
110
|
+
buffer.pointerX = x;
|
|
111
|
+
buffer.pointerY = y;
|
|
112
|
+
buffer.pointerTime = time;
|
|
113
|
+
break;
|
|
114
|
+
case Event.MouseUp:
|
|
115
|
+
buffer.upX = x;
|
|
116
|
+
buffer.upY = y;
|
|
117
|
+
buffer.upTime = time;
|
|
118
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
119
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
120
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
121
|
+
buffer.pointerX = x;
|
|
122
|
+
buffer.pointerY = y;
|
|
123
|
+
buffer.pointerTime = time;
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
buffer.pointerPrevX = buffer.pointerX;
|
|
127
|
+
buffer.pointerPrevY = buffer.pointerY;
|
|
128
|
+
buffer.pointerPrevTime = buffer.pointerTime;
|
|
129
|
+
buffer.pointerX = x;
|
|
130
|
+
buffer.pointerY = y;
|
|
131
|
+
buffer.pointerTime = time;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
update = true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function activity(t: number): void {
|
|
138
|
+
buffer.activityTime = t;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function visibility(t: number, visible: BooleanFlag): void {
|
|
142
|
+
buffer.visible = visible;
|
|
143
|
+
if (!buffer.visible) {
|
|
144
|
+
activity(t);
|
|
145
|
+
}
|
|
146
|
+
update = true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function dynamic(modules: Set<number>): void {
|
|
150
|
+
buffer.modules = Array.from(modules);
|
|
151
|
+
update = true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function compute(): void {
|
|
155
|
+
if (update) {
|
|
156
|
+
encode(Event.Baseline);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function stop(): void {
|
|
161
|
+
reset();
|
|
162
|
+
}
|
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,78 +1,78 @@
|
|
|
1
|
-
import { ConsentData, ConsentSource, ConsentState, ConsentType, Constant, Dimension, Event, GCMConsent, GCMConsentState } from "@clarity-types/data";
|
|
2
|
-
import * as dimension from "@src/data/dimension";
|
|
3
|
-
import encode from "./encode";
|
|
4
|
-
import { consentv2 } from "@src/data/metadata";
|
|
5
|
-
import coreConfig from "@src/core/config";
|
|
6
|
-
|
|
7
|
-
export let data: ConsentData = null;
|
|
8
|
-
let updateConsent: boolean = true;
|
|
9
|
-
|
|
10
|
-
export function start(): void {
|
|
11
|
-
const ics = window.google_tag_data?.ics;
|
|
12
|
-
updateConsent = true;
|
|
13
|
-
if (ics?.addListener) {
|
|
14
|
-
ics.addListener(
|
|
15
|
-
[Constant.AdStorage, Constant.AnalyticsStorage],
|
|
16
|
-
processConsent
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function stop(): void {
|
|
22
|
-
updateConsent = true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function processConsent(): void {
|
|
26
|
-
const ics = window.google_tag_data?.ics;
|
|
27
|
-
if (!ics?.getConsentState) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const analytics_storage = ics.getConsentState(Constant.AnalyticsStorage);
|
|
32
|
-
const ad_storage = ics.getConsentState(Constant.AdStorage);
|
|
33
|
-
const consentState = getConsentState({ ad_Storage: ad_storage, analytics_Storage: analytics_storage });
|
|
34
|
-
consentv2(consentState, ConsentSource.GCM);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getConsentState(googleConsent: GCMConsentState): ConsentState {
|
|
38
|
-
const consentState: ConsentState = {
|
|
39
|
-
ad_Storage: googleConsent.ad_Storage === GCMConsent.Granted ? Constant.Granted : Constant.Denied,
|
|
40
|
-
analytics_Storage: googleConsent.analytics_Storage === GCMConsent.Granted ? Constant.Granted : Constant.Denied,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return consentState;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export function config(consent: ConsentData): void {
|
|
48
|
-
trackConsent(consent.analytics_Storage ? ConsentType.Implicit : ConsentType.None);
|
|
49
|
-
data = consent;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// When we get consent signal as false, we restart the service and track config as false.
|
|
53
|
-
export function consent(): void {
|
|
54
|
-
trackConsent(ConsentType.General);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function trackConsent(consent: ConsentType): void {
|
|
58
|
-
dimension.log(Dimension.Consent, consent.toString());
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function trackConsentv2(consent: ConsentData): void {
|
|
62
|
-
data = consent;
|
|
63
|
-
encode(Event.Consent);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Compute function is called every upload, but we only want to send consent data once.
|
|
67
|
-
export function compute(): void {
|
|
68
|
-
if (updateConsent) {
|
|
69
|
-
encode(Event.Consent);
|
|
70
|
-
updateConsent = false;
|
|
71
|
-
if (!coreConfig.track) {
|
|
72
|
-
const ics = window.google_tag_data?.ics;
|
|
73
|
-
if (ics?.usedUpdate) {
|
|
74
|
-
processConsent();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
import { ConsentData, ConsentSource, ConsentState, ConsentType, Constant, Dimension, Event, GCMConsent, GCMConsentState } from "@clarity-types/data";
|
|
2
|
+
import * as dimension from "@src/data/dimension";
|
|
3
|
+
import encode from "./encode";
|
|
4
|
+
import { consentv2 } from "@src/data/metadata";
|
|
5
|
+
import coreConfig from "@src/core/config";
|
|
6
|
+
|
|
7
|
+
export let data: ConsentData = null;
|
|
8
|
+
let updateConsent: boolean = true;
|
|
9
|
+
|
|
10
|
+
export function start(): void {
|
|
11
|
+
const ics = window.google_tag_data?.ics;
|
|
12
|
+
updateConsent = true;
|
|
13
|
+
if (ics?.addListener) {
|
|
14
|
+
ics.addListener(
|
|
15
|
+
[Constant.AdStorage, Constant.AnalyticsStorage],
|
|
16
|
+
processConsent
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function stop(): void {
|
|
22
|
+
updateConsent = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function processConsent(): void {
|
|
26
|
+
const ics = window.google_tag_data?.ics;
|
|
27
|
+
if (!ics?.getConsentState) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const analytics_storage = ics.getConsentState(Constant.AnalyticsStorage);
|
|
32
|
+
const ad_storage = ics.getConsentState(Constant.AdStorage);
|
|
33
|
+
const consentState = getConsentState({ ad_Storage: ad_storage, analytics_Storage: analytics_storage });
|
|
34
|
+
consentv2(consentState, ConsentSource.GCM);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getConsentState(googleConsent: GCMConsentState): ConsentState {
|
|
38
|
+
const consentState: ConsentState = {
|
|
39
|
+
ad_Storage: googleConsent.ad_Storage === GCMConsent.Granted ? Constant.Granted : Constant.Denied,
|
|
40
|
+
analytics_Storage: googleConsent.analytics_Storage === GCMConsent.Granted ? Constant.Granted : Constant.Denied,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return consentState;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export function config(consent: ConsentData): void {
|
|
48
|
+
trackConsent(consent.analytics_Storage ? ConsentType.Implicit : ConsentType.None);
|
|
49
|
+
data = consent;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// When we get consent signal as false, we restart the service and track config as false.
|
|
53
|
+
export function consent(): void {
|
|
54
|
+
trackConsent(ConsentType.General);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function trackConsent(consent: ConsentType): void {
|
|
58
|
+
dimension.log(Dimension.Consent, consent.toString());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function trackConsentv2(consent: ConsentData): void {
|
|
62
|
+
data = consent;
|
|
63
|
+
encode(Event.Consent);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Compute function is called every upload, but we only want to send consent data once.
|
|
67
|
+
export function compute(): void {
|
|
68
|
+
if (updateConsent) {
|
|
69
|
+
encode(Event.Consent);
|
|
70
|
+
updateConsent = false;
|
|
71
|
+
if (!coreConfig.track) {
|
|
72
|
+
const ics = window.google_tag_data?.ics;
|
|
73
|
+
if (ics?.usedUpdate) {
|
|
74
|
+
processConsent();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
78
|
}
|
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
|
+
}
|