1/** 2 * LiveNetwork â Ads Loader 3 * - Parte SOLO se esiste almeno 1 slot in pagina 4 * - Parte SOLO se Complianz marketing=true (se presente) 5 * - Carica GPT (async) + GAM (defer-like) una sola volta 6 * - Lazy: può aspettare che lâutente si avvicini agli slot 7 */ 8 9(function () { 10 "use strict"; 11 12 const CFG = window.LNV_ADS || {}; 13 if (!CFG.enabled) return; 14 15 const SLOT_SELECTOR = "[data-gam-slot]"; 16 const ROOT_MARGIN = String(CFG.rootMargin || "600px 0px"); 17 18 const GPT_SRC = String(CFG.gpt || ""); 19 const GAM_SRC = String(CFG.gam || ""); 20 21 if (!GPT_SRC || !GAM_SRC) return; 22 23 // ------------------------------------------------------------ 24 // Consent helpers (Complianz) 25 // ------------------------------------------------------------ 26 function hasMarketingConsent() { 27 try { 28 // Complianz: window.cmplz_consent_status.marketing === true 29 return !!( 30 window.cmplz_consent_status && 31 window.cmplz_consent_status.marketing === true 32 ); 33 } catch { 34 return false; 35 } 36 } 37 38 function waitForMarketingConsent(cb) { 39 // Se Complianz non esiste, assumo "ok" (o gestisci diversamente) 40 if (typeof window.cmplz_consent_status === "undefined") { 41 cb(); 42 return; 43 } 44 45 if (hasMarketingConsent()) { 46 cb(); 47 return; 48 } 49 50 // Aspetta cambio consenso (una volta) 51 document.addEventListener( 52 "cmplz_status_change", 53 function () { 54 if (hasMarketingConsent()) cb(); 55 }, 56 { once: true } 57 ); 58 } 59 60 // ------------------------------------------------------------ 61 // Loader scripts (dedupe) 62 // ------------------------------------------------------------ 63 function loadScript(src, opts) { 64 const { async = true } = opts || {}; 65 return new Promise((resolve, reject) => { 66 if (!src) return resolve(); 67 68 const existing = document.querySelector(`script[src="${src}"]`); 69 if (existing) return resolve(); 70 71 const s = document.createElement("script"); 72 s.src = src; 73 s.async = !!async; 74 75 // Complianz category (marketing) 76 s.setAttribute("data-category", "marketing"); 77 78 s.onload = () => resolve(); 79 s.onerror = () => reject(new Error("Failed loading " + src)); 80 81 document.head.appendChild(s); 82 }); 83 } 84 85 let started = false; 86 let startPromise = null; 87 88 function startAdsNow() { 89 if (started) return startPromise || Promise.resolve(); 90 started = true; 91 92 startPromise = (async () => { 93 // GPT async 94 await loadScript(GPT_SRC, { async: true }); 95 // GAM NON async (così esegue in ordine dopo GPT) 96 await loadScript(GAM_SRC, { async: false }); 97 98 // opzionale: se gam.js espone refresh, lo chiamiamo (non necessario) 99 if (window.LNV_GAM_REFRESH) { 100 try { 101 window.LNV_GAM_REFRESH(document); 102 } catch (_) {} 103 } 104 })(); 105 106 return startPromise; 107 } 108 109 // ------------------------------------------------------------ 110 // Trigger logic: solo se ci sono slot 111 // ------------------------------------------------------------ 112 function pageHasSlots() { 113 return !!document.querySelector(SLOT_SELECTOR); 114 } 115 116 function observeSlotsAndStart() { 117 if (!pageHasSlots()) return; 118 119 // Se non câè IO: parte subito (dopo consenso) 120 if (!("IntersectionObserver" in window)) { 121 waitForMarketingConsent(startAdsNow); 122 return; 123 } 124 125 const slots = Array.from(document.querySelectorAll(SLOT_SELECTOR)); 126 if (!slots.length) return; 127 128 const io = new IntersectionObserver( 129 (entries) => { 130 const hit = entries.some((e) => e.isIntersecting); 131 if (!hit) return; 132 133 io.disconnect(); 134 waitForMarketingConsent(startAdsNow); 135 }, 136 { rootMargin: ROOT_MARGIN } 137 ); 138 139 slots.forEach((el) => io.observe(el)); 140 } 141 142 // DOM ready (ma non bloccare) 143 if (document.readyState === "loading") { 144 document.addEventListener("DOMContentLoaded", observeSlotsAndStart, { 145 once: true, 146 });
147 } else { 148 observeSlotsAndStart(); 149 } 150})();
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.