@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.cjs
CHANGED
|
@@ -6308,8 +6308,8 @@ class ZaplierSDK {
|
|
|
6308
6308
|
*/
|
|
6309
6309
|
async makeRequest(endpoint, data, method = "POST") {
|
|
6310
6310
|
const url = `${this.config.apiEndpoint}${endpoint}`;
|
|
6311
|
-
// Always
|
|
6312
|
-
// Use anti-adblock as
|
|
6311
|
+
// Always try standard fetch first to get the response JSON (which contains visitorId)
|
|
6312
|
+
// Use anti-adblock as fallback if standard fetch is blocked or fails
|
|
6313
6313
|
const options = {
|
|
6314
6314
|
method,
|
|
6315
6315
|
headers: {
|
|
@@ -6320,7 +6320,12 @@ class ZaplierSDK {
|
|
|
6320
6320
|
options.body = JSON.stringify(data);
|
|
6321
6321
|
}
|
|
6322
6322
|
try {
|
|
6323
|
-
|
|
6323
|
+
// Add timeout to detect if fetch is blocked/hanging
|
|
6324
|
+
const fetchWithTimeout = Promise.race([
|
|
6325
|
+
fetch(url, options),
|
|
6326
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Fetch timeout - possibly blocked")), 5000)),
|
|
6327
|
+
]);
|
|
6328
|
+
const response = await fetchWithTimeout;
|
|
6324
6329
|
if (!response.ok) {
|
|
6325
6330
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
6326
6331
|
}
|
|
@@ -6336,23 +6341,30 @@ class ZaplierSDK {
|
|
|
6336
6341
|
return jsonResponse;
|
|
6337
6342
|
}
|
|
6338
6343
|
catch (error) {
|
|
6339
|
-
// If standard fetch fails, try anti-adblock as fallback
|
|
6344
|
+
// If standard fetch fails (blocked, timeout, or network error), try anti-adblock as fallback
|
|
6340
6345
|
if (this.antiAdblockManager && method === "POST") {
|
|
6346
|
+
if (this.config.debug) {
|
|
6347
|
+
console.warn(`[Zaplier] Standard fetch failed (${error instanceof Error ? error.message : String(error)}), trying anti-adblock fallback`);
|
|
6348
|
+
}
|
|
6341
6349
|
try {
|
|
6342
6350
|
const result = await this.antiAdblockManager.send(data, endpoint);
|
|
6343
6351
|
if (result.success) {
|
|
6344
6352
|
if (this.config.debug) {
|
|
6345
6353
|
console.log(`[Zaplier] Request sent via ${result.method} (${result.latency}ms) as fallback`);
|
|
6346
6354
|
}
|
|
6347
|
-
//
|
|
6348
|
-
// Note:
|
|
6349
|
-
//
|
|
6355
|
+
// Event was successfully sent via anti-adblock fallback
|
|
6356
|
+
// Note: visitorId will be obtained on the next successful request
|
|
6357
|
+
// (either standard fetch or anti-adblock) when the backend responds with it
|
|
6358
|
+
// This is acceptable because:
|
|
6359
|
+
// 1. The event was successfully tracked
|
|
6360
|
+
// 2. The visitorId will be available after the next event is sent
|
|
6361
|
+
// 3. Making an additional GET request here could also be blocked
|
|
6350
6362
|
return { success: true, method: result.method };
|
|
6351
6363
|
}
|
|
6352
6364
|
}
|
|
6353
6365
|
catch (antiAdblockError) {
|
|
6354
6366
|
if (this.config.debug) {
|
|
6355
|
-
console.warn("[Zaplier] Both standard fetch and anti-adblock failed");
|
|
6367
|
+
console.warn("[Zaplier] Both standard fetch and anti-adblock failed:", antiAdblockError);
|
|
6356
6368
|
}
|
|
6357
6369
|
}
|
|
6358
6370
|
}
|