Skip to content

Commit 63d755e

Browse files
chrisknuClaude
and
Claude
committed
refactor to simpler api_host config
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 67bd268 commit 63d755e

17 files changed

+268
-185
lines changed

dist/mixpanel-core.cjs.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4620,7 +4620,7 @@ MixpanelGroup.prototype._send_request = function(data, callback) {
46204620
return this._mixpanel._track_or_batch({
46214621
type: 'groups',
46224622
data: date_encoded_data,
4623-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
4623+
endpoint: this._mixpanel._getApiHost('groups') + '/' + this._get_config('api_routes')['groups'],
46244624
batcher: this._mixpanel.request_batchers.groups
46254625
}, callback);
46264626
};
@@ -4982,7 +4982,7 @@ MixpanelPeople.prototype._send_request = function(data, callback) {
49824982
return this._mixpanel._track_or_batch({
49834983
type: 'people',
49844984
data: date_encoded_data,
4985-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
4985+
endpoint: this._mixpanel._getApiHost('people') + '/' + this._get_config('api_routes')['engage'],
49864986
batcher: this._mixpanel.request_batchers.people
49874987
}, callback);
49884988
};
@@ -5740,6 +5740,7 @@ var DEFAULT_API_ROUTES = {
57405740
*/
57415741
var DEFAULT_CONFIG = {
57425742
'api_host': 'https://api-js.mixpanel.com',
5743+
'api_hosts': {},
57435744
'api_routes': DEFAULT_API_ROUTES,
57445745
'api_method': 'POST',
57455746
'api_transport': 'XHR',
@@ -5797,7 +5798,6 @@ var DEFAULT_CONFIG = {
57975798
'record_min_ms': 0,
57985799
'record_sessions_percent': 0,
57995800
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js',
5800-
'session_recording_use_proxy': false,
58015801
};
58025802

58035803
var DOM_LOADED = false;
@@ -6722,7 +6722,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
67226722
var ret = this._track_or_batch({
67236723
type: 'events',
67246724
data: data,
6725-
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
6725+
endpoint: this._getApiHost('events') + '/' + this.get_config('api_routes')['track'],
67266726
batcher: this.request_batchers.events,
67276727
should_send_immediately: should_send_immediately,
67286728
send_request_options: options
@@ -7536,6 +7536,17 @@ MixpanelLib.prototype.get_property = function(property_name) {
75367536
return this['persistence'].load_prop([property_name]);
75377537
};
75387538

7539+
/**
7540+
* Get the API host for a specific endpoint type, falling back to the default api_host if not specified
7541+
*
7542+
* @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
7543+
* @returns {String} The API host to use for this endpoint
7544+
* @private
7545+
*/
7546+
MixpanelLib.prototype._getApiHost = function(endpoint_type) {
7547+
return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
7548+
};
7549+
75397550
MixpanelLib.prototype.toString = function() {
75407551
var name = this.get_config('name');
75417552
if (name !== PRIMARY_INSTANCE_NAME) {

dist/mixpanel-recorder.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mixpanel-recorder.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mixpanel-with-async-recorder.cjs.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4620,7 +4620,7 @@ MixpanelGroup.prototype._send_request = function(data, callback) {
46204620
return this._mixpanel._track_or_batch({
46214621
type: 'groups',
46224622
data: date_encoded_data,
4623-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
4623+
endpoint: this._mixpanel._getApiHost('groups') + '/' + this._get_config('api_routes')['groups'],
46244624
batcher: this._mixpanel.request_batchers.groups
46254625
}, callback);
46264626
};
@@ -4982,7 +4982,7 @@ MixpanelPeople.prototype._send_request = function(data, callback) {
49824982
return this._mixpanel._track_or_batch({
49834983
type: 'people',
49844984
data: date_encoded_data,
4985-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
4985+
endpoint: this._mixpanel._getApiHost('people') + '/' + this._get_config('api_routes')['engage'],
49864986
batcher: this._mixpanel.request_batchers.people
49874987
}, callback);
49884988
};
@@ -5740,6 +5740,7 @@ var DEFAULT_API_ROUTES = {
57405740
*/
57415741
var DEFAULT_CONFIG = {
57425742
'api_host': 'https://api-js.mixpanel.com',
5743+
'api_hosts': {},
57435744
'api_routes': DEFAULT_API_ROUTES,
57445745
'api_method': 'POST',
57455746
'api_transport': 'XHR',
@@ -5797,7 +5798,6 @@ var DEFAULT_CONFIG = {
57975798
'record_min_ms': 0,
57985799
'record_sessions_percent': 0,
57995800
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js',
5800-
'session_recording_use_proxy': false,
58015801
};
58025802

58035803
var DOM_LOADED = false;
@@ -6722,7 +6722,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
67226722
var ret = this._track_or_batch({
67236723
type: 'events',
67246724
data: data,
6725-
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
6725+
endpoint: this._getApiHost('events') + '/' + this.get_config('api_routes')['track'],
67266726
batcher: this.request_batchers.events,
67276727
should_send_immediately: should_send_immediately,
67286728
send_request_options: options
@@ -7536,6 +7536,17 @@ MixpanelLib.prototype.get_property = function(property_name) {
75367536
return this['persistence'].load_prop([property_name]);
75377537
};
75387538

7539+
/**
7540+
* Get the API host for a specific endpoint type, falling back to the default api_host if not specified
7541+
*
7542+
* @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
7543+
* @returns {String} The API host to use for this endpoint
7544+
* @private
7545+
*/
7546+
MixpanelLib.prototype._getApiHost = function(endpoint_type) {
7547+
return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
7548+
};
7549+
75397550
MixpanelLib.prototype.toString = function() {
75407551
var name = this.get_config('name');
75417552
if (name !== PRIMARY_INSTANCE_NAME) {

dist/mixpanel.amd.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8336,7 +8336,7 @@ define((function () { 'use strict';
83368336
retryAfter: response.headers.get('Retry-After')
83378337
});
83388338
}.bind(this);
8339-
const apiHost = this.getConfig('session_recording_use_proxy') ? this.getConfig('api_host') : 'https://api.mixpanel.com';
8339+
const apiHost = this._mixpanel.get_config('api_hosts')['record'] || 'https://api.mixpanel.com';
83408340

83418341
win['fetch'](apiHost + '/' + this.getConfig('api_routes')['record'] + '?' + new URLSearchParams(reqParams), {
83428342
'method': 'POST',
@@ -9923,7 +9923,7 @@ define((function () { 'use strict';
99239923
return this._mixpanel._track_or_batch({
99249924
type: 'groups',
99259925
data: date_encoded_data,
9926-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
9926+
endpoint: this._mixpanel._getApiHost('groups') + '/' + this._get_config('api_routes')['groups'],
99279927
batcher: this._mixpanel.request_batchers.groups
99289928
}, callback);
99299929
};
@@ -10285,7 +10285,7 @@ define((function () { 'use strict';
1028510285
return this._mixpanel._track_or_batch({
1028610286
type: 'people',
1028710287
data: date_encoded_data,
10288-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
10288+
endpoint: this._mixpanel._getApiHost('people') + '/' + this._get_config('api_routes')['engage'],
1028910289
batcher: this._mixpanel.request_batchers.people
1029010290
}, callback);
1029110291
};
@@ -10920,6 +10920,7 @@ define((function () { 'use strict';
1092010920
*/
1092110921
var DEFAULT_CONFIG = {
1092210922
'api_host': 'https://api-js.mixpanel.com',
10923+
'api_hosts': {},
1092310924
'api_routes': DEFAULT_API_ROUTES,
1092410925
'api_method': 'POST',
1092510926
'api_transport': 'XHR',
@@ -10977,7 +10978,6 @@ define((function () { 'use strict';
1097710978
'record_min_ms': 0,
1097810979
'record_sessions_percent': 0,
1097910980
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js',
10980-
'session_recording_use_proxy': false,
1098110981
};
1098210982

1098310983
var DOM_LOADED = false;
@@ -11902,7 +11902,7 @@ define((function () { 'use strict';
1190211902
var ret = this._track_or_batch({
1190311903
type: 'events',
1190411904
data: data,
11905-
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
11905+
endpoint: this._getApiHost('events') + '/' + this.get_config('api_routes')['track'],
1190611906
batcher: this.request_batchers.events,
1190711907
should_send_immediately: should_send_immediately,
1190811908
send_request_options: options
@@ -12716,6 +12716,17 @@ define((function () { 'use strict';
1271612716
return this['persistence'].load_prop([property_name]);
1271712717
};
1271812718

12719+
/**
12720+
* Get the API host for a specific endpoint type, falling back to the default api_host if not specified
12721+
*
12722+
* @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
12723+
* @returns {String} The API host to use for this endpoint
12724+
* @private
12725+
*/
12726+
MixpanelLib.prototype._getApiHost = function(endpoint_type) {
12727+
return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
12728+
};
12729+
1271912730
MixpanelLib.prototype.toString = function() {
1272012731
var name = this.get_config('name');
1272112732
if (name !== PRIMARY_INSTANCE_NAME) {

dist/mixpanel.cjs.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8336,7 +8336,7 @@ SessionRecording.prototype._sendRequest = function(currentReplayId, reqParams, r
83368336
retryAfter: response.headers.get('Retry-After')
83378337
});
83388338
}.bind(this);
8339-
const apiHost = this.getConfig('session_recording_use_proxy') ? this.getConfig('api_host') : 'https://api.mixpanel.com';
8339+
const apiHost = this._mixpanel.get_config('api_hosts')['record'] || 'https://api.mixpanel.com';
83408340

83418341
win['fetch'](apiHost + '/' + this.getConfig('api_routes')['record'] + '?' + new URLSearchParams(reqParams), {
83428342
'method': 'POST',
@@ -9923,7 +9923,7 @@ MixpanelGroup.prototype._send_request = function(data, callback) {
99239923
return this._mixpanel._track_or_batch({
99249924
type: 'groups',
99259925
data: date_encoded_data,
9926-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
9926+
endpoint: this._mixpanel._getApiHost('groups') + '/' + this._get_config('api_routes')['groups'],
99279927
batcher: this._mixpanel.request_batchers.groups
99289928
}, callback);
99299929
};
@@ -10285,7 +10285,7 @@ MixpanelPeople.prototype._send_request = function(data, callback) {
1028510285
return this._mixpanel._track_or_batch({
1028610286
type: 'people',
1028710287
data: date_encoded_data,
10288-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
10288+
endpoint: this._mixpanel._getApiHost('people') + '/' + this._get_config('api_routes')['engage'],
1028910289
batcher: this._mixpanel.request_batchers.people
1029010290
}, callback);
1029110291
};
@@ -10920,6 +10920,7 @@ var DEFAULT_API_ROUTES = {
1092010920
*/
1092110921
var DEFAULT_CONFIG = {
1092210922
'api_host': 'https://api-js.mixpanel.com',
10923+
'api_hosts': {},
1092310924
'api_routes': DEFAULT_API_ROUTES,
1092410925
'api_method': 'POST',
1092510926
'api_transport': 'XHR',
@@ -10977,7 +10978,6 @@ var DEFAULT_CONFIG = {
1097710978
'record_min_ms': 0,
1097810979
'record_sessions_percent': 0,
1097910980
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js',
10980-
'session_recording_use_proxy': false,
1098110981
};
1098210982

1098310983
var DOM_LOADED = false;
@@ -11902,7 +11902,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
1190211902
var ret = this._track_or_batch({
1190311903
type: 'events',
1190411904
data: data,
11905-
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
11905+
endpoint: this._getApiHost('events') + '/' + this.get_config('api_routes')['track'],
1190611906
batcher: this.request_batchers.events,
1190711907
should_send_immediately: should_send_immediately,
1190811908
send_request_options: options
@@ -12716,6 +12716,17 @@ MixpanelLib.prototype.get_property = function(property_name) {
1271612716
return this['persistence'].load_prop([property_name]);
1271712717
};
1271812718

12719+
/**
12720+
* Get the API host for a specific endpoint type, falling back to the default api_host if not specified
12721+
*
12722+
* @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
12723+
* @returns {String} The API host to use for this endpoint
12724+
* @private
12725+
*/
12726+
MixpanelLib.prototype._getApiHost = function(endpoint_type) {
12727+
return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
12728+
};
12729+
1271912730
MixpanelLib.prototype.toString = function() {
1272012731
var name = this.get_config('name');
1272112732
if (name !== PRIMARY_INSTANCE_NAME) {

dist/mixpanel.globals.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,7 +4621,7 @@
46214621
return this._mixpanel._track_or_batch({
46224622
type: 'groups',
46234623
data: date_encoded_data,
4624-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
4624+
endpoint: this._mixpanel._getApiHost('groups') + '/' + this._get_config('api_routes')['groups'],
46254625
batcher: this._mixpanel.request_batchers.groups
46264626
}, callback);
46274627
};
@@ -4983,7 +4983,7 @@
49834983
return this._mixpanel._track_or_batch({
49844984
type: 'people',
49854985
data: date_encoded_data,
4986-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
4986+
endpoint: this._mixpanel._getApiHost('people') + '/' + this._get_config('api_routes')['engage'],
49874987
batcher: this._mixpanel.request_batchers.people
49884988
}, callback);
49894989
};
@@ -5741,6 +5741,7 @@
57415741
*/
57425742
var DEFAULT_CONFIG = {
57435743
'api_host': 'https://api-js.mixpanel.com',
5744+
'api_hosts': {},
57445745
'api_routes': DEFAULT_API_ROUTES,
57455746
'api_method': 'POST',
57465747
'api_transport': 'XHR',
@@ -5798,7 +5799,6 @@
57985799
'record_min_ms': 0,
57995800
'record_sessions_percent': 0,
58005801
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js',
5801-
'session_recording_use_proxy': false,
58025802
};
58035803

58045804
var DOM_LOADED = false;
@@ -6723,7 +6723,7 @@
67236723
var ret = this._track_or_batch({
67246724
type: 'events',
67256725
data: data,
6726-
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
6726+
endpoint: this._getApiHost('events') + '/' + this.get_config('api_routes')['track'],
67276727
batcher: this.request_batchers.events,
67286728
should_send_immediately: should_send_immediately,
67296729
send_request_options: options
@@ -7537,6 +7537,17 @@
75377537
return this['persistence'].load_prop([property_name]);
75387538
};
75397539

7540+
/**
7541+
* Get the API host for a specific endpoint type, falling back to the default api_host if not specified
7542+
*
7543+
* @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
7544+
* @returns {String} The API host to use for this endpoint
7545+
* @private
7546+
*/
7547+
MixpanelLib.prototype._getApiHost = function(endpoint_type) {
7548+
return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
7549+
};
7550+
75407551
MixpanelLib.prototype.toString = function() {
75417552
var name = this.get_config('name');
75427553
if (name !== PRIMARY_INSTANCE_NAME) {

dist/mixpanel.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,7 +4621,7 @@
46214621
return this._mixpanel._track_or_batch({
46224622
type: 'groups',
46234623
data: date_encoded_data,
4624-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
4624+
endpoint: this._mixpanel._getApiHost('groups') + '/' + this._get_config('api_routes')['groups'],
46254625
batcher: this._mixpanel.request_batchers.groups
46264626
}, callback);
46274627
};
@@ -4983,7 +4983,7 @@
49834983
return this._mixpanel._track_or_batch({
49844984
type: 'people',
49854985
data: date_encoded_data,
4986-
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
4986+
endpoint: this._mixpanel._getApiHost('people') + '/' + this._get_config('api_routes')['engage'],
49874987
batcher: this._mixpanel.request_batchers.people
49884988
}, callback);
49894989
};
@@ -5741,6 +5741,7 @@
57415741
*/
57425742
var DEFAULT_CONFIG = {
57435743
'api_host': 'https://api-js.mixpanel.com',
5744+
'api_hosts': {},
57445745
'api_routes': DEFAULT_API_ROUTES,
57455746
'api_method': 'POST',
57465747
'api_transport': 'XHR',
@@ -5798,7 +5799,6 @@
57985799
'record_min_ms': 0,
57995800
'record_sessions_percent': 0,
58005801
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js',
5801-
'session_recording_use_proxy': false,
58025802
};
58035803

58045804
var DOM_LOADED = false;
@@ -6723,7 +6723,7 @@
67236723
var ret = this._track_or_batch({
67246724
type: 'events',
67256725
data: data,
6726-
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
6726+
endpoint: this._getApiHost('events') + '/' + this.get_config('api_routes')['track'],
67276727
batcher: this.request_batchers.events,
67286728
should_send_immediately: should_send_immediately,
67296729
send_request_options: options
@@ -7537,6 +7537,17 @@
75377537
return this['persistence'].load_prop([property_name]);
75387538
};
75397539

7540+
/**
7541+
* Get the API host for a specific endpoint type, falling back to the default api_host if not specified
7542+
*
7543+
* @param {String} endpoint_type The type of endpoint (e.g., "events", "people", "groups")
7544+
* @returns {String} The API host to use for this endpoint
7545+
* @private
7546+
*/
7547+
MixpanelLib.prototype._getApiHost = function(endpoint_type) {
7548+
return this.get_config('api_hosts')[endpoint_type] || this.get_config('api_host');
7549+
};
7550+
75407551
MixpanelLib.prototype.toString = function() {
75417552
var name = this.get_config('name');
75427553
if (name !== PRIMARY_INSTANCE_NAME) {

0 commit comments

Comments
 (0)