@decocms/blocks 8.17.0 → 8.18.1
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/fetch.d.ts.map +1 -1
- package/dist/v8/fetch.js +27 -2
- package/dist/v8/fetch.js.map +1 -1
- package/dist/v8/telemetry.d.ts +2 -0
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +21 -6
- package/dist/v8/telemetry.js.map +1 -1
- package/package.json +6 -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/fetch.ts +27 -2
- package/src/v8/telemetry.ts +25 -5
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** Core Web Vitals, in one event on the way out.
|
|
2
|
+
*
|
|
3
|
+
* Not five events, and not one per metric as they settle. Every vital is only final when
|
|
4
|
+
* the page is: LCP can be replaced by a later element, CLS accumulates until the visitor
|
|
5
|
+
* leaves, and INP is the worst interaction of the whole visit. Sending them early means
|
|
6
|
+
* sending them wrong, and sending each separately means four extra rows carrying one
|
|
7
|
+
* number each and repeating the same page, path and visitor.
|
|
8
|
+
*
|
|
9
|
+
* Deliberately not the `web-vitals` library. It is ~2 KB for an attribution model we do
|
|
10
|
+
* not use, and this is the part of the payload every visitor downloads.
|
|
11
|
+
*/
|
|
12
|
+
window.__dqRegister?.((enqueue, _api: Record<string, unknown>, onFinal) => {
|
|
13
|
+
let lcp: number | null = null;
|
|
14
|
+
let cls = 0;
|
|
15
|
+
let inp = 0;
|
|
16
|
+
let sent = false;
|
|
17
|
+
// The vitals are the DOCUMENT's: LCP, FCP and TTFB belong to the hard load, never to a later
|
|
18
|
+
// SPA route. They are sent on the way out, when `location` and the heatmap's view id already
|
|
19
|
+
// name whatever route the visitor ended on, so both are taken here, for the page being
|
|
20
|
+
// measured. The view id a microtask later, once the heatmap module (after this one in the
|
|
21
|
+
// bundle) has opened its first view.
|
|
22
|
+
const path = location.pathname;
|
|
23
|
+
let hv: unknown;
|
|
24
|
+
queueMicrotask(() => {
|
|
25
|
+
hv = _api.hv;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// The first moment the page was hidden. A tab opened in the BACKGROUND — ctrl+click
|
|
29
|
+
// from a listing, "open link in new tab" — keeps accruing largest-contentful-paint
|
|
30
|
+
// until it is first revealed, so its LCP measures how long the visitor took to look at
|
|
31
|
+
// the tab, not how long the content took to appear. Measured on a live storefront:
|
|
32
|
+
// per-page LCP of 152,858 ms and 151,296 ms on product pages (the ones opened from a
|
|
33
|
+
// listing, naturally) against a 936 ms p75 for the whole site — three samples are
|
|
34
|
+
// enough to make the per-page panel unreadable.
|
|
35
|
+
//
|
|
36
|
+
// Paint metrics that land after this point are therefore dropped. TTFB, CLS and INP
|
|
37
|
+
// are kept: none of them is distorted by the tab being hidden.
|
|
38
|
+
let firstHidden = document.visibilityState === "hidden" ? 0 : Infinity;
|
|
39
|
+
addEventListener(
|
|
40
|
+
"visibilitychange",
|
|
41
|
+
() => {
|
|
42
|
+
firstHidden = Math.min(firstHidden, performance.now());
|
|
43
|
+
},
|
|
44
|
+
{ once: true },
|
|
45
|
+
);
|
|
46
|
+
const whileVisible = (v: number | null) => (v === null || v > firstHidden ? null : v);
|
|
47
|
+
|
|
48
|
+
const observe = (type: string, cb: (entries: any[]) => void, opts: any = {}) => {
|
|
49
|
+
try {
|
|
50
|
+
const po = new PerformanceObserver((list) => cb(list.getEntries()));
|
|
51
|
+
po.observe({ type, buffered: true, ...opts });
|
|
52
|
+
return po;
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
} // an unsupported entry type must not break collection
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// The LAST largest-contentful-paint wins: the browser reports a new one whenever a
|
|
59
|
+
// bigger element arrives, and only the final value is the metric.
|
|
60
|
+
observe("largest-contentful-paint", (es) => {
|
|
61
|
+
const last = es[es.length - 1];
|
|
62
|
+
if (last) lcp = last.startTime;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// CLS excludes shifts within 500ms of an interaction — a layout change the visitor
|
|
66
|
+
// asked for is not "unexpected", and counting it punishes responsive UI.
|
|
67
|
+
observe("layout-shift", (es) => {
|
|
68
|
+
for (const e of es) if (!e.hadRecentInput) cls += e.value;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// A true INP is the 98th percentile of interaction latencies. Keeping every interaction
|
|
72
|
+
// to compute that costs memory on a page that may run for an hour, so this is the worst
|
|
73
|
+
// one — which is INP exactly whenever a visit has fewer than fifty interactions, and an
|
|
74
|
+
// upper bound otherwise. The direction of the error is knowable, which is what matters.
|
|
75
|
+
observe(
|
|
76
|
+
"event",
|
|
77
|
+
(es) => {
|
|
78
|
+
for (const e of es) if (e.duration > inp) inp = e.duration;
|
|
79
|
+
},
|
|
80
|
+
{ durationThreshold: 40 },
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const paintOnce = (name: string): number | null => {
|
|
84
|
+
try {
|
|
85
|
+
const e = performance.getEntriesByName(name)[0] as PerformanceEntry | undefined;
|
|
86
|
+
return e ? e.startTime : null;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const ttfb = (): number | null => {
|
|
93
|
+
try {
|
|
94
|
+
const nav = performance.getEntriesByType("navigation")[0] as
|
|
95
|
+
| PerformanceNavigationTiming
|
|
96
|
+
| undefined;
|
|
97
|
+
return nav ? nav.responseStart : null;
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
function send() {
|
|
104
|
+
if (sent) return;
|
|
105
|
+
sent = true;
|
|
106
|
+
const fcp = paintOnce("first-contentful-paint");
|
|
107
|
+
const t = ttfb();
|
|
108
|
+
// Nothing observed at all means an unsupported browser, not a fast page. Sending a
|
|
109
|
+
// row of nulls would dilute every average with visits that were never measured.
|
|
110
|
+
if (lcp === null && fcp === null && t === null && cls === 0 && inp === 0) return;
|
|
111
|
+
enqueue("$vitals", undefined, {
|
|
112
|
+
path,
|
|
113
|
+
vital_lcp: whileVisible(lcp),
|
|
114
|
+
vital_inp: inp || null,
|
|
115
|
+
vital_cls: Math.round(cls * 10000) / 10000,
|
|
116
|
+
vital_ttfb: t,
|
|
117
|
+
vital_fcp: whileVisible(fcp),
|
|
118
|
+
// The heatmap module's view id when it sampled this view: the pilot's INP guardrail compares
|
|
119
|
+
// views with and without heatmap capture on the same site and days.
|
|
120
|
+
heatmap: hv ? { id: hv } : undefined,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Every vital is only final when the page is, so this rides out on core's last flush.
|
|
125
|
+
onFinal(send);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Reasons not to collect at all, evaluated once at boot.
|
|
2
|
+
*
|
|
3
|
+
* Automation detection has a catch: Playwright sets navigator.webdriver, so it would
|
|
4
|
+
* block our own end-to-end tests. `__dqAllowAutomation` is the escape hatch, and it is
|
|
5
|
+
* why 2.8 does not fail for the wrong reason. */
|
|
6
|
+
export function shouldSkip(w: typeof globalThis & Record<string, any>): string | null {
|
|
7
|
+
const nav = w.navigator;
|
|
8
|
+
|
|
9
|
+
if (!w.__dqAllowAutomation) {
|
|
10
|
+
if (nav?.webdriver) return "automation";
|
|
11
|
+
if (w._phantom || w.__nightmare || w.Cypress) return "automation";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
if (w.localStorage?.getItem("__dq_ignore") === "true") return "opt-out";
|
|
16
|
+
} catch {
|
|
17
|
+
/* storage can throw in private mode; not a reason to skip */
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isLocal(w) && !w.__dq?.dev) return "local";
|
|
21
|
+
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A development host. Not collected unless the site asks for it.
|
|
26
|
+
*
|
|
27
|
+
* This was missing entirely, and on a fleet of storefronts built by agencies that is not
|
|
28
|
+
* a small omission: every `npm run dev` against a client's site was writing into that
|
|
29
|
+
* client's production numbers, indistinguishable from real traffic. Plausible ships a
|
|
30
|
+
* separate script variant for the local case and OneDollarStats has `data-devmode`,
|
|
31
|
+
* because both meet the same problem.
|
|
32
|
+
*
|
|
33
|
+
* Opt in with `window.__dq.dev = true` before the script loads. */
|
|
34
|
+
function isLocal(w: typeof globalThis & Record<string, any>): boolean {
|
|
35
|
+
const l = w.location;
|
|
36
|
+
if (!l) return false;
|
|
37
|
+
if (l.protocol === "file:") return true;
|
|
38
|
+
const h = String(l.hostname ?? "");
|
|
39
|
+
return (
|
|
40
|
+
h === "localhost" ||
|
|
41
|
+
h === "127.0.0.1" ||
|
|
42
|
+
h === "::1" ||
|
|
43
|
+
h === "[::1]" ||
|
|
44
|
+
h.endsWith(".local") ||
|
|
45
|
+
h.endsWith(".localhost") ||
|
|
46
|
+
// The private ranges a dev server binds to when someone tests from a phone.
|
|
47
|
+
/^10\./.test(h) ||
|
|
48
|
+
/^192\.168\./.test(h) ||
|
|
49
|
+
/^172\.(1[6-9]|2\d|3[01])\./.test(h)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A page prerendered by Chrome must not count until it becomes visible. Without this any
|
|
54
|
+
* site with prefetch overcounts — which is the whole fleet. */
|
|
55
|
+
export function whenVisible(doc: Document, fn: () => void): void {
|
|
56
|
+
if ((doc as any).prerendering) {
|
|
57
|
+
doc.addEventListener("prerenderingchange", () => fn(), { once: true });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if ((doc.visibilityState as string) === "prerender") {
|
|
61
|
+
doc.addEventListener("visibilitychange", function onVis() {
|
|
62
|
+
if ((doc.visibilityState as string) !== "prerender") {
|
|
63
|
+
doc.removeEventListener("visibilitychange", onVis);
|
|
64
|
+
fn();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
fn();
|
|
70
|
+
}
|