clarity-js 0.8.42 → 0.8.44
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 +6101 -6071
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +6101 -6071
- 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/cookie.ts +90 -0
- 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 +51 -50
- package/src/data/limit.ts +44 -44
- package/src/data/metadata.ts +321 -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/util.ts +18 -0
- 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/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,155 +1,155 @@
|
|
|
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 consent from "@src/data/consent";
|
|
5
|
-
import * as custom from "@src/data/custom";
|
|
6
|
-
import * as dimension from "@src/data/dimension";
|
|
7
|
-
import * as limit from "@src/data/limit";
|
|
8
|
-
import * as metric from "@src/data/metric";
|
|
9
|
-
import * as ping from "@src/data/ping";
|
|
10
|
-
import * as summary from "@src/data/summary";
|
|
11
|
-
import * as upgrade from "@src/data/upgrade";
|
|
12
|
-
import * as variable from "@src/data/variable";
|
|
13
|
-
import * as extract from "@src/data/extract";
|
|
14
|
-
import { queue, track } from "./upload";
|
|
15
|
-
|
|
16
|
-
export default function(event: Event): void {
|
|
17
|
-
const t = time();
|
|
18
|
-
let tokens: Token[] = [t, event];
|
|
19
|
-
switch (event) {
|
|
20
|
-
case Event.Baseline: {
|
|
21
|
-
const b = baseline.state;
|
|
22
|
-
if (b && b.data) {
|
|
23
|
-
tokens = [b.time, b.event];
|
|
24
|
-
tokens.push(b.data.visible);
|
|
25
|
-
tokens.push(b.data.docWidth);
|
|
26
|
-
tokens.push(b.data.docHeight);
|
|
27
|
-
tokens.push(b.data.screenWidth);
|
|
28
|
-
tokens.push(b.data.screenHeight);
|
|
29
|
-
tokens.push(b.data.scrollX);
|
|
30
|
-
tokens.push(b.data.scrollY);
|
|
31
|
-
tokens.push(b.data.pointerX);
|
|
32
|
-
tokens.push(b.data.pointerY);
|
|
33
|
-
tokens.push(b.data.activityTime);
|
|
34
|
-
tokens.push(b.data.scrollTime);
|
|
35
|
-
tokens.push(b.data.pointerTime);
|
|
36
|
-
tokens.push(b.data.moveX);
|
|
37
|
-
tokens.push(b.data.moveY);
|
|
38
|
-
tokens.push(b.data.moveTime);
|
|
39
|
-
tokens.push(b.data.downX);
|
|
40
|
-
tokens.push(b.data.downY);
|
|
41
|
-
tokens.push(b.data.downTime);
|
|
42
|
-
tokens.push(b.data.upX);
|
|
43
|
-
tokens.push(b.data.upY);
|
|
44
|
-
tokens.push(b.data.upTime);
|
|
45
|
-
tokens.push(b.data.pointerPrevX);
|
|
46
|
-
tokens.push(b.data.pointerPrevY);
|
|
47
|
-
tokens.push(b.data.pointerPrevTime);
|
|
48
|
-
tokens.push(b.data.modules);
|
|
49
|
-
queue(tokens, false);
|
|
50
|
-
}
|
|
51
|
-
baseline.reset();
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case Event.Ping:
|
|
55
|
-
tokens.push(ping.data.gap);
|
|
56
|
-
queue(tokens);
|
|
57
|
-
break;
|
|
58
|
-
case Event.Limit:
|
|
59
|
-
tokens.push(limit.data.check);
|
|
60
|
-
queue(tokens, false);
|
|
61
|
-
break;
|
|
62
|
-
case Event.Upgrade:
|
|
63
|
-
tokens.push(upgrade.data.key);
|
|
64
|
-
queue(tokens);
|
|
65
|
-
break;
|
|
66
|
-
case Event.Upload:
|
|
67
|
-
tokens.push(track.sequence);
|
|
68
|
-
tokens.push(track.attempts);
|
|
69
|
-
tokens.push(track.status);
|
|
70
|
-
queue(tokens, false);
|
|
71
|
-
break;
|
|
72
|
-
case Event.Custom:
|
|
73
|
-
// not all custom events have a key - if it wasn't passed server handles just value
|
|
74
|
-
custom.data.key && tokens.push(custom.data.key);
|
|
75
|
-
tokens.push(custom.data.value);
|
|
76
|
-
queue(tokens);
|
|
77
|
-
break;
|
|
78
|
-
case Event.Variable: {
|
|
79
|
-
const variableKeys = Object.keys(variable.data);
|
|
80
|
-
if (variableKeys.length > 0) {
|
|
81
|
-
for (const v of variableKeys) {
|
|
82
|
-
tokens.push(v);
|
|
83
|
-
tokens.push(variable.data[v]);
|
|
84
|
-
}
|
|
85
|
-
variable.reset();
|
|
86
|
-
queue(tokens, false);
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
case Event.Metric: {
|
|
91
|
-
const metricKeys = Object.keys(metric.updates);
|
|
92
|
-
if (metricKeys.length > 0) {
|
|
93
|
-
for (const m of metricKeys) {
|
|
94
|
-
const key = parseInt(m, 10);
|
|
95
|
-
tokens.push(key);
|
|
96
|
-
// For computation, we need microseconds precision that performance.now() API offers
|
|
97
|
-
// However, for data over the wire, we round it off to milliseconds precision.
|
|
98
|
-
tokens.push(Math.round(metric.updates[m]));
|
|
99
|
-
}
|
|
100
|
-
metric.reset();
|
|
101
|
-
queue(tokens, false);
|
|
102
|
-
}
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case Event.Dimension: {
|
|
106
|
-
const dimensionKeys = Object.keys(dimension.updates);
|
|
107
|
-
if (dimensionKeys.length > 0) {
|
|
108
|
-
for (const d of dimensionKeys) {
|
|
109
|
-
const key = parseInt(d, 10);
|
|
110
|
-
tokens.push(key);
|
|
111
|
-
tokens.push(dimension.updates[d]);
|
|
112
|
-
}
|
|
113
|
-
dimension.reset();
|
|
114
|
-
queue(tokens, false);
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case Event.Summary: {
|
|
119
|
-
const eventKeys = Object.keys(summary.data);
|
|
120
|
-
if (eventKeys.length > 0) {
|
|
121
|
-
for (const e of eventKeys) {
|
|
122
|
-
const key = parseInt(e, 10);
|
|
123
|
-
tokens.push(key);
|
|
124
|
-
tokens.push([].concat(...summary.data[e]));
|
|
125
|
-
}
|
|
126
|
-
summary.reset();
|
|
127
|
-
queue(tokens, false);
|
|
128
|
-
}
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
case Event.Extract: {
|
|
132
|
-
const extractKeys = extract.keys;
|
|
133
|
-
extractKeys.forEach(e => {
|
|
134
|
-
tokens.push(e);
|
|
135
|
-
const token = []
|
|
136
|
-
for (const d in extract.data[e]) {
|
|
137
|
-
const key = parseInt(d, 10);
|
|
138
|
-
token.push(key);
|
|
139
|
-
token.push(extract.data[e][d]);
|
|
140
|
-
}
|
|
141
|
-
tokens.push(token);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
extract.reset();
|
|
145
|
-
queue(tokens, false);
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
case Event.Consent:
|
|
149
|
-
tokens.push(consent.data.source);
|
|
150
|
-
tokens.push(consent.data.ad_Storage);
|
|
151
|
-
tokens.push(consent.data.analytics_Storage);
|
|
152
|
-
queue(tokens, false);
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
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 consent from "@src/data/consent";
|
|
5
|
+
import * as custom from "@src/data/custom";
|
|
6
|
+
import * as dimension from "@src/data/dimension";
|
|
7
|
+
import * as limit from "@src/data/limit";
|
|
8
|
+
import * as metric from "@src/data/metric";
|
|
9
|
+
import * as ping from "@src/data/ping";
|
|
10
|
+
import * as summary from "@src/data/summary";
|
|
11
|
+
import * as upgrade from "@src/data/upgrade";
|
|
12
|
+
import * as variable from "@src/data/variable";
|
|
13
|
+
import * as extract from "@src/data/extract";
|
|
14
|
+
import { queue, track } from "./upload";
|
|
15
|
+
|
|
16
|
+
export default function(event: Event): void {
|
|
17
|
+
const t = time();
|
|
18
|
+
let tokens: Token[] = [t, event];
|
|
19
|
+
switch (event) {
|
|
20
|
+
case Event.Baseline: {
|
|
21
|
+
const b = baseline.state;
|
|
22
|
+
if (b && b.data) {
|
|
23
|
+
tokens = [b.time, b.event];
|
|
24
|
+
tokens.push(b.data.visible);
|
|
25
|
+
tokens.push(b.data.docWidth);
|
|
26
|
+
tokens.push(b.data.docHeight);
|
|
27
|
+
tokens.push(b.data.screenWidth);
|
|
28
|
+
tokens.push(b.data.screenHeight);
|
|
29
|
+
tokens.push(b.data.scrollX);
|
|
30
|
+
tokens.push(b.data.scrollY);
|
|
31
|
+
tokens.push(b.data.pointerX);
|
|
32
|
+
tokens.push(b.data.pointerY);
|
|
33
|
+
tokens.push(b.data.activityTime);
|
|
34
|
+
tokens.push(b.data.scrollTime);
|
|
35
|
+
tokens.push(b.data.pointerTime);
|
|
36
|
+
tokens.push(b.data.moveX);
|
|
37
|
+
tokens.push(b.data.moveY);
|
|
38
|
+
tokens.push(b.data.moveTime);
|
|
39
|
+
tokens.push(b.data.downX);
|
|
40
|
+
tokens.push(b.data.downY);
|
|
41
|
+
tokens.push(b.data.downTime);
|
|
42
|
+
tokens.push(b.data.upX);
|
|
43
|
+
tokens.push(b.data.upY);
|
|
44
|
+
tokens.push(b.data.upTime);
|
|
45
|
+
tokens.push(b.data.pointerPrevX);
|
|
46
|
+
tokens.push(b.data.pointerPrevY);
|
|
47
|
+
tokens.push(b.data.pointerPrevTime);
|
|
48
|
+
tokens.push(b.data.modules);
|
|
49
|
+
queue(tokens, false);
|
|
50
|
+
}
|
|
51
|
+
baseline.reset();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case Event.Ping:
|
|
55
|
+
tokens.push(ping.data.gap);
|
|
56
|
+
queue(tokens);
|
|
57
|
+
break;
|
|
58
|
+
case Event.Limit:
|
|
59
|
+
tokens.push(limit.data.check);
|
|
60
|
+
queue(tokens, false);
|
|
61
|
+
break;
|
|
62
|
+
case Event.Upgrade:
|
|
63
|
+
tokens.push(upgrade.data.key);
|
|
64
|
+
queue(tokens);
|
|
65
|
+
break;
|
|
66
|
+
case Event.Upload:
|
|
67
|
+
tokens.push(track.sequence);
|
|
68
|
+
tokens.push(track.attempts);
|
|
69
|
+
tokens.push(track.status);
|
|
70
|
+
queue(tokens, false);
|
|
71
|
+
break;
|
|
72
|
+
case Event.Custom:
|
|
73
|
+
// not all custom events have a key - if it wasn't passed server handles just value
|
|
74
|
+
custom.data.key && tokens.push(custom.data.key);
|
|
75
|
+
tokens.push(custom.data.value);
|
|
76
|
+
queue(tokens);
|
|
77
|
+
break;
|
|
78
|
+
case Event.Variable: {
|
|
79
|
+
const variableKeys = Object.keys(variable.data);
|
|
80
|
+
if (variableKeys.length > 0) {
|
|
81
|
+
for (const v of variableKeys) {
|
|
82
|
+
tokens.push(v);
|
|
83
|
+
tokens.push(variable.data[v]);
|
|
84
|
+
}
|
|
85
|
+
variable.reset();
|
|
86
|
+
queue(tokens, false);
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case Event.Metric: {
|
|
91
|
+
const metricKeys = Object.keys(metric.updates);
|
|
92
|
+
if (metricKeys.length > 0) {
|
|
93
|
+
for (const m of metricKeys) {
|
|
94
|
+
const key = parseInt(m, 10);
|
|
95
|
+
tokens.push(key);
|
|
96
|
+
// For computation, we need microseconds precision that performance.now() API offers
|
|
97
|
+
// However, for data over the wire, we round it off to milliseconds precision.
|
|
98
|
+
tokens.push(Math.round(metric.updates[m]));
|
|
99
|
+
}
|
|
100
|
+
metric.reset();
|
|
101
|
+
queue(tokens, false);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case Event.Dimension: {
|
|
106
|
+
const dimensionKeys = Object.keys(dimension.updates);
|
|
107
|
+
if (dimensionKeys.length > 0) {
|
|
108
|
+
for (const d of dimensionKeys) {
|
|
109
|
+
const key = parseInt(d, 10);
|
|
110
|
+
tokens.push(key);
|
|
111
|
+
tokens.push(dimension.updates[d]);
|
|
112
|
+
}
|
|
113
|
+
dimension.reset();
|
|
114
|
+
queue(tokens, false);
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case Event.Summary: {
|
|
119
|
+
const eventKeys = Object.keys(summary.data);
|
|
120
|
+
if (eventKeys.length > 0) {
|
|
121
|
+
for (const e of eventKeys) {
|
|
122
|
+
const key = parseInt(e, 10);
|
|
123
|
+
tokens.push(key);
|
|
124
|
+
tokens.push([].concat(...summary.data[e]));
|
|
125
|
+
}
|
|
126
|
+
summary.reset();
|
|
127
|
+
queue(tokens, false);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case Event.Extract: {
|
|
132
|
+
const extractKeys = extract.keys;
|
|
133
|
+
extractKeys.forEach(e => {
|
|
134
|
+
tokens.push(e);
|
|
135
|
+
const token = []
|
|
136
|
+
for (const d in extract.data[e]) {
|
|
137
|
+
const key = parseInt(d, 10);
|
|
138
|
+
token.push(key);
|
|
139
|
+
token.push(extract.data[e][d]);
|
|
140
|
+
}
|
|
141
|
+
tokens.push(token);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
extract.reset();
|
|
145
|
+
queue(tokens, false);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case Event.Consent:
|
|
149
|
+
tokens.push(consent.data.source);
|
|
150
|
+
tokens.push(consent.data.ad_Storage);
|
|
151
|
+
tokens.push(consent.data.analytics_Storage);
|
|
152
|
+
queue(tokens, false);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
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
|
+
}
|