mixpanel-browser 2.55.0 → 2.56.0

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.
@@ -1,6 +1,6 @@
1
1
  import Config from './config';
2
2
  import { RequestQueue } from './request-queue';
3
- import { console_with_prefix, _ } from './utils'; // eslint-disable-line camelcase
3
+ import { console_with_prefix, isOnline, _ } from './utils'; // eslint-disable-line camelcase
4
4
 
5
5
  // maximum interval between request retries after exponential backoff
6
6
  var MAX_RETRY_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes
@@ -198,7 +198,12 @@ RequestBatcher.prototype.flush = function(options) {
198
198
  this.flush();
199
199
  } else if (
200
200
  _.isObject(res) &&
201
- (res.httpStatusCode >= 500 || res.httpStatusCode === 429 || res.error === 'timeout')
201
+ (
202
+ res.httpStatusCode >= 500
203
+ || res.httpStatusCode === 429
204
+ || (res.httpStatusCode <= 0 && !isOnline())
205
+ || res.error === 'timeout'
206
+ )
202
207
  ) {
203
208
  // network or API error, or 429 Too Many Requests, retry
204
209
  var retryMS = this.flushInterval * 2;
@@ -22,11 +22,13 @@ var logger = console_with_prefix('batch');
22
22
  var RequestQueue = function(storageKey, options) {
23
23
  options = options || {};
24
24
  this.storageKey = storageKey;
25
- this.storage = options.storage || window.localStorage;
25
+ this.usePersistence = options.usePersistence;
26
+ if (this.usePersistence) {
27
+ this.storage = options.storage || window.localStorage;
28
+ this.lock = new SharedLock(storageKey, {storage: this.storage});
29
+ }
26
30
  this.reportError = options.errorReporter || _.bind(logger.error, logger);
27
- this.lock = new SharedLock(storageKey, {storage: this.storage});
28
31
 
29
- this.usePersistence = options.usePersistence;
30
32
  this.pid = options.pid || null; // pass pid to test out storage lock contention scenarios
31
33
 
32
34
  this.memQueue = [];
package/src/utils.js CHANGED
@@ -8,7 +8,7 @@ if (typeof(window) === 'undefined') {
8
8
  hostname: ''
9
9
  };
10
10
  win = {
11
- navigator: { userAgent: '' },
11
+ navigator: { userAgent: '', onLine: true },
12
12
  document: {
13
13
  location: loc,
14
14
  referrer: ''
@@ -22,6 +22,8 @@ if (typeof(window) === 'undefined') {
22
22
 
23
23
  // Maximum allowed session recording length
24
24
  var MAX_RECORDING_MS = 24 * 60 * 60 * 1000; // 24 hours
25
+ // Maximum allowed value for minimum session recording length
26
+ var MAX_VALUE_FOR_MIN_RECORDING_MS = 8 * 1000; // 8 seconds
25
27
 
26
28
  /*
27
29
  * Saved references to long variable names, so that closure compiler can
@@ -962,7 +964,7 @@ _.HTTPBuildQuery = function(formdata, arg_separator) {
962
964
  _.getQueryParam = function(url, param) {
963
965
  // Expects a raw URL
964
966
 
965
- param = param.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
967
+ param = param.replace(/[[]/g, '\\[').replace(/[\]]/g, '\\]');
966
968
  var regexS = '[\\?&]' + param + '=([^&#]*)',
967
969
  regex = new RegExp(regexS),
968
970
  results = regex.exec(url);
@@ -1419,8 +1421,8 @@ _.dom_query = (function() {
1419
1421
  };
1420
1422
  })();
1421
1423
 
1422
- var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
1423
- var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid'];
1424
+ var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'utm_id', 'utm_source_platform','utm_campaign_id', 'utm_creative_format', 'utm_marketing_tactic'];
1425
+ var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'sccid', 'ttclid', 'twclid', 'wbraid'];
1424
1426
 
1425
1427
  _.info = {
1426
1428
  campaignParams: function(default_value) {
@@ -1702,6 +1704,15 @@ var extract_domain = function(hostname) {
1702
1704
  return matches ? matches[0] : '';
1703
1705
  };
1704
1706
 
1707
+ /**
1708
+ * Check whether we have network connection. default to true for browsers that don't support navigator.onLine (IE)
1709
+ * @returns {boolean}
1710
+ */
1711
+ var isOnline = function() {
1712
+ var onLine = win.navigator['onLine'];
1713
+ return _.isUndefined(onLine) || onLine;
1714
+ };
1715
+
1705
1716
  var JSONStringify = null, JSONParse = null;
1706
1717
  if (typeof JSON !== 'undefined') {
1707
1718
  JSONStringify = JSON.stringify;
@@ -1724,18 +1735,20 @@ _['info']['browserVersion'] = _.info.browserVersion;
1724
1735
  _['info']['properties'] = _.info.properties;
1725
1736
 
1726
1737
  export {
1727
- MAX_RECORDING_MS,
1728
1738
  _,
1729
- userAgent,
1730
- console,
1731
- win as window,
1732
- document,
1733
- navigator,
1734
1739
  cheap_guid,
1735
1740
  console_with_prefix,
1741
+ console,
1742
+ document,
1736
1743
  extract_domain,
1737
- localStorageSupported,
1738
- JSONStringify,
1739
1744
  JSONParse,
1740
- slice
1745
+ JSONStringify,
1746
+ isOnline,
1747
+ localStorageSupported,
1748
+ MAX_RECORDING_MS,
1749
+ MAX_VALUE_FOR_MIN_RECORDING_MS,
1750
+ navigator,
1751
+ slice,
1752
+ userAgent,
1753
+ win as window
1741
1754
  };