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.
@@ -5,6 +5,7 @@ if (typeof(window) === 'undefined') {
5
5
  hostname: ''
6
6
  };
7
7
  win = {
8
+ crypto: {randomUUID: function() {throw Error('unsupported');}},
8
9
  navigator: { userAgent: '', onLine: true },
9
10
  document: {
10
11
  createElement: function() { return {}; },
@@ -4891,7 +4892,7 @@ var IncrementalSource = /* @__PURE__ */ ((IncrementalSource2) => {
4891
4892
 
4892
4893
  var Config = {
4893
4894
  DEBUG: false,
4894
- LIB_VERSION: '2.61.2'
4895
+ LIB_VERSION: '2.62.0'
4895
4896
  };
4896
4897
 
4897
4898
  /* eslint camelcase: "off", eqeqeq: "off" */
@@ -5732,71 +5733,27 @@ _.utf8Encode = function(string) {
5732
5733
  return utftext;
5733
5734
  };
5734
5735
 
5735
- _.UUID = (function() {
5736
-
5737
- // Time-based entropy
5738
- var T = function() {
5739
- var time = 1 * new Date(); // cross-browser version of Date.now()
5740
- var ticks;
5741
- if (win.performance && win.performance.now) {
5742
- ticks = win.performance.now();
5743
- } else {
5744
- // fall back to busy loop
5745
- ticks = 0;
5746
-
5747
- // this while loop figures how many browser ticks go by
5748
- // before 1*new Date() returns a new number, ie the amount
5749
- // of ticks that go by per millisecond
5750
- while (time == 1 * new Date()) {
5751
- ticks++;
5752
- }
5753
- }
5754
- return time.toString(16) + Math.floor(ticks).toString(16);
5755
- };
5756
-
5757
- // Math.Random entropy
5758
- var R = function() {
5759
- return Math.random().toString(16).replace('.', '');
5760
- };
5761
-
5762
- // User agent entropy
5763
- // This function takes the user agent string, and then xors
5764
- // together each sequence of 8 bytes. This produces a final
5765
- // sequence of 8 bytes which it returns as hex.
5766
- var UA = function() {
5767
- var ua = userAgent,
5768
- i, ch, buffer = [],
5769
- ret = 0;
5770
-
5771
- function xor(result, byte_array) {
5772
- var j, tmp = 0;
5773
- for (j = 0; j < byte_array.length; j++) {
5774
- tmp |= (buffer[j] << j * 8);
5775
- }
5776
- return result ^ tmp;
5777
- }
5778
-
5779
- for (i = 0; i < ua.length; i++) {
5780
- ch = ua.charCodeAt(i);
5781
- buffer.unshift(ch & 0xFF);
5782
- if (buffer.length >= 4) {
5783
- ret = xor(ret, buffer);
5784
- buffer = [];
5785
- }
5786
- }
5787
-
5788
- if (buffer.length > 0) {
5789
- ret = xor(ret, buffer);
5736
+ _.UUID = function() {
5737
+ try {
5738
+ // use native Crypto API when available
5739
+ return win['crypto']['randomUUID']();
5740
+ } catch (err) {
5741
+ // fall back to generating our own UUID
5742
+ // based on https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d
5743
+ var uuid = new Array(36);
5744
+ for (var i = 0; i < 36; i++) {
5745
+ uuid[i] = Math.floor(Math.random() * 16);
5790
5746
  }
5747
+ uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100
5748
+ uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero
5749
+ uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one
5750
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
5791
5751
 
5792
- return ret.toString(16);
5793
- };
5794
-
5795
- return function() {
5796
- var se = (screen.height * screen.width).toString(16);
5797
- return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
5798
- };
5799
- })();
5752
+ return _.map(uuid, function(x) {
5753
+ return x.toString(16);
5754
+ }).join('');
5755
+ }
5756
+ };
5800
5757
 
5801
5758
  // _.isBlockedUA()
5802
5759
  // This is to block various web spiders from executing our JS and
@@ -8172,6 +8129,7 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
8172
8129
  this.idleTimeoutId = setTimeout(this._onIdleTimeout, idleTimeoutMs);
8173
8130
  this.idleExpires = new Date().getTime() + idleTimeoutMs;
8174
8131
  }.bind(this);
8132
+ resetIdleTimeout();
8175
8133
 
8176
8134
  var blockSelector = this.getConfig('record_block_selector');
8177
8135
  if (blockSelector === '' || blockSelector === null) {
@@ -8181,6 +8139,10 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
8181
8139
  try {
8182
8140
  this._stopRecording = this._rrwebRecord({
8183
8141
  'emit': function (ev) {
8142
+ if (this.idleExpires && this.idleExpires < ev.timestamp) {
8143
+ this._onIdleTimeout();
8144
+ return;
8145
+ }
8184
8146
  if (isUserEvent(ev)) {
8185
8147
  if (this.batcher.stopped && new Date().getTime() - this.replayStartTime >= this.recordMinMs) {
8186
8148
  // start flushing again after user activity
@@ -8217,8 +8179,6 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
8217
8179
  return;
8218
8180
  }
8219
8181
 
8220
- resetIdleTimeout();
8221
-
8222
8182
  var maxTimeoutMs = this.maxExpires - new Date().getTime();
8223
8183
  this.maxTimeoutId = setTimeout(this._onMaxLengthReached.bind(this), maxTimeoutMs);
8224
8184
  };
@@ -8397,7 +8357,7 @@ SessionRecording.prototype._flushEvents = addOptOutCheckMixpanelLib(function (da
8397
8357
  'replay_start_url': this.replayStartUrl,
8398
8358
  'seq': this.seqNo
8399
8359
  };
8400
- var eventsJson = _.JSONEncode(data);
8360
+ var eventsJson = JSON.stringify(data);
8401
8361
 
8402
8362
  // send ID management props if they exist
8403
8363
  var deviceId = this._mixpanel.get_property('$device_id');
@@ -10531,7 +10491,7 @@ MixpanelPersistence.prototype.save = function() {
10531
10491
 
10532
10492
  this.storage.set(
10533
10493
  this.name,
10534
- _.JSONEncode(this['props']),
10494
+ JSONStringify(this['props']),
10535
10495
  this.expire_days,
10536
10496
  this.cross_subdomain,
10537
10497
  this.secure,
@@ -11752,7 +11712,7 @@ MixpanelLib.prototype.disable = function(events) {
11752
11712
  };
11753
11713
 
11754
11714
  MixpanelLib.prototype._encode_data_for_request = function(data) {
11755
- var encoded_data = _.JSONEncode(data);
11715
+ var encoded_data = JSONStringify(data);
11756
11716
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
11757
11717
  encoded_data = _.base64Encode(encoded_data);
11758
11718
  }
@@ -11,6 +11,7 @@
11
11
  hostname: ''
12
12
  };
13
13
  win = {
14
+ crypto: {randomUUID: function() {throw Error('unsupported');}},
14
15
  navigator: { userAgent: '', onLine: true },
15
16
  document: {
16
17
  createElement: function() { return {}; },
@@ -4897,7 +4898,7 @@
4897
4898
 
4898
4899
  var Config = {
4899
4900
  DEBUG: false,
4900
- LIB_VERSION: '2.61.2'
4901
+ LIB_VERSION: '2.62.0'
4901
4902
  };
4902
4903
 
4903
4904
  /* eslint camelcase: "off", eqeqeq: "off" */
@@ -5738,71 +5739,27 @@
5738
5739
  return utftext;
5739
5740
  };
5740
5741
 
5741
- _.UUID = (function() {
5742
-
5743
- // Time-based entropy
5744
- var T = function() {
5745
- var time = 1 * new Date(); // cross-browser version of Date.now()
5746
- var ticks;
5747
- if (win.performance && win.performance.now) {
5748
- ticks = win.performance.now();
5749
- } else {
5750
- // fall back to busy loop
5751
- ticks = 0;
5752
-
5753
- // this while loop figures how many browser ticks go by
5754
- // before 1*new Date() returns a new number, ie the amount
5755
- // of ticks that go by per millisecond
5756
- while (time == 1 * new Date()) {
5757
- ticks++;
5758
- }
5759
- }
5760
- return time.toString(16) + Math.floor(ticks).toString(16);
5761
- };
5762
-
5763
- // Math.Random entropy
5764
- var R = function() {
5765
- return Math.random().toString(16).replace('.', '');
5766
- };
5767
-
5768
- // User agent entropy
5769
- // This function takes the user agent string, and then xors
5770
- // together each sequence of 8 bytes. This produces a final
5771
- // sequence of 8 bytes which it returns as hex.
5772
- var UA = function() {
5773
- var ua = userAgent,
5774
- i, ch, buffer = [],
5775
- ret = 0;
5776
-
5777
- function xor(result, byte_array) {
5778
- var j, tmp = 0;
5779
- for (j = 0; j < byte_array.length; j++) {
5780
- tmp |= (buffer[j] << j * 8);
5781
- }
5782
- return result ^ tmp;
5783
- }
5784
-
5785
- for (i = 0; i < ua.length; i++) {
5786
- ch = ua.charCodeAt(i);
5787
- buffer.unshift(ch & 0xFF);
5788
- if (buffer.length >= 4) {
5789
- ret = xor(ret, buffer);
5790
- buffer = [];
5791
- }
5792
- }
5793
-
5794
- if (buffer.length > 0) {
5795
- ret = xor(ret, buffer);
5742
+ _.UUID = function() {
5743
+ try {
5744
+ // use native Crypto API when available
5745
+ return win['crypto']['randomUUID']();
5746
+ } catch (err) {
5747
+ // fall back to generating our own UUID
5748
+ // based on https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d
5749
+ var uuid = new Array(36);
5750
+ for (var i = 0; i < 36; i++) {
5751
+ uuid[i] = Math.floor(Math.random() * 16);
5796
5752
  }
5753
+ uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100
5754
+ uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero
5755
+ uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one
5756
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
5797
5757
 
5798
- return ret.toString(16);
5799
- };
5800
-
5801
- return function() {
5802
- var se = (screen.height * screen.width).toString(16);
5803
- return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
5804
- };
5805
- })();
5758
+ return _.map(uuid, function(x) {
5759
+ return x.toString(16);
5760
+ }).join('');
5761
+ }
5762
+ };
5806
5763
 
5807
5764
  // _.isBlockedUA()
5808
5765
  // This is to block various web spiders from executing our JS and
@@ -8178,6 +8135,7 @@
8178
8135
  this.idleTimeoutId = setTimeout(this._onIdleTimeout, idleTimeoutMs);
8179
8136
  this.idleExpires = new Date().getTime() + idleTimeoutMs;
8180
8137
  }.bind(this);
8138
+ resetIdleTimeout();
8181
8139
 
8182
8140
  var blockSelector = this.getConfig('record_block_selector');
8183
8141
  if (blockSelector === '' || blockSelector === null) {
@@ -8187,6 +8145,10 @@
8187
8145
  try {
8188
8146
  this._stopRecording = this._rrwebRecord({
8189
8147
  'emit': function (ev) {
8148
+ if (this.idleExpires && this.idleExpires < ev.timestamp) {
8149
+ this._onIdleTimeout();
8150
+ return;
8151
+ }
8190
8152
  if (isUserEvent(ev)) {
8191
8153
  if (this.batcher.stopped && new Date().getTime() - this.replayStartTime >= this.recordMinMs) {
8192
8154
  // start flushing again after user activity
@@ -8223,8 +8185,6 @@
8223
8185
  return;
8224
8186
  }
8225
8187
 
8226
- resetIdleTimeout();
8227
-
8228
8188
  var maxTimeoutMs = this.maxExpires - new Date().getTime();
8229
8189
  this.maxTimeoutId = setTimeout(this._onMaxLengthReached.bind(this), maxTimeoutMs);
8230
8190
  };
@@ -8403,7 +8363,7 @@
8403
8363
  'replay_start_url': this.replayStartUrl,
8404
8364
  'seq': this.seqNo
8405
8365
  };
8406
- var eventsJson = _.JSONEncode(data);
8366
+ var eventsJson = JSON.stringify(data);
8407
8367
 
8408
8368
  // send ID management props if they exist
8409
8369
  var deviceId = this._mixpanel.get_property('$device_id');
@@ -10537,7 +10497,7 @@
10537
10497
 
10538
10498
  this.storage.set(
10539
10499
  this.name,
10540
- _.JSONEncode(this['props']),
10500
+ JSONStringify(this['props']),
10541
10501
  this.expire_days,
10542
10502
  this.cross_subdomain,
10543
10503
  this.secure,
@@ -11758,7 +11718,7 @@
11758
11718
  };
11759
11719
 
11760
11720
  MixpanelLib.prototype._encode_data_for_request = function(data) {
11761
- var encoded_data = _.JSONEncode(data);
11721
+ var encoded_data = JSONStringify(data);
11762
11722
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
11763
11723
  encoded_data = _.base64Encode(encoded_data);
11764
11724
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mixpanel-browser",
3
- "version": "2.61.2",
3
+ "version": "2.62.0",
4
4
  "description": "The official Mixpanel JavaScript browser client library",
5
5
  "main": "dist/mixpanel.cjs.js",
6
6
  "module": "dist/mixpanel.module.js",
package/src/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var Config = {
2
2
  DEBUG: false,
3
- LIB_VERSION: '2.61.2'
3
+ LIB_VERSION: '2.62.0'
4
4
  };
5
5
 
6
6
  export default Config;
@@ -1,6 +1,6 @@
1
1
  /* eslint camelcase: "off" */
2
2
  import Config from './config';
3
- import { MAX_RECORDING_MS, _, console, userAgent, document, navigator, slice, NOOP_FUNC } from './utils';
3
+ import { MAX_RECORDING_MS, _, console, userAgent, document, navigator, slice, NOOP_FUNC, JSONStringify } from './utils';
4
4
  import { isRecordingExpired } from './recorder/utils';
5
5
  import { window } from './window';
6
6
  import { Autocapture } from './autocapture';
@@ -932,7 +932,7 @@ MixpanelLib.prototype.disable = function(events) {
932
932
  };
933
933
 
934
934
  MixpanelLib.prototype._encode_data_for_request = function(data) {
935
- var encoded_data = _.JSONEncode(data);
935
+ var encoded_data = JSONStringify(data);
936
936
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
937
937
  encoded_data = _.base64Encode(encoded_data);
938
938
  }
@@ -9,7 +9,7 @@ import {
9
9
  REMOVE_ACTION,
10
10
  UNION_ACTION
11
11
  } from './api-actions';
12
- import { _, console } from './utils';
12
+ import { _, console, JSONStringify } from './utils';
13
13
 
14
14
  /*
15
15
  * Constants
@@ -125,7 +125,7 @@ MixpanelPersistence.prototype.save = function() {
125
125
 
126
126
  this.storage.set(
127
127
  this.name,
128
- _.JSONEncode(this['props']),
128
+ JSONStringify(this['props']),
129
129
  this.expire_days,
130
130
  this.cross_subdomain,
131
131
  this.secure,
@@ -187,6 +187,7 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
187
187
  this.idleTimeoutId = setTimeout(this._onIdleTimeout, idleTimeoutMs);
188
188
  this.idleExpires = new Date().getTime() + idleTimeoutMs;
189
189
  }.bind(this);
190
+ resetIdleTimeout();
190
191
 
191
192
  var blockSelector = this.getConfig('record_block_selector');
192
193
  if (blockSelector === '' || blockSelector === null) {
@@ -196,6 +197,10 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
196
197
  try {
197
198
  this._stopRecording = this._rrwebRecord({
198
199
  'emit': function (ev) {
200
+ if (this.idleExpires && this.idleExpires < ev.timestamp) {
201
+ this._onIdleTimeout();
202
+ return;
203
+ }
199
204
  if (isUserEvent(ev)) {
200
205
  if (this.batcher.stopped && new Date().getTime() - this.replayStartTime >= this.recordMinMs) {
201
206
  // start flushing again after user activity
@@ -232,8 +237,6 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
232
237
  return;
233
238
  }
234
239
 
235
- resetIdleTimeout();
236
-
237
240
  var maxTimeoutMs = this.maxExpires - new Date().getTime();
238
241
  this.maxTimeoutId = setTimeout(this._onMaxLengthReached.bind(this), maxTimeoutMs);
239
242
  };
@@ -412,7 +415,7 @@ SessionRecording.prototype._flushEvents = addOptOutCheckMixpanelLib(function (da
412
415
  'replay_start_url': this.replayStartUrl,
413
416
  'seq': this.seqNo
414
417
  };
415
- var eventsJson = _.JSONEncode(data);
418
+ var eventsJson = JSON.stringify(data);
416
419
 
417
420
  // send ID management props if they exist
418
421
  var deviceId = this._mixpanel.get_property('$device_id');
package/src/utils.js CHANGED
@@ -839,71 +839,27 @@ _.utf8Encode = function(string) {
839
839
  return utftext;
840
840
  };
841
841
 
842
- _.UUID = (function() {
843
-
844
- // Time-based entropy
845
- var T = function() {
846
- var time = 1 * new Date(); // cross-browser version of Date.now()
847
- var ticks;
848
- if (window.performance && window.performance.now) {
849
- ticks = window.performance.now();
850
- } else {
851
- // fall back to busy loop
852
- ticks = 0;
853
-
854
- // this while loop figures how many browser ticks go by
855
- // before 1*new Date() returns a new number, ie the amount
856
- // of ticks that go by per millisecond
857
- while (time == 1 * new Date()) {
858
- ticks++;
859
- }
860
- }
861
- return time.toString(16) + Math.floor(ticks).toString(16);
862
- };
863
-
864
- // Math.Random entropy
865
- var R = function() {
866
- return Math.random().toString(16).replace('.', '');
867
- };
868
-
869
- // User agent entropy
870
- // This function takes the user agent string, and then xors
871
- // together each sequence of 8 bytes. This produces a final
872
- // sequence of 8 bytes which it returns as hex.
873
- var UA = function() {
874
- var ua = userAgent,
875
- i, ch, buffer = [],
876
- ret = 0;
877
-
878
- function xor(result, byte_array) {
879
- var j, tmp = 0;
880
- for (j = 0; j < byte_array.length; j++) {
881
- tmp |= (buffer[j] << j * 8);
882
- }
883
- return result ^ tmp;
884
- }
885
-
886
- for (i = 0; i < ua.length; i++) {
887
- ch = ua.charCodeAt(i);
888
- buffer.unshift(ch & 0xFF);
889
- if (buffer.length >= 4) {
890
- ret = xor(ret, buffer);
891
- buffer = [];
892
- }
893
- }
894
-
895
- if (buffer.length > 0) {
896
- ret = xor(ret, buffer);
842
+ _.UUID = function() {
843
+ try {
844
+ // use native Crypto API when available
845
+ return window['crypto']['randomUUID']();
846
+ } catch (err) {
847
+ // fall back to generating our own UUID
848
+ // based on https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d
849
+ var uuid = new Array(36);
850
+ for (var i = 0; i < 36; i++) {
851
+ uuid[i] = Math.floor(Math.random() * 16);
897
852
  }
898
-
899
- return ret.toString(16);
900
- };
901
-
902
- return function() {
903
- var se = (screen.height * screen.width).toString(16);
904
- return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
905
- };
906
- })();
853
+ uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100
854
+ uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero
855
+ uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one
856
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
857
+
858
+ return _.map(uuid, function(x) {
859
+ return x.toString(16);
860
+ }).join('');
861
+ }
862
+ };
907
863
 
908
864
  // _.isBlockedUA()
909
865
  // This is to block various web spiders from executing our JS and
package/src/window.js CHANGED
@@ -5,6 +5,7 @@ if (typeof(window) === 'undefined') {
5
5
  hostname: ''
6
6
  };
7
7
  win = {
8
+ crypto: {randomUUID: function() {throw Error('unsupported');}},
8
9
  navigator: { userAgent: '', onLine: true },
9
10
  document: {
10
11
  createElement: function() { return {}; },