@usesequential/browser 1.0.1 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3
4
+
5
+ - A click that a script makes (`el.click()`, `dispatchEvent`; the browser marks it `isTrusted: false`) is recorded only
6
+ while the person acts: while the page has transient user activation, or within 1 second of the person's own
7
+ pointerup, touchend or keydown. So a tap or key that the page forwards as its own click (FastClick on iOS, a key
8
+ handler on a `role="button"`) is still recorded, and a script that clicks on a timer from page load is not: no
9
+ `$click` and no dead click. A browser that does not set `isTrusted` is unchanged.
10
+ - At most 5 `$click` per element per second, on a monotonic clock. A faster loop on one element, even with events the
11
+ browser trusts, sends no more. Rage and dead clicks are unchanged.
12
+ - A dead click on an option that was already selected carries `$el_state: 'selected'`.
13
+
14
+ ## 1.0.2
15
+
16
+ - The package now holds the same code as the script tag of 3 November 2026. Changes since 1.0.0:
17
+ - Back or Forward is recorded as a pop, also when the app's router answers it with `replaceState`, and a hash-route
18
+ link is recorded as a push. Without the Navigation API, both are recorded as unknown.
19
+ - A `replaceState` that changes only the query is not a pageview.
20
+ - A click sends the element's `aria-label` (`$el_label`) and its link target (`$el_href`).
21
+ - A person's id is never sent as `$anon_distinct_id`; a second sign-in on one browser no longer moves the first
22
+ person's history.
23
+ - `optOut()` also deletes the recorder's `__lx_replay_sample`, and another tab's `optOut()` opts this tab out at once.
24
+ - A held batch is sent again after each pause, as its own request, for up to 5 minutes.
25
+ - The account-menu privacy check no longer treats every "profile" as account UI.
26
+ - In a URL, the user info is removed up to the last `@` of the authority, so a password that contains `@` no longer
27
+ leaves its end in the URL.
28
+ - The "no data-key" and "no data-api" console lines say how to configure without attributes.
29
+
3
30
  ## 1.0.1
4
31
 
5
32
  - README only: where the key comes from when there is no account yet (a trial that a coding agent creates with one call). No code change.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @usesequential/browser 1.0.1: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
1
+ /* @usesequential/browser 1.0.3: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
2
2
  * `boot` below is sequential.js, the file the script tag loads, unchanged. */
3
3
  'use strict';
4
4
  var boot = (function (injectedTag) {
@@ -162,15 +162,20 @@ var boot = (function (injectedTag) {
162
162
  logError('data-release is not a release (1 to 64 printable ASCII characters); events are sent without one.');
163
163
  }
164
164
 
165
- // No key or no API: every method stays present and inert, so a bad tag never throws.
165
+ // No key or no API: every method stays present and inert, so a bad tag never throws. Both lines say how to set the
166
+ // values without attributes, for a loader that drops them.
166
167
  var DISABLED = false;
168
+ var CONFIG_HELP =
169
+ ' Loaded through Google Tag Manager or another loader that drops data-* attributes? Set window.sequentialConfig' +
170
+ ' = { key, api } before the SDK loads: https://www.usesequential.com/docs/sequential#configure-without-attributes';
167
171
  if (!KEY) {
168
- logError('the script tag has no data-key — no events will be sent.');
172
+ logError('the script tag has no data-key — no events will be sent.' + CONFIG_HELP);
169
173
  DISABLED = true;
170
174
  } else if (!API_HOST) {
171
175
  logError(
172
176
  'the script tag has no data-api — no events will be sent. The CDN origin is not the ' +
173
- 'ingest origin, so it cannot be guessed from this script’s own src.'
177
+ 'ingest origin, so it cannot be guessed from this script’s own src.' +
178
+ CONFIG_HELP
174
179
  );
175
180
  DISABLED = true;
176
181
  }
@@ -201,13 +206,13 @@ var boot = (function (injectedTag) {
201
206
  var REQUEST_TIMEOUT_MS = 10000;
202
207
  var MAX_SEND_ATTEMPTS = 3;
203
208
  var RETRY_BASE_MS = 500;
204
- // A 429 (the backend's per-project event rate limit): pause for the server's retry time, clamped; hold the refused
205
- // batch and what is captured meanwhile, capped, the oldest dropped first (sequential.core.ts holdRateLimited).
209
+ // A 429 or a 503 overloaded: pause and hold, as sequential.core.ts holdRateLimited.
206
210
  var RATE_LIMIT_DEFAULT_SEC = 60;
207
211
  var RATE_LIMIT_MIN_SEC = 1;
208
212
  var RATE_LIMIT_MAX_SEC = 300;
209
213
  var MAX_HELD_EVENTS = 100;
210
214
  var MAX_HELD_BYTES = 128 * 1024;
215
+ var MAX_HOLD_MS = 5 * 60 * 1000;
211
216
 
212
217
  var redactor = null;
213
218
 
@@ -222,14 +227,16 @@ var boot = (function (injectedTag) {
222
227
  // out, so a queued optOut() also writes nothing. Meanwhile each write waits in `held` (null removes).
223
228
  var storageOn = false;
224
229
  var held = {};
225
- // What optOut() deletes: every key the SDK writes, except the __sq_opt mark it then sets.
230
+ // What optOut() deletes: every key the SDK writes, except the __sq_opt mark it then sets, and the recorder's
231
+ // __lx_replay_sample (recorder-boot.js sampledIn: '1:' or '0:' + the session id, written when sampling < 1).
226
232
  var STORED_KEYS = [
227
233
  ['localStorage', '__sq_did'],
228
234
  ['localStorage', '__sq_aid'],
229
235
  ['localStorage', '__sq_ath'],
230
236
  ['localStorage', '__sq_ith'],
231
237
  ['sessionStorage', '__sq_sid'],
232
- ['sessionStorage', '__lx_replay_sid']
238
+ ['sessionStorage', '__lx_replay_sid'],
239
+ ['sessionStorage', '__lx_replay_sample']
233
240
  ];
234
241
 
235
242
  // False only when the browser refused the write.
@@ -561,8 +568,13 @@ var boot = (function (injectedTag) {
561
568
  var queueBytes = 0;
562
569
  var flushTimer = null;
563
570
  var pauseTimer = null;
564
- // Events already put back once after a 429 (a batch is resent once). An array, not a WeakSet: this file is ES5.
565
- var resentOnce = [];
571
+ // Refused batches, oldest first, each kept whole and resent one request each: the backend sees the same ids again and
572
+ // stores a batch that did land once (BE src/ingest/dedup.ts).
573
+ var heldBatches = [];
574
+ // When each held event was first refused, as two parallel arrays (not a WeakMap: this file is ES5), at most
575
+ // 2 x MAX_HELD_EVENTS long: more than can be held at once.
576
+ var refusedEvents = [];
577
+ var refusedAt = [];
566
578
 
567
579
  function assign(target, source) {
568
580
  if (!source) return target;
@@ -668,6 +680,7 @@ var boot = (function (injectedTag) {
668
680
  clearContextCookie();
669
681
  queue = [];
670
682
  queueBytes = 0;
683
+ heldBatches = [];
671
684
  clearFlushTimer();
672
685
  if (pauseTimer !== null) {
673
686
  clearTimeout(pauseTimer);
@@ -711,25 +724,48 @@ var boot = (function (injectedTag) {
711
724
  }
712
725
  }
713
726
 
727
+ // Drop the oldest waiting events (held batches first, then the queue) until what waits fits the caps. Only while paused.
714
728
  function trimHeld() {
715
- while (queue.length > MAX_HELD_EVENTS || (queue.length > 1 && queueBytes > MAX_HELD_BYTES)) {
716
- queueBytes -= sizeOf(queue.shift());
729
+ var count = queue.length;
730
+ var bytes = queueBytes;
731
+ var i, j;
732
+ for (i = 0; i < heldBatches.length; i++) {
733
+ count += heldBatches[i].length;
734
+ for (j = 0; j < heldBatches[i].length; j++) bytes += sizeOf(heldBatches[i][j]);
735
+ }
736
+ while (count > MAX_HELD_EVENTS || (count > 1 && bytes > MAX_HELD_BYTES)) {
737
+ var dropped;
738
+ if (heldBatches.length > 0) {
739
+ dropped = heldBatches[0].shift();
740
+ if (heldBatches[0].length === 0) heldBatches.shift();
741
+ } else {
742
+ dropped = queue.shift();
743
+ queueBytes -= sizeOf(dropped);
744
+ }
745
+ count--;
746
+ bytes -= sizeOf(dropped);
717
747
  }
718
748
  }
719
749
 
720
750
  function holdRateLimited(events, sec) {
721
751
  if (stopped) return;
722
- var again = [];
752
+ var now = Date.now();
753
+ var keep = [];
723
754
  for (var i = 0; i < events.length; i++) {
724
- if (resentOnce.indexOf(events[i]) === -1) {
725
- again.push(events[i]);
726
- resentOnce.push(events[i]);
755
+ var k = refusedEvents.indexOf(events[i]);
756
+ if (k === -1) {
757
+ refusedEvents.push(events[i]);
758
+ refusedAt.push(now);
759
+ keep.push(events[i]);
760
+ } else if (now - refusedAt[k] < MAX_HOLD_MS) {
761
+ keep.push(events[i]);
727
762
  }
728
763
  }
729
- while (resentOnce.length > 2 * MAX_HELD_EVENTS) resentOnce.shift();
730
- queue = again.concat(queue);
731
- queueBytes = 0;
732
- for (var j = 0; j < queue.length; j++) queueBytes += sizeOf(queue[j]);
764
+ while (refusedEvents.length > 2 * MAX_HELD_EVENTS) {
765
+ refusedEvents.shift();
766
+ refusedAt.shift();
767
+ }
768
+ if (keep.length > 0) heldBatches.unshift(keep);
733
769
  clearFlushTimer();
734
770
  if (pauseTimer !== null) clearTimeout(pauseTimer);
735
771
  pauseTimer = setTimeout(function () {
@@ -785,19 +821,30 @@ var boot = (function (injectedTag) {
785
821
  });
786
822
  }
787
823
 
824
+ function sendEvents(events) {
825
+ if (!canSend()) return Promise.resolve();
826
+ var body = buildEnvelope(events);
827
+ if (body === null) return Promise.resolve();
828
+ return attemptSend(body, 1, events)['catch'](noop);
829
+ }
830
+
788
831
  function flush() {
789
832
  try {
790
- if (queue.length === 0) return Promise.resolve();
833
+ if (queue.length === 0 && heldBatches.length === 0) return Promise.resolve();
791
834
  clearFlushTimer();
792
835
  // Paused by a 429: the pause's own timer flushes what is held when it ends.
793
836
  if (pauseTimer !== null) return Promise.resolve();
837
+ // Held batches first, each as it was refused; a refusal on the way pauses again and keeps the rest held.
838
+ if (heldBatches.length > 0) {
839
+ return sendEvents(heldBatches.shift()).then(function () {
840
+ if (pauseTimer !== null || stopped) return;
841
+ return flush();
842
+ });
843
+ }
794
844
  var events = queue;
795
845
  queue = [];
796
846
  queueBytes = 0;
797
- if (!canSend()) return Promise.resolve();
798
- var body = buildEnvelope(events);
799
- if (body === null) return Promise.resolve();
800
- return attemptSend(body, 1, events)['catch'](noop);
847
+ return sendEvents(events);
801
848
  } catch (e) {
802
849
  return Promise.resolve();
803
850
  }
@@ -806,9 +853,13 @@ var boot = (function (injectedTag) {
806
853
  function drain() {
807
854
  try {
808
855
  if (optedOut || DISABLED || stopped) return null;
809
- if (queue.length === 0) return null;
856
+ if (queue.length === 0 && heldBatches.length === 0) return null;
810
857
  clearFlushTimer();
811
- var events = queue;
858
+ // The page is going: what is held goes in the one beacon too, oldest first.
859
+ var events = [];
860
+ for (var i = 0; i < heldBatches.length; i++) events = events.concat(heldBatches[i]);
861
+ events = events.concat(queue);
862
+ heldBatches = [];
812
863
  queue = [];
813
864
  queueBytes = 0;
814
865
  var body = buildEnvelope(events);
@@ -906,9 +957,18 @@ var boot = (function (injectedTag) {
906
957
  for (i = 0; i < w.length; i++) if (w[i].length > 2 && inList(idWords, w[i])) return true;
907
958
  }
908
959
 
960
+ // Account UI (the element or its 3 nearest ancestors):
961
+ // as in sequential.autocapture.ts.
962
+ // `profile` alone is not
963
+ // account UI
964
+ // (2026-10-26).
965
+ var ACCOUNT_WORD = /(\b|_)(avatar|account|user[-_]?menu|profile[-_](menu|dropdown|button|avatar)|(my|user)[-_]profile)(\b|_)/;
966
+ var ACCOUNT_LABEL = /^(account|user|profile)$|\b(my|your|open) (account|profile)\b|\b(user|account|profile)( navigation)? (menu|dropdown|options)\b/;
909
967
  function inAccountUi(node) {
910
968
  for (var i = 0; node && node.getAttribute && i++ < 4; node = node.parentNode) {
911
- if (/(\b|_)(avatar|account|profile|user[-_]?menu)(\b|_)/.test((node.getAttribute('class') + ' ' + node.id + ' ' + node.getAttribute('data-testid')).toLowerCase()) || /account|profile|user/i.test(node.getAttribute('aria-label'))) return true;
969
+ if (ACCOUNT_WORD.test((node.getAttribute('class') + ' ' + node.id + ' ' + node.getAttribute('data-testid')).toLowerCase())) return true;
970
+ var label = String(node.getAttribute('aria-label') || '').replace(/\s+/g, ' ').replace(/^ | $/g, '').toLowerCase();
971
+ if (label && ACCOUNT_LABEL.test(label)) return true;
912
972
  }
913
973
  }
914
974
 
@@ -921,23 +981,32 @@ var boot = (function (injectedTag) {
921
981
  learnIdentity(newDistinctId, props);
922
982
  var previous = distinctId;
923
983
  var hasTraits = props !== undefined && props !== null && typeof props === 'object' && Object.keys(props).length > 0;
924
- var hash = hasTraits ? identifyHash(newDistinctId, props) : null;
984
+ // __sq_ith is written on every identify, with no traits too: a stored one says the stored id is a person's.
985
+ var hash = identifyHash(newDistinctId, hasTraits ? props : {});
986
+ var stored = readLocal(IDENTIFY_HASH_KEY, memoryIdentifyHash);
925
987
  if (previous === newDistinctId) {
926
- // Same person again (a reload): changed traits still go out; the same traits, or none, send nothing.
927
- if (hash === null || hash === readLocal(IDENTIFY_HASH_KEY, memoryIdentifyHash)) return;
988
+ // Same person again (a reload): changed traits still go out; the same traits, or none, send nothing. None
989
+ // keeps the stored hash, and writes one only where there is none (an id identified before ith was always set).
990
+ if (hasTraits ? hash === stored : stored !== null && stored !== undefined) return;
928
991
  memoryIdentifyHash = hash;
929
992
  writeLocal(IDENTIFY_HASH_KEY, hash);
930
- captureInternal('$identify', assign({}, props));
993
+ if (hasTraits) captureInternal('$identify', assign({}, props));
931
994
  return;
932
995
  }
933
996
  memoryIdentifyHash = hash;
934
997
  writeLocal(IDENTIFY_HASH_KEY, hash);
935
998
  distinctId = newDistinctId;
936
999
  writeDistinctId(newDistinctId);
937
- contextDistinctId = previous;
938
1000
 
939
1001
  var merged = assign({}, props);
940
- merged.$anon_distinct_id = previous;
1002
+ if (stored === null || stored === undefined) {
1003
+ contextDistinctId = previous;
1004
+ merged.$anon_distinct_id = previous;
1005
+ } else {
1006
+ // Another person on this browser (no reset): the previous id is a person, not an anonymous visitor, so it is
1007
+ // no claim. Sent as one, it moved that person's history to this one (the People duplicate, 2026-10-23).
1008
+ contextDistinctId = newDistinctId;
1009
+ }
941
1010
  captureInternal('$identify', merged);
942
1011
  } catch (e) {}
943
1012
  }
@@ -1006,6 +1075,7 @@ var boot = (function (injectedTag) {
1006
1075
 
1007
1076
  queue = [];
1008
1077
  queueBytes = 0;
1078
+ heldBatches = [];
1009
1079
  clearFlushTimer();
1010
1080
  clearContextCookie();
1011
1081
  forgetStorage();
@@ -1050,6 +1120,17 @@ var boot = (function (injectedTag) {
1050
1120
  } catch (e) {}
1051
1121
  }
1052
1122
 
1123
+ // Another tab's optOut() (__sq_opt set to '1') opts this tab out at once;
1124
+ // it writes back none of the ids that tab deleted.
1125
+ // Another tab's optIn() or localStorage.clear()
1126
+ // does not opt this tab in:
1127
+ // that waits for the next page load.
1128
+ try {
1129
+ window.addEventListener('storage', function (e) {
1130
+ if (e && e.key === OPT_OUT_KEY && e.newValue === '1' && !optedOut) optOut();
1131
+ });
1132
+ } catch (e) {}
1133
+
1053
1134
  function captureException(error, props) {
1054
1135
  try {
1055
1136
  if (optedOut || DISABLED) return;
@@ -1285,10 +1366,28 @@ var boot = (function (injectedTag) {
1285
1366
  route = hashRouteOf(s.slice(hash));
1286
1367
  s = s.slice(0, hash);
1287
1368
  }
1288
- s = s.replace(/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^/?#@]*@/, '$1');
1369
+ // userinfo runs to the authority's LAST '@' (an '@' in the user or password); never past '/', '?' or '#'
1370
+ s = s.replace(/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^/?#]*@/, '$1');
1289
1371
  return rdct.boundedRedact(s + route, URL_MAX);
1290
1372
  }
1291
1373
 
1374
+ // A clicked link's target ($el_href, owner decision 2026-10-26): resolved against the page; a scheme other than http(s)
1375
+ // is the scheme only, another origin its origin only (never another site's path), the page's own origin keeps the path
1376
+ // with no query, fragment or userinfo. Ingest re-scrubs it and is the authority (BE: src/adapters/link-target-scrub.ts):
1377
+ // id-like segments barred, the origin only under mask_attributes strict.
1378
+ function linkTarget(raw) {
1379
+ var page, target;
1380
+ try {
1381
+ page = new URL(String(window.location.href));
1382
+ target = new URL(String(raw), page.href);
1383
+ } catch (e) {
1384
+ return undefined;
1385
+ }
1386
+ if (!/^https?:$/.test(target.protocol)) return target.protocol;
1387
+ if (target.origin !== page.origin) return target.origin;
1388
+ return target.origin + target.pathname;
1389
+ }
1390
+
1292
1391
  function currentUrl() {
1293
1392
  if (!redactor) return undefined;
1294
1393
  try {
@@ -1376,6 +1475,17 @@ var boot = (function (injectedTag) {
1376
1475
  }
1377
1476
  }
1378
1477
 
1478
+ // sequential.autocapture.ts pathKey: the page without its query (pathname + hash route). A replaceState that keeps
1479
+ // it is not a pageview (2026-10-22): a player's ?t= or a list's ?sort= rewritten in place is the same page.
1480
+ function pathKey(href) {
1481
+ try {
1482
+ var u = new URL(href);
1483
+ return u.pathname + hashRouteOf(u.hash);
1484
+ } catch (e) {
1485
+ return String(href);
1486
+ }
1487
+ }
1488
+
1379
1489
  // $nav (sequential.autocapture.ts PageviewNav): popstate is also a forward fragment navigation, so
1380
1490
  // only the Navigation API's navigationType names it; without it, 'unknown'.
1381
1491
  function navFromNavigationType(type) {
@@ -1430,9 +1540,7 @@ var boot = (function (injectedTag) {
1430
1540
  return r.target.getAttribute(r.attributeName) !== r.oldValue;
1431
1541
  }
1432
1542
 
1433
- // The main button and no modifier key: anything else opens a menu, a tab or a selection. Not
1434
- // isPrimary: Chromium sends `click` as a PointerEvent with isPrimary=false; only pointer events
1435
- // check it (isPlainPointer).
1543
+ // As sequential.autocapture.ts isPlainClick and isPlainPointer.
1436
1544
  function isPlainClick(ev) {
1437
1545
  return ev.button === 0 && !ev.ctrlKey && !ev.metaKey && !ev.shiftKey && !ev.altKey;
1438
1546
  }
@@ -1441,6 +1549,12 @@ var boot = (function (injectedTag) {
1441
1549
  return isPlainClick(ev) && ev.isPrimary !== false;
1442
1550
  }
1443
1551
 
1552
+ // Monotonic where there is one, so a step of the wall clock cannot freeze the $click cap's window.
1553
+ function now() {
1554
+ var p = window.performance;
1555
+ return p && p.now ? p.now() : Date.now();
1556
+ }
1557
+
1444
1558
  function startAutocapture(attachUrl) {
1445
1559
  if (autocaptureStarted || !redactor) return;
1446
1560
  autocaptureStarted = true;
@@ -1463,25 +1577,55 @@ var boot = (function (injectedTag) {
1463
1577
  });
1464
1578
  }
1465
1579
 
1466
- // One page key (pathname + search of the RAW URL, + the fragment only for a #/ or #!/ hash
1467
- // route) for every trigger, as in
1468
- // sequential.autocapture.ts pageKey: a router's same-URL replaceState is not a pageview.
1580
+ // One page key for every trigger, as sequential.autocapture.ts pageKey.
1469
1581
  var lastPageKey = null;
1582
+ var lastPathKey = null;
1470
1583
  var lastNavigationType;
1471
1584
  var navigationApi = false;
1472
1585
 
1473
1586
  function checkPage(nav) {
1474
1587
  try {
1475
1588
  lastNavigationType = undefined;
1589
+ popKind = undefined;
1476
1590
  var key = pageKey(String(window.location.href));
1477
1591
  if (key === lastPageKey) return;
1592
+ // A query-only replaceState moves both keys without a pageview (sequential.autocapture.ts checkPage).
1593
+ var path = pathKey(String(window.location.href));
1594
+ var queryOnlyReplace = nav === 'replace' && path === lastPathKey;
1478
1595
  lastPageKey = key;
1596
+ lastPathKey = path;
1597
+ if (queryOnlyReplace) return;
1479
1598
  capturePageview(undefined, nav);
1480
1599
  } catch (e) {}
1481
1600
  }
1482
1601
 
1602
+ // A traversal the page's router answers with replaceState: as sequential.autocapture.ts inPopstate (F1).
1603
+ var popPending = false;
1604
+ var popKind;
1605
+ function onPopCapture() {
1606
+ try {
1607
+ popPending = true;
1608
+ setTimeout(function () {
1609
+ popPending = false;
1610
+ }, 0);
1611
+ } catch (e) {}
1612
+ }
1613
+ function inPopstate() {
1614
+ if (popPending) return true;
1615
+ try {
1616
+ var ev = window.event;
1617
+ return !!ev && ev.type === 'popstate';
1618
+ } catch (e) {
1619
+ return false;
1620
+ }
1621
+ }
1622
+ function hookNav(kind) {
1623
+ return inPopstate() ? (navigationApi ? navFromNavigationType(popKind) : 'unknown') : kind;
1624
+ }
1625
+
1483
1626
  function onPopState() {
1484
- checkPage(navigationApi ? navFromNavigationType(lastNavigationType) : 'unknown');
1627
+ checkPage(navigationApi ? navFromNavigationType(popKind) : 'unknown');
1628
+ popPending = false;
1485
1629
  }
1486
1630
 
1487
1631
  // $click's props; $rageclick and $deadclick send the same, so the detector groups all three.
@@ -1491,29 +1635,61 @@ var boot = (function (injectedTag) {
1491
1635
  var identity = DETECT_IDENTITY && raw !== undefined && (inAccountUi(matched) || namesPerson(raw));
1492
1636
  var noIds = closestMatching(matched, '[data-sq-private]') || (DETECT_IDENTITY && namesPerson(stableSelector(matched)));
1493
1637
  var selector = stableSelector(matched, noIds);
1638
+ // $el_label (the aria-label) and $el_href (the link target, linkTarget) are element text like $el_text (owner
1639
+ // decision 2026-10-26, soc2 rule): none under data-sq-mask/-private, in account UI, or when the text, the label or
1640
+ // the target names the identified person; the label redacted and capped like the text. An icon button's label is
1641
+ // often its only name.
1642
+ var label = masked ? '' : String(matched.getAttribute('aria-label') || '').replace(/\s+/g, ' ').replace(/^ | $/g, '');
1643
+ var anchor = masked ? null : closestMatching(matched, 'a[href]');
1644
+ var href = anchor ? linkTarget(anchor.getAttribute('href')) : undefined;
1645
+ var labelOrHrefIdentity = DETECT_IDENTITY && (label || href) &&
1646
+ (identity || inAccountUi(matched) || (label && namesPerson(label)) || (href && namesPerson(href)));
1494
1647
  return {
1495
1648
  $el_tag_name: tagNameOf(matched),
1496
1649
  $el_selector: cap(selector, EL_SELECTOR_MAX),
1497
1650
  $el_id: matched.id && !noIds ? cap(String(matched.id), EL_ID_MAX) : undefined,
1498
1651
  $el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
1499
- $el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined
1652
+ $el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
1653
+ $el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
1654
+ $el_href: href && !labelOrHrefIdentity ? redactor.boundedRedact(href, URL_MAX) : undefined
1500
1655
  };
1501
1656
  }
1502
1657
 
1658
+ // At most 5 $click per element per second (sequential.autocapture.ts CLICK_CAP): capAt is the window's start, caps
1659
+ // each element's count in it; the clicks past 5 are counted there, not sent.
1660
+ var caps = {};
1661
+ var capAt = 0;
1662
+ // The last trusted pointerup, touchend or keydown (sequential.autocapture.ts GESTURE_MS).
1663
+ var gestureAt = -1e9;
1664
+
1665
+ function onGesture(ev) {
1666
+ if (ev.isTrusted) gestureAt = now();
1667
+ }
1668
+
1503
1669
  function onClick(ev) {
1504
1670
  try {
1505
1671
  var target = ev && ev.target;
1506
1672
  if (!target || target.nodeType !== 1) return;
1673
+ // A script's click (isTrusted false) counts only while the person acts (sequential.autocapture.ts untrusted).
1674
+ if (ev.isTrusted === false) {
1675
+ var ua = window.navigator.userActivation;
1676
+ if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
1677
+ }
1507
1678
  var matched = closestMatching(target, INTERACTIVE_SELECTOR);
1508
1679
  if (!matched) return;
1509
- captureInternal('$click', elementProps(matched));
1680
+ var props = elementProps(matched);
1681
+ var t = now();
1682
+ if (t - capAt >= 1000) {
1683
+ caps = {};
1684
+ capAt = t;
1685
+ }
1686
+ if ((caps[props.$el_selector] = (caps[props.$el_selector] || 0) + 1) <= 5) captureInternal('$click', props);
1510
1687
  if (isPlainClick(ev) && !deadExcluded(matched, target)) openDead(matched);
1511
1688
  } catch (e) {}
1512
1689
  }
1513
1690
 
1514
1691
  // ── rage and dead clicks: as in sequential.autocapture.ts (BE spec 2026-10-08, BE #432) ──
1515
- // One MutationObserver, only while a burst or a dead window is open. No MutationObserver:
1516
- // neither signal runs, because "no effect" cannot be told from "an effect we cannot see".
1692
+ // One MutationObserver, only while a burst or a dead window is open; none: neither signal runs.
1517
1693
  var Observer = window.MutationObserver;
1518
1694
  var rage = null;
1519
1695
  var dead = null;
@@ -1622,7 +1798,7 @@ var boot = (function (injectedTag) {
1622
1798
  if (!Observer || document.visibilityState === 'hidden') return;
1623
1799
  // A new click means the person did something: the old window ends with no event.
1624
1800
  if (dead) clearTimeout(dead.timer);
1625
- dead = { at: Date.now(), el: el, href: String(window.location.href), timer: setTimeout(endDead, DEAD_WAIT_MS) };
1801
+ dead = { at: Date.now(), el: el, href: String(window.location.href), selected: !closestMatching(el, '[data-sq-private]') && selectedState(el), timer: setTimeout(endDead, DEAD_WAIT_MS) };
1626
1802
  syncObserver();
1627
1803
  }
1628
1804
 
@@ -1633,7 +1809,7 @@ var boot = (function (injectedTag) {
1633
1809
  syncObserver();
1634
1810
  if (!d || String(window.location.href) !== d.href) return;
1635
1811
  var props = elementProps(d.el);
1636
- props.$wait_ms = DEAD_WAIT_MS;
1812
+ props.$wait_ms = DEAD_WAIT_MS; if (d.selected) props.$el_state = 'selected';
1637
1813
  captureInternal('$deadclick', props, d.at);
1638
1814
  } catch (e) {}
1639
1815
  }
@@ -1686,15 +1862,20 @@ var boot = (function (injectedTag) {
1686
1862
  document.addEventListener('submit', onSubmit, true);
1687
1863
  document.addEventListener('pointerdown', onPointerDown, true);
1688
1864
  document.addEventListener('pointerup', onPointerUp, true);
1865
+ document.addEventListener('pointerup', onGesture, true);
1866
+ document.addEventListener('touchend', onGesture, true);
1867
+ document.addEventListener('keydown', onGesture, true);
1689
1868
  document.addEventListener('focusin', onFocusIn, true);
1690
1869
  document.addEventListener('selectionchange', onSelectionChange, true);
1691
1870
  document.addEventListener('scroll', onScroll, true);
1871
+ window.addEventListener('popstate', onPopCapture, true);
1692
1872
  window.addEventListener('popstate', onPopState);
1693
1873
  try {
1694
1874
  var navigation = window.navigation;
1695
1875
  if (navigation && typeof navigation.addEventListener === 'function') {
1696
1876
  navigation.addEventListener('navigate', function (ev) {
1697
1877
  lastNavigationType = ev.navigationType;
1878
+ if (ev.navigationType !== 'replace') popKind = ev.navigationType;
1698
1879
  });
1699
1880
  navigationApi = true;
1700
1881
  }
@@ -1707,20 +1888,21 @@ var boot = (function (injectedTag) {
1707
1888
  if (typeof originalPush === 'function') {
1708
1889
  history.pushState = function () {
1709
1890
  var result = originalPush.apply(history, arguments);
1710
- checkPage('push');
1891
+ checkPage(hookNav('push'));
1711
1892
  return result;
1712
1893
  };
1713
1894
  }
1714
1895
  if (typeof originalReplace === 'function') {
1715
1896
  history.replaceState = function () {
1716
1897
  var result = originalReplace.apply(history, arguments);
1717
- checkPage('replace');
1898
+ checkPage(hookNav('replace'));
1718
1899
  return result;
1719
1900
  };
1720
1901
  }
1721
1902
  } catch (e) {}
1722
1903
 
1723
1904
  lastPageKey = pageKey(attachUrl || String(window.location.href));
1905
+ lastPathKey = pathKey(attachUrl || String(window.location.href));
1724
1906
  capturePageview(attachUrl, 'load');
1725
1907
  }
1726
1908
 
@@ -1866,6 +2048,17 @@ var boot = (function (injectedTag) {
1866
2048
  } catch (e) {}
1867
2049
  }
1868
2050
 
2051
+ // F7: already selected when clicked (ARIA, or a class like is-active); only 'selected' is sent ($deadclick)
2052
+ function selectedState(el) {
2053
+ var v = el.getAttribute('aria-current');
2054
+ return ['pressed', 'checked', 'selected'].some(function (a) { return /^\s*true\s*$/i.test(el.getAttribute('aria-' + a)); }) ||
2055
+ (v !== null && !/^\s*(false)?\s*$/i.test(v)) ||
2056
+ String(el.getAttribute('class') || '').toLowerCase().split(/\s+/).some(function (t) {
2057
+ t = t.split(/--|__|[-_]/);
2058
+ return /^(active|selected|checked|current|on)$/.test(t[t.length - 1]) && !t.some(function (x) { return /^(not|un|non|no)$/.test(x); });
2059
+ });
2060
+ }
2061
+
1869
2062
  if (!DISABLED) {
1870
2063
  try {
1871
2064
  document.addEventListener('visibilitychange', function () {
@@ -1878,7 +2071,7 @@ var boot = (function (injectedTag) {
1878
2071
  }
1879
2072
  });
1880
2073
 
1881
- var VERSION = '1.0.1';
2074
+ var VERSION = '1.0.3';
1882
2075
  var running = null;
1883
2076
 
1884
2077
  function logLine(level, message) {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @usesequential/browser 1.0.1: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
1
+ /* @usesequential/browser 1.0.3: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
2
2
  * `boot` below is sequential.js, the file the script tag loads, unchanged. */
3
3
  var boot = (function (injectedTag) {
4
4
  'use strict';
@@ -161,15 +161,20 @@ var boot = (function (injectedTag) {
161
161
  logError('data-release is not a release (1 to 64 printable ASCII characters); events are sent without one.');
162
162
  }
163
163
 
164
- // No key or no API: every method stays present and inert, so a bad tag never throws.
164
+ // No key or no API: every method stays present and inert, so a bad tag never throws. Both lines say how to set the
165
+ // values without attributes, for a loader that drops them.
165
166
  var DISABLED = false;
167
+ var CONFIG_HELP =
168
+ ' Loaded through Google Tag Manager or another loader that drops data-* attributes? Set window.sequentialConfig' +
169
+ ' = { key, api } before the SDK loads: https://www.usesequential.com/docs/sequential#configure-without-attributes';
166
170
  if (!KEY) {
167
- logError('the script tag has no data-key — no events will be sent.');
171
+ logError('the script tag has no data-key — no events will be sent.' + CONFIG_HELP);
168
172
  DISABLED = true;
169
173
  } else if (!API_HOST) {
170
174
  logError(
171
175
  'the script tag has no data-api — no events will be sent. The CDN origin is not the ' +
172
- 'ingest origin, so it cannot be guessed from this script’s own src.'
176
+ 'ingest origin, so it cannot be guessed from this script’s own src.' +
177
+ CONFIG_HELP
173
178
  );
174
179
  DISABLED = true;
175
180
  }
@@ -200,13 +205,13 @@ var boot = (function (injectedTag) {
200
205
  var REQUEST_TIMEOUT_MS = 10000;
201
206
  var MAX_SEND_ATTEMPTS = 3;
202
207
  var RETRY_BASE_MS = 500;
203
- // A 429 (the backend's per-project event rate limit): pause for the server's retry time, clamped; hold the refused
204
- // batch and what is captured meanwhile, capped, the oldest dropped first (sequential.core.ts holdRateLimited).
208
+ // A 429 or a 503 overloaded: pause and hold, as sequential.core.ts holdRateLimited.
205
209
  var RATE_LIMIT_DEFAULT_SEC = 60;
206
210
  var RATE_LIMIT_MIN_SEC = 1;
207
211
  var RATE_LIMIT_MAX_SEC = 300;
208
212
  var MAX_HELD_EVENTS = 100;
209
213
  var MAX_HELD_BYTES = 128 * 1024;
214
+ var MAX_HOLD_MS = 5 * 60 * 1000;
210
215
 
211
216
  var redactor = null;
212
217
 
@@ -221,14 +226,16 @@ var boot = (function (injectedTag) {
221
226
  // out, so a queued optOut() also writes nothing. Meanwhile each write waits in `held` (null removes).
222
227
  var storageOn = false;
223
228
  var held = {};
224
- // What optOut() deletes: every key the SDK writes, except the __sq_opt mark it then sets.
229
+ // What optOut() deletes: every key the SDK writes, except the __sq_opt mark it then sets, and the recorder's
230
+ // __lx_replay_sample (recorder-boot.js sampledIn: '1:' or '0:' + the session id, written when sampling < 1).
225
231
  var STORED_KEYS = [
226
232
  ['localStorage', '__sq_did'],
227
233
  ['localStorage', '__sq_aid'],
228
234
  ['localStorage', '__sq_ath'],
229
235
  ['localStorage', '__sq_ith'],
230
236
  ['sessionStorage', '__sq_sid'],
231
- ['sessionStorage', '__lx_replay_sid']
237
+ ['sessionStorage', '__lx_replay_sid'],
238
+ ['sessionStorage', '__lx_replay_sample']
232
239
  ];
233
240
 
234
241
  // False only when the browser refused the write.
@@ -560,8 +567,13 @@ var boot = (function (injectedTag) {
560
567
  var queueBytes = 0;
561
568
  var flushTimer = null;
562
569
  var pauseTimer = null;
563
- // Events already put back once after a 429 (a batch is resent once). An array, not a WeakSet: this file is ES5.
564
- var resentOnce = [];
570
+ // Refused batches, oldest first, each kept whole and resent one request each: the backend sees the same ids again and
571
+ // stores a batch that did land once (BE src/ingest/dedup.ts).
572
+ var heldBatches = [];
573
+ // When each held event was first refused, as two parallel arrays (not a WeakMap: this file is ES5), at most
574
+ // 2 x MAX_HELD_EVENTS long: more than can be held at once.
575
+ var refusedEvents = [];
576
+ var refusedAt = [];
565
577
 
566
578
  function assign(target, source) {
567
579
  if (!source) return target;
@@ -667,6 +679,7 @@ var boot = (function (injectedTag) {
667
679
  clearContextCookie();
668
680
  queue = [];
669
681
  queueBytes = 0;
682
+ heldBatches = [];
670
683
  clearFlushTimer();
671
684
  if (pauseTimer !== null) {
672
685
  clearTimeout(pauseTimer);
@@ -710,25 +723,48 @@ var boot = (function (injectedTag) {
710
723
  }
711
724
  }
712
725
 
726
+ // Drop the oldest waiting events (held batches first, then the queue) until what waits fits the caps. Only while paused.
713
727
  function trimHeld() {
714
- while (queue.length > MAX_HELD_EVENTS || (queue.length > 1 && queueBytes > MAX_HELD_BYTES)) {
715
- queueBytes -= sizeOf(queue.shift());
728
+ var count = queue.length;
729
+ var bytes = queueBytes;
730
+ var i, j;
731
+ for (i = 0; i < heldBatches.length; i++) {
732
+ count += heldBatches[i].length;
733
+ for (j = 0; j < heldBatches[i].length; j++) bytes += sizeOf(heldBatches[i][j]);
734
+ }
735
+ while (count > MAX_HELD_EVENTS || (count > 1 && bytes > MAX_HELD_BYTES)) {
736
+ var dropped;
737
+ if (heldBatches.length > 0) {
738
+ dropped = heldBatches[0].shift();
739
+ if (heldBatches[0].length === 0) heldBatches.shift();
740
+ } else {
741
+ dropped = queue.shift();
742
+ queueBytes -= sizeOf(dropped);
743
+ }
744
+ count--;
745
+ bytes -= sizeOf(dropped);
716
746
  }
717
747
  }
718
748
 
719
749
  function holdRateLimited(events, sec) {
720
750
  if (stopped) return;
721
- var again = [];
751
+ var now = Date.now();
752
+ var keep = [];
722
753
  for (var i = 0; i < events.length; i++) {
723
- if (resentOnce.indexOf(events[i]) === -1) {
724
- again.push(events[i]);
725
- resentOnce.push(events[i]);
754
+ var k = refusedEvents.indexOf(events[i]);
755
+ if (k === -1) {
756
+ refusedEvents.push(events[i]);
757
+ refusedAt.push(now);
758
+ keep.push(events[i]);
759
+ } else if (now - refusedAt[k] < MAX_HOLD_MS) {
760
+ keep.push(events[i]);
726
761
  }
727
762
  }
728
- while (resentOnce.length > 2 * MAX_HELD_EVENTS) resentOnce.shift();
729
- queue = again.concat(queue);
730
- queueBytes = 0;
731
- for (var j = 0; j < queue.length; j++) queueBytes += sizeOf(queue[j]);
763
+ while (refusedEvents.length > 2 * MAX_HELD_EVENTS) {
764
+ refusedEvents.shift();
765
+ refusedAt.shift();
766
+ }
767
+ if (keep.length > 0) heldBatches.unshift(keep);
732
768
  clearFlushTimer();
733
769
  if (pauseTimer !== null) clearTimeout(pauseTimer);
734
770
  pauseTimer = setTimeout(function () {
@@ -784,19 +820,30 @@ var boot = (function (injectedTag) {
784
820
  });
785
821
  }
786
822
 
823
+ function sendEvents(events) {
824
+ if (!canSend()) return Promise.resolve();
825
+ var body = buildEnvelope(events);
826
+ if (body === null) return Promise.resolve();
827
+ return attemptSend(body, 1, events)['catch'](noop);
828
+ }
829
+
787
830
  function flush() {
788
831
  try {
789
- if (queue.length === 0) return Promise.resolve();
832
+ if (queue.length === 0 && heldBatches.length === 0) return Promise.resolve();
790
833
  clearFlushTimer();
791
834
  // Paused by a 429: the pause's own timer flushes what is held when it ends.
792
835
  if (pauseTimer !== null) return Promise.resolve();
836
+ // Held batches first, each as it was refused; a refusal on the way pauses again and keeps the rest held.
837
+ if (heldBatches.length > 0) {
838
+ return sendEvents(heldBatches.shift()).then(function () {
839
+ if (pauseTimer !== null || stopped) return;
840
+ return flush();
841
+ });
842
+ }
793
843
  var events = queue;
794
844
  queue = [];
795
845
  queueBytes = 0;
796
- if (!canSend()) return Promise.resolve();
797
- var body = buildEnvelope(events);
798
- if (body === null) return Promise.resolve();
799
- return attemptSend(body, 1, events)['catch'](noop);
846
+ return sendEvents(events);
800
847
  } catch (e) {
801
848
  return Promise.resolve();
802
849
  }
@@ -805,9 +852,13 @@ var boot = (function (injectedTag) {
805
852
  function drain() {
806
853
  try {
807
854
  if (optedOut || DISABLED || stopped) return null;
808
- if (queue.length === 0) return null;
855
+ if (queue.length === 0 && heldBatches.length === 0) return null;
809
856
  clearFlushTimer();
810
- var events = queue;
857
+ // The page is going: what is held goes in the one beacon too, oldest first.
858
+ var events = [];
859
+ for (var i = 0; i < heldBatches.length; i++) events = events.concat(heldBatches[i]);
860
+ events = events.concat(queue);
861
+ heldBatches = [];
811
862
  queue = [];
812
863
  queueBytes = 0;
813
864
  var body = buildEnvelope(events);
@@ -905,9 +956,18 @@ var boot = (function (injectedTag) {
905
956
  for (i = 0; i < w.length; i++) if (w[i].length > 2 && inList(idWords, w[i])) return true;
906
957
  }
907
958
 
959
+ // Account UI (the element or its 3 nearest ancestors):
960
+ // as in sequential.autocapture.ts.
961
+ // `profile` alone is not
962
+ // account UI
963
+ // (2026-10-26).
964
+ var ACCOUNT_WORD = /(\b|_)(avatar|account|user[-_]?menu|profile[-_](menu|dropdown|button|avatar)|(my|user)[-_]profile)(\b|_)/;
965
+ var ACCOUNT_LABEL = /^(account|user|profile)$|\b(my|your|open) (account|profile)\b|\b(user|account|profile)( navigation)? (menu|dropdown|options)\b/;
908
966
  function inAccountUi(node) {
909
967
  for (var i = 0; node && node.getAttribute && i++ < 4; node = node.parentNode) {
910
- if (/(\b|_)(avatar|account|profile|user[-_]?menu)(\b|_)/.test((node.getAttribute('class') + ' ' + node.id + ' ' + node.getAttribute('data-testid')).toLowerCase()) || /account|profile|user/i.test(node.getAttribute('aria-label'))) return true;
968
+ if (ACCOUNT_WORD.test((node.getAttribute('class') + ' ' + node.id + ' ' + node.getAttribute('data-testid')).toLowerCase())) return true;
969
+ var label = String(node.getAttribute('aria-label') || '').replace(/\s+/g, ' ').replace(/^ | $/g, '').toLowerCase();
970
+ if (label && ACCOUNT_LABEL.test(label)) return true;
911
971
  }
912
972
  }
913
973
 
@@ -920,23 +980,32 @@ var boot = (function (injectedTag) {
920
980
  learnIdentity(newDistinctId, props);
921
981
  var previous = distinctId;
922
982
  var hasTraits = props !== undefined && props !== null && typeof props === 'object' && Object.keys(props).length > 0;
923
- var hash = hasTraits ? identifyHash(newDistinctId, props) : null;
983
+ // __sq_ith is written on every identify, with no traits too: a stored one says the stored id is a person's.
984
+ var hash = identifyHash(newDistinctId, hasTraits ? props : {});
985
+ var stored = readLocal(IDENTIFY_HASH_KEY, memoryIdentifyHash);
924
986
  if (previous === newDistinctId) {
925
- // Same person again (a reload): changed traits still go out; the same traits, or none, send nothing.
926
- if (hash === null || hash === readLocal(IDENTIFY_HASH_KEY, memoryIdentifyHash)) return;
987
+ // Same person again (a reload): changed traits still go out; the same traits, or none, send nothing. None
988
+ // keeps the stored hash, and writes one only where there is none (an id identified before ith was always set).
989
+ if (hasTraits ? hash === stored : stored !== null && stored !== undefined) return;
927
990
  memoryIdentifyHash = hash;
928
991
  writeLocal(IDENTIFY_HASH_KEY, hash);
929
- captureInternal('$identify', assign({}, props));
992
+ if (hasTraits) captureInternal('$identify', assign({}, props));
930
993
  return;
931
994
  }
932
995
  memoryIdentifyHash = hash;
933
996
  writeLocal(IDENTIFY_HASH_KEY, hash);
934
997
  distinctId = newDistinctId;
935
998
  writeDistinctId(newDistinctId);
936
- contextDistinctId = previous;
937
999
 
938
1000
  var merged = assign({}, props);
939
- merged.$anon_distinct_id = previous;
1001
+ if (stored === null || stored === undefined) {
1002
+ contextDistinctId = previous;
1003
+ merged.$anon_distinct_id = previous;
1004
+ } else {
1005
+ // Another person on this browser (no reset): the previous id is a person, not an anonymous visitor, so it is
1006
+ // no claim. Sent as one, it moved that person's history to this one (the People duplicate, 2026-10-23).
1007
+ contextDistinctId = newDistinctId;
1008
+ }
940
1009
  captureInternal('$identify', merged);
941
1010
  } catch (e) {}
942
1011
  }
@@ -1005,6 +1074,7 @@ var boot = (function (injectedTag) {
1005
1074
 
1006
1075
  queue = [];
1007
1076
  queueBytes = 0;
1077
+ heldBatches = [];
1008
1078
  clearFlushTimer();
1009
1079
  clearContextCookie();
1010
1080
  forgetStorage();
@@ -1049,6 +1119,17 @@ var boot = (function (injectedTag) {
1049
1119
  } catch (e) {}
1050
1120
  }
1051
1121
 
1122
+ // Another tab's optOut() (__sq_opt set to '1') opts this tab out at once;
1123
+ // it writes back none of the ids that tab deleted.
1124
+ // Another tab's optIn() or localStorage.clear()
1125
+ // does not opt this tab in:
1126
+ // that waits for the next page load.
1127
+ try {
1128
+ window.addEventListener('storage', function (e) {
1129
+ if (e && e.key === OPT_OUT_KEY && e.newValue === '1' && !optedOut) optOut();
1130
+ });
1131
+ } catch (e) {}
1132
+
1052
1133
  function captureException(error, props) {
1053
1134
  try {
1054
1135
  if (optedOut || DISABLED) return;
@@ -1284,10 +1365,28 @@ var boot = (function (injectedTag) {
1284
1365
  route = hashRouteOf(s.slice(hash));
1285
1366
  s = s.slice(0, hash);
1286
1367
  }
1287
- s = s.replace(/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^/?#@]*@/, '$1');
1368
+ // userinfo runs to the authority's LAST '@' (an '@' in the user or password); never past '/', '?' or '#'
1369
+ s = s.replace(/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^/?#]*@/, '$1');
1288
1370
  return rdct.boundedRedact(s + route, URL_MAX);
1289
1371
  }
1290
1372
 
1373
+ // A clicked link's target ($el_href, owner decision 2026-10-26): resolved against the page; a scheme other than http(s)
1374
+ // is the scheme only, another origin its origin only (never another site's path), the page's own origin keeps the path
1375
+ // with no query, fragment or userinfo. Ingest re-scrubs it and is the authority (BE: src/adapters/link-target-scrub.ts):
1376
+ // id-like segments barred, the origin only under mask_attributes strict.
1377
+ function linkTarget(raw) {
1378
+ var page, target;
1379
+ try {
1380
+ page = new URL(String(window.location.href));
1381
+ target = new URL(String(raw), page.href);
1382
+ } catch (e) {
1383
+ return undefined;
1384
+ }
1385
+ if (!/^https?:$/.test(target.protocol)) return target.protocol;
1386
+ if (target.origin !== page.origin) return target.origin;
1387
+ return target.origin + target.pathname;
1388
+ }
1389
+
1291
1390
  function currentUrl() {
1292
1391
  if (!redactor) return undefined;
1293
1392
  try {
@@ -1375,6 +1474,17 @@ var boot = (function (injectedTag) {
1375
1474
  }
1376
1475
  }
1377
1476
 
1477
+ // sequential.autocapture.ts pathKey: the page without its query (pathname + hash route). A replaceState that keeps
1478
+ // it is not a pageview (2026-10-22): a player's ?t= or a list's ?sort= rewritten in place is the same page.
1479
+ function pathKey(href) {
1480
+ try {
1481
+ var u = new URL(href);
1482
+ return u.pathname + hashRouteOf(u.hash);
1483
+ } catch (e) {
1484
+ return String(href);
1485
+ }
1486
+ }
1487
+
1378
1488
  // $nav (sequential.autocapture.ts PageviewNav): popstate is also a forward fragment navigation, so
1379
1489
  // only the Navigation API's navigationType names it; without it, 'unknown'.
1380
1490
  function navFromNavigationType(type) {
@@ -1429,9 +1539,7 @@ var boot = (function (injectedTag) {
1429
1539
  return r.target.getAttribute(r.attributeName) !== r.oldValue;
1430
1540
  }
1431
1541
 
1432
- // The main button and no modifier key: anything else opens a menu, a tab or a selection. Not
1433
- // isPrimary: Chromium sends `click` as a PointerEvent with isPrimary=false; only pointer events
1434
- // check it (isPlainPointer).
1542
+ // As sequential.autocapture.ts isPlainClick and isPlainPointer.
1435
1543
  function isPlainClick(ev) {
1436
1544
  return ev.button === 0 && !ev.ctrlKey && !ev.metaKey && !ev.shiftKey && !ev.altKey;
1437
1545
  }
@@ -1440,6 +1548,12 @@ var boot = (function (injectedTag) {
1440
1548
  return isPlainClick(ev) && ev.isPrimary !== false;
1441
1549
  }
1442
1550
 
1551
+ // Monotonic where there is one, so a step of the wall clock cannot freeze the $click cap's window.
1552
+ function now() {
1553
+ var p = window.performance;
1554
+ return p && p.now ? p.now() : Date.now();
1555
+ }
1556
+
1443
1557
  function startAutocapture(attachUrl) {
1444
1558
  if (autocaptureStarted || !redactor) return;
1445
1559
  autocaptureStarted = true;
@@ -1462,25 +1576,55 @@ var boot = (function (injectedTag) {
1462
1576
  });
1463
1577
  }
1464
1578
 
1465
- // One page key (pathname + search of the RAW URL, + the fragment only for a #/ or #!/ hash
1466
- // route) for every trigger, as in
1467
- // sequential.autocapture.ts pageKey: a router's same-URL replaceState is not a pageview.
1579
+ // One page key for every trigger, as sequential.autocapture.ts pageKey.
1468
1580
  var lastPageKey = null;
1581
+ var lastPathKey = null;
1469
1582
  var lastNavigationType;
1470
1583
  var navigationApi = false;
1471
1584
 
1472
1585
  function checkPage(nav) {
1473
1586
  try {
1474
1587
  lastNavigationType = undefined;
1588
+ popKind = undefined;
1475
1589
  var key = pageKey(String(window.location.href));
1476
1590
  if (key === lastPageKey) return;
1591
+ // A query-only replaceState moves both keys without a pageview (sequential.autocapture.ts checkPage).
1592
+ var path = pathKey(String(window.location.href));
1593
+ var queryOnlyReplace = nav === 'replace' && path === lastPathKey;
1477
1594
  lastPageKey = key;
1595
+ lastPathKey = path;
1596
+ if (queryOnlyReplace) return;
1478
1597
  capturePageview(undefined, nav);
1479
1598
  } catch (e) {}
1480
1599
  }
1481
1600
 
1601
+ // A traversal the page's router answers with replaceState: as sequential.autocapture.ts inPopstate (F1).
1602
+ var popPending = false;
1603
+ var popKind;
1604
+ function onPopCapture() {
1605
+ try {
1606
+ popPending = true;
1607
+ setTimeout(function () {
1608
+ popPending = false;
1609
+ }, 0);
1610
+ } catch (e) {}
1611
+ }
1612
+ function inPopstate() {
1613
+ if (popPending) return true;
1614
+ try {
1615
+ var ev = window.event;
1616
+ return !!ev && ev.type === 'popstate';
1617
+ } catch (e) {
1618
+ return false;
1619
+ }
1620
+ }
1621
+ function hookNav(kind) {
1622
+ return inPopstate() ? (navigationApi ? navFromNavigationType(popKind) : 'unknown') : kind;
1623
+ }
1624
+
1482
1625
  function onPopState() {
1483
- checkPage(navigationApi ? navFromNavigationType(lastNavigationType) : 'unknown');
1626
+ checkPage(navigationApi ? navFromNavigationType(popKind) : 'unknown');
1627
+ popPending = false;
1484
1628
  }
1485
1629
 
1486
1630
  // $click's props; $rageclick and $deadclick send the same, so the detector groups all three.
@@ -1490,29 +1634,61 @@ var boot = (function (injectedTag) {
1490
1634
  var identity = DETECT_IDENTITY && raw !== undefined && (inAccountUi(matched) || namesPerson(raw));
1491
1635
  var noIds = closestMatching(matched, '[data-sq-private]') || (DETECT_IDENTITY && namesPerson(stableSelector(matched)));
1492
1636
  var selector = stableSelector(matched, noIds);
1637
+ // $el_label (the aria-label) and $el_href (the link target, linkTarget) are element text like $el_text (owner
1638
+ // decision 2026-10-26, soc2 rule): none under data-sq-mask/-private, in account UI, or when the text, the label or
1639
+ // the target names the identified person; the label redacted and capped like the text. An icon button's label is
1640
+ // often its only name.
1641
+ var label = masked ? '' : String(matched.getAttribute('aria-label') || '').replace(/\s+/g, ' ').replace(/^ | $/g, '');
1642
+ var anchor = masked ? null : closestMatching(matched, 'a[href]');
1643
+ var href = anchor ? linkTarget(anchor.getAttribute('href')) : undefined;
1644
+ var labelOrHrefIdentity = DETECT_IDENTITY && (label || href) &&
1645
+ (identity || inAccountUi(matched) || (label && namesPerson(label)) || (href && namesPerson(href)));
1493
1646
  return {
1494
1647
  $el_tag_name: tagNameOf(matched),
1495
1648
  $el_selector: cap(selector, EL_SELECTOR_MAX),
1496
1649
  $el_id: matched.id && !noIds ? cap(String(matched.id), EL_ID_MAX) : undefined,
1497
1650
  $el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
1498
- $el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined
1651
+ $el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
1652
+ $el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
1653
+ $el_href: href && !labelOrHrefIdentity ? redactor.boundedRedact(href, URL_MAX) : undefined
1499
1654
  };
1500
1655
  }
1501
1656
 
1657
+ // At most 5 $click per element per second (sequential.autocapture.ts CLICK_CAP): capAt is the window's start, caps
1658
+ // each element's count in it; the clicks past 5 are counted there, not sent.
1659
+ var caps = {};
1660
+ var capAt = 0;
1661
+ // The last trusted pointerup, touchend or keydown (sequential.autocapture.ts GESTURE_MS).
1662
+ var gestureAt = -1e9;
1663
+
1664
+ function onGesture(ev) {
1665
+ if (ev.isTrusted) gestureAt = now();
1666
+ }
1667
+
1502
1668
  function onClick(ev) {
1503
1669
  try {
1504
1670
  var target = ev && ev.target;
1505
1671
  if (!target || target.nodeType !== 1) return;
1672
+ // A script's click (isTrusted false) counts only while the person acts (sequential.autocapture.ts untrusted).
1673
+ if (ev.isTrusted === false) {
1674
+ var ua = window.navigator.userActivation;
1675
+ if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
1676
+ }
1506
1677
  var matched = closestMatching(target, INTERACTIVE_SELECTOR);
1507
1678
  if (!matched) return;
1508
- captureInternal('$click', elementProps(matched));
1679
+ var props = elementProps(matched);
1680
+ var t = now();
1681
+ if (t - capAt >= 1000) {
1682
+ caps = {};
1683
+ capAt = t;
1684
+ }
1685
+ if ((caps[props.$el_selector] = (caps[props.$el_selector] || 0) + 1) <= 5) captureInternal('$click', props);
1509
1686
  if (isPlainClick(ev) && !deadExcluded(matched, target)) openDead(matched);
1510
1687
  } catch (e) {}
1511
1688
  }
1512
1689
 
1513
1690
  // ── rage and dead clicks: as in sequential.autocapture.ts (BE spec 2026-10-08, BE #432) ──
1514
- // One MutationObserver, only while a burst or a dead window is open. No MutationObserver:
1515
- // neither signal runs, because "no effect" cannot be told from "an effect we cannot see".
1691
+ // One MutationObserver, only while a burst or a dead window is open; none: neither signal runs.
1516
1692
  var Observer = window.MutationObserver;
1517
1693
  var rage = null;
1518
1694
  var dead = null;
@@ -1621,7 +1797,7 @@ var boot = (function (injectedTag) {
1621
1797
  if (!Observer || document.visibilityState === 'hidden') return;
1622
1798
  // A new click means the person did something: the old window ends with no event.
1623
1799
  if (dead) clearTimeout(dead.timer);
1624
- dead = { at: Date.now(), el: el, href: String(window.location.href), timer: setTimeout(endDead, DEAD_WAIT_MS) };
1800
+ dead = { at: Date.now(), el: el, href: String(window.location.href), selected: !closestMatching(el, '[data-sq-private]') && selectedState(el), timer: setTimeout(endDead, DEAD_WAIT_MS) };
1625
1801
  syncObserver();
1626
1802
  }
1627
1803
 
@@ -1632,7 +1808,7 @@ var boot = (function (injectedTag) {
1632
1808
  syncObserver();
1633
1809
  if (!d || String(window.location.href) !== d.href) return;
1634
1810
  var props = elementProps(d.el);
1635
- props.$wait_ms = DEAD_WAIT_MS;
1811
+ props.$wait_ms = DEAD_WAIT_MS; if (d.selected) props.$el_state = 'selected';
1636
1812
  captureInternal('$deadclick', props, d.at);
1637
1813
  } catch (e) {}
1638
1814
  }
@@ -1685,15 +1861,20 @@ var boot = (function (injectedTag) {
1685
1861
  document.addEventListener('submit', onSubmit, true);
1686
1862
  document.addEventListener('pointerdown', onPointerDown, true);
1687
1863
  document.addEventListener('pointerup', onPointerUp, true);
1864
+ document.addEventListener('pointerup', onGesture, true);
1865
+ document.addEventListener('touchend', onGesture, true);
1866
+ document.addEventListener('keydown', onGesture, true);
1688
1867
  document.addEventListener('focusin', onFocusIn, true);
1689
1868
  document.addEventListener('selectionchange', onSelectionChange, true);
1690
1869
  document.addEventListener('scroll', onScroll, true);
1870
+ window.addEventListener('popstate', onPopCapture, true);
1691
1871
  window.addEventListener('popstate', onPopState);
1692
1872
  try {
1693
1873
  var navigation = window.navigation;
1694
1874
  if (navigation && typeof navigation.addEventListener === 'function') {
1695
1875
  navigation.addEventListener('navigate', function (ev) {
1696
1876
  lastNavigationType = ev.navigationType;
1877
+ if (ev.navigationType !== 'replace') popKind = ev.navigationType;
1697
1878
  });
1698
1879
  navigationApi = true;
1699
1880
  }
@@ -1706,20 +1887,21 @@ var boot = (function (injectedTag) {
1706
1887
  if (typeof originalPush === 'function') {
1707
1888
  history.pushState = function () {
1708
1889
  var result = originalPush.apply(history, arguments);
1709
- checkPage('push');
1890
+ checkPage(hookNav('push'));
1710
1891
  return result;
1711
1892
  };
1712
1893
  }
1713
1894
  if (typeof originalReplace === 'function') {
1714
1895
  history.replaceState = function () {
1715
1896
  var result = originalReplace.apply(history, arguments);
1716
- checkPage('replace');
1897
+ checkPage(hookNav('replace'));
1717
1898
  return result;
1718
1899
  };
1719
1900
  }
1720
1901
  } catch (e) {}
1721
1902
 
1722
1903
  lastPageKey = pageKey(attachUrl || String(window.location.href));
1904
+ lastPathKey = pathKey(attachUrl || String(window.location.href));
1723
1905
  capturePageview(attachUrl, 'load');
1724
1906
  }
1725
1907
 
@@ -1865,6 +2047,17 @@ var boot = (function (injectedTag) {
1865
2047
  } catch (e) {}
1866
2048
  }
1867
2049
 
2050
+ // F7: already selected when clicked (ARIA, or a class like is-active); only 'selected' is sent ($deadclick)
2051
+ function selectedState(el) {
2052
+ var v = el.getAttribute('aria-current');
2053
+ return ['pressed', 'checked', 'selected'].some(function (a) { return /^\s*true\s*$/i.test(el.getAttribute('aria-' + a)); }) ||
2054
+ (v !== null && !/^\s*(false)?\s*$/i.test(v)) ||
2055
+ String(el.getAttribute('class') || '').toLowerCase().split(/\s+/).some(function (t) {
2056
+ t = t.split(/--|__|[-_]/);
2057
+ return /^(active|selected|checked|current|on)$/.test(t[t.length - 1]) && !t.some(function (x) { return /^(not|un|non|no)$/.test(x); });
2058
+ });
2059
+ }
2060
+
1868
2061
  if (!DISABLED) {
1869
2062
  try {
1870
2063
  document.addEventListener('visibilitychange', function () {
@@ -1877,7 +2070,7 @@ var boot = (function (injectedTag) {
1877
2070
  }
1878
2071
  });
1879
2072
 
1880
- var VERSION = '1.0.1';
2073
+ var VERSION = '1.0.3';
1881
2074
  var running = null;
1882
2075
 
1883
2076
  function logLine(level, message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usesequential/browser",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "The Sequential browser SDK as an npm package: analytics and session replay, the same code as the script tag.",
5
5
  "keywords": [
6
6
  "sequential",