Skip to content

Commit e968fed

Browse files
committed
[sc-9487] add option in setApiHostname to apply only for search or stats endpoint
1 parent 8171597 commit e968fed

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ client.setThrottleTime(500);
408408
```
409409

410410
#### Set API hostname
411+
`option` is an object with the following properties, all of which are optional. If `option` is not defined, host name will be applied for all requests.
412+
- **searchApiRequestOnly**: If true, the new host name is only applied for searchApi requests (default: false)
413+
- **statsApiRequestOnly**: If true, the new host name is only applied for statsApi requests (default: false)
411414
```js
412415
// Set API hostname (e.g. for dedicated environments)
413416
client.setApiHostname('api.addsearch.com');

src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var client = function(sitekey, privatekey) {
1616
this.sitekey = sitekey;
1717
this.privatekey = privatekey;
1818
this.apiHostname = API_HOSTNAME;
19+
this.statsApiHostname = API_HOSTNAME;
1920
this.settings = new Settings();
2021
this.sessionId = ('a-' + (Math.random() * 100000000)).substring(0, 10);
2122
this.userTokenInPersonalization = cookie.getCookie(USER_TOKEN_COOKIE_NAME) || util.generateUUID();
@@ -174,7 +175,14 @@ var client = function(sitekey, privatekey) {
174175
/**
175176
* Public functions
176177
*/
177-
this.setApiHostname = function(hostname) {this.apiHostname = hostname;}
178+
this.setApiHostname = function(hostname, conf) {
179+
if (!conf || !conf.statsApiRequestOnly) {
180+
this.apiHostname = hostname;
181+
}
182+
if (!conf || !conf.searchApiRequestOnly) {
183+
this.statsApiHostname = hostname;
184+
}
185+
}
178186
this.getSettings = function() {return this.settings.getSettings();}
179187
this.setLanguage = function(lang) {this.settings.setLanguage(lang);}
180188
this.setCategoryFilters = function(categories) {this.settings.setCategoryFilters(categories);}
@@ -228,7 +236,7 @@ var client = function(sitekey, privatekey) {
228236
numberOfResults: data.numberOfResults,
229237
tag: this.getSettings().analyticsTag
230238
};
231-
sendStats(this.apiHostname, this.sitekey, payload, this.settings.getSettings().statsRequestIntercepted);
239+
sendStats(this.statsApiHostname, this.sitekey, payload, this.settings.getSettings().statsRequestIntercepted);
232240
}
233241

234242
else if (type === 'click') {
@@ -240,7 +248,7 @@ var client = function(sitekey, privatekey) {
240248
position: data.position,
241249
tag: this.getSettings().analyticsTag
242250
};
243-
sendStats(this.apiHostname, this.sitekey, payload, this.settings.getSettings().statsRequestIntercepted);
251+
sendStats(this.statsApiHostname, this.sitekey, payload, this.settings.getSettings().statsRequestIntercepted);
244252
}
245253

246254
else {

0 commit comments

Comments
 (0)