1document.addEventListener("DOMContentLoaded", () => { 2 console.log("[DEBUG] Intercetto chiamate gtag per i consensi..."); 3 4 // Salva il gtag originale 5 const originalGtag = window.gtag; 6 7 window.gtag = function() { 8 try { 9 // Logga tutto per debug 10 console.log("[DEBUG] gtag chiamato con argomenti:", arguments); 11 12 // Se è una chiamata di consenso 13 if (arguments[0] === "consent" && arguments[1] === "update") { 14 const consentObj = arguments[2] || {}; 15 console.log("[DEBUG] Consent object rilevato:", consentObj); 16 17 const adStorage = consentObj.ad_storage === "granted"; 18 const functionalityStorage = consentObj.functionality_storage === "granted"; 19 20 console.log(`[DEBUG] ad_storage: ${adStorage}, functionality_storage: ${functionalityStorage}`); 21 22 if (adStorage && functionalityStorage) { 23 console.log("[DEBUG] Consensi OK â invio richiesta AJAX con 'consenso dato'..."); 24 ediSendRequest("ok_consent"); 25 } else { 26 console.log("[DEBUG] Consensi NON sufficienti â invio richiesta AJAX con 'consenso non_dato'..."); 27 ediSendRequest("ko_consent"); 28 } 29 } 30 } catch (err) { 31 console.error("[DEBUG] Errore intercettando gtag:", err); 32 } 33 34 // Chiama comunque il gtag originale 35 if (typeof originalGtag === "function") { 36 originalGtag.apply(this, arguments); 37 } 38 }; 39 40 async function ediSendRequest(consent) { 41 const action = 'recaptcha'; 42 const endpoints = [ 43 `/wp-json/edi-service-pack/v1/backend-requests/${action}/`, 44 `/ediapi/edi-service-pack/v1/backend-requests/${action}/` 45 ]; 46 47 let lastError = null; 48 49 for (const url of endpoints) { 50 try { 51 // console.log("[DEBUG] Tentativo con URL:", url); 52 53 const response = await fetch(url, { 54 method: 'POST', 55 headers: { 'Content-Type': 'application/json' }, 56 body: JSON.stringify({ consent: consent }) 57 }); 58 59 console.log("[DEBUG] Status HTTP:", response.status); 60 61 if (response.ok) { 62 const result = await response.json(); 63 console.log("[DEBUG] Risposta dal server:", result); 64 return result; // esce subito se funziona 65 } else { 66 // se 404 o altro errore, provo il prossimo 67 lastError = new Error("HTTP " + response.status); 68 } 69 } catch (error) { 70 console.error("[DEBUG] Errore fetch:", error); 71 lastError = error; 72 } 73 } 74 75 // se arrivi qui, nessun endpoint ha risposto 76 throw lastError || new Error("Nessun endpoint disponibile"); 77 } 78});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.