mixpanel-browser 2.61.2 → 2.62.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  var Config = {
4
4
  DEBUG: false,
5
- LIB_VERSION: '2.61.2'
5
+ LIB_VERSION: '2.62.0'
6
6
  };
7
7
 
8
8
  // since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -12,6 +12,7 @@ if (typeof(window) === 'undefined') {
12
12
  hostname: ''
13
13
  };
14
14
  win = {
15
+ crypto: {randomUUID: function() {throw Error('unsupported');}},
15
16
  navigator: { userAgent: '', onLine: true },
16
17
  document: {
17
18
  createElement: function() { return {}; },
@@ -1225,71 +1226,27 @@ _.utf8Encode = function(string) {
1225
1226
  return utftext;
1226
1227
  };
1227
1228
 
1228
- _.UUID = (function() {
1229
-
1230
- // Time-based entropy
1231
- var T = function() {
1232
- var time = 1 * new Date(); // cross-browser version of Date.now()
1233
- var ticks;
1234
- if (win.performance && win.performance.now) {
1235
- ticks = win.performance.now();
1236
- } else {
1237
- // fall back to busy loop
1238
- ticks = 0;
1239
-
1240
- // this while loop figures how many browser ticks go by
1241
- // before 1*new Date() returns a new number, ie the amount
1242
- // of ticks that go by per millisecond
1243
- while (time == 1 * new Date()) {
1244
- ticks++;
1245
- }
1246
- }
1247
- return time.toString(16) + Math.floor(ticks).toString(16);
1248
- };
1249
-
1250
- // Math.Random entropy
1251
- var R = function() {
1252
- return Math.random().toString(16).replace('.', '');
1253
- };
1254
-
1255
- // User agent entropy
1256
- // This function takes the user agent string, and then xors
1257
- // together each sequence of 8 bytes. This produces a final
1258
- // sequence of 8 bytes which it returns as hex.
1259
- var UA = function() {
1260
- var ua = userAgent,
1261
- i, ch, buffer = [],
1262
- ret = 0;
1263
-
1264
- function xor(result, byte_array) {
1265
- var j, tmp = 0;
1266
- for (j = 0; j < byte_array.length; j++) {
1267
- tmp |= (buffer[j] << j * 8);
1268
- }
1269
- return result ^ tmp;
1270
- }
1271
-
1272
- for (i = 0; i < ua.length; i++) {
1273
- ch = ua.charCodeAt(i);
1274
- buffer.unshift(ch & 0xFF);
1275
- if (buffer.length >= 4) {
1276
- ret = xor(ret, buffer);
1277
- buffer = [];
1278
- }
1279
- }
1280
-
1281
- if (buffer.length > 0) {
1282
- ret = xor(ret, buffer);
1229
+ _.UUID = function() {
1230
+ try {
1231
+ // use native Crypto API when available
1232
+ return win['crypto']['randomUUID']();
1233
+ } catch (err) {
1234
+ // fall back to generating our own UUID
1235
+ // based on https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d
1236
+ var uuid = new Array(36);
1237
+ for (var i = 0; i < 36; i++) {
1238
+ uuid[i] = Math.floor(Math.random() * 16);
1283
1239
  }
1240
+ uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100
1241
+ uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero
1242
+ uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one
1243
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
1284
1244
 
1285
- return ret.toString(16);
1286
- };
1287
-
1288
- return function() {
1289
- var se = (screen.height * screen.width).toString(16);
1290
- return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
1291
- };
1292
- })();
1245
+ return _.map(uuid, function(x) {
1246
+ return x.toString(16);
1247
+ }).join('');
1248
+ }
1249
+ };
1293
1250
 
1294
1251
  // _.isBlockedUA()
1295
1252
  // This is to block various web spiders from executing our JS and
@@ -5231,7 +5188,7 @@ MixpanelPersistence.prototype.save = function() {
5231
5188
 
5232
5189
  this.storage.set(
5233
5190
  this.name,
5234
- _.JSONEncode(this['props']),
5191
+ JSONStringify(this['props']),
5235
5192
  this.expire_days,
5236
5193
  this.cross_subdomain,
5237
5194
  this.secure,
@@ -6575,7 +6532,7 @@ MixpanelLib.prototype.disable = function(events) {
6575
6532
  };
6576
6533
 
6577
6534
  MixpanelLib.prototype._encode_data_for_request = function(data) {
6578
- var encoded_data = _.JSONEncode(data);
6535
+ var encoded_data = JSONStringify(data);
6579
6536
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
6580
6537
  encoded_data = _.base64Encode(encoded_data);
6581
6538
  }
@@ -7,6 +7,7 @@ define((function () { 'use strict';
7
7
  hostname: ''
8
8
  };
9
9
  win = {
10
+ crypto: {randomUUID: function() {throw Error('unsupported');}},
10
11
  navigator: { userAgent: '', onLine: true },
11
12
  document: {
12
13
  createElement: function() { return {}; },
@@ -4893,7 +4894,7 @@ define((function () { 'use strict';
4893
4894
 
4894
4895
  var Config = {
4895
4896
  DEBUG: false,
4896
- LIB_VERSION: '2.61.2'
4897
+ LIB_VERSION: '2.62.0'
4897
4898
  };
4898
4899
 
4899
4900
  /* eslint camelcase: "off", eqeqeq: "off" */
@@ -5734,71 +5735,27 @@ define((function () { 'use strict';
5734
5735
  return utftext;
5735
5736
  };
5736
5737
 
5737
- _.UUID = (function() {
5738
-
5739
- // Time-based entropy
5740
- var T = function() {
5741
- var time = 1 * new Date(); // cross-browser version of Date.now()
5742
- var ticks;
5743
- if (win.performance && win.performance.now) {
5744
- ticks = win.performance.now();
5745
- } else {
5746
- // fall back to busy loop
5747
- ticks = 0;
5748
-
5749
- // this while loop figures how many browser ticks go by
5750
- // before 1*new Date() returns a new number, ie the amount
5751
- // of ticks that go by per millisecond
5752
- while (time == 1 * new Date()) {
5753
- ticks++;
5754
- }
5755
- }
5756
- return time.toString(16) + Math.floor(ticks).toString(16);
5757
- };
5758
-
5759
- // Math.Random entropy
5760
- var R = function() {
5761
- return Math.random().toString(16).replace('.', '');
5762
- };
5763
-
5764
- // User agent entropy
5765
- // This function takes the user agent string, and then xors
5766
- // together each sequence of 8 bytes. This produces a final
5767
- // sequence of 8 bytes which it returns as hex.
5768
- var UA = function() {
5769
- var ua = userAgent,
5770
- i, ch, buffer = [],
5771
- ret = 0;
5772
-
5773
- function xor(result, byte_array) {
5774
- var j, tmp = 0;
5775
- for (j = 0; j < byte_array.length; j++) {
5776
- tmp |= (buffer[j] << j * 8);
5777
- }
5778
- return result ^ tmp;
5779
- }
5780
-
5781
- for (i = 0; i < ua.length; i++) {
5782
- ch = ua.charCodeAt(i);
5783
- buffer.unshift(ch & 0xFF);
5784
- if (buffer.length >= 4) {
5785
- ret = xor(ret, buffer);
5786
- buffer = [];
5787
- }
5788
- }
5789
-
5790
- if (buffer.length > 0) {
5791
- ret = xor(ret, buffer);
5738
+ _.UUID = function() {
5739
+ try {
5740
+ // use native Crypto API when available
5741
+ return win['crypto']['randomUUID']();
5742
+ } catch (err) {
5743
+ // fall back to generating our own UUID
5744
+ // based on https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d
5745
+ var uuid = new Array(36);
5746
+ for (var i = 0; i < 36; i++) {
5747
+ uuid[i] = Math.floor(Math.random() * 16);
5792
5748
  }
5749
+ uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100
5750
+ uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero
5751
+ uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one
5752
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
5793
5753
 
5794
- return ret.toString(16);
5795
- };
5796
-
5797
- return function() {
5798
- var se = (screen.height * screen.width).toString(16);
5799
- return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
5800
- };
5801
- })();
5754
+ return _.map(uuid, function(x) {
5755
+ return x.toString(16);
5756
+ }).join('');
5757
+ }
5758
+ };
5802
5759
 
5803
5760
  // _.isBlockedUA()
5804
5761
  // This is to block various web spiders from executing our JS and
@@ -8174,6 +8131,7 @@ define((function () { 'use strict';
8174
8131
  this.idleTimeoutId = setTimeout(this._onIdleTimeout, idleTimeoutMs);
8175
8132
  this.idleExpires = new Date().getTime() + idleTimeoutMs;
8176
8133
  }.bind(this);
8134
+ resetIdleTimeout();
8177
8135
 
8178
8136
  var blockSelector = this.getConfig('record_block_selector');
8179
8137
  if (blockSelector === '' || blockSelector === null) {
@@ -8183,6 +8141,10 @@ define((function () { 'use strict';
8183
8141
  try {
8184
8142
  this._stopRecording = this._rrwebRecord({
8185
8143
  'emit': function (ev) {
8144
+ if (this.idleExpires && this.idleExpires < ev.timestamp) {
8145
+ this._onIdleTimeout();
8146
+ return;
8147
+ }
8186
8148
  if (isUserEvent(ev)) {
8187
8149
  if (this.batcher.stopped && new Date().getTime() - this.replayStartTime >= this.recordMinMs) {
8188
8150
  // start flushing again after user activity
@@ -8219,8 +8181,6 @@ define((function () { 'use strict';
8219
8181
  return;
8220
8182
  }
8221
8183
 
8222
- resetIdleTimeout();
8223
-
8224
8184
  var maxTimeoutMs = this.maxExpires - new Date().getTime();
8225
8185
  this.maxTimeoutId = setTimeout(this._onMaxLengthReached.bind(this), maxTimeoutMs);
8226
8186
  };
@@ -8399,7 +8359,7 @@ define((function () { 'use strict';
8399
8359
  'replay_start_url': this.replayStartUrl,
8400
8360
  'seq': this.seqNo
8401
8361
  };
8402
- var eventsJson = _.JSONEncode(data);
8362
+ var eventsJson = JSON.stringify(data);
8403
8363
 
8404
8364
  // send ID management props if they exist
8405
8365
  var deviceId = this._mixpanel.get_property('$device_id');
@@ -10533,7 +10493,7 @@ define((function () { 'use strict';
10533
10493
 
10534
10494
  this.storage.set(
10535
10495
  this.name,
10536
- _.JSONEncode(this['props']),
10496
+ JSONStringify(this['props']),
10537
10497
  this.expire_days,
10538
10498
  this.cross_subdomain,
10539
10499
  this.secure,
@@ -11754,7 +11714,7 @@ define((function () { 'use strict';
11754
11714
  };
11755
11715
 
11756
11716
  MixpanelLib.prototype._encode_data_for_request = function(data) {
11757
- var encoded_data = _.JSONEncode(data);
11717
+ var encoded_data = JSONStringify(data);
11758
11718
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
11759
11719
  encoded_data = _.base64Encode(encoded_data);
11760
11720
  }
@@ -7,6 +7,7 @@ if (typeof(window) === 'undefined') {
7
7
  hostname: ''
8
8
  };
9
9
  win = {
10
+ crypto: {randomUUID: function() {throw Error('unsupported');}},
10
11
  navigator: { userAgent: '', onLine: true },
11
12
  document: {
12
13
  createElement: function() { return {}; },
@@ -4893,7 +4894,7 @@ var IncrementalSource = /* @__PURE__ */ ((IncrementalSource2) => {
4893
4894
 
4894
4895
  var Config = {
4895
4896
  DEBUG: false,
4896
- LIB_VERSION: '2.61.2'
4897
+ LIB_VERSION: '2.62.0'
4897
4898
  };
4898
4899
 
4899
4900
  /* eslint camelcase: "off", eqeqeq: "off" */
@@ -5734,71 +5735,27 @@ _.utf8Encode = function(string) {
5734
5735
  return utftext;
5735
5736
  };
5736
5737
 
5737
- _.UUID = (function() {
5738
-
5739
- // Time-based entropy
5740
- var T = function() {
5741
- var time = 1 * new Date(); // cross-browser version of Date.now()
5742
- var ticks;
5743
- if (win.performance && win.performance.now) {
5744
- ticks = win.performance.now();
5745
- } else {
5746
- // fall back to busy loop
5747
- ticks = 0;
5748
-
5749
- // this while loop figures how many browser ticks go by
5750
- // before 1*new Date() returns a new number, ie the amount
5751
- // of ticks that go by per millisecond
5752
- while (time == 1 * new Date()) {
5753
- ticks++;
5754
- }
5755
- }
5756
- return time.toString(16) + Math.floor(ticks).toString(16);
5757
- };
5758
-
5759
- // Math.Random entropy
5760
- var R = function() {
5761
- return Math.random().toString(16).replace('.', '');
5762
- };
5763
-
5764
- // User agent entropy
5765
- // This function takes the user agent string, and then xors
5766
- // together each sequence of 8 bytes. This produces a final
5767
- // sequence of 8 bytes which it returns as hex.
5768
- var UA = function() {
5769
- var ua = userAgent,
5770
- i, ch, buffer = [],
5771
- ret = 0;
5772
-
5773
- function xor(result, byte_array) {
5774
- var j, tmp = 0;
5775
- for (j = 0; j < byte_array.length; j++) {
5776
- tmp |= (buffer[j] << j * 8);
5777
- }
5778
- return result ^ tmp;
5779
- }
5780
-
5781
- for (i = 0; i < ua.length; i++) {
5782
- ch = ua.charCodeAt(i);
5783
- buffer.unshift(ch & 0xFF);
5784
- if (buffer.length >= 4) {
5785
- ret = xor(ret, buffer);
5786
- buffer = [];
5787
- }
5788
- }
5789
-
5790
- if (buffer.length > 0) {
5791
- ret = xor(ret, buffer);
5738
+ _.UUID = function() {
5739
+ try {
5740
+ // use native Crypto API when available
5741
+ return win['crypto']['randomUUID']();
5742
+ } catch (err) {
5743
+ // fall back to generating our own UUID
5744
+ // based on https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d
5745
+ var uuid = new Array(36);
5746
+ for (var i = 0; i < 36; i++) {
5747
+ uuid[i] = Math.floor(Math.random() * 16);
5792
5748
  }
5749
+ uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100
5750
+ uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero
5751
+ uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one
5752
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
5793
5753
 
5794
- return ret.toString(16);
5795
- };
5796
-
5797
- return function() {
5798
- var se = (screen.height * screen.width).toString(16);
5799
- return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
5800
- };
5801
- })();
5754
+ return _.map(uuid, function(x) {
5755
+ return x.toString(16);
5756
+ }).join('');
5757
+ }
5758
+ };
5802
5759
 
5803
5760
  // _.isBlockedUA()
5804
5761
  // This is to block various web spiders from executing our JS and
@@ -8174,6 +8131,7 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
8174
8131
  this.idleTimeoutId = setTimeout(this._onIdleTimeout, idleTimeoutMs);
8175
8132
  this.idleExpires = new Date().getTime() + idleTimeoutMs;
8176
8133
  }.bind(this);
8134
+ resetIdleTimeout();
8177
8135
 
8178
8136
  var blockSelector = this.getConfig('record_block_selector');
8179
8137
  if (blockSelector === '' || blockSelector === null) {
@@ -8183,6 +8141,10 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
8183
8141
  try {
8184
8142
  this._stopRecording = this._rrwebRecord({
8185
8143
  'emit': function (ev) {
8144
+ if (this.idleExpires && this.idleExpires < ev.timestamp) {
8145
+ this._onIdleTimeout();
8146
+ return;
8147
+ }
8186
8148
  if (isUserEvent(ev)) {
8187
8149
  if (this.batcher.stopped && new Date().getTime() - this.replayStartTime >= this.recordMinMs) {
8188
8150
  // start flushing again after user activity
@@ -8219,8 +8181,6 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
8219
8181
  return;
8220
8182
  }
8221
8183
 
8222
- resetIdleTimeout();
8223
-
8224
8184
  var maxTimeoutMs = this.maxExpires - new Date().getTime();
8225
8185
  this.maxTimeoutId = setTimeout(this._onMaxLengthReached.bind(this), maxTimeoutMs);
8226
8186
  };
@@ -8399,7 +8359,7 @@ SessionRecording.prototype._flushEvents = addOptOutCheckMixpanelLib(function (da
8399
8359
  'replay_start_url': this.replayStartUrl,
8400
8360
  'seq': this.seqNo
8401
8361
  };
8402
- var eventsJson = _.JSONEncode(data);
8362
+ var eventsJson = JSON.stringify(data);
8403
8363
 
8404
8364
  // send ID management props if they exist
8405
8365
  var deviceId = this._mixpanel.get_property('$device_id');
@@ -10533,7 +10493,7 @@ MixpanelPersistence.prototype.save = function() {
10533
10493
 
10534
10494
  this.storage.set(
10535
10495
  this.name,
10536
- _.JSONEncode(this['props']),
10496
+ JSONStringify(this['props']),
10537
10497
  this.expire_days,
10538
10498
  this.cross_subdomain,
10539
10499
  this.secure,
@@ -11754,7 +11714,7 @@ MixpanelLib.prototype.disable = function(events) {
11754
11714
  };
11755
11715
 
11756
11716
  MixpanelLib.prototype._encode_data_for_request = function(data) {
11757
- var encoded_data = _.JSONEncode(data);
11717
+ var encoded_data = JSONStringify(data);
11758
11718
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
11759
11719
  encoded_data = _.base64Encode(encoded_data);
11760
11720
  }
@@ -3,7 +3,7 @@
3
3
 
4
4
  var Config = {
5
5
  DEBUG: false,
6
- LIB_VERSION: '2.61.2'
6
+ LIB_VERSION: '2.62.0'
7
7
  };
8
8
 
9
9
  // since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -13,6 +13,7 @@
13
13
  hostname: ''
14
14
  };
15
15
  win = {
16
+ crypto: {randomUUID: function() {throw Error('unsupported');}},
16
17
  navigator: { userAgent: '', onLine: true },
17
18
  document: {
18
19
  createElement: function() { return {}; },
@@ -1226,71 +1227,27 @@
1226
1227
  return utftext;
1227
1228
  };
1228
1229
 
1229
- _.UUID = (function() {
1230
-
1231
- // Time-based entropy
1232
- var T = function() {
1233
- var time = 1 * new Date(); // cross-browser version of Date.now()
1234
- var ticks;
1235
- if (win.performance && win.performance.now) {
1236
- ticks = win.performance.now();
1237
- } else {
1238
- // fall back to busy loop
1239
- ticks = 0;
1240
-
1241
- // this while loop figures how many browser ticks go by
1242
- // before 1*new Date() returns a new number, ie the amount
1243
- // of ticks that go by per millisecond
1244
- while (time == 1 * new Date()) {
1245
- ticks++;
1246
- }
1247
- }
1248
- return time.toString(16) + Math.floor(ticks).toString(16);
1249
- };
1250
-
1251
- // Math.Random entropy
1252
- var R = function() {
1253
- return Math.random().toString(16).replace('.', '');
1254
- };
1255
-
1256
- // User agent entropy
1257
- // This function takes the user agent string, and then xors
1258
- // together each sequence of 8 bytes. This produces a final
1259
- // sequence of 8 bytes which it returns as hex.
1260
- var UA = function() {
1261
- var ua = userAgent,
1262
- i, ch, buffer = [],
1263
- ret = 0;
1264
-
1265
- function xor(result, byte_array) {
1266
- var j, tmp = 0;
1267
- for (j = 0; j < byte_array.length; j++) {
1268
- tmp |= (buffer[j] << j * 8);
1269
- }
1270
- return result ^ tmp;
1271
- }
1272
-
1273
- for (i = 0; i < ua.length; i++) {
1274
- ch = ua.charCodeAt(i);
1275
- buffer.unshift(ch & 0xFF);
1276
- if (buffer.length >= 4) {
1277
- ret = xor(ret, buffer);
1278
- buffer = [];
1279
- }
1280
- }
1281
-
1282
- if (buffer.length > 0) {
1283
- ret = xor(ret, buffer);
1230
+ _.UUID = function() {
1231
+ try {
1232
+ // use native Crypto API when available
1233
+ return win['crypto']['randomUUID']();
1234
+ } catch (err) {
1235
+ // fall back to generating our own UUID
1236
+ // based on https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d
1237
+ var uuid = new Array(36);
1238
+ for (var i = 0; i < 36; i++) {
1239
+ uuid[i] = Math.floor(Math.random() * 16);
1284
1240
  }
1241
+ uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100
1242
+ uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero
1243
+ uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one
1244
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
1285
1245
 
1286
- return ret.toString(16);
1287
- };
1288
-
1289
- return function() {
1290
- var se = (screen.height * screen.width).toString(16);
1291
- return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
1292
- };
1293
- })();
1246
+ return _.map(uuid, function(x) {
1247
+ return x.toString(16);
1248
+ }).join('');
1249
+ }
1250
+ };
1294
1251
 
1295
1252
  // _.isBlockedUA()
1296
1253
  // This is to block various web spiders from executing our JS and
@@ -5232,7 +5189,7 @@
5232
5189
 
5233
5190
  this.storage.set(
5234
5191
  this.name,
5235
- _.JSONEncode(this['props']),
5192
+ JSONStringify(this['props']),
5236
5193
  this.expire_days,
5237
5194
  this.cross_subdomain,
5238
5195
  this.secure,
@@ -6576,7 +6533,7 @@
6576
6533
  };
6577
6534
 
6578
6535
  MixpanelLib.prototype._encode_data_for_request = function(data) {
6579
- var encoded_data = _.JSONEncode(data);
6536
+ var encoded_data = JSONStringify(data);
6580
6537
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
6581
6538
  encoded_data = _.base64Encode(encoded_data);
6582
6539
  }