coveo.analytics 2.28.13 → 2.28.15

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.
@@ -728,7 +728,7 @@
728
728
  const v5 = v35('v5', 0x50, sha1);
729
729
  var uuidv5 = v5;
730
730
 
731
- var libVersion = "2.28.13" ;
731
+ var libVersion = "2.28.15" ;
732
732
 
733
733
  var getFormattedLocation = function (location) {
734
734
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -1208,7 +1208,7 @@
1208
1208
  return __generator(this, function (_e) {
1209
1209
  switch (_e.label) {
1210
1210
  case 0:
1211
- if (!navigator.sendBeacon) {
1211
+ if (!this.isAvailable()) {
1212
1212
  throw new Error("navigator.sendBeacon is not supported in this browser. Consider adding a polyfill like \"sendbeacon-polyfill\".");
1213
1213
  }
1214
1214
  _a = this.opts, baseUrl = _a.baseUrl, preprocessRequest = _a.preprocessRequest;
@@ -1233,13 +1233,15 @@
1233
1233
  _e.label = 4;
1234
1234
  case 4:
1235
1235
  _b = __assign.apply(void 0, _c.concat([(_d)])), url = _b.url, body = _b.body;
1236
- console.log("Sending beacon for \"".concat(eventType, "\" with: "), JSON.stringify(payload));
1237
1236
  navigator.sendBeacon(url, body);
1238
1237
  return [2];
1239
1238
  }
1240
1239
  });
1241
1240
  });
1242
1241
  };
1242
+ AnalyticsBeaconClient.prototype.isAvailable = function () {
1243
+ return 'sendBeacon' in navigator;
1244
+ };
1243
1245
  AnalyticsBeaconClient.prototype.deleteHttpCookieVisitorId = function () {
1244
1246
  return Promise.resolve();
1245
1247
  };
@@ -1439,6 +1441,9 @@
1439
1441
  }
1440
1442
  });
1441
1443
  }
1444
+ BrowserRuntime.prototype.getClientDependingOnEventType = function (eventType) {
1445
+ return eventType === 'click' && this.beaconClient.isAvailable() ? this.beaconClient : this.client;
1446
+ };
1442
1447
  return BrowserRuntime;
1443
1448
  }());
1444
1449
  var NodeJSRuntime = (function () {
@@ -1446,6 +1451,9 @@
1446
1451
  this.storage = storage || new NullStorage();
1447
1452
  this.client = new AnalyticsFetchClient(clientOptions);
1448
1453
  }
1454
+ NodeJSRuntime.prototype.getClientDependingOnEventType = function (eventType) {
1455
+ return this.client;
1456
+ };
1449
1457
  return NodeJSRuntime;
1450
1458
  }());
1451
1459
  var NoopRuntime = (function () {
@@ -1453,6 +1461,9 @@
1453
1461
  this.storage = new NullStorage();
1454
1462
  this.client = new NoopAnalyticsClient();
1455
1463
  }
1464
+ NoopRuntime.prototype.getClientDependingOnEventType = function (eventType) {
1465
+ return this.client;
1466
+ };
1456
1467
  return NoopRuntime;
1457
1468
  }());
1458
1469
 
@@ -1885,7 +1896,7 @@
1885
1896
  return [4, this.deferExecution()];
1886
1897
  case 2:
1887
1898
  _a.sent();
1888
- return [4, this.sendFromBufferWithFetch()];
1899
+ return [4, this.sendFromBuffer()];
1889
1900
  case 3: return [2, (_a.sent())];
1890
1901
  }
1891
1902
  });
@@ -1912,14 +1923,14 @@
1912
1923
  CoveoAnalyticsClient.prototype.deferExecution = function () {
1913
1924
  return new Promise(function (resolve) { return setTimeout(resolve, 0); });
1914
1925
  };
1915
- CoveoAnalyticsClient.prototype.sendFromBufferWithFetch = function () {
1926
+ CoveoAnalyticsClient.prototype.sendFromBuffer = function () {
1916
1927
  return __awaiter(this, void 0, void 0, function () {
1917
1928
  var popped, eventType, payload;
1918
1929
  return __generator(this, function (_a) {
1919
1930
  popped = this.bufferedRequests.shift();
1920
1931
  if (popped) {
1921
1932
  eventType = popped.eventType, payload = popped.payload;
1922
- return [2, this.runtime.client.sendEvent(eventType, payload)];
1933
+ return [2, this.runtime.getClientDependingOnEventType(eventType).sendEvent(eventType, payload)];
1923
1934
  }
1924
1935
  return [2];
1925
1936
  });