mixpanel-browser 2.64.0 → 2.66.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.
@@ -13944,7 +13944,7 @@ if (typeof Promise !== 'undefined' && Promise.toString().indexOf('[native code]'
13944
13944
 
13945
13945
  var Config = {
13946
13946
  DEBUG: false,
13947
- LIB_VERSION: '2.64.0'
13947
+ LIB_VERSION: '2.66.0'
13948
13948
  };
13949
13949
 
13950
13950
  /* eslint camelcase: "off", eqeqeq: "off" */
@@ -15429,6 +15429,9 @@ _.info = {
15429
15429
  return 'Microsoft Edge';
15430
15430
  } else if (_.includes(user_agent, 'FBIOS')) {
15431
15431
  return 'Facebook Mobile';
15432
+ } else if (_.includes(user_agent, 'Whale/')) {
15433
+ // https://user-agents.net/browsers/whale-browser
15434
+ return 'Whale Browser';
15432
15435
  } else if (_.includes(user_agent, 'Chrome')) {
15433
15436
  return 'Chrome';
15434
15437
  } else if (_.includes(user_agent, 'CriOS')) {
@@ -15480,7 +15483,8 @@ _.info = {
15480
15483
  'Android Mobile': /android\s(\d+(\.\d+)?)/,
15481
15484
  'Samsung Internet': /SamsungBrowser\/(\d+(\.\d+)?)/,
15482
15485
  'Internet Explorer': /(rv:|MSIE )(\d+(\.\d+)?)/,
15483
- 'Mozilla': /rv:(\d+(\.\d+)?)/
15486
+ 'Mozilla': /rv:(\d+(\.\d+)?)/,
15487
+ 'Whale Browser': /Whale\/(\d+(\.\d+)?)/
15484
15488
  };
15485
15489
  var regex = versionRegexs[browser];
15486
15490
  if (regex === undefined) {
@@ -17347,8 +17351,8 @@ SessionRecording.prototype._sendRequest = function(currentReplayId, reqParams, r
17347
17351
  retryAfter: response.headers.get('Retry-After')
17348
17352
  });
17349
17353
  }.bind(this);
17350
-
17351
- win['fetch'](this.getConfig('api_host') + '/' + this.getConfig('api_routes')['record'] + '?' + new URLSearchParams(reqParams), {
17354
+ var apiHost = (this._mixpanel.get_api_host && this._mixpanel.get_api_host('record')) || this.getConfig('api_host');
17355
+ win['fetch'](apiHost + '/' + this.getConfig('api_routes')['record'] + '?' + new URLSearchParams(reqParams), {
17352
17356
  'method': 'POST',
17353
17357
  'headers': {
17354
17358
  'Authorization': 'Basic ' + btoa(this.getConfig('token') + ':'),
@@ -17565,6 +17569,7 @@ var MixpanelRecorder = function(mixpanelInstance, rrwebRecord, sharedLockStorage
17565
17569
  this._flushInactivePromise = this.recordingRegistry.flushInactiveRecordings();
17566
17570
 
17567
17571
  this.activeRecording = null;
17572
+ this.stopRecordingInProgress = false;
17568
17573
  };
17569
17574
 
17570
17575
  MixpanelRecorder.prototype.startRecording = function(options) {
@@ -17613,19 +17618,26 @@ MixpanelRecorder.prototype.startRecording = function(options) {
17613
17618
  };
17614
17619
 
17615
17620
  MixpanelRecorder.prototype.stopRecording = function() {
17616
- var stopPromise = this._stopCurrentRecording(false);
17617
- this.recordingRegistry.clearActiveRecording();
17618
- this.activeRecording = null;
17619
- return stopPromise;
17621
+ // Prevents activeSerializedRecording from being reused when stopping the recording.
17622
+ this.stopRecordingInProgress = true;
17623
+ return this._stopCurrentRecording(false, true).then(function() {
17624
+ return this.recordingRegistry.clearActiveRecording();
17625
+ }.bind(this)).then(function() {
17626
+ this.stopRecordingInProgress = false;
17627
+ }.bind(this));
17620
17628
  };
17621
17629
 
17622
17630
  MixpanelRecorder.prototype.pauseRecording = function() {
17623
17631
  return this._stopCurrentRecording(false);
17624
17632
  };
17625
17633
 
17626
- MixpanelRecorder.prototype._stopCurrentRecording = function(skipFlush) {
17634
+ MixpanelRecorder.prototype._stopCurrentRecording = function(skipFlush, disableActiveRecording) {
17627
17635
  if (this.activeRecording) {
17628
- return this.activeRecording.stopRecording(skipFlush);
17636
+ var stopRecordingPromise = this.activeRecording.stopRecording(skipFlush);
17637
+ if (disableActiveRecording) {
17638
+ this.activeRecording = null;
17639
+ }
17640
+ return stopRecordingPromise;
17629
17641
  }
17630
17642
  return PromisePolyfill.resolve();
17631
17643
  };
@@ -17638,7 +17650,7 @@ MixpanelRecorder.prototype.resumeRecording = function (startNewIfInactive) {
17638
17650
 
17639
17651
  return this.recordingRegistry.getActiveRecording()
17640
17652
  .then(function (activeSerializedRecording) {
17641
- if (activeSerializedRecording) {
17653
+ if (activeSerializedRecording && !this.stopRecordingInProgress) {
17642
17654
  return this.startRecording({activeSerializedRecording: activeSerializedRecording});
17643
17655
  } else if (startNewIfInactive) {
17644
17656
  return this.startRecording({shouldStopBatcher: false});
@@ -17842,7 +17854,9 @@ function getPropsForDOMEvent(ev, config) {
17842
17854
  '$elements': elementsJson,
17843
17855
  '$el_attr__href': href,
17844
17856
  '$viewportHeight': Math.max(docElement['clientHeight'], win['innerHeight'] || 0),
17845
- '$viewportWidth': Math.max(docElement['clientWidth'], win['innerWidth'] || 0)
17857
+ '$viewportWidth': Math.max(docElement['clientWidth'], win['innerWidth'] || 0),
17858
+ '$pageHeight': document$1['body']['offsetHeight'] || 0,
17859
+ '$pageWidth': document$1['body']['offsetWidth'] || 0,
17846
17860
  };
17847
17861
  _.each(captureExtraAttrs, function(attr) {
17848
17862
  if (!blockAttrsSet[attr] && target.hasAttribute(attr)) {
@@ -18573,19 +18587,19 @@ FeatureFlagManager.prototype.getConfig = function(key) {
18573
18587
  return this.getFullConfig()[key];
18574
18588
  };
18575
18589
 
18576
- FeatureFlagManager.prototype.isEnabled = function() {
18590
+ FeatureFlagManager.prototype.isSystemEnabled = function() {
18577
18591
  return !!this.getMpConfig(FLAGS_CONFIG_KEY);
18578
18592
  };
18579
18593
 
18580
- FeatureFlagManager.prototype.areFeaturesReady = function() {
18581
- if (!this.isEnabled()) {
18594
+ FeatureFlagManager.prototype.areFlagsReady = function() {
18595
+ if (!this.isSystemEnabled()) {
18582
18596
  logger.error('Feature Flags not enabled');
18583
18597
  }
18584
18598
  return !!this.flags;
18585
18599
  };
18586
18600
 
18587
18601
  FeatureFlagManager.prototype.fetchFlags = function() {
18588
- if (!this.isEnabled()) {
18602
+ if (!this.isSystemEnabled()) {
18589
18603
  return;
18590
18604
  }
18591
18605
 
@@ -18611,7 +18625,7 @@ FeatureFlagManager.prototype.fetchFlags = function() {
18611
18625
  _.each(responseFlags, function(data, key) {
18612
18626
  flags.set(key, {
18613
18627
  'key': data['variant_key'],
18614
- 'data': data['variant_value']
18628
+ 'value': data['variant_value']
18615
18629
  });
18616
18630
  });
18617
18631
  this.flags = flags;
@@ -18621,7 +18635,7 @@ FeatureFlagManager.prototype.fetchFlags = function() {
18621
18635
  }.bind(this)).catch(function() {});
18622
18636
  };
18623
18637
 
18624
- FeatureFlagManager.prototype.getFeature = function(featureName, fallback) {
18638
+ FeatureFlagManager.prototype.getVariant = function(featureName, fallback) {
18625
18639
  if (!this.fetchPromise) {
18626
18640
  return new Promise(function(resolve) {
18627
18641
  logger.critical('Feature Flags not initialized');
@@ -18630,15 +18644,15 @@ FeatureFlagManager.prototype.getFeature = function(featureName, fallback) {
18630
18644
  }
18631
18645
 
18632
18646
  return this.fetchPromise.then(function() {
18633
- return this.getFeatureSync(featureName, fallback);
18647
+ return this.getVariantSync(featureName, fallback);
18634
18648
  }.bind(this)).catch(function(error) {
18635
18649
  logger.error(error);
18636
18650
  return fallback;
18637
18651
  });
18638
18652
  };
18639
18653
 
18640
- FeatureFlagManager.prototype.getFeatureSync = function(featureName, fallback) {
18641
- if (!this.areFeaturesReady()) {
18654
+ FeatureFlagManager.prototype.getVariantSync = function(featureName, fallback) {
18655
+ if (!this.areFlagsReady()) {
18642
18656
  logger.log('Flags not loaded yet');
18643
18657
  return fallback;
18644
18658
  }
@@ -18651,31 +18665,37 @@ FeatureFlagManager.prototype.getFeatureSync = function(featureName, fallback) {
18651
18665
  return feature;
18652
18666
  };
18653
18667
 
18654
- FeatureFlagManager.prototype.getFeatureData = function(featureName, fallbackValue) {
18655
- return this.getFeature(featureName, {'data': fallbackValue}).then(function(feature) {
18656
- return feature['data'];
18668
+ FeatureFlagManager.prototype.getVariantValue = function(featureName, fallbackValue) {
18669
+ return this.getVariant(featureName, {'value': fallbackValue}).then(function(feature) {
18670
+ return feature['value'];
18657
18671
  }).catch(function(error) {
18658
18672
  logger.error(error);
18659
18673
  return fallbackValue;
18660
18674
  });
18661
18675
  };
18662
18676
 
18663
- FeatureFlagManager.prototype.getFeatureDataSync = function(featureName, fallbackValue) {
18664
- return this.getFeatureSync(featureName, {'data': fallbackValue})['data'];
18677
+ // TODO remove deprecated method
18678
+ FeatureFlagManager.prototype.getFeatureData = function(featureName, fallbackValue) {
18679
+ logger.critical('mixpanel.flags.get_feature_data() is deprecated and will be removed in a future release. Use mixpanel.flags.get_variant_value() instead.');
18680
+ return this.getVariantValue(featureName, fallbackValue);
18681
+ };
18682
+
18683
+ FeatureFlagManager.prototype.getVariantValueSync = function(featureName, fallbackValue) {
18684
+ return this.getVariantSync(featureName, {'value': fallbackValue})['value'];
18665
18685
  };
18666
18686
 
18667
- FeatureFlagManager.prototype.isFeatureEnabled = function(featureName, fallbackValue) {
18668
- return this.getFeatureData(featureName).then(function() {
18669
- return this.isFeatureEnabledSync(featureName, fallbackValue);
18687
+ FeatureFlagManager.prototype.isEnabled = function(featureName, fallbackValue) {
18688
+ return this.getVariantValue(featureName).then(function() {
18689
+ return this.isEnabledSync(featureName, fallbackValue);
18670
18690
  }.bind(this)).catch(function(error) {
18671
18691
  logger.error(error);
18672
18692
  return fallbackValue;
18673
18693
  });
18674
18694
  };
18675
18695
 
18676
- FeatureFlagManager.prototype.isFeatureEnabledSync = function(featureName, fallbackValue) {
18696
+ FeatureFlagManager.prototype.isEnabledSync = function(featureName, fallbackValue) {
18677
18697
  fallbackValue = fallbackValue || false;
18678
- var val = this.getFeatureDataSync(featureName, fallbackValue);
18698
+ var val = this.getVariantValueSync(featureName, fallbackValue);
18679
18699
  if (val !== true && val !== false) {
18680
18700
  logger.error('Feature flag "' + featureName + '" value: ' + val + ' is not a boolean; returning fallback value: ' + fallbackValue);
18681
18701
  val = fallbackValue;
@@ -18704,13 +18724,16 @@ function minApisSupported() {
18704
18724
 
18705
18725
  safewrapClass(FeatureFlagManager);
18706
18726
 
18707
- FeatureFlagManager.prototype['are_features_ready'] = FeatureFlagManager.prototype.areFeaturesReady;
18708
- FeatureFlagManager.prototype['get_feature'] = FeatureFlagManager.prototype.getFeature;
18727
+ FeatureFlagManager.prototype['are_flags_ready'] = FeatureFlagManager.prototype.areFlagsReady;
18728
+ FeatureFlagManager.prototype['get_variant'] = FeatureFlagManager.prototype.getVariant;
18729
+ FeatureFlagManager.prototype['get_variant_sync'] = FeatureFlagManager.prototype.getVariantSync;
18730
+ FeatureFlagManager.prototype['get_variant_value'] = FeatureFlagManager.prototype.getVariantValue;
18731
+ FeatureFlagManager.prototype['get_variant_value_sync'] = FeatureFlagManager.prototype.getVariantValueSync;
18732
+ FeatureFlagManager.prototype['is_enabled'] = FeatureFlagManager.prototype.isEnabled;
18733
+ FeatureFlagManager.prototype['is_enabled_sync'] = FeatureFlagManager.prototype.isEnabledSync;
18734
+
18735
+ // Deprecated method
18709
18736
  FeatureFlagManager.prototype['get_feature_data'] = FeatureFlagManager.prototype.getFeatureData;
18710
- FeatureFlagManager.prototype['get_feature_data_sync'] = FeatureFlagManager.prototype.getFeatureDataSync;
18711
- FeatureFlagManager.prototype['get_feature_sync'] = FeatureFlagManager.prototype.getFeatureSync;
18712
- FeatureFlagManager.prototype['is_feature_enabled'] = FeatureFlagManager.prototype.isFeatureEnabled;
18713
- FeatureFlagManager.prototype['is_feature_enabled_sync'] = FeatureFlagManager.prototype.isFeatureEnabledSync;
18714
18737
 
18715
18738
  /* eslint camelcase: "off" */
18716
18739
 
@@ -19129,7 +19152,7 @@ MixpanelGroup.prototype._send_request = function(data, callback) {
19129
19152
  return this._mixpanel._track_or_batch({
19130
19153
  type: 'groups',
19131
19154
  data: date_encoded_data,
19132
- endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
19155
+ endpoint: this._mixpanel.get_api_host('groups') + '/' + this._get_config('api_routes')['groups'],
19133
19156
  batcher: this._mixpanel.request_batchers.groups
19134
19157
  }, callback);
19135
19158
  };
@@ -19406,18 +19429,8 @@ MixpanelPeople.prototype.union = addOptOutCheckMixpanelPeople(function(list_name
19406
19429
  * @param {Function} [callback] If provided, the callback will be called when the server responds
19407
19430
  * @deprecated
19408
19431
  */
19409
- MixpanelPeople.prototype.track_charge = addOptOutCheckMixpanelPeople(function(amount, properties, callback) {
19410
- if (!_.isNumber(amount)) {
19411
- amount = parseFloat(amount);
19412
- if (isNaN(amount)) {
19413
- console$1.error('Invalid value passed to mixpanel.people.track_charge - must be a number');
19414
- return;
19415
- }
19416
- }
19417
-
19418
- return this.append('$transactions', _.extend({
19419
- '$amount': amount
19420
- }, properties), callback);
19432
+ MixpanelPeople.prototype.track_charge = addOptOutCheckMixpanelPeople(function() {
19433
+ console$1.error('mixpanel.people.track_charge() is deprecated and no longer has any effect.');
19421
19434
  });
19422
19435
 
19423
19436
  /*
@@ -19491,7 +19504,7 @@ MixpanelPeople.prototype._send_request = function(data, callback) {
19491
19504
  return this._mixpanel._track_or_batch({
19492
19505
  type: 'people',
19493
19506
  data: date_encoded_data,
19494
- endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
19507
+ endpoint: this._mixpanel.get_api_host('people') + '/' + this._get_config('api_routes')['engage'],
19495
19508
  batcher: this._mixpanel.request_batchers.people
19496
19509
  }, callback);
19497
19510
  };
@@ -20128,7 +20141,9 @@ var DEFAULT_API_ROUTES = {
20128
20141
  */
20129
20142
  var DEFAULT_CONFIG = {
20130
20143
  'api_host': 'https://api-js.mixpanel.com',
20144
+ 'api_hosts': {},
20131
20145
  'api_routes': DEFAULT_API_ROUTES,
20146
+ 'api_extra_query_params': {},
20132
20147
  'api_method': 'POST',
20133
20148
  'api_transport': 'XHR',
20134
20149
  'api_payload_format': PAYLOAD_TYPE_BASE64,
@@ -20512,20 +20527,23 @@ MixpanelLib.prototype.start_session_recording = function () {
20512
20527
 
20513
20528
  MixpanelLib.prototype.stop_session_recording = function () {
20514
20529
  if (this._recorder) {
20515
- this._recorder['stopRecording']();
20530
+ return this._recorder['stopRecording']();
20516
20531
  }
20532
+ return Promise.resolve();
20517
20533
  };
20518
20534
 
20519
20535
  MixpanelLib.prototype.pause_session_recording = function () {
20520
20536
  if (this._recorder) {
20521
- this._recorder['pauseRecording']();
20537
+ return this._recorder['pauseRecording']();
20522
20538
  }
20539
+ return Promise.resolve();
20523
20540
  };
20524
20541
 
20525
20542
  MixpanelLib.prototype.resume_session_recording = function () {
20526
20543
  if (this._recorder) {
20527
- this._recorder['resumeRecording']();
20544
+ return this._recorder['resumeRecording']();
20528
20545
  }
20546
+ return Promise.resolve();
20529
20547
  };
20530
20548
 
20531
20549
  MixpanelLib.prototype.is_recording_heatmap_data = function () {
@@ -20716,6 +20734,8 @@ MixpanelLib.prototype._send_request = function(url, data, options, callback) {
20716
20734
  delete data['data'];
20717
20735
  }
20718
20736
 
20737
+ _.extend(data, this.get_config('api_extra_query_params'));
20738
+
20719
20739
  url += '?' + _.HTTPBuildQuery(data);
20720
20740
 
20721
20741
  var lib = this;
@@ -21123,7 +21143,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
21123
21143
  var ret = this._track_or_batch({
21124
21144
  type: 'events',
21125
21145
  data: data,
21126
- endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
21146
+ endpoint: this.get_api_host('events') + '/' + this.get_config('api_routes')['track'],
21127
21147
  batcher: this.request_batchers.events,
21128
21148
  should_send_immediately: should_send_immediately,
21129
21149
  send_request_options: options
@@ -21625,13 +21645,31 @@ MixpanelLib.prototype.identify = function(
21625
21645
  * Useful for clearing data when a user logs out.
21626
21646
  */
21627
21647
  MixpanelLib.prototype.reset = function() {
21628
- this['persistence'].clear();
21629
- this._flags.identify_called = false;
21630
- var uuid = _.UUID();
21631
- this.register_once({
21632
- 'distinct_id': DEVICE_ID_PREFIX + uuid,
21633
- '$device_id': uuid
21634
- }, '');
21648
+ var self = this;
21649
+
21650
+ var reset = function () {
21651
+ self['persistence'].clear();
21652
+ self._flags.identify_called = false;
21653
+ var uuid = _.UUID();
21654
+ self.register_once({
21655
+ 'distinct_id': DEVICE_ID_PREFIX + uuid,
21656
+ '$device_id': uuid
21657
+ }, '');
21658
+ };
21659
+
21660
+ if (self._recorder) {
21661
+ self.stop_session_recording()
21662
+ .then(function () {
21663
+ reset();
21664
+ self._check_and_start_session_recording();
21665
+ })
21666
+ .catch(_.bind(function (err) {
21667
+ reset();
21668
+ this.report_error('Error restarting recording session', err);
21669
+ }, this));
21670
+ } else {
21671
+ reset();
21672
+ }
21635
21673
  };
21636
21674
 
21637
21675
  /**
@@ -21942,6 +21980,16 @@ MixpanelLib.prototype.get_property = function(property_name) {
21942
21980
  return this['persistence'].load_prop([property_name]);
21943
21981
  };
21944
21982
 
21983
+ /**
21984
+ * Get the API host for a specific endpoint type, falling back to the default api_host if not specified
21985
+ *
21986
+ * @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
21987
+ * @returns {String} The API host to use for this endpoint
21988
+ */
21989
+ MixpanelLib.prototype.get_api_host = function(endpoint_type) {
21990
+ return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
21991
+ };
21992
+
21945
21993
  MixpanelLib.prototype.toString = function() {
21946
21994
  var name = this.get_config('name');
21947
21995
  if (name !== PRIMARY_INSTANCE_NAME) {
@@ -22237,6 +22285,7 @@ MixpanelLib.prototype['alias'] = MixpanelLib.protot
22237
22285
  MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
22238
22286
  MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
22239
22287
  MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
22288
+ MixpanelLib.prototype['get_api_host'] = MixpanelLib.prototype.get_api_host;
22240
22289
  MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
22241
22290
  MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
22242
22291
  MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;