@decocms/blocks 8.16.1 → 8.18.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/dist/v8/analytics/client.d.ts +48 -0
- package/dist/v8/analytics/client.d.ts.map +1 -0
- package/dist/v8/analytics/client.js +71 -0
- package/dist/v8/analytics/client.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/click.d.ts +2 -0
- package/dist/v8/analytics/runtime/modules/click.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/click.js +48 -0
- package/dist/v8/analytics/runtime/modules/click.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/commerce.d.ts +2 -0
- package/dist/v8/analytics/runtime/modules/commerce.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/commerce.js +41 -0
- package/dist/v8/analytics/runtime/modules/commerce.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/consent.d.ts +33 -0
- package/dist/v8/analytics/runtime/modules/consent.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/consent.js +154 -0
- package/dist/v8/analytics/runtime/modules/consent.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/deco.d.ts +2 -0
- package/dist/v8/analytics/runtime/modules/deco.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/deco.js +209 -0
- package/dist/v8/analytics/runtime/modules/deco.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/engagement.d.ts +2 -0
- package/dist/v8/analytics/runtime/modules/engagement.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/engagement.js +128 -0
- package/dist/v8/analytics/runtime/modules/engagement.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/errors.d.ts +2 -0
- package/dist/v8/analytics/runtime/modules/errors.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/errors.js +167 -0
- package/dist/v8/analytics/runtime/modules/errors.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/heatmap.d.ts +2 -0
- package/dist/v8/analytics/runtime/modules/heatmap.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/heatmap.js +316 -0
- package/dist/v8/analytics/runtime/modules/heatmap.js.map +1 -0
- package/dist/v8/analytics/runtime/modules/vitals.d.ts +2 -0
- package/dist/v8/analytics/runtime/modules/vitals.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/modules/vitals.js +119 -0
- package/dist/v8/analytics/runtime/modules/vitals.js.map +1 -0
- package/dist/v8/analytics/runtime/src/guards.d.ts +10 -0
- package/dist/v8/analytics/runtime/src/guards.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/src/guards.js +70 -0
- package/dist/v8/analytics/runtime/src/guards.js.map +1 -0
- package/dist/v8/analytics/runtime/src/index.d.ts +2 -0
- package/dist/v8/analytics/runtime/src/index.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/src/index.js +562 -0
- package/dist/v8/analytics/runtime/src/index.js.map +1 -0
- package/dist/v8/analytics/runtime/src/queue.d.ts +15 -0
- package/dist/v8/analytics/runtime/src/queue.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/src/queue.js +36 -0
- package/dist/v8/analytics/runtime/src/queue.js.map +1 -0
- package/dist/v8/analytics/runtime/src/trim.d.ts +13 -0
- package/dist/v8/analytics/runtime/src/trim.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/src/trim.js +38 -0
- package/dist/v8/analytics/runtime/src/trim.js.map +1 -0
- package/dist/v8/analytics/runtime/view/heat-core.d.ts +69 -0
- package/dist/v8/analytics/runtime/view/heat-core.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/view/heat-core.js +314 -0
- package/dist/v8/analytics/runtime/view/heat-core.js.map +1 -0
- package/dist/v8/analytics/runtime/view/view.d.ts +51 -0
- package/dist/v8/analytics/runtime/view/view.d.ts.map +1 -0
- package/dist/v8/analytics/runtime/view/view.js +525 -0
- package/dist/v8/analytics/runtime/view/view.js.map +1 -0
- package/dist/v8/analytics/shared/anchor.d.ts +71 -0
- package/dist/v8/analytics/shared/anchor.d.ts.map +1 -0
- package/dist/v8/analytics/shared/anchor.js +155 -0
- package/dist/v8/analytics/shared/anchor.js.map +1 -0
- package/dist/v8/analytics/shared/contract.d.ts +294 -0
- package/dist/v8/analytics/shared/contract.d.ts.map +1 -0
- package/dist/v8/analytics/shared/contract.js +652 -0
- package/dist/v8/analytics/shared/contract.js.map +1 -0
- package/dist/v8/builtins/data.d.ts +20 -6
- package/dist/v8/builtins/data.d.ts.map +1 -1
- package/dist/v8/builtins/data.js +33 -8
- package/dist/v8/builtins/data.js.map +1 -1
- package/dist/v8/cms.js +2 -2
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/settings.d.ts +28 -9
- package/dist/v8/settings.d.ts.map +1 -1
- package/dist/v8/settings.js +6 -10
- package/dist/v8/settings.js.map +1 -1
- package/dist/v8/telemetry.d.ts +13 -11
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +27 -17
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/types.d.ts +7 -3
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +6 -1
- package/skills/deco-storefront-performance/references/render-location.md +3 -2
- package/skills/deco-v7-to-v8-migration/references/telemetry.md +1 -1
- package/skills/deco-v7-to-v8-migration/scripts/siteSettings.ts +1 -1
- package/src/v8/analytics/client.ts +110 -0
- package/src/v8/analytics/runtime/globals.d.ts +36 -0
- package/src/v8/analytics/runtime/modules/click.ts +54 -0
- package/src/v8/analytics/runtime/modules/commerce.ts +73 -0
- package/src/v8/analytics/runtime/modules/consent.ts +150 -0
- package/src/v8/analytics/runtime/modules/deco.ts +207 -0
- package/src/v8/analytics/runtime/modules/engagement.ts +140 -0
- package/src/v8/analytics/runtime/modules/errors.ts +217 -0
- package/src/v8/analytics/runtime/modules/heatmap.ts +360 -0
- package/src/v8/analytics/runtime/modules/vitals.ts +128 -0
- package/src/v8/analytics/runtime/src/guards.ts +70 -0
- package/src/v8/analytics/runtime/src/index.ts +606 -0
- package/src/v8/analytics/runtime/src/queue.ts +40 -0
- package/src/v8/analytics/runtime/src/trim.ts +39 -0
- package/src/v8/analytics/runtime/view/heat-core.ts +335 -0
- package/src/v8/analytics/runtime/view/view.ts +596 -0
- package/src/v8/analytics/shared/anchor.ts +171 -0
- package/src/v8/analytics/shared/contract.ts +691 -0
- package/src/v8/analytics/tsconfig.json +14 -0
- package/src/v8/builtins/data.ts +44 -9
- package/src/v8/cms.ts +4 -4
- package/src/v8/settings.ts +13 -16
- package/src/v8/telemetry.ts +33 -29
- package/src/v8/types.ts +7 -3
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/** Element anchors for heatmaps: the ONE definition of "which element was clicked", shared by
|
|
2
|
+
* the browser runtime (`runtime/modules/heatmap.ts`) and the viewer that paints the heat on a
|
|
3
|
+
* server-rendered snapshot (insights-mcp vendors this file verbatim).
|
|
4
|
+
*
|
|
5
|
+
* Both sides must produce the same hash for the same element, so this file is self-contained:
|
|
6
|
+
* no imports, no globals beyond the DOM node it is handed, nothing that differs between a
|
|
7
|
+
* visitor's browser and a sandboxed iframe. `tests/fixtures/anchor-vectors.json` pins the output;
|
|
8
|
+
* a change to anything below that moves a vector is a breaking change for every heatmap already
|
|
9
|
+
* collected, so it bumps ANCHOR_VERSION and ships in both repos at once.
|
|
10
|
+
*
|
|
11
|
+
* The algorithm, exactly:
|
|
12
|
+
*
|
|
13
|
+
* 1. ANCHOR. From the click target, walk up at most 6 elements (target included) and take the
|
|
14
|
+
* first that matches ACTIONABLE (interactive = true). If none does, repeat the walk and take
|
|
15
|
+
* the first element carrying a `data-fs-*` attribute that is not a page wrapper, stopping at a
|
|
16
|
+
* Deco section (interactive = false). Else the target.
|
|
17
|
+
* A click on the <span> inside "Comprar" counts for the button, which is what a reader expects.
|
|
18
|
+
*
|
|
19
|
+
* 2. ROOT, the first that applies:
|
|
20
|
+
* a. the nearest `section[data-manifest-key]` (Deco CMS section, self included):
|
|
21
|
+
* identity `<manifest key>#<ordinal among sections with the same key, document order>`;
|
|
22
|
+
* b. the OUTERMOST element on the anchor's ancestor chain (self included, `body` excluded)
|
|
23
|
+
* carrying a `data-fs-*` attribute whose component name is not a page wrapper (WRAPPER):
|
|
24
|
+
* identity `fs:<name>#<ordinal among elements carrying that attribute>`. Outermost, not
|
|
25
|
+
* nearest: measured on FILA, New Balance and Umbro (2026-10-26), none of which render a
|
|
26
|
+
* single `data-manifest-key` section, the outermost FastStore component is the
|
|
27
|
+
* section-sized one (`hero-slideshow`, `tabbed-product-shelf`, `desktop-header`), while the
|
|
28
|
+
* nearest is a product card or a link whose ordinal shifts as lazy content loads;
|
|
29
|
+
* c. the nearest ancestor-or-self with an `id` that does not look generated (BAD_ID):
|
|
30
|
+
* identity `#<id>`;
|
|
31
|
+
* d. `body`: identity "" (the wire sends section index -1).
|
|
32
|
+
* `<name>` is the attribute name without `data-fs-`. A `data-fs-*` attribute is chosen as the
|
|
33
|
+
* alphabetically FIRST one on the element, so attribute order never matters.
|
|
34
|
+
*
|
|
35
|
+
* 3. PATH from root (exclusive) to anchor (inclusive), root first, segments joined by `>`:
|
|
36
|
+
* `<localName>` + (`[<first data-fs-* attribute name>]` if any) + `:` + nth-of-type (1-based).
|
|
37
|
+
* Example: `div:2>article[data-fs-product-card]:3>a:1`. Empty when the anchor is the root.
|
|
38
|
+
* Classes, text, href, src and non-root ids are excluded on purpose: classes churn on every
|
|
39
|
+
* Tailwind deploy, and text/href are PII and change daily.
|
|
40
|
+
*
|
|
41
|
+
* 4. HASH: `cyrb53(identity + "|" + path)`, a 53-bit integer (exact in a JS number and in JSON),
|
|
42
|
+
* sent as base36. Collision odds at ~5,000 clickable elements per page: about 1e-9.
|
|
43
|
+
*/
|
|
44
|
+
export const ANCHOR_VERSION = 1;
|
|
45
|
+
export const ACTIONABLE = "a,button,input,select,textarea,label,summary,[role=button],[role=link],[role=tab]," +
|
|
46
|
+
'[role=menuitem],[role=option],[role=checkbox],[tabindex]:not([tabindex="-1"])';
|
|
47
|
+
/** FastStore component names that wrap a whole page rather than one part of it. Umbro's home is
|
|
48
|
+
* `data-fs-home` around every block; taking it as the root would put the whole page in one
|
|
49
|
+
* "section". */
|
|
50
|
+
export const WRAPPER = /^(home|page|layout|content|main|root|wrapper|container|region|grid)$/;
|
|
51
|
+
/** Ids minted by a framework or a counter: different on every render, so useless as a root. */
|
|
52
|
+
export const BAD_ID = /\d{4,}|^:r|^radix-|^headlessui-|[0-9a-f]{8}|react-aria|[:«»]/;
|
|
53
|
+
/** cyrb53 (bryc, public domain): a fast 53-bit string hash with good avalanche. */
|
|
54
|
+
export function cyrb53(s, seed = 0) {
|
|
55
|
+
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
56
|
+
for (let i = 0; i < s.length; i++) {
|
|
57
|
+
const ch = s.charCodeAt(i);
|
|
58
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
59
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
60
|
+
}
|
|
61
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
62
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
63
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
64
|
+
}
|
|
65
|
+
/** The alphabetically first `data-fs-*` attribute name on an element, or "". */
|
|
66
|
+
export function fsAttr(e) {
|
|
67
|
+
let m = "";
|
|
68
|
+
for (const n of e.getAttributeNames())
|
|
69
|
+
if (n.startsWith("data-fs-") && (!m || n < m))
|
|
70
|
+
m = n;
|
|
71
|
+
return m;
|
|
72
|
+
}
|
|
73
|
+
/** Step 1. Returns the anchor and whether it is interactive. */
|
|
74
|
+
export function anchorOf(t) {
|
|
75
|
+
let e = t;
|
|
76
|
+
for (let i = 0; e && i < 6; e = e.parentElement, i++)
|
|
77
|
+
if (e.matches(ACTIONABLE))
|
|
78
|
+
return [e, true];
|
|
79
|
+
// Never a page wrapper, and never across a Deco section: an <h2> clicked inside a section must
|
|
80
|
+
// not anchor on the `data-fs-home` that wraps every section of the page.
|
|
81
|
+
e = t;
|
|
82
|
+
for (let i = 0; e && i < 6 && !e.matches("section[data-manifest-key]"); e = e.parentElement, i++) {
|
|
83
|
+
const f = fsAttr(e);
|
|
84
|
+
if (f && !WRAPPER.test(f.slice(8)))
|
|
85
|
+
return [e, false];
|
|
86
|
+
}
|
|
87
|
+
return [t, false];
|
|
88
|
+
}
|
|
89
|
+
const ordinal = (list, e, same) => {
|
|
90
|
+
let n = 0;
|
|
91
|
+
for (const x of list) {
|
|
92
|
+
if (x === e)
|
|
93
|
+
return n;
|
|
94
|
+
if (same(x))
|
|
95
|
+
n++;
|
|
96
|
+
}
|
|
97
|
+
return n;
|
|
98
|
+
};
|
|
99
|
+
/** A FastStore component root by step 2b, or "" — exported so a viewer can enumerate roots. */
|
|
100
|
+
export function fsRootName(e) {
|
|
101
|
+
const a = fsAttr(e);
|
|
102
|
+
return a && !WRAPPER.test(a.slice(8)) && /^[a-z0-9-]+$/.test(a) ? a : "";
|
|
103
|
+
}
|
|
104
|
+
/** Step 2. Returns the root element (null for body) and its identity. */
|
|
105
|
+
export function rootOf(a) {
|
|
106
|
+
const d = a.ownerDocument;
|
|
107
|
+
const s = a.closest("section[data-manifest-key]");
|
|
108
|
+
if (s) {
|
|
109
|
+
const k = s.getAttribute("data-manifest-key");
|
|
110
|
+
return [
|
|
111
|
+
s,
|
|
112
|
+
k +
|
|
113
|
+
"#" +
|
|
114
|
+
ordinal(d.querySelectorAll("section[data-manifest-key]"), s, (x) => x.getAttribute("data-manifest-key") === k),
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
let fs = null, name = "";
|
|
118
|
+
for (let e = a; e && e !== d.body; e = e.parentElement) {
|
|
119
|
+
const n = fsRootName(e);
|
|
120
|
+
if (n) {
|
|
121
|
+
fs = e;
|
|
122
|
+
name = n;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (fs)
|
|
126
|
+
return [
|
|
127
|
+
fs,
|
|
128
|
+
"fs:" + name.slice(8) + "#" + ordinal(d.querySelectorAll("[" + name + "]"), fs, () => true),
|
|
129
|
+
];
|
|
130
|
+
for (let e = a; e && e !== d.body; e = e.parentElement) {
|
|
131
|
+
if (e.id && !BAD_ID.test(e.id))
|
|
132
|
+
return [e, "#" + e.id];
|
|
133
|
+
}
|
|
134
|
+
return [null, ""];
|
|
135
|
+
}
|
|
136
|
+
/** Step 3. */
|
|
137
|
+
export function pathOf(root, a) {
|
|
138
|
+
const out = [];
|
|
139
|
+
for (let e = a, i = 0; e && e !== root && e !== e.ownerDocument.body && i < 64; e = e.parentElement, i++) {
|
|
140
|
+
let n = 1;
|
|
141
|
+
for (let s = e.previousElementSibling; s; s = s.previousElementSibling)
|
|
142
|
+
if (s.localName === e.localName)
|
|
143
|
+
n++;
|
|
144
|
+
const f = fsAttr(e);
|
|
145
|
+
out.push(e.localName + (f ? "[" + f + "]" : "") + ":" + n);
|
|
146
|
+
}
|
|
147
|
+
return out.reverse().join(">");
|
|
148
|
+
}
|
|
149
|
+
/** Steps 2-4 for an element already chosen as anchor: what the wire carries and what a viewer
|
|
150
|
+
* matches on. `root` is the identity string ("" = body), `el` the base36 hash. */
|
|
151
|
+
export function anchorHash(a) {
|
|
152
|
+
const [rootEl, root] = rootOf(a);
|
|
153
|
+
return { root, el: cyrb53(root + "|" + pathOf(rootEl, a)).toString(36), rootEl };
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=anchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor.js","sourceRoot":"","sources":["../../../../src/v8/analytics/shared/anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,U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AAC,CAAC,SAAS;gBAAE,CAAC,EAAE,CAAC;QACvC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACpB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;mFACmF;AACnF,MAAM,UAAU,UAAU,CAAC,CAAU;IACnC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/** The payload contract — one definition, imported by the runtime and by the Worker.
|
|
2
|
+
*
|
|
3
|
+
* It lived in two files with duplicated constants, which is the reliable way to end up
|
|
4
|
+
* with a client truncating at 200 and a server truncating at 250. The runtime applies
|
|
5
|
+
* these rules to save bandwidth; the Worker applies them because the endpoint is public
|
|
6
|
+
* and the client is by definition untrusted. Same rules, different reasons.
|
|
7
|
+
*
|
|
8
|
+
* Fields deliberately do NOT share one charset. Applying a single rule everywhere is the
|
|
9
|
+
* mistake: `plp-ranking` is a frozen experiment key owned by another team and contains a
|
|
10
|
+
* hyphen, and an order id from a customer's OMS is opaque and case-sensitive. Normalising
|
|
11
|
+
* those would break a join and an invoice respectively.
|
|
12
|
+
*/
|
|
13
|
+
export declare const LIMITS: {
|
|
14
|
+
readonly requestBytes: number;
|
|
15
|
+
readonly batchBytes: number;
|
|
16
|
+
readonly eventsPerBatch: 50;
|
|
17
|
+
readonly eventBytes: 1024;
|
|
18
|
+
readonly errorEventBytes: number;
|
|
19
|
+
readonly heatmapEventBytes: number;
|
|
20
|
+
readonly hmClicks: 40;
|
|
21
|
+
readonly hmRoots: 32;
|
|
22
|
+
readonly hmBands: 40;
|
|
23
|
+
readonly hmRootLen: 120;
|
|
24
|
+
readonly queueMax: 200;
|
|
25
|
+
readonly nameLen: 40;
|
|
26
|
+
readonly propKeys: 24;
|
|
27
|
+
readonly keyLen: 40;
|
|
28
|
+
readonly valueLen: 200;
|
|
29
|
+
readonly expEntries: 8;
|
|
30
|
+
readonly expKeyLen: 60;
|
|
31
|
+
readonly pathLen: 512;
|
|
32
|
+
readonly refLen: 256;
|
|
33
|
+
readonly itemIds: 20;
|
|
34
|
+
readonly itemIdLen: 64;
|
|
35
|
+
readonly transactionIdLen: 64;
|
|
36
|
+
readonly flushMs: 10000;
|
|
37
|
+
};
|
|
38
|
+
/** `_trunc` is `LowCardinality(String)`. A free-text flag would rebuild the cardinality
|
|
39
|
+
* problem inside the column that exists to detect it, so the vocabulary is closed —
|
|
40
|
+
* and small, which keeps its dictionary at a handful of entries for the whole fleet. */
|
|
41
|
+
/** Flags are namespaced by the field they concern. `value.type` was ambiguous: there is
|
|
42
|
+
* also a column called `value` holding money, so a reader could not tell whether the flag
|
|
43
|
+
* meant "a prop was the wrong type" or "the amount would not parse". Now `props.*` is
|
|
44
|
+
* about the props map and `amount.*` is about money.
|
|
45
|
+
*
|
|
46
|
+
* The four the client needs are exported individually as well as in the map below.
|
|
47
|
+
* esbuild cannot tree-shake a single property off an object it sees referenced, so
|
|
48
|
+
* `FLAGS.propsCount` drags all twenty-one strings into the browser bundle. Naming them
|
|
49
|
+
* separately keeps the client at the four it uses. */
|
|
50
|
+
export declare const F_PROPS_COUNT = "props.count";
|
|
51
|
+
export declare const F_PROPS_TYPE = "props.type";
|
|
52
|
+
export declare const F_PROPS_LEN = "props.len";
|
|
53
|
+
export declare const F_QUEUE_OVERFLOW = "queue.overflow";
|
|
54
|
+
/** More events arrived in one request than `eventsPerBatch` allows. The surplus is discarded
|
|
55
|
+
* and the survivors carry this, so the loss is visible in the warehouse rather than inferred
|
|
56
|
+
* from a gap — the same contract `queue.overflow` makes on the client. */
|
|
57
|
+
export declare const F_BATCH_OVERFLOW = "batch.overflow";
|
|
58
|
+
export declare const FLAGS: {
|
|
59
|
+
readonly nameEmpty: "name.empty";
|
|
60
|
+
readonly nameCharset: "name.charset";
|
|
61
|
+
readonly nameLen: "name.len";
|
|
62
|
+
readonly nameReserved: "name.reserved";
|
|
63
|
+
readonly keyCharset: "key.charset";
|
|
64
|
+
readonly keyLen: "key.len";
|
|
65
|
+
readonly propsCount: "props.count";
|
|
66
|
+
readonly propsType: "props.type";
|
|
67
|
+
readonly propsLen: "props.len";
|
|
68
|
+
readonly propsControl: "props.control";
|
|
69
|
+
readonly expCount: "exp.count";
|
|
70
|
+
readonly expCharset: "exp.charset";
|
|
71
|
+
readonly currencyInvalid: "currency.invalid";
|
|
72
|
+
readonly amountType: "amount.type";
|
|
73
|
+
readonly pathLen: "path.len";
|
|
74
|
+
readonly refLen: "referrer.len";
|
|
75
|
+
readonly itemIdsCount: "item_ids.count";
|
|
76
|
+
readonly tsSkew: "ts.skew";
|
|
77
|
+
readonly queueOverflow: "queue.overflow";
|
|
78
|
+
readonly eventSize: "event.size";
|
|
79
|
+
readonly eventIdMinted: "event_id.minted";
|
|
80
|
+
readonly saltDerived: "salt.derived";
|
|
81
|
+
readonly saltEphemeral: "salt.ephemeral";
|
|
82
|
+
readonly consentNoSecret: "consent.no_secret";
|
|
83
|
+
readonly saltSecretUnsplit: "salt.unsplit";
|
|
84
|
+
readonly originMismatch: "origin.mismatch";
|
|
85
|
+
readonly nameUnregistered: "name.unregistered";
|
|
86
|
+
readonly propsUnregistered: "props.unregistered";
|
|
87
|
+
readonly hmLen: "hm.len";
|
|
88
|
+
readonly hmShape: "hm.shape";
|
|
89
|
+
readonly edgeNoBotScore: "edge.no_bot_score";
|
|
90
|
+
readonly importVendor: "import.vendor";
|
|
91
|
+
readonly importDayGrain: "import.day_grain";
|
|
92
|
+
};
|
|
93
|
+
export type Flag = (typeof FLAGS)[keyof typeof FLAGS];
|
|
94
|
+
export type Primitive = string | number | boolean;
|
|
95
|
+
export type Props = Record<string, Primitive>;
|
|
96
|
+
/** Platform events. Anything else arriving with a `$` is a site reaching into a namespace
|
|
97
|
+
* that is not its own: the prefix is stripped and the attempt recorded. */
|
|
98
|
+
/** Platform events. Anything else arriving with a `$` is a site reaching into a namespace
|
|
99
|
+
* that is not its own: the prefix is stripped and the attempt recorded.
|
|
100
|
+
*
|
|
101
|
+
* The engagement four are reserved for the same reason as the rest — they are generated
|
|
102
|
+
* by our module, not by the site, so a registry must not ask a site to declare them and
|
|
103
|
+
* a site must not be able to forge them. */
|
|
104
|
+
export declare const RESERVED_NAMES: readonly ["$pageview", "$error", "$vitals", "$exposure", "$scroll", "$outbound", "$download", "$search", "$heatmap"];
|
|
105
|
+
/** Whether the sampling valve is allowed to drop this event.
|
|
106
|
+
*
|
|
107
|
+
* Sampling used to apply to EVERYTHING, `$pageview` included, and that is not what anyone
|
|
108
|
+
* else does: GA4 samples in the REPORT when a query exceeds its quota, never at
|
|
109
|
+
* collection, and Plausible does not sample at all. Dropping pageviews also produced the
|
|
110
|
+
* worst possible arithmetic — a visitor with k events survives a rate r with probability
|
|
111
|
+
* 1-(1-r)^k, so a nominal 10% sample kept ~50% of visitors while keeping exactly 10% of
|
|
112
|
+
* events, a five-fold overcount of uniques.
|
|
113
|
+
*
|
|
114
|
+
* The collector's own `$` events are exempt, and that dissolves the problem rather than
|
|
115
|
+
* mitigating it: every visit carries a `$pageview`, so if pageviews never drop then
|
|
116
|
+
* visitor counts are exact at any rate. They are also bounded per pageview by
|
|
117
|
+
* construction — one pageview, one vitals, one scroll, errors already collapsed into
|
|
118
|
+
* `error_count` — so exempting them sheds almost no volume.
|
|
119
|
+
*
|
|
120
|
+
* What floods a site is custom events: `track()` in a render loop is the emergency this
|
|
121
|
+
* valve exists for, and it is the only thing the valve now touches. */
|
|
122
|
+
export declare function isSampleable(name: string): boolean;
|
|
123
|
+
/** What the store's own Worker may write through `EdgeIngest`, and the props each one carries.
|
|
124
|
+
*
|
|
125
|
+
* A CLOSED vocabulary, unlike the tag's. The edge is ours: these are the requests a store
|
|
126
|
+
* Worker sees on both sides of a Fresh x TanStack split, emitted by one wrapper rather than by
|
|
127
|
+
* each site's code, and that sameness is the whole reason they can be a ruler for an A/B test
|
|
128
|
+
* between two codebases. A name outside this list is refused and counted; a prop outside it is
|
|
129
|
+
* kept and flagged `props.unregistered`, like the site registry does.
|
|
130
|
+
*
|
|
131
|
+
* They land in `edge_events`, never in `raw_events` (D20), so no panel, rollup or session
|
|
132
|
+
* built on the tag ever counts a checkout API call as a page view. */
|
|
133
|
+
export declare const EDGE_EVENTS: {
|
|
134
|
+
/** One per HTML document, on both sides of the split. `og` is the orderGroup on the order
|
|
135
|
+
* confirmation (`/checkout/orderPlaced?og=`): it links a VTEX order to the visit that saw it.
|
|
136
|
+
* `sc` is the sales channel of the request; `cart` the hashed orderForm on checkout documents. */
|
|
137
|
+
readonly $edge_page: readonly ["page", "status", "prefetch", "cache", "ttfb_ms", "og", "sc", "cart", "fetch_site"];
|
|
138
|
+
/** One per call to the VTEX checkout API. `step` includes `gatewayCallback`. The cart shape
|
|
139
|
+
* (`qty` .. `items_value`, `payment`, `coupon`) is read from the orderForm that `shippingData`
|
|
140
|
+
* and `paymentData` return; `error` is the VTEX code and message on a status >= 400. */
|
|
141
|
+
readonly checkout_step: readonly ["step", "status", "cart", "payment", "coupon", "shipping_paid", "items", "referer", "error", "ms", "from_checkout", "qty", "lines", "sellers", "packages", "shipping", "items_value"];
|
|
142
|
+
/** One per call that changes the cart outside the checkout: `add`, `remove`, `update`,
|
|
143
|
+
* `coupon`, `simulate`. The route differs per side (v7's invoke route on Fresh, the TanStack
|
|
144
|
+
* invoke route), and the store Worker maps both to this. */
|
|
145
|
+
readonly cart_action: readonly ["action", "status", "cart", "items"];
|
|
146
|
+
/** What the shopper is paying and why, beside `checkout_step` on `shippingData` and
|
|
147
|
+
* `paymentData`: discounts, promotions, the orderForm's messages, unavailable items, gifts,
|
|
148
|
+
* who VTEX thinks the shopper is, and what the payment POST asked for. */
|
|
149
|
+
readonly checkout_summary: readonly ["step", "status", "cart", "value", "items_value", "discounts", "shipping", "qty", "lines", "promos", "promo_hash", "promo_names", "messages", "message_count", "unavailable", "selectable_gifts", "gift_items", "priced_items", "utm_source", "coupon", "tags", "channels", "pay_systems", "installments", "pay_value", "logged_in", "can_edit", "email", "profile_id", "saved_cards", "saved_addresses", "cookies"];
|
|
150
|
+
/** The checkout page's own beacon, forwarded by the store Worker: JS errors, the step the
|
|
151
|
+
* shopper is on, the click on "place order" (`kind = buy`) and what followed it, the messages
|
|
152
|
+
* on screen, the exit. `kind` is the beacon's, `msg`/`aux`/`n` its three fields. */
|
|
153
|
+
readonly checkout_js: readonly ["kind", "msg", "aux", "n", "cart"];
|
|
154
|
+
};
|
|
155
|
+
export type EdgeEventName = keyof typeof EDGE_EVENTS;
|
|
156
|
+
/** Props per edge event. Above the tag's `propKeys` because the vocabulary is closed and ours:
|
|
157
|
+
* `checkout_summary` carries 32 fields, and packing them into fewer keys would trade a query on
|
|
158
|
+
* a column for a parse of a string. */
|
|
159
|
+
export declare const EDGE_PROP_KEYS = 40;
|
|
160
|
+
/** Size budget per edge event, for the same reason: the tag's 1 KB is a budget for a visitor's
|
|
161
|
+
* upload on mobile data, and an edge event never travels over one. */
|
|
162
|
+
export declare const EDGE_EVENT_BYTES = 4096;
|
|
163
|
+
export declare const EDGE_EVENT_NAMES: EdgeEventName[];
|
|
164
|
+
/** The side of a Fresh x TanStack split, as an experiment.
|
|
165
|
+
*
|
|
166
|
+
* `withABTesting` (decocms/blocks, compat-v7) keeps the side in the `_deco_bucket` cookie as
|
|
167
|
+
* `<side>:<percent>`. The runtime's deco adapter reads it into `exp`, and the store Worker
|
|
168
|
+
* stamps the same pair on what it sends through `EdgeIngest`, so both halves of the funnel
|
|
169
|
+
* group by one experiment with one pair of variant names. Changing a value here without
|
|
170
|
+
* changing the store side splits the funnel in two. */
|
|
171
|
+
export declare const STOREFRONT_EXP: {
|
|
172
|
+
readonly cookie: "_deco_bucket";
|
|
173
|
+
readonly name: "storefront";
|
|
174
|
+
readonly variants: Record<string, string>;
|
|
175
|
+
};
|
|
176
|
+
/** The campaign parameters worth a typed column, and nothing else. `utm` is a Map with
|
|
177
|
+
* LowCardinality keys: an open vocabulary is exactly how that becomes a cardinality
|
|
178
|
+
* problem, since anything appending `utm_<random>` to a URL would mint a key forever.
|
|
179
|
+
* The five UTM parameters are the standard set; `gclid` and `fbclid` are here because
|
|
180
|
+
* they are what actually arrives from paid traffic and are otherwise lost. */
|
|
181
|
+
export declare const CAMPAIGN_KEYS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "gclid", "fbclid"];
|
|
182
|
+
/** Strip the `utm_` prefix on the way in: the column is already called `utm`, so storing
|
|
183
|
+
* `utm_source` spends five characters per row per key restating it. */
|
|
184
|
+
export declare const campaignKey: (raw: string) => string | null;
|
|
185
|
+
/** Short keys on the wire, full names in the column. At 452M events a month, field names
|
|
186
|
+
* are a double-digit percentage of a 293-byte event — and the browser pays that upload on
|
|
187
|
+
* mobile data. Plausible does the same for the same reason. The Worker expands them, so
|
|
188
|
+
* nothing downstream ever sees the abbreviation. */
|
|
189
|
+
/** What a minted self-serve key looks like: a prefix and 22 URL-safe characters, the same
|
|
190
|
+
* shape the visitor hash uses.
|
|
191
|
+
*
|
|
192
|
+
* It lives in the CONTRACT rather than in the Worker's config module because it is one:
|
|
193
|
+
* whoever mints keys and whoever reads them have to agree, and those will not be the same
|
|
194
|
+
* codebase (D9). Deliberately NOT a secret — Plausible puts the equivalent in the script's
|
|
195
|
+
* filename, OneDollarStats uses the hostname itself, and a public identifier is the only
|
|
196
|
+
* thing a browser tag can carry. That is exactly why a key-sourced site is recorded as
|
|
197
|
+
* `tag` and never billed from. Checking the shape is a BOUND, not authentication: without
|
|
198
|
+
* it, any string of any length from any visitor becomes a KV read we pay for. */
|
|
199
|
+
export declare const KEY_SHAPE: RegExp;
|
|
200
|
+
export declare const WIRE: {
|
|
201
|
+
readonly event_id: "i";
|
|
202
|
+
/** A stable per-browser identifier, present ONLY on a tier-1 site whose visitor has
|
|
203
|
+
* granted consent. Absent otherwise, which is the whole point: at tier 0 there is
|
|
204
|
+
* nothing to send, and the Worker derives identity from a salt it rotates and forgets
|
|
205
|
+
* daily. Never stored as sent — the Worker hashes it with the site so the same browser
|
|
206
|
+
* is a different identifier on every customer's site. */
|
|
207
|
+
readonly client_id: "ci";
|
|
208
|
+
readonly ts: "t";
|
|
209
|
+
readonly name: "n";
|
|
210
|
+
readonly path: "p";
|
|
211
|
+
readonly referrer: "r";
|
|
212
|
+
readonly exp: "x";
|
|
213
|
+
readonly props: "d";
|
|
214
|
+
readonly value: "v";
|
|
215
|
+
readonly currency: "c";
|
|
216
|
+
readonly items_count: "q";
|
|
217
|
+
readonly item_ids: "s";
|
|
218
|
+
readonly transaction_id: "o";
|
|
219
|
+
readonly error_type: "et";
|
|
220
|
+
readonly error_message: "em";
|
|
221
|
+
readonly error_file: "ef";
|
|
222
|
+
readonly error_line: "el";
|
|
223
|
+
readonly error_stack: "es";
|
|
224
|
+
readonly error_fingerprint: "eg";
|
|
225
|
+
readonly error_count: "ec";
|
|
226
|
+
readonly utm: "u";
|
|
227
|
+
readonly vital_lcp: "vl";
|
|
228
|
+
readonly vital_inp: "vi";
|
|
229
|
+
readonly vital_cls: "vc";
|
|
230
|
+
readonly vital_ttfb: "vt";
|
|
231
|
+
readonly vital_fcp: "vf";
|
|
232
|
+
readonly heatmap: "hm";
|
|
233
|
+
readonly _trunc: "_";
|
|
234
|
+
};
|
|
235
|
+
export type Sink = (f: Flag) => void;
|
|
236
|
+
/** snake_case, letter-initial, no spaces. The name becomes a panel label and a grouping
|
|
237
|
+
* key, so case and punctuation fragment one event across variants of itself — and a
|
|
238
|
+
* fragmented name also inflates the `LowCardinality` dictionary it lives in.
|
|
239
|
+
*
|
|
240
|
+
* Normalising is right. Doing it silently is not: two names collapsing into one is
|
|
241
|
+
* something the sender has to be able to see. */
|
|
242
|
+
export declare function normalizeName(input: unknown, flag: Sink, reserved?: readonly string[]): string;
|
|
243
|
+
/** Control characters are replaced rather than truncated around: a newline inside a value
|
|
244
|
+
* breaks line-oriented reads of the same data downstream, and a tab breaks TSV. */
|
|
245
|
+
export declare function normalizeProps(input: unknown, flag: Sink, maxKeys?: number): Record<string, string>;
|
|
246
|
+
/** Case and hyphens preserved: these keys are a frozen contract owned elsewhere, and
|
|
247
|
+
* rewriting `plp-ranking` into `plp_ranking` would silently break the join they exist
|
|
248
|
+
* for. Invalid keys are dropped rather than coerced, for the same reason. */
|
|
249
|
+
export declare function normalizeExp(input: unknown, flag: Sink): Record<string, string>;
|
|
250
|
+
/** ISO 4217, three letters. Anything else is emptied and flagged: a half-valid currency on
|
|
251
|
+
* a revenue row is worse than a missing one. */
|
|
252
|
+
export declare function normalizeCurrency(input: unknown, flag: Sink): string;
|
|
253
|
+
/** Unparseable becomes null and is flagged, never coerced to zero. A silent zero in a
|
|
254
|
+
* revenue report is a wrong number; a null is a missing one, and only one of those gets
|
|
255
|
+
* noticed. */
|
|
256
|
+
export declare function normalizeAmount(input: unknown, flag: Sink): number | null;
|
|
257
|
+
/** An id that ClickHouse will accept, minted when the sender did not supply a usable one.
|
|
258
|
+
*
|
|
259
|
+
* This closes a hole that cost whole batches. `event_id` is a `UUID` column, and an absent
|
|
260
|
+
* id normalised to `""` -- which fails to parse, and a JSONEachRow INSERT fails as ONE
|
|
261
|
+
* statement. So a single event without an id destroyed every event in the same request,
|
|
262
|
+
* the sender got its 204, and the only trace was `events_lost`. Measured: one event with
|
|
263
|
+
* no `i` field, ClickHouse code 27, `inserted: 0`, `eventsLost: 1`.
|
|
264
|
+
*
|
|
265
|
+
* Our own runtime always sends one, which is exactly why this went unnoticed -- but the
|
|
266
|
+
* endpoint is public, and a server-side sender or a third-party SDK writing the lean
|
|
267
|
+
* version of our contract is not a hypothetical. `sanitize.ts` promises never to "reject a
|
|
268
|
+
* batch because one event is bad", and this is the one place it silently did. */
|
|
269
|
+
export declare function normalizeEventId(input: unknown, flag: Sink): string;
|
|
270
|
+
export declare function normalizeOpaque(input: unknown, max: number): string;
|
|
271
|
+
export declare function normalizeItemIds(input: unknown, flag: Sink): string[];
|
|
272
|
+
export declare function normalizeTs(input: unknown, flag: Sink): string;
|
|
273
|
+
/** Deduped and sorted, so two events that hit the same limits produce a byte-identical
|
|
274
|
+
* array — which is what lets the column compress instead of merely storing. */
|
|
275
|
+
export declare function flagSink(initial?: readonly string[]): {
|
|
276
|
+
flag: Sink;
|
|
277
|
+
list: () => string[];
|
|
278
|
+
};
|
|
279
|
+
/** The config fields the SERVED BUNDLE is built from — and nothing else.
|
|
280
|
+
*
|
|
281
|
+
* Purging on every config write would throw away the fleet's cache for changes that do not move
|
|
282
|
+
* a single byte of the script. `domains` is only ever read server-side, to cross-check an Origin
|
|
283
|
+
* against a declared key; `schema` drives validation in the Worker; `goals` belongs to the read
|
|
284
|
+
* side. None of them reach the browser.
|
|
285
|
+
*
|
|
286
|
+
* Kept here, next to the wire contract, because it is exactly that: a promise about what the
|
|
287
|
+
* bundle depends on. When `serveScript` starts reading another field, it goes in this list, and
|
|
288
|
+
* the test that compares the two catches it if it does not. */
|
|
289
|
+
export declare const BUNDLE_FIELDS: readonly ["id", "sampling", "tier", "hash", "modules", "heatmapRate", "errorHosts"];
|
|
290
|
+
/** A stable fingerprint of just those fields, for deciding whether a write needs a purge.
|
|
291
|
+
* Key order is fixed rather than whatever `JSON.stringify` produces from an object literal,
|
|
292
|
+
* since two configs equal in content must not differ here by the order someone typed them. */
|
|
293
|
+
export declare function bundleFingerprint(cfg: Record<string, unknown> | null | undefined): string;
|
|
294
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../src/v8/analytics/shared/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,MAAM;aACjB,YAAY;aAGZ,UAAU;aACV,cAAc,EAAE,EAAE;aAClB,UAAU,EAAE,IAAI;aAChB,eAAe;aAIf,iBAAiB;aACjB,QAAQ,EAAE,EAAE;aACZ,OAAO,EAAE,EAAE;aACX,OAAO,EAAE,EAAE;aACX,SAAS,EAAE,GAAG;aACd,QAAQ,EAAE,GAAG;aAIb,OAAO,EAAE,EAAE;aACX,QAAQ,EAAE,EAAE;aACZ,MAAM,EAAE,EAAE;aACV,QAAQ,EAAE,GAAG;aAEb,UAAU,EAAE,CAAC;aACb,SAAS,EAAE,EAAE;aACb,OAAO,EAAE,GAAG;aACZ,MAAM,EAAE,GAAG;aACX,OAAO,EAAE,EAAE;aACX,SAAS,EAAE,EAAE;aACb,gBAAgB,EAAE,EAAE;aACpB,OAAO,EAAE,KAAM;CACP,CAAC;AAEX;;yFAEyF;AACzF;;;;;;;;uDAQuD;AACvD,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAC3C,eAAO,MAAM,YAAY,eAAe,CAAC;AACzC,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AACjD;;2EAE2E;AAC3E,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAEjD,eAAO,MAAM,KAAK;aAChB,SAAS,EAAE,YAAY;aACvB,WAAW,EAAE,cAAc;aAC3B,OAAO,EAAE,UAAU;aACnB,YAAY,EAAE,eAAe;aAC7B,UAAU,EAAE,aAAa;aACzB,MAAM,EAAE,SAAS;aACjB,UAAU;aACV,SAAS;aACT,QAAQ;aACR,YAAY,EAAE,eAAe;aAC7B,QAAQ,EAAE,WAAW;aACrB,UA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