@uniweb/core 1.6.3 → 1.6.4

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/tracker.js +19 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
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/theming": "~1.2.1",
57
- "@uniweb/semantic-parser": "~1.13.2"
56
+ "@uniweb/semantic-parser": "~1.13.2",
57
+ "@uniweb/theming": "~1.2.1"
58
58
  },
59
59
  "scripts": {
60
60
  "test": "vitest run"
package/src/tracker.js CHANGED
@@ -292,10 +292,6 @@ export default class Tracker {
292
292
  // already run.
293
293
  /** When the current path became active. */
294
294
  this.pageEnteredAt = null
295
- /** Hidden time accrued on the current path, in ms. */
296
- this.hiddenMs = 0
297
- /** When the document last became hidden, or `null` while visible. */
298
- this.hiddenSince = null
299
295
  /** Guards against a second report for one page visit — see `reportTimeOnPage`. */
300
296
  this.pageReported = false
301
297
 
@@ -662,8 +658,6 @@ export default class Tracker {
662
658
  */
663
659
  startTimeOnPage() {
664
660
  this.pageEnteredAt = Date.now()
665
- this.hiddenMs = 0
666
- this.hiddenSince = null
667
661
  this.pageReported = false
668
662
  }
669
663
 
@@ -677,21 +671,20 @@ export default class Tracker {
677
671
  * skewed — a tab left open overnight sits in the same mean as forty readers —
678
672
  * so a clamp is genuinely needed; it is just not needed *here*.
679
673
  *
680
- * ⛔ **Hidden time is subtracted**, or this measures tab-open rather than
681
- * reading. A backgrounded tab accrues nothing.
682
- *
683
- * ⛔ **Reported at a route change and at `pagehide` — NOT when the document
684
- * merely becomes hidden.** Visibility is a *pause*, not an end: someone who
685
- * switches tabs to look something up and comes back is still reading. Emitting
686
- * on hidden would truncate exactly the engaged readers this metric exists to
687
- * find, and — because the consumer derives a mean from a sum and a count —
688
- * emitting more than once per page visit would inflate the count and make
689
- * every mean wrong. Hence `pageReported`: **at most one per page visit.**
690
- *
691
- * ⚠️ **The cost of that choice, stated rather than hidden:** a page discarded
692
- * while hidden, without `pagehide`, is never reported. That is an
693
- * under-count, it is bounded, and it fails in the direction that does not
694
- * corrupt the statistic.
674
+ * ⭐ **Reported at the first of three ends: a route change, `pagehide`, or the
675
+ * document becoming hidden** [Diego, 2026-11-03]. A phone visitor who switches
676
+ * apps, to paste a copied prompt or answer a message, may never come back, and
677
+ * the phone can then discard the page with no `pagehide`. Reported only at
678
+ * `pagehide`, about four in ten views on a mostly-phone site carried no time
679
+ * at all (24robert.ca, 2026-11-01, measured by hosting). So every view now
680
+ * reports the time until the visitor first left it, and the number is a floor.
681
+ *
682
+ * ⚖️ **The cost, stated rather than hidden:** a reader who switches away and
683
+ * comes back is counted only up to the switch. The view still reports once,
684
+ * since the consumer derives a mean from a sum and a count: a second event for
685
+ * one visit would inflate the count and make every mean wrong. Hence
686
+ * `pageReported`: **at most one per page visit.** The next page starts a new
687
+ * one. *(Until that day, hidden was a pause and its time was subtracted.)*
695
688
  *
696
689
  * @private
697
690
  */
@@ -699,11 +692,7 @@ export default class Tracker {
699
692
  if (this.pageReported || this.pageEnteredAt === null || !this.currentPath) return
700
693
  if (!this.arms('time_on_page')) return
701
694
 
702
- const now = Date.now()
703
- // A tab hidden at this instant has not yet had its span folded in.
704
- const openHidden = this.hiddenSince === null ? 0 : now - this.hiddenSince
705
- const durationMs = now - this.pageEnteredAt - this.hiddenMs - openHidden
706
-
695
+ const durationMs = Date.now() - this.pageEnteredAt
707
696
  this.pageReported = true
708
697
  // Negative is not reachable by arithmetic, but a clock adjustment mid-visit
709
698
  // would produce one, and a negative duration poisons a sum the consumer
@@ -726,13 +715,12 @@ export default class Tracker {
726
715
  this.flush(true)
727
716
  })
728
717
  window.addEventListener('visibilitychange', () => {
718
+ // The last moment a phone promises: a page hidden may be discarded with no
719
+ // `pagehide`. So the view's time is queued first, as at `pagehide`, and
720
+ // everything goes by beacon.
729
721
  if (document.visibilityState === 'hidden') {
730
- // A pause, not an end — see `reportTimeOnPage`. Only the clock stops.
731
- if (this.hiddenSince === null) this.hiddenSince = Date.now()
722
+ this.reportTimeOnPage()
732
723
  this.flush(true)
733
- } else if (this.hiddenSince !== null) {
734
- this.hiddenMs += Date.now() - this.hiddenSince
735
- this.hiddenSince = null
736
724
  }
737
725
  })
738
726
  }