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.
@@ -3,7 +3,7 @@
3
3
 
4
4
  var Config = {
5
5
  DEBUG: false,
6
- LIB_VERSION: '2.64.0'
6
+ LIB_VERSION: '2.66.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
@@ -1871,6 +1871,9 @@
1871
1871
  return 'Microsoft Edge';
1872
1872
  } else if (_.includes(user_agent, 'FBIOS')) {
1873
1873
  return 'Facebook Mobile';
1874
+ } else if (_.includes(user_agent, 'Whale/')) {
1875
+ // https://user-agents.net/browsers/whale-browser
1876
+ return 'Whale Browser';
1874
1877
  } else if (_.includes(user_agent, 'Chrome')) {
1875
1878
  return 'Chrome';
1876
1879
  } else if (_.includes(user_agent, 'CriOS')) {
@@ -1922,7 +1925,8 @@
1922
1925
  'Android Mobile': /android\s(\d+(\.\d+)?)/,
1923
1926
  'Samsung Internet': /SamsungBrowser\/(\d+(\.\d+)?)/,
1924
1927
  'Internet Explorer': /(rv:|MSIE )(\d+(\.\d+)?)/,
1925
- 'Mozilla': /rv:(\d+(\.\d+)?)/
1928
+ 'Mozilla': /rv:(\d+(\.\d+)?)/,
1929
+ 'Whale Browser': /Whale\/(\d+(\.\d+)?)/
1926
1930
  };
1927
1931
  var regex = versionRegexs[browser];
1928
1932
  if (regex === undefined) {
@@ -2300,7 +2304,9 @@
2300
2304
  '$elements': elementsJson,
2301
2305
  '$el_attr__href': href,
2302
2306
  '$viewportHeight': Math.max(docElement['clientHeight'], win['innerHeight'] || 0),
2303
- '$viewportWidth': Math.max(docElement['clientWidth'], win['innerWidth'] || 0)
2307
+ '$viewportWidth': Math.max(docElement['clientWidth'], win['innerWidth'] || 0),
2308
+ '$pageHeight': document$1['body']['offsetHeight'] || 0,
2309
+ '$pageWidth': document$1['body']['offsetWidth'] || 0,
2304
2310
  };
2305
2311
  _.each(captureExtraAttrs, function(attr) {
2306
2312
  if (!blockAttrsSet[attr] && target.hasAttribute(attr)) {
@@ -3031,19 +3037,19 @@
3031
3037
  return this.getFullConfig()[key];
3032
3038
  };
3033
3039
 
3034
- FeatureFlagManager.prototype.isEnabled = function() {
3040
+ FeatureFlagManager.prototype.isSystemEnabled = function() {
3035
3041
  return !!this.getMpConfig(FLAGS_CONFIG_KEY);
3036
3042
  };
3037
3043
 
3038
- FeatureFlagManager.prototype.areFeaturesReady = function() {
3039
- if (!this.isEnabled()) {
3044
+ FeatureFlagManager.prototype.areFlagsReady = function() {
3045
+ if (!this.isSystemEnabled()) {
3040
3046
  logger$3.error('Feature Flags not enabled');
3041
3047
  }
3042
3048
  return !!this.flags;
3043
3049
  };
3044
3050
 
3045
3051
  FeatureFlagManager.prototype.fetchFlags = function() {
3046
- if (!this.isEnabled()) {
3052
+ if (!this.isSystemEnabled()) {
3047
3053
  return;
3048
3054
  }
3049
3055
 
@@ -3069,7 +3075,7 @@
3069
3075
  _.each(responseFlags, function(data, key) {
3070
3076
  flags.set(key, {
3071
3077
  'key': data['variant_key'],
3072
- 'data': data['variant_value']
3078
+ 'value': data['variant_value']
3073
3079
  });
3074
3080
  });
3075
3081
  this.flags = flags;
@@ -3079,7 +3085,7 @@
3079
3085
  }.bind(this)).catch(function() {});
3080
3086
  };
3081
3087
 
3082
- FeatureFlagManager.prototype.getFeature = function(featureName, fallback) {
3088
+ FeatureFlagManager.prototype.getVariant = function(featureName, fallback) {
3083
3089
  if (!this.fetchPromise) {
3084
3090
  return new Promise(function(resolve) {
3085
3091
  logger$3.critical('Feature Flags not initialized');
@@ -3088,15 +3094,15 @@
3088
3094
  }
3089
3095
 
3090
3096
  return this.fetchPromise.then(function() {
3091
- return this.getFeatureSync(featureName, fallback);
3097
+ return this.getVariantSync(featureName, fallback);
3092
3098
  }.bind(this)).catch(function(error) {
3093
3099
  logger$3.error(error);
3094
3100
  return fallback;
3095
3101
  });
3096
3102
  };
3097
3103
 
3098
- FeatureFlagManager.prototype.getFeatureSync = function(featureName, fallback) {
3099
- if (!this.areFeaturesReady()) {
3104
+ FeatureFlagManager.prototype.getVariantSync = function(featureName, fallback) {
3105
+ if (!this.areFlagsReady()) {
3100
3106
  logger$3.log('Flags not loaded yet');
3101
3107
  return fallback;
3102
3108
  }
@@ -3109,31 +3115,37 @@
3109
3115
  return feature;
3110
3116
  };
3111
3117
 
3112
- FeatureFlagManager.prototype.getFeatureData = function(featureName, fallbackValue) {
3113
- return this.getFeature(featureName, {'data': fallbackValue}).then(function(feature) {
3114
- return feature['data'];
3118
+ FeatureFlagManager.prototype.getVariantValue = function(featureName, fallbackValue) {
3119
+ return this.getVariant(featureName, {'value': fallbackValue}).then(function(feature) {
3120
+ return feature['value'];
3115
3121
  }).catch(function(error) {
3116
3122
  logger$3.error(error);
3117
3123
  return fallbackValue;
3118
3124
  });
3119
3125
  };
3120
3126
 
3121
- FeatureFlagManager.prototype.getFeatureDataSync = function(featureName, fallbackValue) {
3122
- return this.getFeatureSync(featureName, {'data': fallbackValue})['data'];
3127
+ // TODO remove deprecated method
3128
+ FeatureFlagManager.prototype.getFeatureData = function(featureName, fallbackValue) {
3129
+ logger$3.critical('mixpanel.flags.get_feature_data() is deprecated and will be removed in a future release. Use mixpanel.flags.get_variant_value() instead.');
3130
+ return this.getVariantValue(featureName, fallbackValue);
3131
+ };
3132
+
3133
+ FeatureFlagManager.prototype.getVariantValueSync = function(featureName, fallbackValue) {
3134
+ return this.getVariantSync(featureName, {'value': fallbackValue})['value'];
3123
3135
  };
3124
3136
 
3125
- FeatureFlagManager.prototype.isFeatureEnabled = function(featureName, fallbackValue) {
3126
- return this.getFeatureData(featureName).then(function() {
3127
- return this.isFeatureEnabledSync(featureName, fallbackValue);
3137
+ FeatureFlagManager.prototype.isEnabled = function(featureName, fallbackValue) {
3138
+ return this.getVariantValue(featureName).then(function() {
3139
+ return this.isEnabledSync(featureName, fallbackValue);
3128
3140
  }.bind(this)).catch(function(error) {
3129
3141
  logger$3.error(error);
3130
3142
  return fallbackValue;
3131
3143
  });
3132
3144
  };
3133
3145
 
3134
- FeatureFlagManager.prototype.isFeatureEnabledSync = function(featureName, fallbackValue) {
3146
+ FeatureFlagManager.prototype.isEnabledSync = function(featureName, fallbackValue) {
3135
3147
  fallbackValue = fallbackValue || false;
3136
- var val = this.getFeatureDataSync(featureName, fallbackValue);
3148
+ var val = this.getVariantValueSync(featureName, fallbackValue);
3137
3149
  if (val !== true && val !== false) {
3138
3150
  logger$3.error('Feature flag "' + featureName + '" value: ' + val + ' is not a boolean; returning fallback value: ' + fallbackValue);
3139
3151
  val = fallbackValue;
@@ -3162,13 +3174,16 @@
3162
3174
 
3163
3175
  safewrapClass(FeatureFlagManager);
3164
3176
 
3165
- FeatureFlagManager.prototype['are_features_ready'] = FeatureFlagManager.prototype.areFeaturesReady;
3166
- FeatureFlagManager.prototype['get_feature'] = FeatureFlagManager.prototype.getFeature;
3177
+ FeatureFlagManager.prototype['are_flags_ready'] = FeatureFlagManager.prototype.areFlagsReady;
3178
+ FeatureFlagManager.prototype['get_variant'] = FeatureFlagManager.prototype.getVariant;
3179
+ FeatureFlagManager.prototype['get_variant_sync'] = FeatureFlagManager.prototype.getVariantSync;
3180
+ FeatureFlagManager.prototype['get_variant_value'] = FeatureFlagManager.prototype.getVariantValue;
3181
+ FeatureFlagManager.prototype['get_variant_value_sync'] = FeatureFlagManager.prototype.getVariantValueSync;
3182
+ FeatureFlagManager.prototype['is_enabled'] = FeatureFlagManager.prototype.isEnabled;
3183
+ FeatureFlagManager.prototype['is_enabled_sync'] = FeatureFlagManager.prototype.isEnabledSync;
3184
+
3185
+ // Deprecated method
3167
3186
  FeatureFlagManager.prototype['get_feature_data'] = FeatureFlagManager.prototype.getFeatureData;
3168
- FeatureFlagManager.prototype['get_feature_data_sync'] = FeatureFlagManager.prototype.getFeatureDataSync;
3169
- FeatureFlagManager.prototype['get_feature_sync'] = FeatureFlagManager.prototype.getFeatureSync;
3170
- FeatureFlagManager.prototype['is_feature_enabled'] = FeatureFlagManager.prototype.isFeatureEnabled;
3171
- FeatureFlagManager.prototype['is_feature_enabled_sync'] = FeatureFlagManager.prototype.isFeatureEnabledSync;
3172
3187
 
3173
3188
  /* eslint camelcase: "off" */
3174
3189
 
@@ -4775,7 +4790,7 @@
4775
4790
  return this._mixpanel._track_or_batch({
4776
4791
  type: 'groups',
4777
4792
  data: date_encoded_data,
4778
- endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
4793
+ endpoint: this._mixpanel.get_api_host('groups') + '/' + this._get_config('api_routes')['groups'],
4779
4794
  batcher: this._mixpanel.request_batchers.groups
4780
4795
  }, callback);
4781
4796
  };
@@ -5052,18 +5067,8 @@
5052
5067
  * @param {Function} [callback] If provided, the callback will be called when the server responds
5053
5068
  * @deprecated
5054
5069
  */
5055
- MixpanelPeople.prototype.track_charge = addOptOutCheckMixpanelPeople(function(amount, properties, callback) {
5056
- if (!_.isNumber(amount)) {
5057
- amount = parseFloat(amount);
5058
- if (isNaN(amount)) {
5059
- console.error('Invalid value passed to mixpanel.people.track_charge - must be a number');
5060
- return;
5061
- }
5062
- }
5063
-
5064
- return this.append('$transactions', _.extend({
5065
- '$amount': amount
5066
- }, properties), callback);
5070
+ MixpanelPeople.prototype.track_charge = addOptOutCheckMixpanelPeople(function() {
5071
+ console.error('mixpanel.people.track_charge() is deprecated and no longer has any effect.');
5067
5072
  });
5068
5073
 
5069
5074
  /*
@@ -5137,7 +5142,7 @@
5137
5142
  return this._mixpanel._track_or_batch({
5138
5143
  type: 'people',
5139
5144
  data: date_encoded_data,
5140
- endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
5145
+ endpoint: this._mixpanel.get_api_host('people') + '/' + this._get_config('api_routes')['engage'],
5141
5146
  batcher: this._mixpanel.request_batchers.people
5142
5147
  }, callback);
5143
5148
  };
@@ -5897,7 +5902,9 @@
5897
5902
  */
5898
5903
  var DEFAULT_CONFIG = {
5899
5904
  'api_host': 'https://api-js.mixpanel.com',
5905
+ 'api_hosts': {},
5900
5906
  'api_routes': DEFAULT_API_ROUTES,
5907
+ 'api_extra_query_params': {},
5901
5908
  'api_method': 'POST',
5902
5909
  'api_transport': 'XHR',
5903
5910
  'api_payload_format': PAYLOAD_TYPE_BASE64,
@@ -6281,20 +6288,23 @@
6281
6288
 
6282
6289
  MixpanelLib.prototype.stop_session_recording = function () {
6283
6290
  if (this._recorder) {
6284
- this._recorder['stopRecording']();
6291
+ return this._recorder['stopRecording']();
6285
6292
  }
6293
+ return Promise.resolve();
6286
6294
  };
6287
6295
 
6288
6296
  MixpanelLib.prototype.pause_session_recording = function () {
6289
6297
  if (this._recorder) {
6290
- this._recorder['pauseRecording']();
6298
+ return this._recorder['pauseRecording']();
6291
6299
  }
6300
+ return Promise.resolve();
6292
6301
  };
6293
6302
 
6294
6303
  MixpanelLib.prototype.resume_session_recording = function () {
6295
6304
  if (this._recorder) {
6296
- this._recorder['resumeRecording']();
6305
+ return this._recorder['resumeRecording']();
6297
6306
  }
6307
+ return Promise.resolve();
6298
6308
  };
6299
6309
 
6300
6310
  MixpanelLib.prototype.is_recording_heatmap_data = function () {
@@ -6485,6 +6495,8 @@
6485
6495
  delete data['data'];
6486
6496
  }
6487
6497
 
6498
+ _.extend(data, this.get_config('api_extra_query_params'));
6499
+
6488
6500
  url += '?' + _.HTTPBuildQuery(data);
6489
6501
 
6490
6502
  var lib = this;
@@ -6892,7 +6904,7 @@
6892
6904
  var ret = this._track_or_batch({
6893
6905
  type: 'events',
6894
6906
  data: data,
6895
- endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
6907
+ endpoint: this.get_api_host('events') + '/' + this.get_config('api_routes')['track'],
6896
6908
  batcher: this.request_batchers.events,
6897
6909
  should_send_immediately: should_send_immediately,
6898
6910
  send_request_options: options
@@ -7394,13 +7406,31 @@
7394
7406
  * Useful for clearing data when a user logs out.
7395
7407
  */
7396
7408
  MixpanelLib.prototype.reset = function() {
7397
- this['persistence'].clear();
7398
- this._flags.identify_called = false;
7399
- var uuid = _.UUID();
7400
- this.register_once({
7401
- 'distinct_id': DEVICE_ID_PREFIX + uuid,
7402
- '$device_id': uuid
7403
- }, '');
7409
+ var self = this;
7410
+
7411
+ var reset = function () {
7412
+ self['persistence'].clear();
7413
+ self._flags.identify_called = false;
7414
+ var uuid = _.UUID();
7415
+ self.register_once({
7416
+ 'distinct_id': DEVICE_ID_PREFIX + uuid,
7417
+ '$device_id': uuid
7418
+ }, '');
7419
+ };
7420
+
7421
+ if (self._recorder) {
7422
+ self.stop_session_recording()
7423
+ .then(function () {
7424
+ reset();
7425
+ self._check_and_start_session_recording();
7426
+ })
7427
+ .catch(_.bind(function (err) {
7428
+ reset();
7429
+ this.report_error('Error restarting recording session', err);
7430
+ }, this));
7431
+ } else {
7432
+ reset();
7433
+ }
7404
7434
  };
7405
7435
 
7406
7436
  /**
@@ -7711,6 +7741,16 @@
7711
7741
  return this['persistence'].load_prop([property_name]);
7712
7742
  };
7713
7743
 
7744
+ /**
7745
+ * Get the API host for a specific endpoint type, falling back to the default api_host if not specified
7746
+ *
7747
+ * @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
7748
+ * @returns {String} The API host to use for this endpoint
7749
+ */
7750
+ MixpanelLib.prototype.get_api_host = function(endpoint_type) {
7751
+ return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
7752
+ };
7753
+
7714
7754
  MixpanelLib.prototype.toString = function() {
7715
7755
  var name = this.get_config('name');
7716
7756
  if (name !== PRIMARY_INSTANCE_NAME) {
@@ -8006,6 +8046,7 @@
8006
8046
  MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
8007
8047
  MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
8008
8048
  MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
8049
+ MixpanelLib.prototype['get_api_host'] = MixpanelLib.prototype.get_api_host;
8009
8050
  MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
8010
8051
  MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
8011
8052
  MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;