@uniweb/core 1.6.2 → 1.6.3
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/tracker.js +42 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"vitest": "^4.1.7"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@uniweb/
|
|
57
|
-
"@uniweb/
|
|
56
|
+
"@uniweb/theming": "~1.2.1",
|
|
57
|
+
"@uniweb/semantic-parser": "~1.13.2"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run"
|
package/src/tracker.js
CHANGED
|
@@ -162,6 +162,36 @@ function captureAcquisition() {
|
|
|
162
162
|
return Object.keys(context).length > 0 ? context : null
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* The landing address's values for the query keys a conversion carries, read once at construction.
|
|
167
|
+
*
|
|
168
|
+
* ⭐ **The keys are named by whoever collects, never by this file** — `tracking.landing`, a host's
|
|
169
|
+
* or a site's own. Which campaign keys and which ad-platform click IDs matter is a collector's
|
|
170
|
+
* business, and the list grows with the platforms it sends to; a list held here would name vendors
|
|
171
|
+
* in a public package and need a release for each [framework, answering hosting, 2026-11-03].
|
|
172
|
+
*
|
|
173
|
+
* ⛔ Only the keys named, only from the address the visitor arrived at, held for this document and
|
|
174
|
+
* sent only on `conversion` — the event whose attribution otherwise depends on a collector joining
|
|
175
|
+
* it to the arrival. A query can carry a search term or a token, so nothing unnamed is read.
|
|
176
|
+
*
|
|
177
|
+
* Called only for an enabled tracker in a browser, so it checks neither. Every site loads this
|
|
178
|
+
* file, so it is as small as it can be read: no keys, or none on the address, is `null`.
|
|
179
|
+
*
|
|
180
|
+
* @param {string[]} [keys]
|
|
181
|
+
* @returns {Object<string, string>|null}
|
|
182
|
+
*/
|
|
183
|
+
function captureLanding(keys) {
|
|
184
|
+
let landing = null
|
|
185
|
+
if (Array.isArray(keys)) {
|
|
186
|
+
const params = new URLSearchParams(window.location.search)
|
|
187
|
+
for (const key of keys) {
|
|
188
|
+
const value = typeof key === 'string' && params.get(key)
|
|
189
|
+
if (value) (landing ||= {})[key] = value
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return landing
|
|
193
|
+
}
|
|
194
|
+
|
|
165
195
|
/**
|
|
166
196
|
* An opaque key for one document lifetime. Never stored, never persisted.
|
|
167
197
|
*
|
|
@@ -199,6 +229,8 @@ export default class Tracker {
|
|
|
199
229
|
* @param {number} [options.flushIntervalMs=5000] - batch window, MILLISECONDS
|
|
200
230
|
* @param {number} [options.maxQueueSize=10]
|
|
201
231
|
* @param {boolean} [options.debug=false]
|
|
232
|
+
* @param {string[]} [options.landing] - query keys of the landing address each `conversion`
|
|
233
|
+
* carries, as `landing: { key: value }`; see `captureLanding`
|
|
202
234
|
*/
|
|
203
235
|
constructor(options = {}) {
|
|
204
236
|
this.endpoint = options.endpoint || null
|
|
@@ -232,6 +264,8 @@ export default class Tracker {
|
|
|
232
264
|
|
|
233
265
|
this.queue = []
|
|
234
266
|
this.acquisition = null
|
|
267
|
+
// What a conversion carries of the landing address, when a collector named keys.
|
|
268
|
+
this.landing = null
|
|
235
269
|
|
|
236
270
|
// One key per document, minted only when there is somewhere to send it.
|
|
237
271
|
// Rides the ENVELOPE beside `event` rather than inside a payload, because
|
|
@@ -295,6 +329,7 @@ export default class Tracker {
|
|
|
295
329
|
|
|
296
330
|
if (isBrowser && this.isEnabled()) {
|
|
297
331
|
this.acquisition = captureAcquisition()
|
|
332
|
+
this.landing = captureLanding(options.landing)
|
|
298
333
|
// Minted even when consent is pending: events buffered before the visitor
|
|
299
334
|
// answers must carry the SAME key as those after it, or granting consent
|
|
300
335
|
// would split one visit in two. It never leaves the device until the
|
|
@@ -424,6 +459,11 @@ export default class Tracker {
|
|
|
424
459
|
/**
|
|
425
460
|
* Report an event.
|
|
426
461
|
*
|
|
462
|
+
* A `conversion` also carries `landing`, the landing address's values for the keys a
|
|
463
|
+
* collector named (`captureLanding`), so its attribution survives navigation without the
|
|
464
|
+
* collector joining it to the arrival. Set after the caller's fields: it is this page
|
|
465
|
+
* load's fact, not a caller's.
|
|
466
|
+
*
|
|
427
467
|
* @param {string} event - event name, e.g. 'video_milestone'. Open registry.
|
|
428
468
|
* @param {Object} [data] - the caller's own fields; `path` overrides the
|
|
429
469
|
* current route, which is what block-scoped callers supply.
|
|
@@ -431,7 +471,8 @@ export default class Tracker {
|
|
|
431
471
|
track(event, data = {}) {
|
|
432
472
|
if (!this.isEnabled() || !event) return
|
|
433
473
|
const { path, ...rest } = data
|
|
434
|
-
|
|
474
|
+
const landing = event === 'conversion' && this.landing ? { landing: this.landing } : null
|
|
475
|
+
this.enqueue({ event, path: path || this.currentPath || undefined, ...rest, ...landing })
|
|
435
476
|
}
|
|
436
477
|
|
|
437
478
|
/**
|