posthog-js 1.29.2 → 1.29.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/dist/es.js CHANGED
@@ -881,7 +881,7 @@ var LZString = {
881
881
  }
882
882
  };
883
883
 
884
- var version = "1.29.2";
884
+ var version = "1.29.3";
885
885
 
886
886
  // e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
887
887
 
@@ -4341,19 +4341,27 @@ var RequestQueue = /*#__PURE__*/function (_RequestQueueScaffold) {
4341
4341
  }, {
4342
4342
  key: "unload",
4343
4343
  value: function unload() {
4344
+ var _this3 = this;
4345
+
4344
4346
  clearTimeout(this._poller);
4345
4347
  var requests = this._event_queue.length > 0 ? this.formatQueue() : {};
4346
4348
  this._event_queue.length = 0;
4347
-
4348
- for (var key in requests) {
4349
- var _requests$key3 = requests[key],
4350
- _url2 = _requests$key3.url,
4351
- _data2 = _requests$key3.data,
4352
- _options = _requests$key3.options;
4353
- this.handlePollRequest(_url2, _data2, _objectSpread2(_objectSpread2({}, _options), {}, {
4349
+ var requestValues = Object.values(requests); // Always force events to be sent before recordings, as events are more important, and recordings are bigger and thus less likely to arrive
4350
+
4351
+ var sortedRequests = [].concat(_toConsumableArray(requestValues.filter(function (r) {
4352
+ return r.url.indexOf('/e') === 0;
4353
+ })), _toConsumableArray(requestValues.filter(function (r) {
4354
+ return r.url.indexOf('/e') !== 0;
4355
+ })));
4356
+ sortedRequests.map(function (_ref) {
4357
+ var url = _ref.url,
4358
+ data = _ref.data,
4359
+ options = _ref.options;
4360
+
4361
+ _this3.handlePollRequest(url, data, _objectSpread2(_objectSpread2({}, options), {}, {
4354
4362
  transport: 'sendBeacon'
4355
4363
  }));
4356
- }
4364
+ });
4357
4365
  }
4358
4366
  }, {
4359
4367
  key: "formatQueue",
@@ -6128,10 +6136,11 @@ var PostHog = /*#__PURE__*/function () {
6128
6136
  distinct_id: uuid,
6129
6137
  $device_id: uuid
6130
6138
  }, '');
6131
- } // Set up the window close event handler "unload"
6139
+ } // Set up event handler for pageleave
6140
+ // Use `onpagehide` if available, see https://calendar.perfplanet.com/2020/beaconing-in-practice/#beaconing-reliability-avoiding-abandons
6132
6141
 
6133
6142
 
6134
- win.addEventListener && win.addEventListener('unload', this._handle_unload.bind(this));
6143
+ win.addEventListener && win.addEventListener('onpagehide' in self ? 'pagehide' : 'unload', this._handle_unload.bind(this));
6135
6144
  } // Private methods
6136
6145
 
6137
6146
  }, {