@shware/analytics 12.0.0 → 12.1.0
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 +38 -1
- package/dist/schema/index.cjs +10 -2
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +3 -0
- package/dist/schema/index.d.cts.map +1 -1
- package/dist/schema/index.d.mts +3 -0
- package/dist/schema/index.d.mts.map +1 -1
- package/dist/schema/index.mjs +10 -2
- package/dist/schema/index.mjs.map +1 -1
- package/dist/third-parties/google-analytics.cjs +1 -1
- package/dist/third-parties/google-analytics.cjs.map +1 -1
- package/dist/third-parties/google-analytics.d.cts +1 -1
- package/dist/third-parties/google-analytics.d.mts +1 -1
- package/dist/third-parties/google-analytics.mjs +1 -1
- package/dist/third-parties/google-analytics.mjs.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.cjs +1 -1
- package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.cts +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.mts +1 -1
- package/dist/third-parties/linkedin-insight-tag.mjs +1 -1
- package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -1
- package/dist/third-parties/meta-pixel.cjs +1 -1
- package/dist/third-parties/meta-pixel.cjs.map +1 -1
- package/dist/third-parties/meta-pixel.d.cts +1 -1
- package/dist/third-parties/meta-pixel.d.mts +1 -1
- package/dist/third-parties/meta-pixel.mjs +1 -1
- package/dist/third-parties/meta-pixel.mjs.map +1 -1
- package/dist/third-parties/microsoft-uet.cjs +1 -1
- package/dist/third-parties/microsoft-uet.cjs.map +1 -1
- package/dist/third-parties/microsoft-uet.d.cts +1 -1
- package/dist/third-parties/microsoft-uet.d.mts +1 -1
- package/dist/third-parties/microsoft-uet.mjs +1 -1
- package/dist/third-parties/microsoft-uet.mjs.map +1 -1
- package/dist/third-parties/openai-pixel.cjs +1 -1
- package/dist/third-parties/openai-pixel.cjs.map +1 -1
- package/dist/third-parties/openai-pixel.d.cts +1 -1
- package/dist/third-parties/openai-pixel.d.mts +1 -1
- package/dist/third-parties/openai-pixel.mjs +1 -1
- package/dist/third-parties/openai-pixel.mjs.map +1 -1
- package/dist/third-parties/reddit-pixel.cjs +1 -1
- package/dist/third-parties/reddit-pixel.cjs.map +1 -1
- package/dist/third-parties/reddit-pixel.d.cts +1 -1
- package/dist/third-parties/reddit-pixel.d.mts +1 -1
- package/dist/third-parties/reddit-pixel.mjs +1 -1
- package/dist/third-parties/reddit-pixel.mjs.map +1 -1
- package/dist/track/index.cjs +77 -42
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.d.cts +28 -4
- package/dist/track/index.d.cts.map +1 -1
- package/dist/track/index.d.mts +28 -4
- package/dist/track/index.d.mts.map +1 -1
- package/dist/track/index.mjs +77 -43
- package/dist/track/index.mjs.map +1 -1
- package/dist/track/once.cjs +65 -17
- package/dist/track/once.cjs.map +1 -1
- package/dist/track/once.d.cts +5 -4
- package/dist/track/once.d.cts.map +1 -1
- package/dist/track/once.d.mts +5 -4
- package/dist/track/once.d.mts.map +1 -1
- package/dist/track/once.mjs +66 -18
- package/dist/track/once.mjs.map +1 -1
- package/dist/track/types.d.cts +19 -2
- package/dist/track/types.d.cts.map +1 -1
- package/dist/track/types.d.mts +19 -2
- package/dist/track/types.d.mts.map +1 -1
- package/package.json +1 -1
package/dist/track/once.cjs
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_setup_index = require("../setup/index.cjs");
|
|
3
3
|
const require_track_index = require("./index.cjs");
|
|
4
|
+
let uuid = require("uuid");
|
|
4
5
|
//#region src/track/once.ts
|
|
5
6
|
const DEFAULT_TTL = 7776e6;
|
|
6
7
|
/**
|
|
7
|
-
* `{"v":
|
|
8
|
-
* than an object keyed by `key`: an object would move integer-like keys ("123") to
|
|
9
|
-
* lose the order the oldest are dropped by. Escaping the value for the medium is the
|
|
10
|
-
* job, so this is plain JSON.
|
|
8
|
+
* `{"v":2,"entries":[[key, id, expiresAt, sent], …]}`, oldest first. Entries are tuples in an
|
|
9
|
+
* array rather than an object keyed by `key`: an object would move integer-like keys ("123") to
|
|
10
|
+
* the front and lose the order the oldest are dropped by. Escaping the value for the medium is the
|
|
11
|
+
* storage's job, so this is plain JSON.
|
|
12
|
+
*
|
|
13
|
+
* `id` is the event id the key goes out under, decided by the first call and kept while `sent`
|
|
14
|
+
* is false — a send that failed, or a page reloaded before its batch went out. The third-party
|
|
15
|
+
* trackers fire when the event is tracked, not when it is sent, so that first call has already
|
|
16
|
+
* reported the occurrence to them: the next call reuses the id, fires none of them again, and
|
|
17
|
+
* the server (`on conflict (id) do nothing`) stores the event once even if the failed send had in
|
|
18
|
+
* fact arrived.
|
|
19
|
+
*
|
|
20
|
+
* Version 1 records (`[key, expiresAt]`, written before the id was kept) are read as sent: that
|
|
21
|
+
* is all a v1 record ever held, and dropping them would report every remembered occurrence again.
|
|
11
22
|
*/
|
|
12
|
-
const VERSION =
|
|
23
|
+
const VERSION = 2;
|
|
13
24
|
function storageKey(name) {
|
|
14
25
|
return `track_once.${name}`;
|
|
15
26
|
}
|
|
@@ -25,21 +36,41 @@ function read(name) {
|
|
|
25
36
|
}
|
|
26
37
|
if (typeof record !== "object" || record === null) return [];
|
|
27
38
|
const { v, entries } = record;
|
|
28
|
-
if (
|
|
29
|
-
return entries.flatMap((entry) => {
|
|
39
|
+
if (!Array.isArray(entries)) return [];
|
|
40
|
+
if (v === 1) return entries.flatMap((entry) => {
|
|
30
41
|
if (!Array.isArray(entry)) return [];
|
|
31
42
|
const [key, expiresAt] = entry;
|
|
32
43
|
if (typeof key !== "string" || typeof expiresAt !== "number") return [];
|
|
33
44
|
return [{
|
|
34
45
|
key,
|
|
35
|
-
|
|
46
|
+
id: "",
|
|
47
|
+
expiresAt,
|
|
48
|
+
sent: true
|
|
49
|
+
}];
|
|
50
|
+
});
|
|
51
|
+
if (v !== VERSION) return [];
|
|
52
|
+
return entries.flatMap((entry) => {
|
|
53
|
+
if (!Array.isArray(entry)) return [];
|
|
54
|
+
const [key, id, expiresAt, sent] = entry;
|
|
55
|
+
if (typeof key !== "string" || typeof id !== "string" || typeof expiresAt !== "number") return [];
|
|
56
|
+
if (typeof sent !== "boolean") return [];
|
|
57
|
+
return [{
|
|
58
|
+
key,
|
|
59
|
+
id,
|
|
60
|
+
expiresAt,
|
|
61
|
+
sent
|
|
36
62
|
}];
|
|
37
63
|
});
|
|
38
64
|
}
|
|
39
65
|
function write(name, entries) {
|
|
40
66
|
const record = {
|
|
41
67
|
v: VERSION,
|
|
42
|
-
entries: entries.slice(-20).map((
|
|
68
|
+
entries: entries.slice(-20).map((e) => [
|
|
69
|
+
e.key,
|
|
70
|
+
e.id,
|
|
71
|
+
e.expiresAt,
|
|
72
|
+
e.sent
|
|
73
|
+
])
|
|
43
74
|
};
|
|
44
75
|
require_setup_index.config.storage.setItem(storageKey(name), JSON.stringify(record));
|
|
45
76
|
}
|
|
@@ -67,10 +98,11 @@ function clearPending(name, key) {
|
|
|
67
98
|
* re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
|
|
68
99
|
* was queued.
|
|
69
100
|
*
|
|
70
|
-
* The key is
|
|
71
|
-
* send that fails is tried again by the next call instead of being lost
|
|
72
|
-
*
|
|
73
|
-
*
|
|
101
|
+
* The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a
|
|
102
|
+
* send that fails is tried again by the next call instead of being lost — under the same event id,
|
|
103
|
+
* so the third-party trackers fired by the first call are not fired again (see `VERSION`); within
|
|
104
|
+
* one page a key already queued is not queued twice. When the storage cannot be read or written
|
|
105
|
+
* the event is tracked anyway: a rare duplicate is better than a lost conversion.
|
|
74
106
|
*
|
|
75
107
|
* Deduplication is per device and storage. A second device still reports its own occurrence, so
|
|
76
108
|
* figures that must be exact (revenue) belong to server-side records.
|
|
@@ -78,20 +110,33 @@ function clearPending(name, key) {
|
|
|
78
110
|
function trackOnce(name, properties, { key, ttl = DEFAULT_TTL, ...options }) {
|
|
79
111
|
if (isPending(name, key)) return false;
|
|
80
112
|
const now = Date.now();
|
|
113
|
+
let earlier;
|
|
114
|
+
let id = (0, uuid.v7)();
|
|
81
115
|
try {
|
|
82
|
-
|
|
116
|
+
const entries = live(read(name), now);
|
|
117
|
+
earlier = entries.find((entry) => entry.key === key);
|
|
118
|
+
if (earlier?.sent) return false;
|
|
119
|
+
if (earlier) id = earlier.id;
|
|
120
|
+
else write(name, [...entries, {
|
|
121
|
+
key,
|
|
122
|
+
id,
|
|
123
|
+
expiresAt: now + ttl,
|
|
124
|
+
sent: false
|
|
125
|
+
}]);
|
|
83
126
|
} catch (e) {
|
|
84
127
|
if (e instanceof Error) console.log(e.message);
|
|
85
128
|
}
|
|
86
129
|
markPending(name, key);
|
|
87
|
-
require_track_index.
|
|
130
|
+
require_track_index.queueEvent(name, properties, {
|
|
88
131
|
...options,
|
|
89
132
|
onSucceed: (response) => {
|
|
90
133
|
clearPending(name, key);
|
|
91
134
|
try {
|
|
92
135
|
write(name, [...live(read(name), Date.now()).filter((entry) => entry.key !== key), {
|
|
93
136
|
key,
|
|
94
|
-
|
|
137
|
+
id,
|
|
138
|
+
expiresAt: Date.now() + ttl,
|
|
139
|
+
sent: true
|
|
95
140
|
}]);
|
|
96
141
|
} catch (e) {
|
|
97
142
|
if (e instanceof Error) console.log(e.message);
|
|
@@ -102,7 +147,10 @@ function trackOnce(name, properties, { key, ttl = DEFAULT_TTL, ...options }) {
|
|
|
102
147
|
clearPending(name, key);
|
|
103
148
|
options.onError?.(error);
|
|
104
149
|
}
|
|
105
|
-
}
|
|
150
|
+
}, earlier ? {
|
|
151
|
+
id,
|
|
152
|
+
pixels: false
|
|
153
|
+
} : { id });
|
|
106
154
|
return true;
|
|
107
155
|
}
|
|
108
156
|
//#endregion
|
package/dist/track/once.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.cjs","names":["config"],"sources":["../../src/track/once.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport { type TrackOptions,
|
|
1
|
+
{"version":3,"file":"once.cjs","names":["config","uuidv7"],"sources":["../../src/track/once.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { config } from '../setup/index';\nimport { type TrackOptions, queueEvent } from './index';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport interface TrackOnceOptions extends TrackOptions {\n /**\n * What makes this occurrence the same one again: a checkout session id for `purchase`, an order\n * id, a transaction id. Required, never derived from the properties, so the caller decides what\n * \"once\" means. The same key under another event name is a different occurrence.\n */\n key: string;\n /** How long a sent key is remembered, in milliseconds. 90 days by default. */\n ttl?: number;\n}\n\nconst DEFAULT_TTL = 90 * 24 * 60 * 60 * 1000;\n/** Keys remembered per event name; the oldest are forgotten first. */\nconst MAX_ENTRIES = 20;\n\n/**\n * `{\"v\":2,\"entries\":[[key, id, expiresAt, sent], …]}`, oldest first. Entries are tuples in an\n * array rather than an object keyed by `key`: an object would move integer-like keys (\"123\") to\n * the front and lose the order the oldest are dropped by. Escaping the value for the medium is the\n * storage's job, so this is plain JSON.\n *\n * `id` is the event id the key goes out under, decided by the first call and kept while `sent`\n * is false — a send that failed, or a page reloaded before its batch went out. The third-party\n * trackers fire when the event is tracked, not when it is sent, so that first call has already\n * reported the occurrence to them: the next call reuses the id, fires none of them again, and\n * the server (`on conflict (id) do nothing`) stores the event once even if the failed send had in\n * fact arrived.\n *\n * Version 1 records (`[key, expiresAt]`, written before the id was kept) are read as sent: that\n * is all a v1 record ever held, and dropping them would report every remembered occurrence again.\n */\nconst VERSION = 2;\n\ntype Entry = { key: string; id: string; expiresAt: number; sent: boolean };\n\nfunction storageKey(name: string) {\n return `track_once.${name}`;\n}\n\n/** The stored entries, or none for a record that is missing, of another version or malformed. */\nfunction read(name: string): Entry[] {\n const raw = config.storage.getItem(storageKey(name));\n if (!raw) return [];\n let record: unknown;\n try {\n record = JSON.parse(raw);\n } catch {\n return [];\n }\n if (typeof record !== 'object' || record === null) return [];\n const { v, entries } = record as { v?: unknown; entries?: unknown };\n if (!Array.isArray(entries)) return [];\n if (v === 1) {\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, expiresAt] = entry as unknown[];\n if (typeof key !== 'string' || typeof expiresAt !== 'number') return [];\n // Sent is all v1 remembered; the id it went out under is gone, and no longer needed.\n return [{ key, id: '', expiresAt, sent: true }];\n });\n }\n if (v !== VERSION) return [];\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, id, expiresAt, sent] = entry as unknown[];\n if (typeof key !== 'string' || typeof id !== 'string' || typeof expiresAt !== 'number') {\n return [];\n }\n if (typeof sent !== 'boolean') return [];\n return [{ key, id, expiresAt, sent }];\n });\n}\n\nfunction write(name: string, entries: Entry[]) {\n const record = {\n v: VERSION,\n entries: entries.slice(-MAX_ENTRIES).map((e) => [e.key, e.id, e.expiresAt, e.sent]),\n };\n config.storage.setItem(storageKey(name), JSON.stringify(record));\n}\n\nfunction live(entries: Entry[], now: number) {\n return entries.filter((entry) => entry.expiresAt > now);\n}\n\n/** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */\nconst pending = new Map<string, Set<string>>();\n\nfunction isPending(name: string, key: string) {\n return pending.get(name)?.has(key) ?? false;\n}\n\nfunction markPending(name: string, key: string) {\n const keys = pending.get(name);\n if (keys) keys.add(key);\n else pending.set(name, new Set([key]));\n}\n\nfunction clearPending(name: string, key: string) {\n const keys = pending.get(name);\n if (!keys) return;\n keys.delete(key);\n if (keys.size === 0) pending.delete(name);\n}\n\n/**\n * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a\n * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event\n * was queued.\n *\n * The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a\n * send that fails is tried again by the next call instead of being lost — under the same event id,\n * so the third-party trackers fired by the first call are not fired again (see `VERSION`); within\n * one page a key already queued is not queued twice. When the storage cannot be read or written\n * the event is tracked anyway: a rare duplicate is better than a lost conversion.\n *\n * Deduplication is per device and storage. A second device still reports its own occurrence, so\n * figures that must be exact (revenue) belong to server-side records.\n */\nexport function trackOnce<T extends EventName = EventName>(\n name: TrackName<T>,\n properties: TrackProperties<T> | undefined,\n { key, ttl = DEFAULT_TTL, ...options }: TrackOnceOptions\n): boolean {\n if (isPending(name, key)) return false;\n\n const now = Date.now();\n // An earlier call that failed to send: its id, and its pixels already fired.\n let earlier: Entry | undefined;\n let id = uuidv7();\n try {\n const entries = live(read(name), now);\n earlier = entries.find((entry) => entry.key === key);\n if (earlier?.sent) return false;\n if (earlier) id = earlier.id;\n else write(name, [...entries, { key, id, expiresAt: now + ttl, sent: false }]);\n } catch (e: unknown) {\n // Unrecorded, a failed send would fire the pixels again on the next call: a rare duplicate\n // there beats not tracking.\n if (e instanceof Error) console.log(e.message);\n }\n\n markPending(name, key);\n queueEvent(\n name,\n properties,\n {\n ...options,\n onSucceed: (response) => {\n clearPending(name, key);\n try {\n const entries = live(read(name), Date.now()).filter((entry) => entry.key !== key);\n write(name, [...entries, { key, id, expiresAt: Date.now() + ttl, sent: true }]);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n options.onSucceed?.(response);\n },\n onError: (error) => {\n // Not sent: the entry stays unsent, with its id, so a later call can try again.\n clearPending(name, key);\n options.onError?.(error);\n },\n },\n earlier ? { id, pixels: false } : { id }\n );\n return true;\n}\n"],"mappings":";;;;;AAgBA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAoBpB,MAAM,UAAU;AAIhB,SAAS,WAAW,MAAc;CAChC,OAAO,cAAc;AACvB;;AAGA,SAAS,KAAK,MAAuB;CACnC,MAAM,MAAMA,oBAAAA,OAAO,QAAQ,QAAQ,WAAW,IAAI,CAAC;CACnD,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,QAAQ;EACN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AAK,MAAM;IAAK,CAAC,CAAC;GAChF,SAAS,GAAY;IACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;GAC/C;GACA,QAAQ,YAAY,QAAQ;EAC9B;EACA,UAAU,UAAU;GAElB,aAAa,MAAM,GAAG;GACtB,QAAQ,UAAU,KAAK;EACzB;CACF,GACA,UAAU;EAAE;EAAI,QAAQ;CAAM,IAAI,EAAE,GAAG,CACzC;CACA,OAAO;AACT"}
|
package/dist/track/once.d.cts
CHANGED
|
@@ -16,10 +16,11 @@ export interface TrackOnceOptions extends TrackOptions {
|
|
|
16
16
|
* re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
|
|
17
17
|
* was queued.
|
|
18
18
|
*
|
|
19
|
-
* The key is
|
|
20
|
-
* send that fails is tried again by the next call instead of being lost
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a
|
|
20
|
+
* send that fails is tried again by the next call instead of being lost — under the same event id,
|
|
21
|
+
* so the third-party trackers fired by the first call are not fired again (see `VERSION`); within
|
|
22
|
+
* one page a key already queued is not queued twice. When the storage cannot be read or written
|
|
23
|
+
* the event is tracked anyway: a rare duplicate is better than a lost conversion.
|
|
23
24
|
*
|
|
24
25
|
* Deduplication is per device and storage. A second device still reports its own occurrence, so
|
|
25
26
|
* figures that must be exact (revenue) belong to server-side records.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.d.cts","names":[],"sources":["../../src/track/once.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"once.d.cts","names":[],"sources":["../../src/track/once.ts"],"mappings":";;;iBAKiB,yBAAyB;;;;;;EAMxC;;EAEA;;;;;;;;;;;;;;;;wBA+Gc,UAAU,UAAU,YAAY,WAC9C,MAAM,UAAU,IAChB,YAAY,gBAAgB,kBAC1B,KAAK,QAAsB,WAAW"}
|
package/dist/track/once.d.mts
CHANGED
|
@@ -16,10 +16,11 @@ export interface TrackOnceOptions extends TrackOptions {
|
|
|
16
16
|
* re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
|
|
17
17
|
* was queued.
|
|
18
18
|
*
|
|
19
|
-
* The key is
|
|
20
|
-
* send that fails is tried again by the next call instead of being lost
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a
|
|
20
|
+
* send that fails is tried again by the next call instead of being lost — under the same event id,
|
|
21
|
+
* so the third-party trackers fired by the first call are not fired again (see `VERSION`); within
|
|
22
|
+
* one page a key already queued is not queued twice. When the storage cannot be read or written
|
|
23
|
+
* the event is tracked anyway: a rare duplicate is better than a lost conversion.
|
|
23
24
|
*
|
|
24
25
|
* Deduplication is per device and storage. A second device still reports its own occurrence, so
|
|
25
26
|
* figures that must be exact (revenue) belong to server-side records.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.d.mts","names":[],"sources":["../../src/track/once.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"once.d.mts","names":[],"sources":["../../src/track/once.ts"],"mappings":";;;iBAKiB,yBAAyB;;;;;;EAMxC;;EAEA;;;;;;;;;;;;;;;;wBA+Gc,UAAU,UAAU,YAAY,WAC9C,MAAM,UAAU,IAChB,YAAY,gBAAgB,kBAC1B,KAAK,QAAsB,WAAW"}
|
package/dist/track/once.mjs
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { config } from "../setup/index.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { queueEvent } from "./index.mjs";
|
|
3
|
+
import { v7 } from "uuid";
|
|
3
4
|
//#region src/track/once.ts
|
|
4
5
|
const DEFAULT_TTL = 7776e6;
|
|
5
6
|
/**
|
|
6
|
-
* `{"v":
|
|
7
|
-
* than an object keyed by `key`: an object would move integer-like keys ("123") to
|
|
8
|
-
* lose the order the oldest are dropped by. Escaping the value for the medium is the
|
|
9
|
-
* job, so this is plain JSON.
|
|
7
|
+
* `{"v":2,"entries":[[key, id, expiresAt, sent], …]}`, oldest first. Entries are tuples in an
|
|
8
|
+
* array rather than an object keyed by `key`: an object would move integer-like keys ("123") to
|
|
9
|
+
* the front and lose the order the oldest are dropped by. Escaping the value for the medium is the
|
|
10
|
+
* storage's job, so this is plain JSON.
|
|
11
|
+
*
|
|
12
|
+
* `id` is the event id the key goes out under, decided by the first call and kept while `sent`
|
|
13
|
+
* is false — a send that failed, or a page reloaded before its batch went out. The third-party
|
|
14
|
+
* trackers fire when the event is tracked, not when it is sent, so that first call has already
|
|
15
|
+
* reported the occurrence to them: the next call reuses the id, fires none of them again, and
|
|
16
|
+
* the server (`on conflict (id) do nothing`) stores the event once even if the failed send had in
|
|
17
|
+
* fact arrived.
|
|
18
|
+
*
|
|
19
|
+
* Version 1 records (`[key, expiresAt]`, written before the id was kept) are read as sent: that
|
|
20
|
+
* is all a v1 record ever held, and dropping them would report every remembered occurrence again.
|
|
10
21
|
*/
|
|
11
|
-
const VERSION =
|
|
22
|
+
const VERSION = 2;
|
|
12
23
|
function storageKey(name) {
|
|
13
24
|
return `track_once.${name}`;
|
|
14
25
|
}
|
|
@@ -24,21 +35,41 @@ function read(name) {
|
|
|
24
35
|
}
|
|
25
36
|
if (typeof record !== "object" || record === null) return [];
|
|
26
37
|
const { v, entries } = record;
|
|
27
|
-
if (
|
|
28
|
-
return entries.flatMap((entry) => {
|
|
38
|
+
if (!Array.isArray(entries)) return [];
|
|
39
|
+
if (v === 1) return entries.flatMap((entry) => {
|
|
29
40
|
if (!Array.isArray(entry)) return [];
|
|
30
41
|
const [key, expiresAt] = entry;
|
|
31
42
|
if (typeof key !== "string" || typeof expiresAt !== "number") return [];
|
|
32
43
|
return [{
|
|
33
44
|
key,
|
|
34
|
-
|
|
45
|
+
id: "",
|
|
46
|
+
expiresAt,
|
|
47
|
+
sent: true
|
|
48
|
+
}];
|
|
49
|
+
});
|
|
50
|
+
if (v !== VERSION) return [];
|
|
51
|
+
return entries.flatMap((entry) => {
|
|
52
|
+
if (!Array.isArray(entry)) return [];
|
|
53
|
+
const [key, id, expiresAt, sent] = entry;
|
|
54
|
+
if (typeof key !== "string" || typeof id !== "string" || typeof expiresAt !== "number") return [];
|
|
55
|
+
if (typeof sent !== "boolean") return [];
|
|
56
|
+
return [{
|
|
57
|
+
key,
|
|
58
|
+
id,
|
|
59
|
+
expiresAt,
|
|
60
|
+
sent
|
|
35
61
|
}];
|
|
36
62
|
});
|
|
37
63
|
}
|
|
38
64
|
function write(name, entries) {
|
|
39
65
|
const record = {
|
|
40
66
|
v: VERSION,
|
|
41
|
-
entries: entries.slice(-20).map((
|
|
67
|
+
entries: entries.slice(-20).map((e) => [
|
|
68
|
+
e.key,
|
|
69
|
+
e.id,
|
|
70
|
+
e.expiresAt,
|
|
71
|
+
e.sent
|
|
72
|
+
])
|
|
42
73
|
};
|
|
43
74
|
config.storage.setItem(storageKey(name), JSON.stringify(record));
|
|
44
75
|
}
|
|
@@ -66,10 +97,11 @@ function clearPending(name, key) {
|
|
|
66
97
|
* re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
|
|
67
98
|
* was queued.
|
|
68
99
|
*
|
|
69
|
-
* The key is
|
|
70
|
-
* send that fails is tried again by the next call instead of being lost
|
|
71
|
-
*
|
|
72
|
-
*
|
|
100
|
+
* The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a
|
|
101
|
+
* send that fails is tried again by the next call instead of being lost — under the same event id,
|
|
102
|
+
* so the third-party trackers fired by the first call are not fired again (see `VERSION`); within
|
|
103
|
+
* one page a key already queued is not queued twice. When the storage cannot be read or written
|
|
104
|
+
* the event is tracked anyway: a rare duplicate is better than a lost conversion.
|
|
73
105
|
*
|
|
74
106
|
* Deduplication is per device and storage. A second device still reports its own occurrence, so
|
|
75
107
|
* figures that must be exact (revenue) belong to server-side records.
|
|
@@ -77,20 +109,33 @@ function clearPending(name, key) {
|
|
|
77
109
|
function trackOnce(name, properties, { key, ttl = DEFAULT_TTL, ...options }) {
|
|
78
110
|
if (isPending(name, key)) return false;
|
|
79
111
|
const now = Date.now();
|
|
112
|
+
let earlier;
|
|
113
|
+
let id = v7();
|
|
80
114
|
try {
|
|
81
|
-
|
|
115
|
+
const entries = live(read(name), now);
|
|
116
|
+
earlier = entries.find((entry) => entry.key === key);
|
|
117
|
+
if (earlier?.sent) return false;
|
|
118
|
+
if (earlier) id = earlier.id;
|
|
119
|
+
else write(name, [...entries, {
|
|
120
|
+
key,
|
|
121
|
+
id,
|
|
122
|
+
expiresAt: now + ttl,
|
|
123
|
+
sent: false
|
|
124
|
+
}]);
|
|
82
125
|
} catch (e) {
|
|
83
126
|
if (e instanceof Error) console.log(e.message);
|
|
84
127
|
}
|
|
85
128
|
markPending(name, key);
|
|
86
|
-
|
|
129
|
+
queueEvent(name, properties, {
|
|
87
130
|
...options,
|
|
88
131
|
onSucceed: (response) => {
|
|
89
132
|
clearPending(name, key);
|
|
90
133
|
try {
|
|
91
134
|
write(name, [...live(read(name), Date.now()).filter((entry) => entry.key !== key), {
|
|
92
135
|
key,
|
|
93
|
-
|
|
136
|
+
id,
|
|
137
|
+
expiresAt: Date.now() + ttl,
|
|
138
|
+
sent: true
|
|
94
139
|
}]);
|
|
95
140
|
} catch (e) {
|
|
96
141
|
if (e instanceof Error) console.log(e.message);
|
|
@@ -101,7 +146,10 @@ function trackOnce(name, properties, { key, ttl = DEFAULT_TTL, ...options }) {
|
|
|
101
146
|
clearPending(name, key);
|
|
102
147
|
options.onError?.(error);
|
|
103
148
|
}
|
|
104
|
-
}
|
|
149
|
+
}, earlier ? {
|
|
150
|
+
id,
|
|
151
|
+
pixels: false
|
|
152
|
+
} : { id });
|
|
105
153
|
return true;
|
|
106
154
|
}
|
|
107
155
|
//#endregion
|
package/dist/track/once.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.mjs","names":[],"sources":["../../src/track/once.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport { type TrackOptions,
|
|
1
|
+
{"version":3,"file":"once.mjs","names":["uuidv7"],"sources":["../../src/track/once.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { config } from '../setup/index';\nimport { type TrackOptions, queueEvent } from './index';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport interface TrackOnceOptions extends TrackOptions {\n /**\n * What makes this occurrence the same one again: a checkout session id for `purchase`, an order\n * id, a transaction id. Required, never derived from the properties, so the caller decides what\n * \"once\" means. The same key under another event name is a different occurrence.\n */\n key: string;\n /** How long a sent key is remembered, in milliseconds. 90 days by default. */\n ttl?: number;\n}\n\nconst DEFAULT_TTL = 90 * 24 * 60 * 60 * 1000;\n/** Keys remembered per event name; the oldest are forgotten first. */\nconst MAX_ENTRIES = 20;\n\n/**\n * `{\"v\":2,\"entries\":[[key, id, expiresAt, sent], …]}`, oldest first. Entries are tuples in an\n * array rather than an object keyed by `key`: an object would move integer-like keys (\"123\") to\n * the front and lose the order the oldest are dropped by. Escaping the value for the medium is the\n * storage's job, so this is plain JSON.\n *\n * `id` is the event id the key goes out under, decided by the first call and kept while `sent`\n * is false — a send that failed, or a page reloaded before its batch went out. The third-party\n * trackers fire when the event is tracked, not when it is sent, so that first call has already\n * reported the occurrence to them: the next call reuses the id, fires none of them again, and\n * the server (`on conflict (id) do nothing`) stores the event once even if the failed send had in\n * fact arrived.\n *\n * Version 1 records (`[key, expiresAt]`, written before the id was kept) are read as sent: that\n * is all a v1 record ever held, and dropping them would report every remembered occurrence again.\n */\nconst VERSION = 2;\n\ntype Entry = { key: string; id: string; expiresAt: number; sent: boolean };\n\nfunction storageKey(name: string) {\n return `track_once.${name}`;\n}\n\n/** The stored entries, or none for a record that is missing, of another version or malformed. */\nfunction read(name: string): Entry[] {\n const raw = config.storage.getItem(storageKey(name));\n if (!raw) return [];\n let record: unknown;\n try {\n record = JSON.parse(raw);\n } catch {\n return [];\n }\n if (typeof record !== 'object' || record === null) return [];\n const { v, entries } = record as { v?: unknown; entries?: unknown };\n if (!Array.isArray(entries)) return [];\n if (v === 1) {\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, expiresAt] = entry as unknown[];\n if (typeof key !== 'string' || typeof expiresAt !== 'number') return [];\n // Sent is all v1 remembered; the id it went out under is gone, and no longer needed.\n return [{ key, id: '', expiresAt, sent: true }];\n });\n }\n if (v !== VERSION) return [];\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, id, expiresAt, sent] = entry as unknown[];\n if (typeof key !== 'string' || typeof id !== 'string' || typeof expiresAt !== 'number') {\n return [];\n }\n if (typeof sent !== 'boolean') return [];\n return [{ key, id, expiresAt, sent }];\n });\n}\n\nfunction write(name: string, entries: Entry[]) {\n const record = {\n v: VERSION,\n entries: entries.slice(-MAX_ENTRIES).map((e) => [e.key, e.id, e.expiresAt, e.sent]),\n };\n config.storage.setItem(storageKey(name), JSON.stringify(record));\n}\n\nfunction live(entries: Entry[], now: number) {\n return entries.filter((entry) => entry.expiresAt > now);\n}\n\n/** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */\nconst pending = new Map<string, Set<string>>();\n\nfunction isPending(name: string, key: string) {\n return pending.get(name)?.has(key) ?? false;\n}\n\nfunction markPending(name: string, key: string) {\n const keys = pending.get(name);\n if (keys) keys.add(key);\n else pending.set(name, new Set([key]));\n}\n\nfunction clearPending(name: string, key: string) {\n const keys = pending.get(name);\n if (!keys) return;\n keys.delete(key);\n if (keys.size === 0) pending.delete(name);\n}\n\n/**\n * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a\n * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event\n * was queued.\n *\n * The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a\n * send that fails is tried again by the next call instead of being lost — under the same event id,\n * so the third-party trackers fired by the first call are not fired again (see `VERSION`); within\n * one page a key already queued is not queued twice. When the storage cannot be read or written\n * the event is tracked anyway: a rare duplicate is better than a lost conversion.\n *\n * Deduplication is per device and storage. A second device still reports its own occurrence, so\n * figures that must be exact (revenue) belong to server-side records.\n */\nexport function trackOnce<T extends EventName = EventName>(\n name: TrackName<T>,\n properties: TrackProperties<T> | undefined,\n { key, ttl = DEFAULT_TTL, ...options }: TrackOnceOptions\n): boolean {\n if (isPending(name, key)) return false;\n\n const now = Date.now();\n // An earlier call that failed to send: its id, and its pixels already fired.\n let earlier: Entry | undefined;\n let id = uuidv7();\n try {\n const entries = live(read(name), now);\n earlier = entries.find((entry) => entry.key === key);\n if (earlier?.sent) return false;\n if (earlier) id = earlier.id;\n else write(name, [...entries, { key, id, expiresAt: now + ttl, sent: false }]);\n } catch (e: unknown) {\n // Unrecorded, a failed send would fire the pixels again on the next call: a rare duplicate\n // there beats not tracking.\n if (e instanceof Error) console.log(e.message);\n }\n\n markPending(name, key);\n queueEvent(\n name,\n properties,\n {\n ...options,\n onSucceed: (response) => {\n clearPending(name, key);\n try {\n const entries = live(read(name), Date.now()).filter((entry) => entry.key !== key);\n write(name, [...entries, { key, id, expiresAt: Date.now() + ttl, sent: true }]);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n options.onSucceed?.(response);\n },\n onError: (error) => {\n // Not sent: the entry stays unsent, with its id, so a later call can try again.\n clearPending(name, key);\n options.onError?.(error);\n },\n },\n earlier ? { id, pixels: false } : { id }\n );\n return true;\n}\n"],"mappings":";;;;AAgBA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAoBpB,MAAM,UAAU;AAIhB,SAAS,WAAW,MAAc;CAChC,OAAO,cAAc;AACvB;;AAGA,SAAS,KAAK,MAAuB;CACnC,MAAM,MAAM,OAAO,QAAQ,QAAQ,WAAW,IAAI,CAAC;CACnD,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,QAAQ;EACN,OAAO,CAAC;CACV;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO,CAAC;CAC3D,MAAM,EAAE,GAAG,YAA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;EACA,UAAU,UAAU;GAElB,aAAa,MAAM,GAAG;GACtB,QAAQ,UAAU,KAAK;EACzB;CACF,GACA,UAAU;EAAE;EAAI,QAAQ;CAAM,IAAI,EAAE,GAAG,CACzC;CACA,OAAO;AACT"}
|
package/dist/track/types.d.cts
CHANGED
|
@@ -66,7 +66,16 @@ export interface UserProvidedData extends UserProvidedData$1 {
|
|
|
66
66
|
fb_login_id?: string;
|
|
67
67
|
fb_page_id?: string;
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* A browser pixel or app SDK an event is forwarded to. Called synchronously when the event is
|
|
71
|
+
* tracked, before it is sent, with `event_id` — the client-generated id the event is stored and
|
|
72
|
+
* sent to the conversions APIs under — as the platform's deduplication id.
|
|
73
|
+
*
|
|
74
|
+
* Returning `false` means "not ready": the pixel's global (`fbq`, `rdt`, `gtag`, …) is not on the
|
|
75
|
+
* page yet, its snippet still loading. The SDK then calls the tracker once more, with the same
|
|
76
|
+
* event and id, on the next macrotask. Any other return value (`void` included) is a handled call.
|
|
77
|
+
*/
|
|
78
|
+
export type ThirdPartyTracker = <T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string) => void | boolean;
|
|
70
79
|
export interface PlatformInfo {
|
|
71
80
|
os?: string;
|
|
72
81
|
os_name?: string;
|
|
@@ -263,8 +272,16 @@ export interface TrackEvent<T extends EventName = EventName> {
|
|
|
263
272
|
properties?: TrackProperties<T>;
|
|
264
273
|
created_at: string;
|
|
265
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* What `POST /events` answers: one `{ id }` per event, in the order sent.
|
|
277
|
+
*
|
|
278
|
+
* Since 12.1 the client generates each event's id and sends it in the DTO; the SDK no longer
|
|
279
|
+
* reads this answer, and `onSucceed` reports the client's id. Servers keep answering it for
|
|
280
|
+
* clients before 12.1, which fire their pixels with the id found here. To be removed in the next
|
|
281
|
+
* major.
|
|
282
|
+
*/
|
|
266
283
|
export type TrackEventResponse = {
|
|
267
|
-
/**
|
|
284
|
+
/** The event's id, the one the pixels and the conversions APIs deduplicate on. */
|
|
268
285
|
id: string;
|
|
269
286
|
}[];
|
|
270
287
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":["GAUserProvidedData"],"sources":["../../src/track/types.ts"],"mappings":";;YAEY;YACA,YAAY;YAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;YAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;YAEpB;YACA;iBAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,yBAAyBA;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":["GAUserProvidedData"],"sources":["../../src/track/types.ts"],"mappings":";;YAEY;YACA,YAAY;YAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;YAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;YAEpB;YACA;iBAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,yBAAyBA;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;;;;;;;;;;YAYU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;iBAGe;EACf;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;iBAGe;;EAEf;EACA;;iBAGe;EACf;EACA;EACA;;;;;;;;;;iBAWe;EACf;EACA;EACA;;;;;;;EAOA;;;;;;EAMA;;;;;;;;;;;;;iBAce;EAEf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;EAMA;;EAEA;;EAEA;;EAEA;EAEA;EACA;EACA;EACA;;;;;;;;EAQA;;;;;;EAMA;EACA;EACA;EACA;;EAEA;;EAEA;EAEA;;EAEA;EAEA;;EAEA;;EAEA;;EAEA;EAEA;;;;;EAKA;EAEA;;EAEA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;;;;;;;iBAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;iBAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;iBAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;;;;;;;;;YAWU;;EAEV"}
|
package/dist/track/types.d.mts
CHANGED
|
@@ -66,7 +66,16 @@ export interface UserProvidedData extends UserProvidedData$1 {
|
|
|
66
66
|
fb_login_id?: string;
|
|
67
67
|
fb_page_id?: string;
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* A browser pixel or app SDK an event is forwarded to. Called synchronously when the event is
|
|
71
|
+
* tracked, before it is sent, with `event_id` — the client-generated id the event is stored and
|
|
72
|
+
* sent to the conversions APIs under — as the platform's deduplication id.
|
|
73
|
+
*
|
|
74
|
+
* Returning `false` means "not ready": the pixel's global (`fbq`, `rdt`, `gtag`, …) is not on the
|
|
75
|
+
* page yet, its snippet still loading. The SDK then calls the tracker once more, with the same
|
|
76
|
+
* event and id, on the next macrotask. Any other return value (`void` included) is a handled call.
|
|
77
|
+
*/
|
|
78
|
+
export type ThirdPartyTracker = <T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string) => void | boolean;
|
|
70
79
|
export interface PlatformInfo {
|
|
71
80
|
os?: string;
|
|
72
81
|
os_name?: string;
|
|
@@ -263,8 +272,16 @@ export interface TrackEvent<T extends EventName = EventName> {
|
|
|
263
272
|
properties?: TrackProperties<T>;
|
|
264
273
|
created_at: string;
|
|
265
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* What `POST /events` answers: one `{ id }` per event, in the order sent.
|
|
277
|
+
*
|
|
278
|
+
* Since 12.1 the client generates each event's id and sends it in the DTO; the SDK no longer
|
|
279
|
+
* reads this answer, and `onSucceed` reports the client's id. Servers keep answering it for
|
|
280
|
+
* clients before 12.1, which fire their pixels with the id found here. To be removed in the next
|
|
281
|
+
* major.
|
|
282
|
+
*/
|
|
266
283
|
export type TrackEventResponse = {
|
|
267
|
-
/**
|
|
284
|
+
/** The event's id, the one the pixels and the conversions APIs deduplicate on. */
|
|
268
285
|
id: string;
|
|
269
286
|
}[];
|
|
270
287
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":["GAUserProvidedData"],"sources":["../../src/track/types.ts"],"mappings":";;YAEY;YACA,YAAY;YAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;YAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;YAEpB;YACA;iBAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,yBAAyBA;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":["GAUserProvidedData"],"sources":["../../src/track/types.ts"],"mappings":";;YAEY;YACA,YAAY;YAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;YAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;YAEpB;YACA;iBAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,yBAAyBA;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;;;;;;;;;;YAYU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;iBAGe;EACf;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;iBAGe;;EAEf;EACA;;iBAGe;EACf;EACA;EACA;;;;;;;;;;iBAWe;EACf;EACA;EACA;;;;;;;EAOA;;;;;;EAMA;;;;;;;;;;;;;iBAce;EAEf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;EAMA;;EAEA;;EAEA;;EAEA;EAEA;EACA;EACA;EACA;;;;;;;;EAQA;;;;;;EAMA;EACA;EACA;EACA;;EAEA;;EAEA;EAEA;;EAEA;EAEA;;EAEA;;EAEA;;EAEA;EAEA;;;;;EAKA;EAEA;;EAEA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;;;;;;;iBAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;iBAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UA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