Skip to content
Open
Show file tree
Hide file tree
Changes from 15 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
85 changes: 75 additions & 10 deletions clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7442,7 +7442,8 @@
globalUnsubscribe: true,
flutterVersion: null,
variableStore: {},
pushConfig: null // domain: window.location.hostname, url -> getHostName()
pushConfig: null,
enableFetchApi: false // domain: window.location.hostname, url -> getHostName()
// gcookie: -> device

};
Expand Down Expand Up @@ -8476,6 +8477,44 @@
_classPrivateFieldLooseBase(this, _fireRequest)[_fireRequest](url, 1, skipARP, sendOULFlag, evtName);
}

static async handleFetchResponse(url) {
try {
const response = await fetch(url, {
method: 'GET',
headers: {
Accept: 'application/json'
}
});

if (!response.ok) {
throw new Error("Network response was not ok: ".concat(response.statusText));
}

const jsonResponse = await response.json();
const {
tr,
meta,
wpe
} = jsonResponse;

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

if (meta) {
window.$WZRK_WR.s(meta);
}

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 @@ -8542,7 +8581,7 @@
return this.device.gcookie.slice(-3) === OPTOUT_COOKIE_ENDSWITH;
};

var _fireRequest2 = function _fireRequest2(url, tries, skipARP, sendOULFlag, evtName) {
var _fireRequest2 = async function _fireRequest2(url, tries, skipARP, sendOULFlag, evtName) {
var _window$clevertap, _window$wizrocket;

if (_classPrivateFieldLooseBase(this, _dropRequestDueToOptOut)[_dropRequestDueToOptOut]()) {
Expand Down Expand Up @@ -8620,14 +8659,18 @@
ctCbScripts[0].parentNode.removeChild(ctCbScripts[0]);
}

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);
if (!$ct.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);
}
};

RequestDispatcher.logger = void 0;
Expand Down Expand Up @@ -16143,6 +16186,8 @@

var _pageChangeTimeoutId = _classPrivateFieldLooseKey("pageChangeTimeoutId");

var _enableFetchApi = _classPrivateFieldLooseKey("enableFetchApi");

var _processOldValues = _classPrivateFieldLooseKey("processOldValues");

var _debounce = _classPrivateFieldLooseKey("debounce");
Expand Down Expand Up @@ -16189,6 +16234,15 @@
$ct.dismissSpamControl = dismissSpamControl;
}

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

set enableFetchApi(value) {
_classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi] = value;
$ct.enableFetchApi = value;
}

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

Expand Down Expand Up @@ -16270,6 +16324,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 @@ -16293,6 +16351,7 @@
});
_classPrivateFieldLooseBase(this, _dismissSpamControl)[_dismissSpamControl] = clevertap.dismissSpamControl || false;
this.shpfyProxyPath = clevertap.shpfyProxyPath || '';
_classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi] = clevertap.enableFetchApi || false;
_classPrivateFieldLooseBase(this, _session)[_session] = new SessionManager({
logger: _classPrivateFieldLooseBase(this, _logger)[_logger],
isPersonalisationActive: this._isPersonalisationActive
Expand Down Expand Up @@ -16347,6 +16406,7 @@
});
this.spa = clevertap.spa;
this.dismissSpamControl = clevertap.dismissSpamControl;
this.enableFetchApi = clevertap.enableFetchApi;
this.user = new User({
isPersonalisationActive: this._isPersonalisationActive
});
Expand Down Expand Up @@ -17010,6 +17070,11 @@
this.createCustomIdIfValid(config.customId);
}

if (config.enableFetchApi) {
_classPrivateFieldLooseBase(this, _enableFetchApi)[_enableFetchApi] = config.enableFetchApi;
$ct.enableFetchApi = config.enableFetchApi;
}

const currLocation = location.href;
const urlParams = getURLParams(currLocation.toLowerCase()); // eslint-disable-next-line eqeqeq

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clevertap.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"jest": "^26.4.2",
"regenerator-runtime": "^0.14.1",
"rollup": "^2.26.5",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-sourcemaps": "^0.6.3",
Expand Down
17 changes: 17 additions & 0 deletions src/clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class CleverTap {
#dismissSpamControl
enablePersonalization
#pageChangeTimeoutId
#enableFetchApi

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

get enableFetchApi () {
return this.#enableFetchApi
}

set enableFetchApi (value) {
this.#enableFetchApi = value
$ct.enableFetchApi = value
}

constructor (clevertap = {}) {
this.#onloadcalled = 0
this._isPersonalisationActive = this._isPersonalisationActive.bind(this)
Expand All @@ -114,6 +124,7 @@ export default class CleverTap {
this.#device = new DeviceManager({ logger: this.#logger, customId: result?.isValid ? result?.sanitizedId : null })
this.#dismissSpamControl = clevertap.dismissSpamControl || false
this.shpfyProxyPath = clevertap.shpfyProxyPath || ''
this.#enableFetchApi = clevertap.enableFetchApi || false
this.#session = new SessionManager({
logger: this.#logger,
isPersonalisationActive: this._isPersonalisationActive
Expand Down Expand Up @@ -175,6 +186,7 @@ export default class CleverTap {

this.spa = clevertap.spa
this.dismissSpamControl = clevertap.dismissSpamControl
this.enableFetchApi = clevertap.enableFetchApi

this.user = new User({
isPersonalisationActive: this._isPersonalisationActive
Expand Down Expand Up @@ -717,6 +729,11 @@ export default class CleverTap {
this.createCustomIdIfValid(config.customId)
}

if (config.enableFetchApi) {
this.#enableFetchApi = config.enableFetchApi
$ct.enableFetchApi = config.enableFetchApi
}

const currLocation = location.href
const urlParams = getURLParams(currLocation.toLowerCase())

Expand Down
45 changes: 36 additions & 9 deletions src/util/requestDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class RequestDispatcher {
minDelayFrequency = 0

// ANCHOR - Requests get fired from here
static #fireRequest (url, tries, skipARP, sendOULFlag, evtName) {
static async #fireRequest (url, tries, skipARP, sendOULFlag, evtName) {
if (this.#dropRequestDueToOptOut()) {
this.logger.debug('req dropped due to optout cookie: ' + this.device.gcookie)
return
Expand Down Expand Up @@ -82,14 +82,18 @@ export default class RequestDispatcher {
while (ctCbScripts[0] && ctCbScripts[0].parentNode) {
ctCbScripts[0].parentNode.removeChild(ctCbScripts[0])
}
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)
if (!$ct.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)
}
}

/**
Expand Down Expand Up @@ -130,6 +134,29 @@ export default class RequestDispatcher {
return url
}

static async handleFetchResponse (url) {
try {
const response = await fetch(url, { method: 'GET', headers: { Accept: 'application/json' } })
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`)
}
const jsonResponse = await response.json()
const { tr, meta, wpe } = jsonResponse
if (tr) {
window.$WZRK_WR.tr(tr)
}
if (meta) {
window.$WZRK_WR.s(meta)
}
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)

Expand Down
3 changes: 2 additions & 1 deletion src/util/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ export const $ct = {
globalUnsubscribe: true,
flutterVersion: null,
variableStore: {},
pushConfig: null
pushConfig: null,
enableFetchApi: false
// domain: window.location.hostname, url -> getHostName()
// gcookie: -> device
}
Loading
Loading