@uniweb/core 0.10.1 → 0.10.2
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/package.json +3 -3
- package/src/page.js +18 -7
- package/src/tracker.js +45 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"vitest": "^4.1.7"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@uniweb/
|
|
44
|
-
"@uniweb/
|
|
43
|
+
"@uniweb/theming": "^0.1.15",
|
|
44
|
+
"@uniweb/semantic-parser": "^1.2.3"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "vitest run"
|
package/src/page.js
CHANGED
|
@@ -48,13 +48,24 @@ export default class Page {
|
|
|
48
48
|
// Rewrite target (if set, this route is served by an external site)
|
|
49
49
|
this.rewrite = pageData.rewrite || null
|
|
50
50
|
|
|
51
|
-
//
|
|
52
|
-
// page.yml)
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
51
|
+
// This page's answer on section-level instrumentation (`trackSections` in
|
|
52
|
+
// page.yml) — an OVERRIDE, not a switch.
|
|
53
|
+
//
|
|
54
|
+
// ⭐ **Three states, and the third is the point.** `undefined` means the page
|
|
55
|
+
// said nothing and the site's own `tracking.emit` decides; `true` and
|
|
56
|
+
// `false` override it in either direction, so an owner can instrument one
|
|
57
|
+
// page of a quiet site or exempt a noisy page of a loud one.
|
|
58
|
+
//
|
|
59
|
+
// ⛔ **`|| false` was wrong here and collapsed the tri-state**, which made
|
|
60
|
+
// page-level the ONLY spelling and forced every owner to tick pages
|
|
61
|
+
// individually. The wire already carried all three — `content-collector`
|
|
62
|
+
// emits the key only when it is `!= null` — so nothing but this line had to
|
|
63
|
+
// change. ⇒ Read `?? undefined`, never a boolean coercion.
|
|
64
|
+
//
|
|
65
|
+
// The runtime passes it to `Tracker.arms('section_view', …)`, which is where
|
|
66
|
+
// the precedence against the host's own list is resolved. It means nothing
|
|
67
|
+
// without a tracking destination.
|
|
68
|
+
this.trackSections = pageData.trackSections ?? undefined
|
|
58
69
|
|
|
59
70
|
// Two orthogonal visibility axes:
|
|
60
71
|
// • `hidden` — REACHABILITY. When true the page is excluded from the published
|
package/src/tracker.js
CHANGED
|
@@ -207,6 +207,17 @@ export default class Tracker {
|
|
|
207
207
|
// reports three times.
|
|
208
208
|
this.currentPath = null
|
|
209
209
|
|
|
210
|
+
// What the runtime may ARM, as two independent narrowings. Both are `null`
|
|
211
|
+
// when nothing narrows, which is the common case and the cheap one.
|
|
212
|
+
//
|
|
213
|
+
// ⛔ **Neither ever filters `track()`.** The registry is open by design, and
|
|
214
|
+
// a client-side allowlist over a foundation's own events would export one
|
|
215
|
+
// host's policy onto every host — including hosts that sent no list, whose
|
|
216
|
+
// sites would silently drop everything their foundation emits. These gate
|
|
217
|
+
// the runtime's OWN emissions and nothing else. See `arms()`.
|
|
218
|
+
this.hostEvents = options.hostEvents ? new Set(options.hostEvents) : null
|
|
219
|
+
this.siteEmit = options.siteEmit ? new Set(options.siteEmit) : null
|
|
220
|
+
|
|
210
221
|
this.framed = detectFramed()
|
|
211
222
|
|
|
212
223
|
// Called once when consent moves to granted, and never otherwise. The
|
|
@@ -259,6 +270,39 @@ export default class Tracker {
|
|
|
259
270
|
return !!this.endpoint && this.isLiveDocument()
|
|
260
271
|
}
|
|
261
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Whether the runtime should ARM one of its own automatic emitters.
|
|
275
|
+
*
|
|
276
|
+
* ⭐ **Three questions, in the order that makes each one's absence safe:**
|
|
277
|
+
*
|
|
278
|
+
* 1. **Is there anywhere to send, in a live document?** — `isEnabled()`.
|
|
279
|
+
* 2. **Will the host consume this?** `hostEvents` is the host's cost switch:
|
|
280
|
+
* no point arming an observer for a row nobody stores. ⛔ **Absent means NO
|
|
281
|
+
* NARROWING, never an empty set** — a host that sends no list is an older
|
|
282
|
+
* or simpler one, and reading absence as "consume nothing" would take
|
|
283
|
+
* every site on that host dark with every gate reading yes.
|
|
284
|
+
* 3. **Did the site ask for it?** `siteEmit` is the operator's own selection.
|
|
285
|
+
* Absent means everything.
|
|
286
|
+
*
|
|
287
|
+
* `override` is the per-page answer where one exists (`page.trackSections`).
|
|
288
|
+
* It replaces the SITE's answer and cannot escape the host's: a page may
|
|
289
|
+
* widen what its own site configured, and may not conjure a row the host
|
|
290
|
+
* declined to store.
|
|
291
|
+
*
|
|
292
|
+
* ⛔ **Not consulted by `track()`.** A foundation's events are never gated —
|
|
293
|
+
* see the constructor.
|
|
294
|
+
*
|
|
295
|
+
* @param {string} event
|
|
296
|
+
* @param {boolean} [override] - the per-page decision, when the caller has one
|
|
297
|
+
* @returns {boolean}
|
|
298
|
+
*/
|
|
299
|
+
arms(event, override) {
|
|
300
|
+
if (!this.isEnabled()) return false
|
|
301
|
+
if (this.hostEvents && !this.hostEvents.has(event)) return false
|
|
302
|
+
if (override != null) return !!override
|
|
303
|
+
return !this.siteEmit || this.siteEmit.has(event)
|
|
304
|
+
}
|
|
305
|
+
|
|
262
306
|
/** @returns {'granted'|'denied'|'pending'} */
|
|
263
307
|
consentStatus() {
|
|
264
308
|
return this.consent
|
|
@@ -333,7 +377,7 @@ export default class Tracker {
|
|
|
333
377
|
* @param {string} path
|
|
334
378
|
*/
|
|
335
379
|
trackPageView(path) {
|
|
336
|
-
if (!this.
|
|
380
|
+
if (!this.arms('page_view') || !path) return
|
|
337
381
|
if (path === this.currentPath) return
|
|
338
382
|
this.currentPath = path
|
|
339
383
|
// Promptly, rather than waiting out the batch window: a page view is the
|