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