@decocms/blocks 8.19.0 → 8.20.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.
|
@@ -32,6 +32,16 @@ export interface AnalyticsClientOptions {
|
|
|
32
32
|
heatmapRate?: number;
|
|
33
33
|
/** Errors module: cross-origin script hosts that count as the site's own. */
|
|
34
34
|
errorHosts?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* The visitor's A/B tests as the page rendered them: each test of the saved `experiments`
|
|
37
|
+
* block on or off, exactly the map that decided the page (on TanStack, what the worker
|
|
38
|
+
* decided, `requestAssignments(request)?.experiments`). Every event then carries each test's
|
|
39
|
+
* arm, `on` or `off`, in `exp`, the first page view included, and the collector stores it as
|
|
40
|
+
* it stores any `exp`. Passing the decision rather than an id keeps what is measured equal to
|
|
41
|
+
* what was shown, a preview's switched tests and a release change included. Leave it unset
|
|
42
|
+
* on a preview, whose switched tests are no visitor's.
|
|
43
|
+
*/
|
|
44
|
+
experiments?: Readonly<Record<string, boolean>>;
|
|
35
45
|
}
|
|
36
46
|
/**
|
|
37
47
|
* Starts collection in the browser: the page view now and on every client-side
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/v8/analytics/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,2EAA2E;AAC3E,MAAM,MAAM,eAAe,GACvB,OAAO,GACP,UAAU,GACV,SAAS,GACT,MAAM,GACN,YAAY,GACZ,QAAQ,GACR,SAAS,GACT,QAAQ,CAAC;AAEb,MAAM,WAAW,sBAAsB;IACrC,+FAA+F;IAC/F,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mGAAmG;IACnG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF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AC,GAAG,IAAI,CAAC,CAkDzC"}
|
|
@@ -8,6 +8,18 @@
|
|
|
8
8
|
* `startAnalytics()` does the work in the browser and never rejects, so a
|
|
9
9
|
* failure is "analytics stopped", never "the page broke".
|
|
10
10
|
*/
|
|
11
|
+
/** The decided tests as the collector's `exp` values, `on` or `off`; non-boolean entries left out. */
|
|
12
|
+
function armsOf(experiments) {
|
|
13
|
+
const arms = Object.create(null);
|
|
14
|
+
if (typeof experiments !== "object" || experiments === null)
|
|
15
|
+
return arms;
|
|
16
|
+
for (const name of Object.keys(experiments)) {
|
|
17
|
+
const on = experiments[name];
|
|
18
|
+
if (typeof on === "boolean")
|
|
19
|
+
arms[name] = on ? "on" : "off";
|
|
20
|
+
}
|
|
21
|
+
return arms;
|
|
22
|
+
}
|
|
11
23
|
/** One loader per file, so a bundler splits each module into its own chunk. */
|
|
12
24
|
const MODULES = {
|
|
13
25
|
click: () => import("./runtime/modules/click.js"),
|
|
@@ -35,8 +47,15 @@ export async function startAnalytics(options = {}) {
|
|
|
35
47
|
return null;
|
|
36
48
|
const w = window;
|
|
37
49
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
const arms = armsOf(options.experiments);
|
|
51
|
+
if (w.__dqBooted) {
|
|
52
|
+
// The tag booted first: its API is the client, so the arms go through it.
|
|
53
|
+
if (typeof w.__dq?.track !== "function")
|
|
54
|
+
return null;
|
|
55
|
+
for (const name of Object.keys(arms))
|
|
56
|
+
w.__dq.setExperiment?.(name, arms[name]);
|
|
57
|
+
return w.__dq;
|
|
58
|
+
}
|
|
40
59
|
// The same fields the collector writes ahead of `/_dq/a.js`, and the same precedence: what
|
|
41
60
|
// the page already set on `window.__dq` wins. `q` is held back and replayed below, once
|
|
42
61
|
// every module has registered: core replays its stub in a microtask, and a module in its
|
|
@@ -53,13 +72,20 @@ export async function startAnalytics(options = {}) {
|
|
|
53
72
|
...(options.key ? { k: options.key } : {}),
|
|
54
73
|
...(options.heatmapRate !== undefined ? { hr: options.heatmapRate } : {}),
|
|
55
74
|
...(options.errorHosts?.length ? { er: options.errorHosts } : {}),
|
|
56
|
-
}, page,
|
|
75
|
+
}, page,
|
|
76
|
+
// The page's own map (another script's tests) is kept; on a name both carry, the arm the
|
|
77
|
+
// page rendered wins. Set before core boots, so the first page view carries it.
|
|
78
|
+
Object.keys(arms).length ? { x: { ...page.x, ...arms } } : {}, { q: [] });
|
|
57
79
|
await import("./runtime/src/index.js");
|
|
58
80
|
// Core assigns its API only when it collects; skipped means skipped, modules included.
|
|
59
81
|
if (typeof w.__dq.track !== "function")
|
|
60
82
|
return null;
|
|
61
83
|
for (const name of new Set(options.modules ?? []))
|
|
62
84
|
await MODULES[name]?.();
|
|
85
|
+
// A module may set a test of its own on load: `deco` reads v7's `deco_segment`, which a
|
|
86
|
+
// migrated visitor still carries and v8 never rewrites. The arm the page rendered wins.
|
|
87
|
+
for (const name of Object.keys(arms))
|
|
88
|
+
w.__dq.setExperiment?.(name, arms[name]);
|
|
63
89
|
for (const r of queued)
|
|
64
90
|
w.__dq.q?.push?.(r);
|
|
65
91
|
return w.__dq;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/v8/analytics/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/v8/analytics/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA+CH,sGAAsG;AACtG,SAAS,MAAM,CACb,WAA0D;IAE1D,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA2B,CAAC;IAC3D,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACzE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5C,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,CA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AC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClE,EACD,IAAI;QACJ,yFAAyF;QACzF,gFAAgF;QAChF,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAI,IAAI,CAAC,CAAY,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EACzE,EAAE,CAAC,EAAE,EAAE,EAAE,CACV,CAAC;QAEF,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;QACvC,uFAAuF;QACvF,IAAI,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC;QAEpD,KAAK,MAAM,IAAI,IAAI,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;YAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QAC3E,wFAAwF;QACxF,wFAAwF;QACxF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/E,KAAK,MAAM,CAAC,IAAI,MAAM;YAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,CAAC,CAAC,IAAI,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -42,6 +42,29 @@ export interface AnalyticsClientOptions {
|
|
|
42
42
|
heatmapRate?: number;
|
|
43
43
|
/** Errors module: cross-origin script hosts that count as the site's own. */
|
|
44
44
|
errorHosts?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* The visitor's A/B tests as the page rendered them: each test of the saved `experiments`
|
|
47
|
+
* block on or off, exactly the map that decided the page (on TanStack, what the worker
|
|
48
|
+
* decided, `requestAssignments(request)?.experiments`). Every event then carries each test's
|
|
49
|
+
* arm, `on` or `off`, in `exp`, the first page view included, and the collector stores it as
|
|
50
|
+
* it stores any `exp`. Passing the decision rather than an id keeps what is measured equal to
|
|
51
|
+
* what was shown, a preview's switched tests and a release change included. Leave it unset
|
|
52
|
+
* on a preview, whose switched tests are no visitor's.
|
|
53
|
+
*/
|
|
54
|
+
experiments?: Readonly<Record<string, boolean>>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The decided tests as the collector's `exp` values, `on` or `off`; non-boolean entries left out. */
|
|
58
|
+
function armsOf(
|
|
59
|
+
experiments: Readonly<Record<string, boolean>> | undefined,
|
|
60
|
+
): Record<string, string> {
|
|
61
|
+
const arms = Object.create(null) as Record<string, string>;
|
|
62
|
+
if (typeof experiments !== "object" || experiments === null) return arms;
|
|
63
|
+
for (const name of Object.keys(experiments)) {
|
|
64
|
+
const on = experiments[name];
|
|
65
|
+
if (typeof on === "boolean") arms[name] = on ? "on" : "off";
|
|
66
|
+
}
|
|
67
|
+
return arms;
|
|
45
68
|
}
|
|
46
69
|
|
|
47
70
|
/** One loader per file, so a bundler splits each module into its own chunk. */
|
|
@@ -73,7 +96,13 @@ export async function startAnalytics(
|
|
|
73
96
|
if (typeof window === "undefined") return null;
|
|
74
97
|
const w = window as unknown as Record<string, any>;
|
|
75
98
|
try {
|
|
76
|
-
|
|
99
|
+
const arms = armsOf(options.experiments);
|
|
100
|
+
if (w.__dqBooted) {
|
|
101
|
+
// The tag booted first: its API is the client, so the arms go through it.
|
|
102
|
+
if (typeof w.__dq?.track !== "function") return null;
|
|
103
|
+
for (const name of Object.keys(arms)) w.__dq.setExperiment?.(name, arms[name]);
|
|
104
|
+
return w.__dq;
|
|
105
|
+
}
|
|
77
106
|
|
|
78
107
|
// The same fields the collector writes ahead of `/_dq/a.js`, and the same precedence: what
|
|
79
108
|
// the page already set on `window.__dq` wins. `q` is held back and replayed below, once
|
|
@@ -94,6 +123,9 @@ export async function startAnalytics(
|
|
|
94
123
|
...(options.errorHosts?.length ? { er: options.errorHosts } : {}),
|
|
95
124
|
},
|
|
96
125
|
page,
|
|
126
|
+
// The page's own map (another script's tests) is kept; on a name both carry, the arm the
|
|
127
|
+
// page rendered wins. Set before core boots, so the first page view carries it.
|
|
128
|
+
Object.keys(arms).length ? { x: { ...(page.x as object), ...arms } } : {},
|
|
97
129
|
{ q: [] },
|
|
98
130
|
);
|
|
99
131
|
|
|
@@ -102,6 +134,9 @@ export async function startAnalytics(
|
|
|
102
134
|
if (typeof w.__dq.track !== "function") return null;
|
|
103
135
|
|
|
104
136
|
for (const name of new Set(options.modules ?? [])) await MODULES[name]?.();
|
|
137
|
+
// A module may set a test of its own on load: `deco` reads v7's `deco_segment`, which a
|
|
138
|
+
// migrated visitor still carries and v8 never rewrites. The arm the page rendered wins.
|
|
139
|
+
for (const name of Object.keys(arms)) w.__dq.setExperiment?.(name, arms[name]);
|
|
105
140
|
for (const r of queued) w.__dq.q?.push?.(r);
|
|
106
141
|
return w.__dq;
|
|
107
142
|
} catch {
|