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.
@@ -3,7 +3,7 @@
3
3
 
4
4
  var Config = {
5
5
  DEBUG: false,
6
- LIB_VERSION: '2.61.2'
6
+ LIB_VERSION: '2.63.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] &= -5; // 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
@@ -2175,6 +2132,8 @@
2175
2132
  };
2176
2133
 
2177
2134
  // stateless utils
2135
+ // mostly from https://github.com/mixpanel/mixpanel-js/blob/989ada50f518edab47b9c4fd9535f9fbd5ec5fc0/src/autotrack-utils.js
2136
+
2178
2137
 
2179
2138
  var EV_CHANGE = 'change';
2180
2139
  var EV_CLICK = 'click';
@@ -3021,6 +2980,7 @@
3021
2980
 
3022
2981
  /* eslint camelcase: "off" */
3023
2982
 
2983
+
3024
2984
  /**
3025
2985
  * DomTracker Object
3026
2986
  * @constructor
@@ -3324,7 +3284,7 @@
3324
3284
  * @type {import('./wrapper').StorageWrapper}
3325
3285
  */
3326
3286
  var LocalStorageWrapper = function (storageOverride) {
3327
- this.storage = storageOverride || localStorage;
3287
+ this.storage = storageOverride || win.localStorage;
3328
3288
  };
3329
3289
 
3330
3290
  LocalStorageWrapper.prototype.init = function () {
@@ -4071,6 +4031,7 @@
4071
4031
  * These functions are used internally by the SDK and are not intended to be publicly exposed.
4072
4032
  */
4073
4033
 
4034
+
4074
4035
  /**
4075
4036
  * A function used to track a Mixpanel event (e.g. MixpanelLib.track)
4076
4037
  * @callback trackFunction
@@ -4359,6 +4320,7 @@
4359
4320
 
4360
4321
  /* eslint camelcase: "off" */
4361
4322
 
4323
+
4362
4324
  /** @const */ var SET_ACTION = '$set';
4363
4325
  /** @const */ var SET_ONCE_ACTION = '$set_once';
4364
4326
  /** @const */ var UNSET_ACTION = '$unset';
@@ -5118,6 +5080,7 @@
5118
5080
 
5119
5081
  /* eslint camelcase: "off" */
5120
5082
 
5083
+
5121
5084
  /*
5122
5085
  * Constants
5123
5086
  */
@@ -5232,7 +5195,7 @@
5232
5195
 
5233
5196
  this.storage.set(
5234
5197
  this.name,
5235
- _.JSONEncode(this['props']),
5198
+ JSONStringify(this['props']),
5236
5199
  this.expire_days,
5237
5200
  this.cross_subdomain,
5238
5201
  this.secure,
@@ -6576,7 +6539,7 @@
6576
6539
  };
6577
6540
 
6578
6541
  MixpanelLib.prototype._encode_data_for_request = function(data) {
6579
- var encoded_data = _.JSONEncode(data);
6542
+ var encoded_data = JSONStringify(data);
6580
6543
  if (this.get_config('api_payload_format') === PAYLOAD_TYPE_BASE64) {
6581
6544
  encoded_data = _.base64Encode(encoded_data);
6582
6545
  }