@gemx-dev/clarity-js 0.8.39

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.
Files changed (118) hide show
  1. package/README.md +1 -0
  2. package/build/clarity.extended.js +1 -0
  3. package/build/clarity.insight.js +1 -0
  4. package/build/clarity.js +6433 -0
  5. package/build/clarity.livechat.js +1 -0
  6. package/build/clarity.min.js +1 -0
  7. package/build/clarity.module.js +6429 -0
  8. package/build/clarity.performance.js +1 -0
  9. package/build/dynamic/clarity.crisp.js +1 -0
  10. package/build/dynamic/clarity.tidio.js +1 -0
  11. package/package.json +55 -0
  12. package/rollup.config.ts +161 -0
  13. package/src/clarity.ts +71 -0
  14. package/src/core/api.ts +8 -0
  15. package/src/core/config.ts +29 -0
  16. package/src/core/copy.ts +3 -0
  17. package/src/core/dynamic.ts +57 -0
  18. package/src/core/event.ts +53 -0
  19. package/src/core/hash.ts +19 -0
  20. package/src/core/history.ts +71 -0
  21. package/src/core/index.ts +81 -0
  22. package/src/core/measure.ts +19 -0
  23. package/src/core/report.ts +35 -0
  24. package/src/core/scrub.ts +202 -0
  25. package/src/core/task.ts +181 -0
  26. package/src/core/throttle.ts +46 -0
  27. package/src/core/time.ts +26 -0
  28. package/src/core/timeout.ts +10 -0
  29. package/src/core/version.ts +2 -0
  30. package/src/data/baseline.ts +162 -0
  31. package/src/data/compress.ts +31 -0
  32. package/src/data/consent.ts +75 -0
  33. package/src/data/custom.ts +23 -0
  34. package/src/data/dimension.ts +53 -0
  35. package/src/data/encode.ts +155 -0
  36. package/src/data/envelope.ts +53 -0
  37. package/src/data/extract.ts +211 -0
  38. package/src/data/index.ts +50 -0
  39. package/src/data/limit.ts +44 -0
  40. package/src/data/metadata.ts +408 -0
  41. package/src/data/metric.ts +51 -0
  42. package/src/data/ping.ts +36 -0
  43. package/src/data/signal.ts +30 -0
  44. package/src/data/summary.ts +34 -0
  45. package/src/data/token.ts +39 -0
  46. package/src/data/upgrade.ts +44 -0
  47. package/src/data/upload.ts +333 -0
  48. package/src/data/variable.ts +84 -0
  49. package/src/diagnostic/encode.ts +40 -0
  50. package/src/diagnostic/fraud.ts +37 -0
  51. package/src/diagnostic/index.ts +13 -0
  52. package/src/diagnostic/internal.ts +28 -0
  53. package/src/diagnostic/script.ts +35 -0
  54. package/src/dynamic/agent/blank.ts +2 -0
  55. package/src/dynamic/agent/crisp.ts +40 -0
  56. package/src/dynamic/agent/encode.ts +25 -0
  57. package/src/dynamic/agent/index.ts +8 -0
  58. package/src/dynamic/agent/livechat.ts +58 -0
  59. package/src/dynamic/agent/tidio.ts +44 -0
  60. package/src/global.ts +6 -0
  61. package/src/index.ts +9 -0
  62. package/src/insight/blank.ts +14 -0
  63. package/src/insight/encode.ts +61 -0
  64. package/src/insight/snapshot.ts +115 -0
  65. package/src/interaction/change.ts +38 -0
  66. package/src/interaction/click.ts +163 -0
  67. package/src/interaction/clipboard.ts +32 -0
  68. package/src/interaction/encode.ts +207 -0
  69. package/src/interaction/focus.ts +25 -0
  70. package/src/interaction/index.ts +60 -0
  71. package/src/interaction/input.ts +58 -0
  72. package/src/interaction/pointer.ts +137 -0
  73. package/src/interaction/resize.ts +50 -0
  74. package/src/interaction/scroll.ts +129 -0
  75. package/src/interaction/selection.ts +66 -0
  76. package/src/interaction/submit.ts +30 -0
  77. package/src/interaction/timeline.ts +69 -0
  78. package/src/interaction/unload.ts +26 -0
  79. package/src/interaction/visibility.ts +28 -0
  80. package/src/layout/animation.ts +133 -0
  81. package/src/layout/custom.ts +43 -0
  82. package/src/layout/discover.ts +31 -0
  83. package/src/layout/document.ts +46 -0
  84. package/src/layout/dom.ts +439 -0
  85. package/src/layout/encode.ts +154 -0
  86. package/src/layout/index.ts +42 -0
  87. package/src/layout/mutation.ts +412 -0
  88. package/src/layout/node.ts +294 -0
  89. package/src/layout/offset.ts +19 -0
  90. package/src/layout/region.ts +151 -0
  91. package/src/layout/schema.ts +63 -0
  92. package/src/layout/selector.ts +82 -0
  93. package/src/layout/style.ts +160 -0
  94. package/src/layout/target.ts +32 -0
  95. package/src/layout/traverse.ts +28 -0
  96. package/src/performance/blank.ts +10 -0
  97. package/src/performance/encode.ts +31 -0
  98. package/src/performance/index.ts +12 -0
  99. package/src/performance/interaction.ts +125 -0
  100. package/src/performance/navigation.ts +31 -0
  101. package/src/performance/observer.ts +112 -0
  102. package/src/queue.ts +33 -0
  103. package/test/core.test.ts +139 -0
  104. package/test/helper.ts +167 -0
  105. package/test/html/core.html +34 -0
  106. package/test/stub.test.ts +7 -0
  107. package/test/tsconfig.test.json +6 -0
  108. package/tsconfig.json +21 -0
  109. package/tslint.json +33 -0
  110. package/types/agent.d.ts +39 -0
  111. package/types/core.d.ts +150 -0
  112. package/types/data.d.ts +568 -0
  113. package/types/diagnostic.d.ts +24 -0
  114. package/types/global.d.ts +30 -0
  115. package/types/index.d.ts +40 -0
  116. package/types/interaction.d.ts +174 -0
  117. package/types/layout.d.ts +277 -0
  118. package/types/performance.d.ts +31 -0
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,75 @@
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 "./metadata";
5
+
6
+ export let data: ConsentData = null;
7
+ let updateConsent: boolean = true;
8
+
9
+ export function start(): void {
10
+ const ics = window.google_tag_data?.ics;
11
+ updateConsent = true;
12
+ if (ics?.addListener) {
13
+ ics.addListener(
14
+ [Constant.AdStorage, Constant.AnalyticsStorage],
15
+ processConsent
16
+ );
17
+ }
18
+ }
19
+
20
+ export function stop(): void {
21
+ updateConsent = true;
22
+ }
23
+
24
+ function processConsent(): void {
25
+ const ics = window.google_tag_data?.ics;
26
+ if (!ics?.getConsentState) {
27
+ return;
28
+ }
29
+
30
+ const analytics_storage = ics.getConsentState(Constant.AnalyticsStorage);
31
+ const ad_storage = ics.getConsentState(Constant.AdStorage);
32
+ const consentState = getConsentState({ ad_Storage: ad_storage, analytics_Storage: analytics_storage });
33
+ consentv2(consentState, ConsentSource.GCM);
34
+ }
35
+
36
+ function getConsentState(googleConsent: GCMConsentState): ConsentState {
37
+ const consentState: ConsentState = {
38
+ ad_Storage: googleConsent.ad_Storage === GCMConsent.Granted ? Constant.Granted : Constant.Denied,
39
+ analytics_Storage: googleConsent.analytics_Storage === GCMConsent.Granted ? Constant.Granted : Constant.Denied,
40
+ };
41
+
42
+ return consentState;
43
+ }
44
+
45
+
46
+ export function config(consent: ConsentData): void {
47
+ trackConsent(consent.analytics_Storage ? ConsentType.Implicit : ConsentType.None);
48
+ data = consent;
49
+ }
50
+
51
+ // When we get consent signal as false, we restart the service and track config as false.
52
+ export function consent(): void {
53
+ trackConsent(ConsentType.General);
54
+ }
55
+
56
+ function trackConsent(consent: ConsentType): void {
57
+ dimension.log(Dimension.Consent, consent.toString());
58
+ }
59
+
60
+ export function trackConsentv2(consent: ConsentData): void {
61
+ data = consent;
62
+ encode(Event.Consent);
63
+ }
64
+
65
+ // Compute function is called every upload, but we only want to send consent data once.
66
+ export function compute(): void {
67
+ if (updateConsent) {
68
+ encode(Event.Consent);
69
+ updateConsent = false;
70
+ const ics = window.google_tag_data?.ics;
71
+ if (ics?.usedUpdate) {
72
+ processConsent();
73
+ }
74
+ }
75
+ }
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }