clarity-js 0.7.52 → 0.7.56

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/build/clarity.js CHANGED
@@ -85,11 +85,11 @@ function setup() {
85
85
  w[c] = function () {
86
86
  (w[c].q = w[c].q || []).push(arguments);
87
87
  // if the start function was called, don't queue it and instead process the queue
88
- arguments[0] === "start" && w[c].q.unshift(w[c].q.pop()) && process$7();
88
+ arguments[0] === "start" && w[c].q.unshift(w[c].q.pop()) && process$8();
89
89
  };
90
90
  }
91
91
  }
92
- function process$7() {
92
+ function process$8() {
93
93
  if (typeof w !== "undefined") {
94
94
  // Do not execute or reset global "clarity" variable if a version of Clarity is already running on the page
95
95
  if (w[c] && w[c].v) {
@@ -165,7 +165,7 @@ function stop$F() {
165
165
  startTime = 0;
166
166
  }
167
167
 
168
- var version$1 = "0.7.52";
168
+ var version$1 = "0.7.56";
169
169
 
170
170
  // tslint:disable: no-bitwise
171
171
  function hash (input, precision) {
@@ -542,16 +542,16 @@ function clearTimeout(handle) {
542
542
  var data$h;
543
543
  var last = 0;
544
544
  var interval = 0;
545
- var timeout$6 = null;
545
+ var timeout$7 = null;
546
546
  function start$F() {
547
547
  interval = 60000 /* Setting.PingInterval */;
548
548
  last = 0;
549
549
  }
550
550
  function reset$q() {
551
- if (timeout$6) {
552
- clearTimeout(timeout$6);
551
+ if (timeout$7) {
552
+ clearTimeout(timeout$7);
553
553
  }
554
- timeout$6 = setTimeout(ping, interval);
554
+ timeout$7 = setTimeout(ping, interval);
555
555
  last = time();
556
556
  }
557
557
  function ping() {
@@ -559,14 +559,14 @@ function ping() {
559
559
  data$h = { gap: now - last };
560
560
  encode$1(25 /* Event.Ping */);
561
561
  if (data$h.gap < 300000 /* Setting.PingTimeout */) {
562
- timeout$6 = setTimeout(ping, interval);
562
+ timeout$7 = setTimeout(ping, interval);
563
563
  }
564
564
  else {
565
565
  suspend();
566
566
  }
567
567
  }
568
568
  function stop$C() {
569
- clearTimeout(timeout$6);
569
+ clearTimeout(timeout$7);
570
570
  last = 0;
571
571
  interval = 0;
572
572
  }
@@ -1158,7 +1158,7 @@ function add(node, parent, data, source) {
1158
1158
  };
1159
1159
  privacy(node, values[id], parentValue);
1160
1160
  updateSelector(values[id]);
1161
- size$1(values[id]);
1161
+ updateImageSize(values[id]);
1162
1162
  track$6(id, source);
1163
1163
  }
1164
1164
  function update$1(node, parent, data, source) {
@@ -1235,6 +1235,7 @@ function iframe(node) {
1235
1235
  return doc && iframeMap.has(doc) ? iframeMap.get(doc) : null;
1236
1236
  }
1237
1237
  function privacy(node, value, parent) {
1238
+ var _a;
1238
1239
  var data = value.data;
1239
1240
  var metadata = value.metadata;
1240
1241
  var current = metadata.privacy;
@@ -1279,6 +1280,12 @@ function privacy(node, value, parent) {
1279
1280
  // In a mode where we mask sensitive information by default, look through class names to aggressively mask content
1280
1281
  metadata.privacy = inspect(attributes["class" /* Constant.Class */], maskText, metadata);
1281
1282
  break;
1283
+ case tag === "IMG" /* Constant.ImageTag */:
1284
+ // Mask images with blob src as it is not publicly available anyway.
1285
+ if ((_a = attributes.src) === null || _a === void 0 ? void 0 : _a.startsWith('blob:')) {
1286
+ metadata.privacy = 3 /* Privacy.TextImage */;
1287
+ }
1288
+ break;
1282
1289
  }
1283
1290
  }
1284
1291
  function inspect(input, lookup, metadata) {
@@ -1385,9 +1392,17 @@ function removeNodeFromNodesMap(id) {
1385
1392
  }
1386
1393
  }
1387
1394
  }
1388
- function size$1(value) {
1395
+ function updateImageSize(value) {
1389
1396
  // If this element is a image node, and is masked, then track box model for the current element
1390
1397
  if (value.data.tag === "IMG" /* Constant.ImageTag */ && value.metadata.privacy === 3 /* Privacy.TextImage */) {
1398
+ var img_1 = getNode(value.id);
1399
+ // We will not capture the natural image dimensions until it loads.
1400
+ if (img_1 && (!img_1.complete || img_1.naturalWidth === 0)) {
1401
+ // This will trigger mutation to update the original width and height after image loads.
1402
+ bind(img_1, 'load', function () {
1403
+ img_1.setAttribute('data-clarity-loaded', "".concat(shortid()));
1404
+ });
1405
+ }
1391
1406
  value.metadata.size = [];
1392
1407
  }
1393
1408
  }
@@ -1898,7 +1913,7 @@ function stop$s() {
1898
1913
  reset$h();
1899
1914
  }
1900
1915
 
1901
- var timeout$5 = null;
1916
+ var timeout$6 = null;
1902
1917
  var state$6 = [];
1903
1918
  function start$t() {
1904
1919
  reset$g();
@@ -1924,23 +1939,23 @@ function recompute$6(evt) {
1924
1939
  state$6.pop();
1925
1940
  }
1926
1941
  state$6.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
1927
- clearTimeout(timeout$5);
1928
- timeout$5 = setTimeout(process$6, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
1942
+ clearTimeout(timeout$6);
1943
+ timeout$6 = setTimeout(process$7, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
1929
1944
  }
1930
1945
  }
1931
- function process$6(event) {
1946
+ function process$7(event) {
1932
1947
  schedule$1(encode$3.bind(this, event));
1933
1948
  }
1934
1949
  function reset$g() {
1935
1950
  state$6 = [];
1936
1951
  }
1937
1952
  function stop$r() {
1938
- clearTimeout(timeout$5);
1953
+ clearTimeout(timeout$6);
1939
1954
  reset$g();
1940
1955
  }
1941
1956
 
1942
1957
  var state$5 = [];
1943
- var timeout$4 = null;
1958
+ var timeout$5 = null;
1944
1959
  function start$s() {
1945
1960
  reset$f();
1946
1961
  }
@@ -2005,16 +2020,16 @@ function handler$2(current) {
2005
2020
  state$5.pop();
2006
2021
  }
2007
2022
  state$5.push(current);
2008
- clearTimeout(timeout$4);
2009
- timeout$4 = setTimeout(process$5, 500 /* Setting.LookAhead */, current.event);
2023
+ clearTimeout(timeout$5);
2024
+ timeout$5 = setTimeout(process$6, 500 /* Setting.LookAhead */, current.event);
2010
2025
  break;
2011
2026
  default:
2012
2027
  state$5.push(current);
2013
- process$5(current.event);
2028
+ process$6(current.event);
2014
2029
  break;
2015
2030
  }
2016
2031
  }
2017
- function process$5(event) {
2032
+ function process$6(event) {
2018
2033
  schedule$1(encode$3.bind(this, event));
2019
2034
  }
2020
2035
  function reset$f() {
@@ -2029,14 +2044,15 @@ function similar$1(last, current) {
2029
2044
  return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.Interval */;
2030
2045
  }
2031
2046
  function stop$q() {
2032
- clearTimeout(timeout$4);
2047
+ clearTimeout(timeout$5);
2033
2048
  // Send out any pending pointer events in the pipeline
2034
2049
  if (state$5.length > 0) {
2035
- process$5(state$5[state$5.length - 1].event);
2050
+ process$6(state$5[state$5.length - 1].event);
2036
2051
  }
2037
2052
  }
2038
2053
 
2039
2054
  var data$b;
2055
+ var timeout$4 = null;
2040
2056
  function start$r() {
2041
2057
  bind(window, "resize", recompute$5);
2042
2058
  recompute$5();
@@ -2049,10 +2065,15 @@ function recompute$5() {
2049
2065
  width: de && "clientWidth" in de ? Math.min(de.clientWidth, window.innerWidth) : window.innerWidth,
2050
2066
  height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
2051
2067
  };
2052
- encode$3(11 /* Event.Resize */);
2068
+ clearTimeout(timeout$4);
2069
+ timeout$4 = setTimeout(process$5, 500 /* Setting.LookAhead */, 11 /* Event.Resize */);
2070
+ }
2071
+ function process$5(event) {
2072
+ schedule$1(encode$3.bind(this, event));
2053
2073
  }
2054
2074
  function reset$e() {
2055
2075
  data$b = null;
2076
+ clearTimeout(timeout$4);
2056
2077
  }
2057
2078
  function stop$p() {
2058
2079
  reset$e();
@@ -2702,9 +2723,6 @@ function ld(json) {
2702
2723
  max(12 /* Metric.RatingCount */, num$1(json["ratingCount" /* JsonLD.RatingCount */]));
2703
2724
  max(17 /* Metric.ReviewCount */, num$1(json["reviewCount" /* JsonLD.ReviewCount */]));
2704
2725
  break;
2705
- case "person" /* JsonLD.Author */:
2706
- log(8 /* Dimension.AuthorName */, json["name" /* JsonLD.Name */]);
2707
- break;
2708
2726
  case "offer" /* JsonLD.Offer */:
2709
2727
  log(7 /* Dimension.ProductAvailability */, json["availability" /* JsonLD.Availability */]);
2710
2728
  log(14 /* Dimension.ProductCondition */, json["itemCondition" /* JsonLD.ItemCondition */]);
@@ -4500,8 +4518,11 @@ function check$2(bytes) {
4500
4518
  }
4501
4519
  function trigger(reason) {
4502
4520
  data$4.check = reason;
4503
- clear();
4504
- stop();
4521
+ // limit the dimensions we collect, but we don't need to stop Clarity entirely if we hit the limit
4522
+ if (reason !== 5 /* Check.Collection */) {
4523
+ clear();
4524
+ stop();
4525
+ }
4505
4526
  }
4506
4527
  function compute$3() {
4507
4528
  if (data$4.check !== 0 /* Check.None */) {
@@ -4514,13 +4535,16 @@ function stop$a() {
4514
4535
 
4515
4536
  var data$3 = null;
4516
4537
  var updates = null;
4538
+ var limited = false;
4517
4539
  function start$a() {
4518
4540
  data$3 = {};
4519
4541
  updates = {};
4542
+ limited = false;
4520
4543
  }
4521
4544
  function stop$9() {
4522
4545
  data$3 = {};
4523
4546
  updates = {};
4547
+ limited = false;
4524
4548
  }
4525
4549
  function log(dimension, value) {
4526
4550
  // Check valid value before moving ahead
@@ -4531,6 +4555,14 @@ function log(dimension, value) {
4531
4555
  data$3[dimension] = [];
4532
4556
  }
4533
4557
  if (data$3[dimension].indexOf(value) < 0) {
4558
+ // Limit check to ensure we have a cap on number of dimensions we can collect
4559
+ if (data$3[dimension].length > 128 /* Setting.CollectionLimit */) {
4560
+ if (!limited) {
4561
+ limited = true;
4562
+ trigger(5 /* Check.Collection */);
4563
+ }
4564
+ return;
4565
+ }
4534
4566
  data$3[dimension].push(value);
4535
4567
  // If this is a new value, track it as part of updates object
4536
4568
  // This allows us to only send back new values in subsequent payloads
@@ -4538,10 +4570,6 @@ function log(dimension, value) {
4538
4570
  updates[dimension] = [];
4539
4571
  }
4540
4572
  updates[dimension].push(value);
4541
- // Limit check to ensure we have a cap on number of dimensions we can collect
4542
- if (data$3[dimension].length > 128 /* Setting.CollectionLimit */) {
4543
- trigger(5 /* Check.Collection */);
4544
- }
4545
4573
  }
4546
4574
  }
4547
4575
  }
@@ -4550,6 +4578,7 @@ function compute$2() {
4550
4578
  }
4551
4579
  function reset$3() {
4552
4580
  updates = {};
4581
+ limited = false;
4553
4582
  }
4554
4583
 
4555
4584
  function config$1(track) {
@@ -5319,6 +5348,9 @@ var getInteractionCountForNavigation = function () {
5319
5348
  * the slowest 2% of interactions, helping identify a likely P98 candidate.
5320
5349
  */
5321
5350
  var estimateP98LongestInteraction = function () {
5351
+ if (!longestInteractionList.length) {
5352
+ return -1;
5353
+ }
5322
5354
  var candidateInteractionIndex = Math.min(longestInteractionList.length - 1, Math.floor(getInteractionCountForNavigation() / 50));
5323
5355
  return longestInteractionList[candidateInteractionIndex].latency;
5324
5356
  };
@@ -5504,7 +5536,7 @@ function start(config$1) {
5504
5536
  // If it's an internal call to start, without explicit configuration,
5505
5537
  // re-process any newly accumulated items in the queue
5506
5538
  if (config$1 === null) {
5507
- process$7();
5539
+ process$8();
5508
5540
  }
5509
5541
  }
5510
5542
  }