mixpanel-browser 2.61.2 → 2.63.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.63.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] &= -5; // 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
@@ -2174,6 +2131,8 @@ var isRecordingExpired = function(serializedRecording) {
2174
2131
  };
2175
2132
 
2176
2133
  // stateless utils
2134
+ // mostly from https://github.com/mixpanel/mixpanel-js/blob/989ada50f518edab47b9c4fd9535f9fbd5ec5fc0/src/autotrack-utils.js
2135
+
2177
2136
 
2178
2137
  var EV_CHANGE = 'change';
2179
2138
  var EV_CLICK = 'click';
@@ -3020,6 +2979,7 @@ safewrapClass(Autocapture);
3020
2979
 
3021
2980
  /* eslint camelcase: "off" */
3022
2981
 
2982
+
3023
2983
  /**
3024
2984
  * DomTracker Object
3025
2985
  * @constructor
@@ -3323,7 +3283,7 @@ SharedLock.prototype.withLock = function(lockedCB, pid) {
3323
3283
  * @type {import('./wrapper').StorageWrapper}
3324
3284
  */
3325
3285
  var LocalStorageWrapper = function (storageOverride) {
3326
- this.storage = storageOverride || localStorage;
3286
+ this.storage = storageOverride || win.localStorage;
3327
3287
  };
3328
3288
 
3329
3289
  LocalStorageWrapper.prototype.init = function () {
@@ -4070,6 +4030,7 @@ RequestBatcher.prototype.reportError = function(msg, err) {
4070
4030
  * These functions are used internally by the SDK and are not intended to be publicly exposed.
4071
4031
  */
4072
4032
 
4033
+
4073
4034
  /**
4074
4035
  * A function used to track a Mixpanel event (e.g. MixpanelLib.track)
4075
4036
  * @callback trackFunction
@@ -4358,6 +4319,7 @@ function _addOptOutCheck(method, getConfigValue) {
4358
4319
 
4359
4320
  /* eslint camelcase: "off" */
4360
4321
 
4322
+
4361
4323
  /** @const */ var SET_ACTION = '$set';
4362
4324
  /** @const */ var SET_ONCE_ACTION = '$set_once';
4363
4325
  /** @const */ var UNSET_ACTION = '$unset';
@@ -5117,6 +5079,7 @@ MixpanelPeople.prototype['toString'] = MixpanelPeople.prototype.toString;
5117
5079
 
5118
5080
  /* eslint camelcase: "off" */
5119
5081
 
5082
+
5120
5083
  /*
5121
5084
  * Constants
5122
5085
  */
@@ -5231,7 +5194,7 @@ MixpanelPersistence.prototype.save = function() {
5231
5194
 
5232
5195
  this.storage.set(
5233
5196
  this.name,
5234
- _.JSONEncode(this['props']),
5197
+ JSONStringify(this['props']),
5235
5198
  this.expire_days,
5236
5199
  this.cross_subdomain,
5237
5200
  this.secure,
@@ -6575,7 +6538,7 @@ MixpanelLib.prototype.disable = function(events) {
6575
6538
  };
6576
6539
 
6577
6540
  MixpanelLib.prototype._encode_data_for_request = function(data) {
6578
- var encoded_data = _.JSONEncode(data);
6541
+ var encoded_data = JSONStringify(data);
6579
6542
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
6580
6543
  encoded_data = _.base64Encode(encoded_data);
6581
6544
  }