Skip to content

Commit 5d47871

Browse files
committed
feat: support for proxy url for bypassing ad-blockers
1 parent b45849e commit 5d47871

File tree

12 files changed

+145
-25
lines changed

12 files changed

+145
-25
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.73.0] - 2025-08-18
9+
10+
### Added
11+
12+
- Added support for redirecting all network calls through a custom proxy URL for browser environments. This feature allows users to route all SDK network requests (settings, tracking, etc.) through their own proxy server. This is particularly useful for bypassing ad-blockers that may interfere with VWO's default network requests.
13+
14+
```javascript
15+
const settingsFile = await vwoSdk.getSettingsFile(accountId, sdkKey, null, { proxyUrl: 'http://localhost:3000' });
16+
17+
// If you are not calling getSettingsFile and are using locally stored settings,
18+
// you can pass the proxyUrl directly in the launch method.
19+
const clientInstance = vwoSdk.launch({
20+
settingsFile: localSettings, // local json parsed settings
21+
proxyUrl: 'http://localhost:3000', // your custome proxy url here
22+
});
23+
```
24+
825
## [1.72.0] - 2025-02-25
926

1027
### Feat

dist/vwo-javascript-sdk.js

Lines changed: 58 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vwo-javascript-sdk.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/vwo-javascript-sdk.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vwo-javascript-sdk.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.

lib/VWO.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ class VWO {
5151
this.logger = config.logger;
5252
this.returnPromiseFor = config.returnPromiseFor;
5353
this.asyncStorageConfig = config.asyncStorageConfig;
54+
this.proxyUrl = config.proxyUrl;
55+
56+
// set proxy url in the settings file if it is provided
57+
if (config.settingsFile && DataTypeUtil.isObject(config.settingsFile) && this.proxyUrl) {
58+
config.settingsFile.proxyUrl = this.proxyUrl;
59+
}
5460
this.optOut = false;
5561

5662
if (this.userStorageService === undefined && config.asyncStorageConfig) {

lib/constants/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ module.exports = {
5151
HTTPS_PROTOCOL: 'https://',
5252

5353
SDK_QUERY_PARAM: 'sdk',
54-
SDK_VERSION_QUERY_PARAM: 'sdk-v'
54+
SDK_VERSION_QUERY_PARAM: 'sdk-v',
55+
SERVER_SIDE: 'server-side'
5556
};

lib/index.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ declare module 'vwo-node-sdk' {
2222
*
2323
* @returns Settings file.
2424
*/
25-
export function getSettingsFile(accountId: string, apiKey: string, userStorageService?: VWOUserStorageConfig): Promise<object>;
25+
export function getSettingsFile(accountId: string, apiKey: string, userStorageService?: VWOUserStorageConfig, config?: VWOGetSettingsFileExternalConfig): Promise<object>;
26+
27+
/**
28+
* VWO Get Settings File Configuration
29+
*/
30+
export interface VWOGetSettingsFileExternalConfig {
31+
proxyUrl?: string;
32+
}
2633

2734
/**
2835
* Creates an instance of the VWO
@@ -391,6 +398,11 @@ declare module 'vwo-node-sdk' {
391398
*/
392399
callback?: (properties: Record<string, any>) => void;
393400
};
401+
402+
/**
403+
* Proxy URL for the VWO SDK
404+
*/
405+
proxyUrl?: string;
394406
}
395407

396408
// For synchronous code

lib/utils/ImpressionUtil.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ let ImpressionUtil = {
6969
*/
7070
buildEventForPushing(configObj, tagKey, tagValue, userId) {
7171
const properties = Object.assign({}, getBaseProperties(configObj, userId));
72-
properties.url = Constants.HTTPS_PROTOCOL + UrlService.getBaseUrl() + UrlEnum.PUSH;
72+
properties.url = this._buildUrlWithProxy(configObj, UrlEnum.PUSH);
7373
properties.tags = JSON.stringify({
7474
u: {
7575
[encodeURIComponent(tagKey)]: encodeURIComponent(tagValue)
@@ -143,7 +143,7 @@ let ImpressionUtil = {
143143
usageStats
144144
);
145145
properties.ed = JSON.stringify({ p: 'server' });
146-
properties.url = Constants.HTTPS_PROTOCOL + UrlService.getBaseUrl() + UrlEnum.TRACK_USER;
146+
properties.url = this._buildUrlWithProxy(configObj, UrlEnum.TRACK_USER);
147147

148148
logger.log(
149149
LogLevelEnum.DEBUG,
@@ -229,7 +229,7 @@ let ImpressionUtil = {
229229

230230
properties.visitor_ua = visitorUserAgent;
231231
properties.visitor_ip = userIpAddress;
232-
properties.url = Constants.HTTPS_PROTOCOL + UrlService.getBaseUrl() + UrlEnum.TRACK_GOAL;
232+
properties.url = this._buildUrlWithProxy(configObj, UrlEnum.TRACK_GOAL);
233233

234234
properties['goal_id'] = goalId;
235235
if (goal.type === GoalTypeEnum.REVENUE && ValidateUtil.isValidValue(revenue)) {
@@ -337,7 +337,8 @@ let ImpressionUtil = {
337337
usageStats
338338
);
339339

340-
properties.url = Constants.HTTPS_PROTOCOL + UrlService.getBaseUrl() + UrlEnum.EVENTS;
340+
properties.url = this._buildUrlWithProxy(config, UrlEnum.EVENTS);
341+
341342
return properties;
342343
},
343344

@@ -513,6 +514,27 @@ let ImpressionUtil = {
513514
const logProperties = Object.assign({}, properties);
514515
delete logProperties.env;
515516
return JSON.stringify(logProperties);
517+
},
518+
519+
/**
520+
* Builds the url with proxy url if it is provided
521+
* @param {Object} configObj
522+
* @param {String} event
523+
* @returns {String} url with proxy url if it is provided
524+
*/
525+
_buildUrlWithProxy(configObj, event) {
526+
let url = Constants.HTTPS_PROTOCOL + UrlService.getBaseUrl() + event;
527+
// if we are in browser environment and not in serverless environment
528+
if (typeof process.env === 'undefined' && typeof XMLHttpRequest !== 'undefined') {
529+
if (configObj.proxyUrl) {
530+
if (configObj.collectionPrefix) {
531+
url = configObj.proxyUrl + '/' + configObj.collectionPrefix + event;
532+
} else {
533+
url = configObj.proxyUrl + event;
534+
}
535+
}
536+
}
537+
return url;
516538
}
517539
};
518540

lib/utils/SettingsFileUtil.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,24 @@ let SettingsFileUtil = {
4848
hostname = config.hostname || hostname;
4949
path = config.path || path;
5050
}
51+
let url;
52+
if (config.proxyUrl) {
53+
url = `${config.proxyUrl}${path}`;
54+
} else {
55+
url = `${protocol}://${hostname}${path}`;
56+
}
5157

5258
if (typeof process.env === 'undefined') {
5359
if (typeof XMLHttpRequest === 'undefined') {
5460
return require('./FetchUtil').send({
5561
method: 'GET',
56-
url: `${protocol}://${hostname}${path}`,
62+
url: url,
5763
userStorageService
5864
});
5965
}
6066
return require('./XhrUtil').send({
6167
method: 'GET',
62-
url: `${protocol}://${hostname}${path}`,
68+
url: url,
6369
userStorageService
6470
});
6571
} else {

0 commit comments

Comments
 (0)