clarity-js 0.7.65 → 0.7.67
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 +5410 -5355
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +5410 -5355
- 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 +26 -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 +156 -156
- package/src/interaction/clipboard.ts +34 -34
- package/src/interaction/encode.ts +191 -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 +149 -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 +151 -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 +157 -157
- package/types/layout.d.ts +273 -273
- package/types/performance.d.ts +64 -64
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
|
+
}
|
package/src/data/encode.ts
CHANGED
|
@@ -1,127 +1,134 @@
|
|
|
1
|
-
import { Event, Token } from "@clarity-types/data";
|
|
2
|
-
import { time } from "@src/core/time";
|
|
3
|
-
import * as baseline from "@src/data/baseline";
|
|
4
|
-
import * as custom from "@src/data/custom";
|
|
5
|
-
import * as dimension from "@src/data/dimension";
|
|
6
|
-
import * as limit from "@src/data/limit";
|
|
7
|
-
import * as metric from "@src/data/metric";
|
|
8
|
-
import * as ping from "@src/data/ping";
|
|
9
|
-
import * as summary from "@src/data/summary";
|
|
10
|
-
import * as upgrade from "@src/data/upgrade";
|
|
11
|
-
import * as variable from "@src/data/variable";
|
|
12
|
-
import * as extract from "@src/data/extract";
|
|
13
|
-
import { queue, track } from "./upload";
|
|
14
|
-
|
|
15
|
-
export default function(event: Event): void {
|
|
16
|
-
let t = time();
|
|
17
|
-
let tokens: Token[] = [t, event];
|
|
18
|
-
switch (event) {
|
|
19
|
-
case Event.Baseline:
|
|
20
|
-
let b = baseline.state;
|
|
21
|
-
if (b) {
|
|
22
|
-
tokens = [b.time, b.event];
|
|
23
|
-
tokens.push(b.data.visible);
|
|
24
|
-
tokens.push(b.data.docWidth);
|
|
25
|
-
tokens.push(b.data.docHeight);
|
|
26
|
-
tokens.push(b.data.screenWidth);
|
|
27
|
-
tokens.push(b.data.screenHeight);
|
|
28
|
-
tokens.push(b.data.scrollX);
|
|
29
|
-
tokens.push(b.data.scrollY);
|
|
30
|
-
tokens.push(b.data.pointerX);
|
|
31
|
-
tokens.push(b.data.pointerY);
|
|
32
|
-
tokens.push(b.data.activityTime);
|
|
33
|
-
tokens.push(b.data.scrollTime);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
tokens
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
tokens
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
tokens.push(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
tokens.push(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
1
|
+
import { Event, Token } from "@clarity-types/data";
|
|
2
|
+
import { time } from "@src/core/time";
|
|
3
|
+
import * as baseline from "@src/data/baseline";
|
|
4
|
+
import * as custom from "@src/data/custom";
|
|
5
|
+
import * as dimension from "@src/data/dimension";
|
|
6
|
+
import * as limit from "@src/data/limit";
|
|
7
|
+
import * as metric from "@src/data/metric";
|
|
8
|
+
import * as ping from "@src/data/ping";
|
|
9
|
+
import * as summary from "@src/data/summary";
|
|
10
|
+
import * as upgrade from "@src/data/upgrade";
|
|
11
|
+
import * as variable from "@src/data/variable";
|
|
12
|
+
import * as extract from "@src/data/extract";
|
|
13
|
+
import { queue, track } from "./upload";
|
|
14
|
+
|
|
15
|
+
export default function(event: Event): void {
|
|
16
|
+
let t = time();
|
|
17
|
+
let tokens: Token[] = [t, event];
|
|
18
|
+
switch (event) {
|
|
19
|
+
case Event.Baseline:
|
|
20
|
+
let b = baseline.state;
|
|
21
|
+
if (b) {
|
|
22
|
+
tokens = [b.time, b.event];
|
|
23
|
+
tokens.push(b.data.visible);
|
|
24
|
+
tokens.push(b.data.docWidth);
|
|
25
|
+
tokens.push(b.data.docHeight);
|
|
26
|
+
tokens.push(b.data.screenWidth);
|
|
27
|
+
tokens.push(b.data.screenHeight);
|
|
28
|
+
tokens.push(b.data.scrollX);
|
|
29
|
+
tokens.push(b.data.scrollY);
|
|
30
|
+
tokens.push(b.data.pointerX);
|
|
31
|
+
tokens.push(b.data.pointerY);
|
|
32
|
+
tokens.push(b.data.activityTime);
|
|
33
|
+
tokens.push(b.data.scrollTime);
|
|
34
|
+
tokens.push(b.data.pointerTime);
|
|
35
|
+
tokens.push(b.data.moveX);
|
|
36
|
+
tokens.push(b.data.moveY);
|
|
37
|
+
tokens.push(b.data.moveTime);
|
|
38
|
+
tokens.push(b.data.downX);
|
|
39
|
+
tokens.push(b.data.downY);
|
|
40
|
+
tokens.push(b.data.downTime);
|
|
41
|
+
queue(tokens, false);
|
|
42
|
+
}
|
|
43
|
+
baseline.reset();
|
|
44
|
+
break;
|
|
45
|
+
case Event.Ping:
|
|
46
|
+
tokens.push(ping.data.gap);
|
|
47
|
+
queue(tokens);
|
|
48
|
+
break;
|
|
49
|
+
case Event.Limit:
|
|
50
|
+
tokens.push(limit.data.check);
|
|
51
|
+
queue(tokens, false);
|
|
52
|
+
break;
|
|
53
|
+
case Event.Upgrade:
|
|
54
|
+
tokens.push(upgrade.data.key);
|
|
55
|
+
queue(tokens);
|
|
56
|
+
break;
|
|
57
|
+
case Event.Upload:
|
|
58
|
+
tokens.push(track.sequence);
|
|
59
|
+
tokens.push(track.attempts);
|
|
60
|
+
tokens.push(track.status);
|
|
61
|
+
queue(tokens, false);
|
|
62
|
+
break;
|
|
63
|
+
case Event.Custom:
|
|
64
|
+
// not all custom events have a key - if it wasn't passed server handles just value
|
|
65
|
+
custom.data.key && tokens.push(custom.data.key);
|
|
66
|
+
tokens.push(custom.data.value);
|
|
67
|
+
queue(tokens);
|
|
68
|
+
break;
|
|
69
|
+
case Event.Variable:
|
|
70
|
+
let variableKeys = Object.keys(variable.data);
|
|
71
|
+
if (variableKeys.length > 0) {
|
|
72
|
+
for (let v of variableKeys) {
|
|
73
|
+
tokens.push(v);
|
|
74
|
+
tokens.push(variable.data[v]);
|
|
75
|
+
}
|
|
76
|
+
variable.reset();
|
|
77
|
+
queue(tokens, false);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case Event.Metric:
|
|
81
|
+
let metricKeys = Object.keys(metric.updates);
|
|
82
|
+
if (metricKeys.length > 0) {
|
|
83
|
+
for (let m of metricKeys) {
|
|
84
|
+
let key = parseInt(m, 10);
|
|
85
|
+
tokens.push(key);
|
|
86
|
+
// For computation, we need microseconds precision that performance.now() API offers
|
|
87
|
+
// However, for data over the wire, we round it off to milliseconds precision.
|
|
88
|
+
tokens.push(Math.round(metric.updates[m]));
|
|
89
|
+
}
|
|
90
|
+
metric.reset();
|
|
91
|
+
queue(tokens, false);
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case Event.Dimension:
|
|
95
|
+
let dimensionKeys = Object.keys(dimension.updates);
|
|
96
|
+
if (dimensionKeys.length > 0) {
|
|
97
|
+
for (let d of dimensionKeys) {
|
|
98
|
+
let key = parseInt(d, 10);
|
|
99
|
+
tokens.push(key);
|
|
100
|
+
tokens.push(dimension.updates[d]);
|
|
101
|
+
}
|
|
102
|
+
dimension.reset();
|
|
103
|
+
queue(tokens, false);
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case Event.Summary:
|
|
107
|
+
let eventKeys = Object.keys(summary.data);
|
|
108
|
+
if (eventKeys.length > 0) {
|
|
109
|
+
for (let e of eventKeys) {
|
|
110
|
+
let key = parseInt(e, 10);
|
|
111
|
+
tokens.push(key);
|
|
112
|
+
tokens.push([].concat(...summary.data[e]));
|
|
113
|
+
}
|
|
114
|
+
summary.reset();
|
|
115
|
+
queue(tokens, false);
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case Event.Extract:
|
|
119
|
+
let extractKeys = extract.keys;
|
|
120
|
+
extractKeys.forEach((e => {
|
|
121
|
+
tokens.push(e);
|
|
122
|
+
let token = []
|
|
123
|
+
for (let d in extract.data[e]) {
|
|
124
|
+
let key = parseInt(d, 10);
|
|
125
|
+
token.push(key);
|
|
126
|
+
token.push(extract.data[e][d]);
|
|
127
|
+
}
|
|
128
|
+
tokens.push(token);
|
|
129
|
+
}));
|
|
130
|
+
|
|
131
|
+
extract.reset();
|
|
132
|
+
queue(tokens, false);
|
|
133
|
+
}
|
|
134
|
+
}
|
package/src/data/envelope.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { BooleanFlag, Token, Upload, Envelope, ApplicationPlatform } from "@clarity-types/data";
|
|
2
|
-
import { time } from "@src/core/time";
|
|
3
|
-
import version from "@src/core/version";
|
|
4
|
-
import * as metadata from "@src/data/metadata";
|
|
5
|
-
import * as scrub from "@src/core/scrub";
|
|
6
|
-
|
|
7
|
-
export let data: Envelope = null;
|
|
8
|
-
|
|
9
|
-
export function start(): void {
|
|
10
|
-
const m = metadata.data;
|
|
11
|
-
data = {
|
|
12
|
-
version,
|
|
13
|
-
sequence: 0,
|
|
14
|
-
start: 0,
|
|
15
|
-
duration: 0,
|
|
16
|
-
projectId: m.projectId,
|
|
17
|
-
userId: m.userId,
|
|
18
|
-
sessionId: m.sessionId,
|
|
19
|
-
pageNum: m.pageNum,
|
|
20
|
-
upload: Upload.Async,
|
|
21
|
-
end: BooleanFlag.False,
|
|
22
|
-
applicationPlatform: ApplicationPlatform.WebApp,
|
|
23
|
-
url: ''
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function stop(): void {
|
|
28
|
-
data = null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function envelope(last: boolean): Token[] {
|
|
32
|
-
data.start = data.start + data.duration;
|
|
33
|
-
data.duration = time() - data.start;
|
|
34
|
-
data.sequence++;
|
|
35
|
-
data.upload = last && "sendBeacon" in navigator ? Upload.Beacon : Upload.Async;
|
|
36
|
-
data.end = last ? BooleanFlag.True : BooleanFlag.False;
|
|
37
|
-
data.applicationPlatform = ApplicationPlatform.WebApp;
|
|
38
|
-
data.url = scrub.url(location.href, false, true);
|
|
39
|
-
return [
|
|
40
|
-
data.version,
|
|
41
|
-
data.sequence,
|
|
42
|
-
data.start,
|
|
43
|
-
data.duration,
|
|
44
|
-
data.projectId,
|
|
45
|
-
data.userId,
|
|
46
|
-
data.sessionId,
|
|
47
|
-
data.pageNum,
|
|
48
|
-
data.upload,
|
|
49
|
-
data.end,
|
|
50
|
-
data.applicationPlatform,
|
|
51
|
-
data.url
|
|
52
|
-
];
|
|
53
|
-
}
|
|
1
|
+
import { BooleanFlag, Token, Upload, Envelope, ApplicationPlatform } from "@clarity-types/data";
|
|
2
|
+
import { time } from "@src/core/time";
|
|
3
|
+
import version from "@src/core/version";
|
|
4
|
+
import * as metadata from "@src/data/metadata";
|
|
5
|
+
import * as scrub from "@src/core/scrub";
|
|
6
|
+
|
|
7
|
+
export let data: Envelope = null;
|
|
8
|
+
|
|
9
|
+
export function start(): void {
|
|
10
|
+
const m = metadata.data;
|
|
11
|
+
data = {
|
|
12
|
+
version,
|
|
13
|
+
sequence: 0,
|
|
14
|
+
start: 0,
|
|
15
|
+
duration: 0,
|
|
16
|
+
projectId: m.projectId,
|
|
17
|
+
userId: m.userId,
|
|
18
|
+
sessionId: m.sessionId,
|
|
19
|
+
pageNum: m.pageNum,
|
|
20
|
+
upload: Upload.Async,
|
|
21
|
+
end: BooleanFlag.False,
|
|
22
|
+
applicationPlatform: ApplicationPlatform.WebApp,
|
|
23
|
+
url: ''
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function stop(): void {
|
|
28
|
+
data = null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function envelope(last: boolean): Token[] {
|
|
32
|
+
data.start = data.start + data.duration;
|
|
33
|
+
data.duration = time() - data.start;
|
|
34
|
+
data.sequence++;
|
|
35
|
+
data.upload = last && "sendBeacon" in navigator ? Upload.Beacon : Upload.Async;
|
|
36
|
+
data.end = last ? BooleanFlag.True : BooleanFlag.False;
|
|
37
|
+
data.applicationPlatform = ApplicationPlatform.WebApp;
|
|
38
|
+
data.url = scrub.url(location.href, false, true);
|
|
39
|
+
return [
|
|
40
|
+
data.version,
|
|
41
|
+
data.sequence,
|
|
42
|
+
data.start,
|
|
43
|
+
data.duration,
|
|
44
|
+
data.projectId,
|
|
45
|
+
data.userId,
|
|
46
|
+
data.sessionId,
|
|
47
|
+
data.pageNum,
|
|
48
|
+
data.upload,
|
|
49
|
+
data.end,
|
|
50
|
+
data.applicationPlatform,
|
|
51
|
+
data.url
|
|
52
|
+
];
|
|
53
|
+
}
|