@zaplier/sdk 1.0.0 → 1.0.1
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 +43 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +43 -29
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +43 -29
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/modules/anti-adblock.d.ts.map +1 -1
- package/dist/src/sdk.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4834,7 +4834,7 @@ class ResourceSpoofTransport {
|
|
|
4834
4834
|
class WebRTCTransport {
|
|
4835
4835
|
constructor() {
|
|
4836
4836
|
this.name = 'webrtc';
|
|
4837
|
-
this.available = typeof RTCPeerConnection !== 'undefined';
|
|
4837
|
+
this.available = typeof globalThis.RTCPeerConnection !== 'undefined';
|
|
4838
4838
|
this.connected = false;
|
|
4839
4839
|
}
|
|
4840
4840
|
async send(data, endpoint) {
|
|
@@ -4873,7 +4873,7 @@ class WebRTCTransport {
|
|
|
4873
4873
|
return;
|
|
4874
4874
|
return new Promise((resolve, reject) => {
|
|
4875
4875
|
try {
|
|
4876
|
-
this.pc = new RTCPeerConnection({
|
|
4876
|
+
this.pc = new globalThis.RTCPeerConnection({
|
|
4877
4877
|
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
|
|
4878
4878
|
});
|
|
4879
4879
|
this.dataChannel = this.pc.createDataChannel('tracking', {
|
|
@@ -6307,30 +6307,9 @@ class ZaplierSDK {
|
|
|
6307
6307
|
* Make HTTP request to backend using anti-adblock system
|
|
6308
6308
|
*/
|
|
6309
6309
|
async makeRequest(endpoint, data, method = "POST") {
|
|
6310
|
-
// Use anti-adblock manager if available
|
|
6311
|
-
if (this.antiAdblockManager && method === "POST") {
|
|
6312
|
-
try {
|
|
6313
|
-
const result = await this.antiAdblockManager.send(data, endpoint);
|
|
6314
|
-
if (result.success) {
|
|
6315
|
-
if (this.config.debug) {
|
|
6316
|
-
console.log(`[Zaplier] Request sent via ${result.method} (${result.latency}ms)`);
|
|
6317
|
-
}
|
|
6318
|
-
// Return success response for compatibility
|
|
6319
|
-
return { success: true, method: result.method };
|
|
6320
|
-
}
|
|
6321
|
-
else {
|
|
6322
|
-
throw new Error(`Anti-adblock failed: ${result.error}`);
|
|
6323
|
-
}
|
|
6324
|
-
}
|
|
6325
|
-
catch (error) {
|
|
6326
|
-
if (this.config.debug) {
|
|
6327
|
-
console.warn("[Zaplier] Anti-adblock failed, falling back to standard fetch");
|
|
6328
|
-
}
|
|
6329
|
-
// Fall through to standard fetch
|
|
6330
|
-
}
|
|
6331
|
-
}
|
|
6332
|
-
// Fallback to standard fetch
|
|
6333
6310
|
const url = `${this.config.apiEndpoint}${endpoint}`;
|
|
6311
|
+
// Always use standard fetch to get the response JSON (which contains visitorId)
|
|
6312
|
+
// Use anti-adblock as a parallel fallback method if standard fetch fails
|
|
6334
6313
|
const options = {
|
|
6335
6314
|
method,
|
|
6336
6315
|
headers: {
|
|
@@ -6340,11 +6319,46 @@ class ZaplierSDK {
|
|
|
6340
6319
|
if (method === "POST" && data) {
|
|
6341
6320
|
options.body = JSON.stringify(data);
|
|
6342
6321
|
}
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6322
|
+
try {
|
|
6323
|
+
const response = await fetch(url, options);
|
|
6324
|
+
if (!response.ok) {
|
|
6325
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
6326
|
+
}
|
|
6327
|
+
const jsonResponse = await response.json();
|
|
6328
|
+
// If anti-adblock is enabled, also send via anti-adblock as a backup
|
|
6329
|
+
// (but don't wait for it or use its response)
|
|
6330
|
+
if (this.antiAdblockManager && method === "POST") {
|
|
6331
|
+
// Send in parallel without blocking
|
|
6332
|
+
this.antiAdblockManager.send(data, endpoint).catch(() => {
|
|
6333
|
+
// Silently fail - we already got the response from standard fetch
|
|
6334
|
+
});
|
|
6335
|
+
}
|
|
6336
|
+
return jsonResponse;
|
|
6337
|
+
}
|
|
6338
|
+
catch (error) {
|
|
6339
|
+
// If standard fetch fails, try anti-adblock as fallback
|
|
6340
|
+
if (this.antiAdblockManager && method === "POST") {
|
|
6341
|
+
try {
|
|
6342
|
+
const result = await this.antiAdblockManager.send(data, endpoint);
|
|
6343
|
+
if (result.success) {
|
|
6344
|
+
if (this.config.debug) {
|
|
6345
|
+
console.log(`[Zaplier] Request sent via ${result.method} (${result.latency}ms) as fallback`);
|
|
6346
|
+
}
|
|
6347
|
+
// Try to get response from a separate request
|
|
6348
|
+
// Note: This is a limitation - we can't get visitorId from anti-adblock transports
|
|
6349
|
+
// But at least the event was sent
|
|
6350
|
+
return { success: true, method: result.method };
|
|
6351
|
+
}
|
|
6352
|
+
}
|
|
6353
|
+
catch (antiAdblockError) {
|
|
6354
|
+
if (this.config.debug) {
|
|
6355
|
+
console.warn("[Zaplier] Both standard fetch and anti-adblock failed");
|
|
6356
|
+
}
|
|
6357
|
+
}
|
|
6358
|
+
}
|
|
6359
|
+
// Re-throw original error if all methods failed
|
|
6360
|
+
throw error;
|
|
6346
6361
|
}
|
|
6347
|
-
return response.json();
|
|
6348
6362
|
}
|
|
6349
6363
|
/**
|
|
6350
6364
|
* Process queued events
|