@zaplier/sdk 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +20 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +20 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +20 -8
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/sdk.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -6304,8 +6304,8 @@ class ZaplierSDK {
|
|
|
6304
6304
|
*/
|
|
6305
6305
|
async makeRequest(endpoint, data, method = "POST") {
|
|
6306
6306
|
const url = `${this.config.apiEndpoint}${endpoint}`;
|
|
6307
|
-
// Always
|
|
6308
|
-
// Use anti-adblock as
|
|
6307
|
+
// Always try standard fetch first to get the response JSON (which contains visitorId)
|
|
6308
|
+
// Use anti-adblock as fallback if standard fetch is blocked or fails
|
|
6309
6309
|
const options = {
|
|
6310
6310
|
method,
|
|
6311
6311
|
headers: {
|
|
@@ -6316,7 +6316,12 @@ class ZaplierSDK {
|
|
|
6316
6316
|
options.body = JSON.stringify(data);
|
|
6317
6317
|
}
|
|
6318
6318
|
try {
|
|
6319
|
-
|
|
6319
|
+
// Add timeout to detect if fetch is blocked/hanging
|
|
6320
|
+
const fetchWithTimeout = Promise.race([
|
|
6321
|
+
fetch(url, options),
|
|
6322
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Fetch timeout - possibly blocked")), 5000)),
|
|
6323
|
+
]);
|
|
6324
|
+
const response = await fetchWithTimeout;
|
|
6320
6325
|
if (!response.ok) {
|
|
6321
6326
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
6322
6327
|
}
|
|
@@ -6332,23 +6337,30 @@ class ZaplierSDK {
|
|
|
6332
6337
|
return jsonResponse;
|
|
6333
6338
|
}
|
|
6334
6339
|
catch (error) {
|
|
6335
|
-
// If standard fetch fails, try anti-adblock as fallback
|
|
6340
|
+
// If standard fetch fails (blocked, timeout, or network error), try anti-adblock as fallback
|
|
6336
6341
|
if (this.antiAdblockManager && method === "POST") {
|
|
6342
|
+
if (this.config.debug) {
|
|
6343
|
+
console.warn(`[Zaplier] Standard fetch failed (${error instanceof Error ? error.message : String(error)}), trying anti-adblock fallback`);
|
|
6344
|
+
}
|
|
6337
6345
|
try {
|
|
6338
6346
|
const result = await this.antiAdblockManager.send(data, endpoint);
|
|
6339
6347
|
if (result.success) {
|
|
6340
6348
|
if (this.config.debug) {
|
|
6341
6349
|
console.log(`[Zaplier] Request sent via ${result.method} (${result.latency}ms) as fallback`);
|
|
6342
6350
|
}
|
|
6343
|
-
//
|
|
6344
|
-
// Note:
|
|
6345
|
-
//
|
|
6351
|
+
// Event was successfully sent via anti-adblock fallback
|
|
6352
|
+
// Note: visitorId will be obtained on the next successful request
|
|
6353
|
+
// (either standard fetch or anti-adblock) when the backend responds with it
|
|
6354
|
+
// This is acceptable because:
|
|
6355
|
+
// 1. The event was successfully tracked
|
|
6356
|
+
// 2. The visitorId will be available after the next event is sent
|
|
6357
|
+
// 3. Making an additional GET request here could also be blocked
|
|
6346
6358
|
return { success: true, method: result.method };
|
|
6347
6359
|
}
|
|
6348
6360
|
}
|
|
6349
6361
|
catch (antiAdblockError) {
|
|
6350
6362
|
if (this.config.debug) {
|
|
6351
|
-
console.warn("[Zaplier] Both standard fetch and anti-adblock failed");
|
|
6363
|
+
console.warn("[Zaplier] Both standard fetch and anti-adblock failed:", antiAdblockError);
|
|
6352
6364
|
}
|
|
6353
6365
|
}
|
|
6354
6366
|
}
|