Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3afb547
fetch api changes
AshwinSaxena01 Mar 6, 2025
3b74737
added enableFetchApi flag
AshwinSaxena01 Mar 6, 2025
b228081
Merge branch 'develop' into fetch-api
AshwinSaxena01 Mar 7, 2025
17c14e4
latest builds
AshwinSaxena01 Mar 7, 2025
2e4f83f
getter setter for enableFetchApi
AshwinSaxena01 Mar 10, 2025
ae3dc60
refactored init and added global var
AshwinSaxena01 Mar 10, 2025
d97c1d8
reverted token config change
AshwinSaxena01 Mar 10, 2025
d15da53
fixed typo
AshwinSaxena01 Mar 10, 2025
f2b2b98
added handleFetchResponse method
AshwinSaxena01 Mar 13, 2025
fed3ee2
added logger
AshwinSaxena01 Mar 17, 2025
468141d
Merge branch 'develop' into fetch-api
singhkunal2050 Jun 10, 2025
b298c47
Updated jest.config to handle async and await
KambleSonam Jun 24, 2025
4712430
Fixed the spec files
KambleSonam Jun 25, 2025
5971458
reverted jest.config.js file
KambleSonam Jun 26, 2025
b771d50
Merge remote-tracking branch 'origin/develop' into fetch-api
KambleSonam Jul 2, 2025
3c951a7
meta obj update
KambleSonam Jul 14, 2025
d4d8177
Merge remote-tracking branch 'origin/develop' into fetch-api
KambleSonam Jul 14, 2025
a8b8612
Merge remote-tracking branch 'origin/develop' into fetch-api
KambleSonam Jul 18, 2025
945be5b
corrected parsing of rn in meta
KambleSonam Jul 18, 2025
b1f4faf
changed logs from console to logger in Variablestore
KambleSonam Jul 18, 2025
daabb8c
updated build files
KambleSonam Jul 18, 2025
1d3bf9b
Merge remote-tracking branch 'origin/develop' into fetch-api
KambleSonam Jul 25, 2025
00f1fff
Updated changelog
KambleSonam Jul 25, 2025
a301e9f
SDK Release 2.2.0 (#463)
singhkunal2050 Aug 26, 2025
0ea74b7
Merge branch 'master' of github.com:CleverTap/clevertap-web-sdk into …
kkyusuftk Sep 1, 2025
109f4ff
fix: removed $ct dependency
kkyusuftk Sep 1, 2025
d47d5c6
removed async await
kkyusuftk Sep 2, 2025
a75f261
added new build files
kkyusuftk Sep 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [2.3.0] 2nd Sept 2025
- Added Fetch API support for network requests

## [2.2.0] 26th August 2025
- Added Isolate Sub-Domain flag in init fn.

Expand Down
100 changes: 91 additions & 9 deletions clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8544,6 +8544,59 @@
_classPrivateFieldLooseBase(this, _fireRequest)[_fireRequest](url, 1, skipARP, sendOULFlag, evtName);
}

static handleFetchResponse(url) {
return fetch(url, {
method: 'GET',
headers: {
Accept: 'application/json'
}
}).then(response => {
if (!response.ok) {
throw new Error("Network response was not ok: ".concat(response.statusText));
}

return response.json();
}).then(jsonResponse => {
const {
tr,
meta,
wpe
} = jsonResponse;

if (tr) {
window.$WZRK_WR.tr(tr);
}

if (meta) {
const {
g,
sid,
rf,
rn,
optOut
} = meta;

if (g && sid !== undefined && rf !== undefined && rn !== undefined) {
const parsedRn = parseInt(rn); // Include optOut as 5th parameter if present

if (optOut !== undefined) {
window.$WZRK_WR.s(g, sid, rf, parsedRn, optOut);
} else {
window.$WZRK_WR.s(g, sid, rf, parsedRn);
}
}
}

if (wpe) {
window.$WZRK_WR.enableWebPush(wpe.enabled, wpe.key);
}

this.logger.debug('req snt -> url: ' + url);
}).catch(error => {
this.logger.error('Fetch error:', error);
});
}

getDelayFrequency() {
this.logger.debug('Network retry #' + this.networkRetryCount); // Retry with delay as 1s for first 10 retries

Expand Down Expand Up @@ -8688,21 +8741,27 @@

while (ctCbScripts[0] && ctCbScripts[0].parentNode) {
ctCbScripts[0].parentNode.removeChild(ctCbScripts[0]);
} // Use the static flag instead of the global $ct map


if (!this.enableFetchApi) {
const s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('src', url);
s.setAttribute('class', 'ct-jp-cb');
s.setAttribute('rel', 'nofollow');
s.async = true;
document.getElementsByTagName('head')[0].appendChild(s);
this.logger.debug('req snt -> url: ' + url);
} else {
this.handleFetchResponse(url);
}

const s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('src', url);
s.setAttribute('class', 'ct-jp-cb');
s.setAttribute('rel', 'nofollow');
s.async = true;
document.getElementsByTagName('head')[0].appendChild(s);
this.logger.debug('req snt -> url: ' + url);
};

RequestDispatcher.logger = void 0;
RequestDispatcher.device = void 0;
RequestDispatcher.account = void 0;
RequestDispatcher.enableFetchApi = false;
Object.defineProperty(RequestDispatcher, _fireRequest, {
value: _fireRequest2
});
Expand Down Expand Up @@ -17158,6 +17217,8 @@

var _pageChangeTimeoutId = _classPrivateFieldLooseKey("pageChangeTimeoutId");

var _enableFetchApi = _classPrivateFieldLooseKey("enableFetchApi");

var _processOldValues = _classPrivateFieldLooseKey("processOldValues");

var _debounce = _classPrivateFieldLooseKey("debounce");
Expand Down Expand Up @@ -17204,6 +17265,16 @@
$ct.dismissSpamControl = dismissSpamControl;
}

get enableFetchApi() {
return _classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi];
}

set enableFetchApi(value) {
_classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi] = value; // propagate the setting to RequestDispatcher so util layer can honour it

RequestDispatcher.enableFetchApi = value;
}

constructor() {
var _clevertap$account, _clevertap$account2, _clevertap$account3, _clevertap$account4, _clevertap$account5, _clevertap$config, _clevertap$config2, _clevertap$dismissSpa, _clevertap$dismissSpa2, _clevertap$account6;

Expand Down Expand Up @@ -17285,6 +17356,10 @@
writable: true,
value: void 0
});
Object.defineProperty(this, _enableFetchApi, {
writable: true,
value: void 0
});
this.popupCallbacks = {};
this.popupCurrentWzrkId = '';
_classPrivateFieldLooseBase(this, _onloadcalled)[_onloadcalled] = 0;
Expand All @@ -17308,6 +17383,8 @@
});
_classPrivateFieldLooseBase(this, _dismissSpamControl)[_dismissSpamControl] = (_clevertap$dismissSpa = clevertap.dismissSpamControl) !== null && _clevertap$dismissSpa !== void 0 ? _clevertap$dismissSpa : true;
this.shpfyProxyPath = clevertap.shpfyProxyPath || '';
_classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi] = clevertap.enableFetchApi || false;
RequestDispatcher.enableFetchApi = _classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi];
_classPrivateFieldLooseBase(this, _session)[_session] = new SessionManager({
logger: _classPrivateFieldLooseBase(this, _logger)[_logger],
isPersonalisationActive: this._isPersonalisationActive
Expand Down Expand Up @@ -18029,6 +18106,11 @@

if (config === null || config === void 0 ? void 0 : config.customId) {
this.createCustomIdIfValid(config.customId);
}

if (config.enableFetchApi) {
_classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi] = config.enableFetchApi;
RequestDispatcher.enableFetchApi = config.enableFetchApi;
} // Only process OUL backup events if BLOCK_REQUEST_COOKIE is set
// This ensures user identity is established before other events

Expand Down
2 changes: 1 addition & 1 deletion clevertap.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions clevertap.min.js

Large diffs are not rendered by default.

22 changes: 8 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
"dependencies": {
"crypto-js": "^4.2.0"
}
}
}
20 changes: 20 additions & 0 deletions src/clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import User from './modules/user'
import { Logger, logLevels } from './modules/logger'
import SessionManager from './modules/session'
import ReqestManager from './modules/request'
import RequestDispatcher from './util/requestDispatcher'
import {
CAMP_COOKIE_NAME,
SCOOKIE_PREFIX,
Expand Down Expand Up @@ -71,6 +72,7 @@ export default class CleverTap {
#dismissSpamControl
enablePersonalization
#pageChangeTimeoutId
#enableFetchApi

get spa () {
return this.#isSpa
Expand Down Expand Up @@ -99,6 +101,16 @@ export default class CleverTap {
$ct.dismissSpamControl = dismissSpamControl
}

get enableFetchApi () {
return this.#enableFetchApi
}

set enableFetchApi (value) {
this.#enableFetchApi = value
// propagate the setting to RequestDispatcher so util layer can honour it
RequestDispatcher.enableFetchApi = value
}

constructor (clevertap = {}) {
this.#onloadcalled = 0
this._isPersonalisationActive = this._isPersonalisationActive.bind(this)
Expand All @@ -117,6 +129,8 @@ export default class CleverTap {
this.#device = new DeviceManager({ logger: this.#logger, customId: result?.isValid ? result?.sanitizedId : null })
this.#dismissSpamControl = clevertap.dismissSpamControl ?? true
this.shpfyProxyPath = clevertap.shpfyProxyPath || ''
this.#enableFetchApi = clevertap.enableFetchApi || false
RequestDispatcher.enableFetchApi = this.#enableFetchApi
this.#session = new SessionManager({
logger: this.#logger,
isPersonalisationActive: this._isPersonalisationActive
Expand Down Expand Up @@ -724,6 +738,12 @@ export default class CleverTap {
if (config?.customId) {
this.createCustomIdIfValid(config.customId)
}

if (config.enableFetchApi) {
this.#enableFetchApi = config.enableFetchApi
RequestDispatcher.enableFetchApi = config.enableFetchApi
}

// Only process OUL backup events if BLOCK_REQUEST_COOKIE is set
// This ensures user identity is established before other events
if (StorageManager.readFromLSorCookie(BLOCK_REQUEST_COOKIE) === true) {
Expand Down
Loading