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