mixpanel-browser 2.65.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.65.0'
13945
+ LIB_VERSION: '2.66.0'
13946
13946
  };
13947
13947
 
13948
13948
  /* eslint camelcase: "off", eqeqeq: "off" */
@@ -17349,8 +17349,8 @@ SessionRecording.prototype._sendRequest = function(currentReplayId, reqParams, r
17349
17349
  retryAfter: response.headers.get('Retry-After')
17350
17350
  });
17351
17351
  }.bind(this);
17352
-
17353
- 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), {
17354
17354
  'method': 'POST',
17355
17355
  'headers': {
17356
17356
  'Authorization': 'Basic ' + btoa(this.getConfig('token') + ':'),
@@ -17567,6 +17567,7 @@ var MixpanelRecorder = function(mixpanelInstance, rrwebRecord, sharedLockStorage
17567
17567
  this._flushInactivePromise = this.recordingRegistry.flushInactiveRecordings();
17568
17568
 
17569
17569
  this.activeRecording = null;
17570
+ this.stopRecordingInProgress = false;
17570
17571
  };
17571
17572
 
17572
17573
  MixpanelRecorder.prototype.startRecording = function(options) {
@@ -17615,19 +17616,26 @@ MixpanelRecorder.prototype.startRecording = function(options) {
17615
17616
  };
17616
17617
 
17617
17618
  MixpanelRecorder.prototype.stopRecording = function() {
17618
- var stopPromise = this._stopCurrentRecording(false);
17619
- this.recordingRegistry.clearActiveRecording();
17620
- this.activeRecording = null;
17621
- 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));
17622
17626
  };
17623
17627
 
17624
17628
  MixpanelRecorder.prototype.pauseRecording = function() {
17625
17629
  return this._stopCurrentRecording(false);
17626
17630
  };
17627
17631
 
17628
- MixpanelRecorder.prototype._stopCurrentRecording = function(skipFlush) {
17632
+ MixpanelRecorder.prototype._stopCurrentRecording = function(skipFlush, disableActiveRecording) {
17629
17633
  if (this.activeRecording) {
17630
- return this.activeRecording.stopRecording(skipFlush);
17634
+ var stopRecordingPromise = this.activeRecording.stopRecording(skipFlush);
17635
+ if (disableActiveRecording) {
17636
+ this.activeRecording = null;
17637
+ }
17638
+ return stopRecordingPromise;
17631
17639
  }
17632
17640
  return PromisePolyfill.resolve();
17633
17641
  };
@@ -17640,7 +17648,7 @@ MixpanelRecorder.prototype.resumeRecording = function (startNewIfInactive) {
17640
17648
 
17641
17649
  return this.recordingRegistry.getActiveRecording()
17642
17650
  .then(function (activeSerializedRecording) {
17643
- if (activeSerializedRecording) {
17651
+ if (activeSerializedRecording && !this.stopRecordingInProgress) {
17644
17652
  return this.startRecording({activeSerializedRecording: activeSerializedRecording});
17645
17653
  } else if (startNewIfInactive) {
17646
17654
  return this.startRecording({shouldStopBatcher: false});
@@ -19142,7 +19150,7 @@ MixpanelGroup.prototype._send_request = function(data, callback) {
19142
19150
  return this._mixpanel._track_or_batch({
19143
19151
  type: 'groups',
19144
19152
  data: date_encoded_data,
19145
- 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'],
19146
19154
  batcher: this._mixpanel.request_batchers.groups
19147
19155
  }, callback);
19148
19156
  };
@@ -19494,7 +19502,7 @@ MixpanelPeople.prototype._send_request = function(data, callback) {
19494
19502
  return this._mixpanel._track_or_batch({
19495
19503
  type: 'people',
19496
19504
  data: date_encoded_data,
19497
- 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'],
19498
19506
  batcher: this._mixpanel.request_batchers.people
19499
19507
  }, callback);
19500
19508
  };
@@ -20131,6 +20139,7 @@ var DEFAULT_API_ROUTES = {
20131
20139
  */
20132
20140
  var DEFAULT_CONFIG = {
20133
20141
  'api_host': 'https://api-js.mixpanel.com',
20142
+ 'api_hosts': {},
20134
20143
  'api_routes': DEFAULT_API_ROUTES,
20135
20144
  'api_extra_query_params': {},
20136
20145
  'api_method': 'POST',
@@ -20516,20 +20525,23 @@ MixpanelLib.prototype.start_session_recording = function () {
20516
20525
 
20517
20526
  MixpanelLib.prototype.stop_session_recording = function () {
20518
20527
  if (this._recorder) {
20519
- this._recorder['stopRecording']();
20528
+ return this._recorder['stopRecording']();
20520
20529
  }
20530
+ return Promise.resolve();
20521
20531
  };
20522
20532
 
20523
20533
  MixpanelLib.prototype.pause_session_recording = function () {
20524
20534
  if (this._recorder) {
20525
- this._recorder['pauseRecording']();
20535
+ return this._recorder['pauseRecording']();
20526
20536
  }
20537
+ return Promise.resolve();
20527
20538
  };
20528
20539
 
20529
20540
  MixpanelLib.prototype.resume_session_recording = function () {
20530
20541
  if (this._recorder) {
20531
- this._recorder['resumeRecording']();
20542
+ return this._recorder['resumeRecording']();
20532
20543
  }
20544
+ return Promise.resolve();
20533
20545
  };
20534
20546
 
20535
20547
  MixpanelLib.prototype.is_recording_heatmap_data = function () {
@@ -21129,7 +21141,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
21129
21141
  var ret = this._track_or_batch({
21130
21142
  type: 'events',
21131
21143
  data: data,
21132
- 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'],
21133
21145
  batcher: this.request_batchers.events,
21134
21146
  should_send_immediately: should_send_immediately,
21135
21147
  send_request_options: options
@@ -21631,15 +21643,31 @@ MixpanelLib.prototype.identify = function(
21631
21643
  * Useful for clearing data when a user logs out.
21632
21644
  */
21633
21645
  MixpanelLib.prototype.reset = function() {
21634
- this['persistence'].clear();
21635
- this._flags.identify_called = false;
21636
- var uuid = _.UUID();
21637
- this.register_once({
21638
- 'distinct_id': DEVICE_ID_PREFIX + uuid,
21639
- '$device_id': uuid
21640
- }, '');
21641
- this.stop_session_recording();
21642
- this._check_and_start_session_recording();
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
+ }
21643
21671
  };
21644
21672
 
21645
21673
  /**
@@ -21950,6 +21978,16 @@ MixpanelLib.prototype.get_property = function(property_name) {
21950
21978
  return this['persistence'].load_prop([property_name]);
21951
21979
  };
21952
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
+
21953
21991
  MixpanelLib.prototype.toString = function() {
21954
21992
  var name = this.get_config('name');
21955
21993
  if (name !== PRIMARY_INSTANCE_NAME) {
@@ -22245,6 +22283,7 @@ MixpanelLib.prototype['alias'] = MixpanelLib.protot
22245
22283
  MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
22246
22284
  MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
22247
22285
  MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
22286
+ MixpanelLib.prototype['get_api_host'] = MixpanelLib.prototype.get_api_host;
22248
22287
  MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
22249
22288
  MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
22250
22289
  MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
@@ -13948,7 +13948,7 @@
13948
13948
 
13949
13949
  var Config = {
13950
13950
  DEBUG: false,
13951
- LIB_VERSION: '2.65.0'
13951
+ LIB_VERSION: '2.66.0'
13952
13952
  };
13953
13953
 
13954
13954
  /* eslint camelcase: "off", eqeqeq: "off" */
@@ -17355,8 +17355,8 @@
17355
17355
  retryAfter: response.headers.get('Retry-After')
17356
17356
  });
17357
17357
  }.bind(this);
17358
-
17359
- win['fetch'](this.getConfig('api_host') + '/' + this.getConfig('api_routes')['record'] + '?' + new URLSearchParams(reqParams), {
17358
+ var apiHost = (this._mixpanel.get_api_host && this._mixpanel.get_api_host('record')) || this.getConfig('api_host');
17359
+ win['fetch'](apiHost + '/' + this.getConfig('api_routes')['record'] + '?' + new URLSearchParams(reqParams), {
17360
17360
  'method': 'POST',
17361
17361
  'headers': {
17362
17362
  'Authorization': 'Basic ' + btoa(this.getConfig('token') + ':'),
@@ -17573,6 +17573,7 @@
17573
17573
  this._flushInactivePromise = this.recordingRegistry.flushInactiveRecordings();
17574
17574
 
17575
17575
  this.activeRecording = null;
17576
+ this.stopRecordingInProgress = false;
17576
17577
  };
17577
17578
 
17578
17579
  MixpanelRecorder.prototype.startRecording = function(options) {
@@ -17621,19 +17622,26 @@
17621
17622
  };
17622
17623
 
17623
17624
  MixpanelRecorder.prototype.stopRecording = function() {
17624
- var stopPromise = this._stopCurrentRecording(false);
17625
- this.recordingRegistry.clearActiveRecording();
17626
- this.activeRecording = null;
17627
- return stopPromise;
17625
+ // Prevents activeSerializedRecording from being reused when stopping the recording.
17626
+ this.stopRecordingInProgress = true;
17627
+ return this._stopCurrentRecording(false, true).then(function() {
17628
+ return this.recordingRegistry.clearActiveRecording();
17629
+ }.bind(this)).then(function() {
17630
+ this.stopRecordingInProgress = false;
17631
+ }.bind(this));
17628
17632
  };
17629
17633
 
17630
17634
  MixpanelRecorder.prototype.pauseRecording = function() {
17631
17635
  return this._stopCurrentRecording(false);
17632
17636
  };
17633
17637
 
17634
- MixpanelRecorder.prototype._stopCurrentRecording = function(skipFlush) {
17638
+ MixpanelRecorder.prototype._stopCurrentRecording = function(skipFlush, disableActiveRecording) {
17635
17639
  if (this.activeRecording) {
17636
- return this.activeRecording.stopRecording(skipFlush);
17640
+ var stopRecordingPromise = this.activeRecording.stopRecording(skipFlush);
17641
+ if (disableActiveRecording) {
17642
+ this.activeRecording = null;
17643
+ }
17644
+ return stopRecordingPromise;
17637
17645
  }
17638
17646
  return PromisePolyfill.resolve();
17639
17647
  };
@@ -17646,7 +17654,7 @@
17646
17654
 
17647
17655
  return this.recordingRegistry.getActiveRecording()
17648
17656
  .then(function (activeSerializedRecording) {
17649
- if (activeSerializedRecording) {
17657
+ if (activeSerializedRecording && !this.stopRecordingInProgress) {
17650
17658
  return this.startRecording({activeSerializedRecording: activeSerializedRecording});
17651
17659
  } else if (startNewIfInactive) {
17652
17660
  return this.startRecording({shouldStopBatcher: false});
@@ -19148,7 +19156,7 @@
19148
19156
  return this._mixpanel._track_or_batch({
19149
19157
  type: 'groups',
19150
19158
  data: date_encoded_data,
19151
- endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
19159
+ endpoint: this._mixpanel.get_api_host('groups') + '/' + this._get_config('api_routes')['groups'],
19152
19160
  batcher: this._mixpanel.request_batchers.groups
19153
19161
  }, callback);
19154
19162
  };
@@ -19500,7 +19508,7 @@
19500
19508
  return this._mixpanel._track_or_batch({
19501
19509
  type: 'people',
19502
19510
  data: date_encoded_data,
19503
- endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
19511
+ endpoint: this._mixpanel.get_api_host('people') + '/' + this._get_config('api_routes')['engage'],
19504
19512
  batcher: this._mixpanel.request_batchers.people
19505
19513
  }, callback);
19506
19514
  };
@@ -20137,6 +20145,7 @@
20137
20145
  */
20138
20146
  var DEFAULT_CONFIG = {
20139
20147
  'api_host': 'https://api-js.mixpanel.com',
20148
+ 'api_hosts': {},
20140
20149
  'api_routes': DEFAULT_API_ROUTES,
20141
20150
  'api_extra_query_params': {},
20142
20151
  'api_method': 'POST',
@@ -20522,20 +20531,23 @@
20522
20531
 
20523
20532
  MixpanelLib.prototype.stop_session_recording = function () {
20524
20533
  if (this._recorder) {
20525
- this._recorder['stopRecording']();
20534
+ return this._recorder['stopRecording']();
20526
20535
  }
20536
+ return Promise.resolve();
20527
20537
  };
20528
20538
 
20529
20539
  MixpanelLib.prototype.pause_session_recording = function () {
20530
20540
  if (this._recorder) {
20531
- this._recorder['pauseRecording']();
20541
+ return this._recorder['pauseRecording']();
20532
20542
  }
20543
+ return Promise.resolve();
20533
20544
  };
20534
20545
 
20535
20546
  MixpanelLib.prototype.resume_session_recording = function () {
20536
20547
  if (this._recorder) {
20537
- this._recorder['resumeRecording']();
20548
+ return this._recorder['resumeRecording']();
20538
20549
  }
20550
+ return Promise.resolve();
20539
20551
  };
20540
20552
 
20541
20553
  MixpanelLib.prototype.is_recording_heatmap_data = function () {
@@ -21135,7 +21147,7 @@
21135
21147
  var ret = this._track_or_batch({
21136
21148
  type: 'events',
21137
21149
  data: data,
21138
- endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
21150
+ endpoint: this.get_api_host('events') + '/' + this.get_config('api_routes')['track'],
21139
21151
  batcher: this.request_batchers.events,
21140
21152
  should_send_immediately: should_send_immediately,
21141
21153
  send_request_options: options
@@ -21637,15 +21649,31 @@
21637
21649
  * Useful for clearing data when a user logs out.
21638
21650
  */
21639
21651
  MixpanelLib.prototype.reset = function() {
21640
- this['persistence'].clear();
21641
- this._flags.identify_called = false;
21642
- var uuid = _.UUID();
21643
- this.register_once({
21644
- 'distinct_id': DEVICE_ID_PREFIX + uuid,
21645
- '$device_id': uuid
21646
- }, '');
21647
- this.stop_session_recording();
21648
- this._check_and_start_session_recording();
21652
+ var self = this;
21653
+
21654
+ var reset = function () {
21655
+ self['persistence'].clear();
21656
+ self._flags.identify_called = false;
21657
+ var uuid = _.UUID();
21658
+ self.register_once({
21659
+ 'distinct_id': DEVICE_ID_PREFIX + uuid,
21660
+ '$device_id': uuid
21661
+ }, '');
21662
+ };
21663
+
21664
+ if (self._recorder) {
21665
+ self.stop_session_recording()
21666
+ .then(function () {
21667
+ reset();
21668
+ self._check_and_start_session_recording();
21669
+ })
21670
+ .catch(_.bind(function (err) {
21671
+ reset();
21672
+ this.report_error('Error restarting recording session', err);
21673
+ }, this));
21674
+ } else {
21675
+ reset();
21676
+ }
21649
21677
  };
21650
21678
 
21651
21679
  /**
@@ -21956,6 +21984,16 @@
21956
21984
  return this['persistence'].load_prop([property_name]);
21957
21985
  };
21958
21986
 
21987
+ /**
21988
+ * Get the API host for a specific endpoint type, falling back to the default api_host if not specified
21989
+ *
21990
+ * @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
21991
+ * @returns {String} The API host to use for this endpoint
21992
+ */
21993
+ MixpanelLib.prototype.get_api_host = function(endpoint_type) {
21994
+ return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
21995
+ };
21996
+
21959
21997
  MixpanelLib.prototype.toString = function() {
21960
21998
  var name = this.get_config('name');
21961
21999
  if (name !== PRIMARY_INSTANCE_NAME) {
@@ -22251,6 +22289,7 @@
22251
22289
  MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
22252
22290
  MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
22253
22291
  MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
22292
+ MixpanelLib.prototype['get_api_host'] = MixpanelLib.prototype.get_api_host;
22254
22293
  MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
22255
22294
  MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
22256
22295
  MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mixpanel-browser",
3
- "version": "2.65.0",
3
+ "version": "2.66.0",
4
4
  "description": "The official Mixpanel JavaScript browser client library",
5
5
  "main": "dist/mixpanel.cjs.js",
6
6
  "module": "dist/mixpanel.module.js",
@@ -22,6 +22,7 @@
22
22
  "unit-test": "BABEL_ENV=test mocha --require babel-core/register tests/unit/*.js",
23
23
  "validate": "npm ls"
24
24
  },
25
+ "types": "./src/index.d.ts",
25
26
  "repository": {
26
27
  "type": "git",
27
28
  "url": "https://github.com/mixpanel/mixpanel-js.git"
package/src/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var Config = {
2
2
  DEBUG: false,
3
- LIB_VERSION: '2.65.0'
3
+ LIB_VERSION: '2.66.0'
4
4
  };
5
5
 
6
6
  export default Config;