universal-ad-loader 0.1.1 → 0.2.0
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/CHANGELOG.md +24 -0
- package/README.md +58 -4
- package/dist/index.cjs +363 -46
- package/dist/index.d.ts +46 -4
- package/dist/index.mjs +363 -46
- package/dist/ual.js +363 -46
- package/dist/ual.min.js +24 -5
- package/docs/cdn.md +30 -15
- package/docs/esempio.md +1 -1
- package/package.json +3 -3
- package/schema/ual-config.schema.json +9 -1
package/dist/ual.min.js
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
|
-
(()=>{function
|
|
2
|
-
|
|
1
|
+
(()=>{function he(){let e={};return{on(t,n){return(e[t]=e[t]||[]).push(n),()=>this.off(t,n)},off(t,n){e[t]=(e[t]||[]).filter(r=>r!==n)},emit(t,n){[...e[t]||[],...e["*"]||[]].forEach(r=>{try{r(n,t)}catch(o){console.error("[UAL] handler error",t,o)}})}}}var ge="[UAL]",Q=!1;try{Q=/[?&]ual_debug=1/.test(location.search)||localStorage.getItem("ual_debug")==="1"}catch(e){}function ie(e){Q=!!e}function ye(){return Q}function L(...e){Q&&console.log(ge,...e)}function k(...e){console.warn(ge,...e)}function R(e,t={}){return new Promise((n,r)=>{let o=document.querySelector(`script[data-ual-src="${e}"]`);if(o){if(o.dataset.loaded)return n();o.addEventListener("load",()=>n()),o.addEventListener("error",r);return}let s=document.createElement("script");s.async=!0,s.src=e,s.dataset.ualSrc=e,Object.entries(t).forEach(([a,c])=>s.setAttribute(a,c)),s.onload=()=>{s.dataset.loaded="1",n()},s.onerror=()=>r(new Error("Script load failed: "+e)),document.head.appendChild(s)})}function ve(e,t){return e.replace(/\{([\w.]+)\}/g,(n,r)=>{let o=r.split(".").reduce((s,a)=>s==null?void 0:s[a],t);return o==null?"":encodeURIComponent(String(o))})}function O(e){(e||[]).forEach(t=>{if(!t)return;try{if(navigator.sendBeacon&&navigator.sendBeacon(t))return}catch(r){}let n=new Image(1,1);n.src=t})}function B(e,t,n){let r;return Promise.race([e,new Promise(o=>{r=setTimeout(()=>o(n),t)})]).finally(()=>clearTimeout(r))}function J(){return Math.floor(Math.random()*1e10)}function be(){let e=window.innerWidth||document.documentElement.clientWidth;return e<768?"mobile":e<1024?"tablet":"desktop"}var vt={site:null,consent:{mode:"tcf",timeoutMs:4e3,requiredPurposes:[1]},lazy:{enabled:!0,fetchMargin:"200px"},viewability:{threshold:.5,durationMs:1e3},collapseEmpty:!0,providerTimeoutMs:3e3,targeting:{},providers:{},slots:{},pageRules:[]};async function xe(e){let t=e;if(typeof e=="string"){let n=await fetch(e,{credentials:"omit"});if(!n.ok)throw new Error("Config HTTP "+n.status);t=await n.json()}return Se(vt,t||{})}var we=["optional","required","contextual"];function Ee(e,t){let n=r=>k("Config: "+r);e.site||n('manca "site"');for(let[r,o]of Object.entries(e.providers||{})){if(!o||!o.adapter){n(`provider "${r}" senza "adapter"`);continue}t&&!t.has(o.adapter)&&n(`provider "${r}": adapter "${o.adapter}" non registrato (registralo con registerAdapter prima dell'init)`),o.consent&&!we.includes(o.consent)&&n(`provider "${r}": consent "${o.consent}" non valido (${we.join("|")})`)}for(let[r,o]of Object.entries(e.slots||{})){if(!o||!Array.isArray(o.providers)||!o.providers.length){n(`slot "${r}" senza "providers"`);continue}o.providers.forEach(s=>{let a=typeof s=="string"?s:s&&s.id;(!a||!e.providers[a])&&n(`slot "${r}": provider "${a}" non definito in "providers"`)})}}function Se(e,t){let n={...e};for(let r of Object.keys(t)){let o=t[r];n[r]=o&&typeof o=="object"&&!Array.isArray(o)&&e[r]&&typeof e[r]=="object"&&!Array.isArray(e[r])?Se(e[r],o):o}return n}function ke(e,t=location.pathname){let n={...e,slots:JSON.parse(JSON.stringify(e.slots)),targeting:{...e.targeting}};for(let r of e.pageRules||[]){let o;try{o=new RegExp(r.match)}catch(s){k("pageRule regex non valida",r.match);continue}o.test(t)&&((r.disable||[]).forEach(s=>{n.slots[s]&&(n.slots[s].enabled=!1)}),(r.enable||[]).forEach(s=>{n.slots[s]&&(n.slots[s].enabled=!0)}),Object.assign(n.targeting,r.targeting||{}),Object.entries(r.slots||{}).forEach(([s,a])=>{n.slots[s]={...n.slots[s],...a}}))}return n}function Ae(e){let t=window.innerWidth||document.documentElement.clientWidth;if(Array.isArray(e.sizeMapping)&&e.sizeMapping.length){let n=[...e.sizeMapping].sort((r,o)=>o.minWidth-r.minWidth).find(r=>t>=r.minWidth);return n?n.sizes:[]}return e.sizes||[]}function Te(e){return new Promise(t=>{if(typeof window.__tcfapi=="function")return t(!0);let n=Date.now(),r=setInterval(()=>{typeof window.__tcfapi=="function"?(clearInterval(r),t(!0)):Date.now()-n>e&&(clearInterval(r),t(!1))},50)})}function Ce(e,t){window.__tcfapi("addEventListener",2,(n,r)=>{!r||!n||(n.gdprApplies===!1||n.eventStatus==="tcloaded"||n.eventStatus==="useractioncomplete")&&t(bt(n,e))})}var Ie=Symbol("timeout");async function ze(e={},t){let n={mode:"tcf",timeoutMs:4e3,cmpWaitMs:1500,lateWatchMs:3e4,requiredPurposes:[1],vendorId:null,...e};if(n.mode==="none")return{gdprApplies:!1,tcString:"",purposes:{},granted:!0,source:"none"};if(!await Te(n.cmpWaitMs))return L("Nessuna CMP TCF trovata (continuo a cercarla)"),t&&Te(n.lateWatchMs).then(c=>{c&&Ce(n,t)}),{gdprApplies:void 0,tcString:"",purposes:{},granted:!1,source:"no-cmp"};let o=!1,s=new Promise(c=>{Ce(n,d=>{o?t&&t(d):(o=!0,c(d))})}),a=await B(s,n.timeoutMs,Ie);return o=!0,a===Ie?{gdprApplies:!0,tcString:"",purposes:{},granted:!1,source:"timeout"}:a}function bt(e,t){let n=e.purpose&&e.purpose.consents||{},r=e.vendor&&e.vendor.consents||{},o=e.gdprApplies===!1||t.requiredPurposes.every(a=>n[a]===!0);o&&e.gdprApplies!==!1&&t.vendorId&&(o=r[t.vendorId]===!0);let s={gdprApplies:e.gdprApplies,tcString:e.tcString||"",purposes:n,vendorConsents:r,granted:o,source:"tcf"};return L("Consenso",s.granted?"OK":"limitato",s),s}var j={title:150,body:300,sponsoredBy:60,cta:30,displayUrl:100,price:30,label:20},wt=["card","list","compact"],q=(e,t)=>typeof e=="string"?e.trim().slice(0,t):"";function Le(e,t){if(!e||typeof e!="object")return{ok:!1,reason:"native mancante"};let n=q(e.title,j.title);if(!n)return{ok:!1,reason:"native: titolo mancante"};let r=s=>{let a=typeof s=="string"?{src:s}:s,c=a&&typeof a=="object"?t(a.src,!0):null;if(!c)return null;let d=f=>{let p=Math.round(Number(f));return p>0&&p<=2e3?p:0};return{src:c,width:d(a.width),height:d(a.height)}},o=Number(e.rating);return{ok:!0,native:{title:n,body:q(e.body,j.body),sponsoredBy:q(e.sponsoredBy,j.sponsoredBy),cta:q(e.cta,j.cta),displayUrl:q(e.displayUrl,j.displayUrl),price:q(e.price,j.price),rating:Number.isFinite(o)&&o>=0&&o<=5?o:null,image:r(e.image),icon:r(e.icon),layout:wt.includes(e.layout)?e.layout:"card",label:q(e.label,j.label)||"Sponsored"}}}var xt=`
|
|
2
|
+
:host{display:block;max-width:100%;font:inherit;color:inherit;line-height:1.35}
|
|
3
|
+
*{box-sizing:border-box}
|
|
4
|
+
.card{display:flex;flex-direction:column;gap:.5em;padding:.75em;text-decoration:none;color:inherit;border:1px solid var(--ual-native-border,rgba(128,128,128,.35));border-radius:var(--ual-native-radius,8px);background:var(--ual-native-bg,transparent);position:relative}
|
|
5
|
+
a.card:hover .title{text-decoration:underline}
|
|
6
|
+
.label{font-size:.72em;letter-spacing:.04em;text-transform:uppercase;opacity:.75}
|
|
7
|
+
.main{display:block;width:100%;height:auto;border-radius:calc(var(--ual-native-radius,8px) - 2px);background:rgba(128,128,128,.12)}
|
|
8
|
+
.row{display:flex;gap:.6em;align-items:flex-start}
|
|
9
|
+
.icon{width:2.4em;height:2.4em;flex:none;border-radius:6px;object-fit:cover}
|
|
10
|
+
.title{font-weight:700;font-size:1.05em}
|
|
11
|
+
.body{opacity:.9;font-size:.92em}
|
|
12
|
+
.meta{font-size:.8em;opacity:.7}
|
|
13
|
+
.cta{align-self:flex-start;font-weight:600;font-size:.9em;padding:.35em .8em;border-radius:999px;background:var(--ual-native-accent,#2563eb);color:var(--ual-native-accent-text,#fff)}
|
|
14
|
+
.price{font-weight:600}
|
|
15
|
+
.layout-list{flex-direction:row;align-items:flex-start}
|
|
16
|
+
.layout-list .main{width:35%;max-width:180px;flex:none}
|
|
17
|
+
.layout-list .text{display:flex;flex-direction:column;gap:.35em;min-width:0}
|
|
18
|
+
.layout-compact .main{display:none}
|
|
19
|
+
`;function A(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function Me(e,t,n){let r=A("img",t);return r.src=e.src,r.alt=n||"",r.loading="lazy",r.referrerPolicy="strict-origin-when-cross-origin",e.width&&e.height&&(r.width=e.width,r.height=e.height),r}function Oe(e,t,{onClick:n}={}){let r=t.native,o=A("div","ual-native"),s=o.attachShadow?o.attachShadow({mode:"open"}):o,a=document.createElement("style");a.textContent=xt,s.appendChild(a);let c=t.clickUrl?A("a",`card layout-${r.layout}`):A("div",`card layout-${r.layout}`);t.clickUrl&&(c.href=t.clickUrl,c.target="_blank",c.rel="noopener noreferrer sponsored nofollow",c.addEventListener("click",()=>{n&&n()})),c.appendChild(A("span","label",r.label)),r.image&&c.appendChild(Me(r.image,"main",r.title));let d=A("div","text"),f=A("div","row");r.icon&&f.appendChild(Me(r.icon,"icon",""));let p=A("div");p.appendChild(A("div","title",r.title)),r.sponsoredBy&&p.appendChild(A("div","meta",r.sponsoredBy)),f.appendChild(p),d.appendChild(f),r.body&&d.appendChild(A("div","body",r.body));let w=[r.displayUrl,r.rating!==null?`\u2605 ${r.rating}`:""].filter(Boolean).join(" \xB7 ");return w&&d.appendChild(A("div","meta",w)),r.price&&d.appendChild(A("div","price",r.price)),r.cta&&d.appendChild(A("span","cta",r.cta)),c.appendChild(d),s.appendChild(c),e.innerHTML="",e.appendChild(o),{el:o,destroy:()=>o.remove()}}var Et=[["firstQuartile",.25],["midpoint",.5],["thirdQuartile",.75]],je=["firstQuartile","midpoint","thirdQuartile","complete"],$e=.5;function Pe(e,t,n){if(!(n>0)||!(t>=0))return[];let r=t/n,o=[];for(let[s,a]of Et)r>=a&&!e.has(s)&&(e.add(s),o.push(s));return o}function qe(e,t){let n=t(e.src);return n?{ok:!0,video:{src:n,poster:t(e.poster,!0)||"",mime:typeof e.mime=="string"&&/^video\/[\w.+-]+$/.test(e.mime)?e.mime:""}}:{ok:!1,reason:"video: src non valido (ammessi solo http e https)"}}function St(e){let t=document.createElement("button");return t.type="button",t.textContent=e,t.style.cssText="position:absolute;right:8px;bottom:8px;z-index:2;padding:4px 10px;border:0;border-radius:999px;background:rgba(0,0,0,.65);color:#fff;font:600 12px/1.4 system-ui,sans-serif;cursor:pointer",t}function _e(e,t,{onClick:n,onEvent:r,onError:o}={}){let s=document.createElement("div");s.className="ual-video",s.style.cssText=`position:relative;display:block;margin:0 auto;width:${t.width}px;max-width:100%;aspect-ratio:${t.width}/${t.height};background:#000;overflow:hidden`;let a=document.createElement("video");a.muted=!0,a.defaultMuted=!0,a.playsInline=!0,a.setAttribute("playsinline",""),a.preload="metadata",a.disablePictureInPicture=!0,a.controls=!1,a.style.cssText="display:block;width:100%;height:100%;object-fit:contain",t.video.poster&&(a.poster=t.video.poster);let c=document.createElement("source");c.src=t.video.src,t.video.mime&&(c.type=t.video.mime),a.appendChild(c),s.appendChild(a);let d=document.createElement("span");if(d.textContent="Advertisement",d.style.cssText="position:absolute;left:8px;top:8px;z-index:2;padding:2px 6px;border-radius:4px;background:rgba(0,0,0,.55);color:#fff;font:600 11px/1.4 system-ui,sans-serif",s.appendChild(d),t.clickUrl){let h=document.createElement("a");h.href=t.clickUrl,h.target="_blank",h.rel="noopener noreferrer sponsored nofollow",h.setAttribute("aria-label","Open the advertiser page"),h.style.cssText="position:absolute;inset:0;z-index:1",h.addEventListener("click",()=>{n&&n()}),s.appendChild(h)}let f=St("Sound on");f.setAttribute("aria-label","Turn sound on"),f.addEventListener("click",()=>{a.muted=!a.muted,f.textContent=a.muted?"Sound on":"Sound off",f.setAttribute("aria-label",a.muted?"Turn sound on":"Turn sound off")}),s.appendChild(f);let p=t.trackers||{},w=new Set,E=!1,m=(h,$)=>{O($),r&&r(h)};a.addEventListener("playing",()=>{E||(E=!0,m("start",p.start))}),a.addEventListener("timeupdate",()=>{Pe(w,a.currentTime,a.duration).forEach(h=>m(h,p.quartile&&p.quartile[h]))}),a.addEventListener("ended",()=>{Pe(w,a.duration,a.duration).forEach(h=>m(h,p.quartile&&p.quartile[h])),w.has("complete")||(w.add("complete"),m("complete",p.quartile&&p.quartile.complete))}),a.addEventListener("error",()=>{o&&o(new Error("video: file non riproducibile"))});let x=!1,z=()=>{if(!a.ended)if(x&&document.visibilityState==="visible"){let h=a.play();h&&h.catch&&h.catch(()=>{})}else a.pause()},I="IntersectionObserver"in window?new IntersectionObserver(h=>{h.forEach($=>{x=$.intersectionRatio>=$e}),z()},{threshold:[0,$e,1]}):null;return I&&I.observe(s),document.addEventListener("visibilitychange",z),e.innerHTML="",e.appendChild(s),{el:s,destroy:()=>{I&&I.disconnect(),document.removeEventListener("visibilitychange",z),a.pause(),a.removeAttribute("src"),c.remove(),a.load(),s.remove()}}}var Re="allow-scripts allow-popups allow-popups-to-escape-sandbox",Y=2e3,kt=0,oe=new Map;function Ue(e){let t=Math.round(Number(e));return t>0&&t<=Y?t:0}function U(e,t){if(typeof e!="string"||!e)return null;try{let n=new URL(e,location.href);if(n.protocol==="http:"||n.protocol==="https:"||t&&n.protocol==="data:"&&/^data:image\//i.test(n.href))return n.href}catch(n){}return null}function N(e){return(Array.isArray(e)?e:[]).map(t=>U(t)).filter(Boolean)}function At(e){let t={};return!e||typeof e!="object"||Object.keys(e).slice(0,20).forEach(n=>{/^[\w-]{1,40}$/.test(n)&&(t[n]=N(e[n]))}),t}function Be(e){if(!e||typeof e!="object")return{ok:!1,reason:"annuncio non valido"};let t=e.type||(e.url?"url":e.src?"image":"html"),n=Ue(e.width),r=Ue(e.height);if(t!=="native"&&(!n||!r))return{ok:!1,reason:`dimensioni non valide (${e.width}x${e.height}, max ${Y})`};let o=e.trackers||{},s={type:t,width:n,height:r,alt:e.alt==null?void 0:String(e.alt),clickUrl:U(e.clickUrl)||"",trackers:{impression:N(o.impression),viewable:N(o.viewable),click:N(o.click),start:N(o.start),quartile:Object.fromEntries(je.map(a=>[a,N(o.quartile&&o.quartile[a])])),custom:At(o.custom)},sandbox:typeof e.sandbox=="string"?e.sandbox:void 0};if(t==="image"){if(s.src=U(e.src,!0),!s.src)return{ok:!1,reason:"src immagine non valido (ammessi http, https, data:image)"}}else if(t==="url"){if(s.url=U(e.url),!s.url)return{ok:!1,reason:"url non valido (ammessi solo http e https)"}}else if(t==="html"){if(typeof e.html!="string"||!e.html)return{ok:!1,reason:"html mancante"};s.html=e.html}else if(t==="native"){let a=Le(e.native,U);if(!a.ok)return a;s.native=a.native}else if(t==="video"){let a=qe(e,U);if(!a.ok)return a;s.video=a.video}else return{ok:!1,reason:"tipo sconosciuto: "+t};return{ok:!0,ad:s}}function Ne(e){return String(e).split(/\s+/).filter(Boolean)}function Tt(e){let t=e.sandbox&&e.sandbox!=="none"?e.sandbox:null;if(e.type==="url"){let n=!0;try{n=new URL(e.url).origin===location.origin}catch(r){}return e.sandbox==="none"&&!n?null:Ne(t||Re+" allow-same-origin").filter(r=>r!=="allow-top-navigation"&&!(n&&r==="allow-same-origin")).join(" ")}return Ne(t||Re).filter(n=>n!=="allow-top-navigation"&&n!=="allow-same-origin").join(" ")}function De(e){return JSON.stringify(String(e)).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function Ct(e,t){return`<script>(function(){
|
|
20
|
+
var C=${De(e)};
|
|
3
21
|
function s(m){m.ual=C;parent.postMessage(m,'*');}
|
|
4
|
-
window.clickTag=${
|
|
22
|
+
window.clickTag=${De(t||"")};
|
|
5
23
|
window.UALExt={
|
|
6
24
|
resize:function(w,h){s({cmd:'resize',w:w,h:h});},
|
|
7
25
|
expand:function(w,h){s({cmd:'resize',w:w,h:h,expanded:true});},
|
|
8
26
|
collapse:function(){s({cmd:'collapse'});},
|
|
9
27
|
close:function(){s({cmd:'close'});},
|
|
10
|
-
click:function(){s({cmd:'click'});if(window.clickTag)window.open(window.clickTag,'_blank');}
|
|
28
|
+
click:function(){s({cmd:'click'});if(window.clickTag)window.open(window.clickTag,'_blank');},
|
|
29
|
+
track:function(n){s({cmd:'track',name:String(n)});}
|
|
11
30
|
};
|
|
12
|
-
})();<\/script>`}function ee(e){return String(e).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function st(e,r){let t='<!doctype html><html><head><meta charset="utf-8"><base target="_blank"><style>html,body{margin:0;padding:0;overflow:hidden;background:transparent}img{display:block;border:0;max-width:100%}</style>'+ot(r,e.clickUrl)+"</head><body>",o="";if(e.type==="image"){let i=`<img src="${ee(e.src)}" width="${e.width}" height="${e.height}" alt="${ee(e.alt||"Advertisement")}">`;o=e.clickUrl?`<a href="${ee(e.clickUrl)}" rel="noopener sponsored" onclick="parent.postMessage({ual:'${r}',cmd:'click'},'*')">${i}</a>`:i}else o=e.html||"";return t+o+"</body></html>"}function Ce(e,r,{slotId:t,onClick:o,onClose:i}={}){at();let a="ual"+ ++rt,c=document.createElement("iframe");c.title="Advertisement",c.setAttribute("scrolling","no"),c.setAttribute("frameborder","0"),c.setAttribute("loading","eager"),c.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),c.style.cssText=`border:0;display:block;margin:0 auto;width:${r.width}px;height:${r.height}px;max-width:100%`,c.width=r.width,c.height=r.height;let l=it(r);return l!==null&&c.setAttribute("sandbox",l),r.type==="url"?c.src=r.url:c.srcdoc=st(r,a),te.set(a,{iframe:c,slotId:t,ad:r,original:{w:r.width,h:r.height},onClick:()=>{q(r.trackers&&r.trackers.click),o&&o()},onClose:i}),e.innerHTML="",e.appendChild(c),{iframe:c,channel:a,destroy:()=>te.delete(a)}}var Me=!1;function at(){Me||(Me=!0,window.addEventListener("message",lt))}function lt(e){let r=e.data;if(!r||typeof r!="object"||!r.ual)return;let t=te.get(r.ual);if(!(!t||e.source!==t.iframe.contentWindow))switch(r.cmd){case"resize":{let o=Math.min(+r.w||t.original.w,B),i=Math.min(+r.h||t.original.h,B);t.iframe.style.width=o+"px",t.iframe.style.height=i+"px";break}case"collapse":t.iframe.style.width=t.original.w+"px",t.iframe.style.height=t.original.h+"px";break;case"close":t.onClose&&t.onClose();break;case"click":t.onClick();break;default:}}function Oe(e,{threshold:r=.5,durationMs:t=1e3}={},o){if(!("IntersectionObserver"in window))return()=>{};let i=null,a=!1,c=!1,l=()=>{a||i||document.visibilityState!=="visible"||(i=setTimeout(()=>{a=!0,E(),o()},t))},u=()=>{clearTimeout(i),i=null},f=new IntersectionObserver(A=>{A.forEach(p=>{c=p.intersectionRatio>=r,c?l():u()})},{threshold:[0,r,1]}),y=()=>document.visibilityState==="visible"&&c?l():u();document.addEventListener("visibilitychange",y),f.observe(e);function E(){u(),f.disconnect(),document.removeEventListener("visibilitychange",y)}return E}var ct=new Set(["unconfigured","disabled","closed"]),dt=242500;function $e(e){let r=ce(),t=null,o=null,i={},a={gdprApplies:void 0,tcString:"",purposes:{},granted:!1,source:"pending"},c=Promise.resolve(a),l=!1,u=null,f=new Map,y=new Map,E=0,A=null,p=null,v=new Set,M=null;function z(){return{site:t.site,page:{url:location.href,path:location.pathname,ref:document.referrer,title:document.title},device:pe(),viewport:{w:window.innerWidth,h:window.innerHeight},targeting:{...t.targeting},consent:a,debug:ue()}}function k(){let n=ye(o);return Object.assign(n.targeting,i),n}function _(n){let s=a;if(!(s.granted===n.granted&&s.tcString===n.tcString&&s.source===n.source)&&(a=n,r.emit("consent",a),!s.granted&&n.granted))for(let d of[...f.values()])d.consentSkipped&&U(d)}function U(n,s=20){if(f.get(n.instanceId)===n){if(n.status==="loading"||n.status==="queued"){s>0&&setTimeout(()=>U(n,s-1),250);return}K(n)}}function We(n){return u?(S("init gi\xE0 eseguito"),u):(u=He(n).catch(s=>{throw u=null,s}),u)}async function He(n){o=await ge(n),o.debug&&Y(!0),he(o,e),t=k(),I("Config",t),c=Ae(t.consent,_).then(s=>(_(s),s)),document.readyState==="loading"&&await new Promise(s=>document.addEventListener("DOMContentLoaded",s,{once:!0})),l=!0,Xe(),V(document),Je(),r.emit("ready",{site:t.site})}function V(n){let s=[];n.nodeType===1&&n.matches&&n.matches("[data-ad-slot]")&&s.push(n),n.querySelectorAll&&n.querySelectorAll("[data-ad-slot]").forEach(d=>s.push(d)),s.forEach(Be)}function Be(n){let s=n.dataset.ualId;if(!s)return oe(n);f.has(s)||ct.has(n.dataset.ualStatus)||(ie(n),oe(n))}function ie(n){delete n.dataset.ualId,delete n.dataset.ualStatus,n.querySelectorAll(":scope > .ual-label, :scope > .ual-creative").forEach(s=>s.remove()),n.classList.remove("ual-slot","ual-filled"),n.style.display="",n.style.minHeight=""}function oe(n){let s=n.getAttribute("data-ad-slot"),d=t.slots[s];if(n.dataset.ualId=s+"#"+ ++E,!d){I("Slot non configurato, ignorato:",s),n.dataset.ualStatus="unconfigured";return}if(d.enabled===!1){I("Slot disabilitato:",s),n.dataset.ualStatus="disabled",X(n,d);return}let w={};try{w=n.dataset.adParams?JSON.parse(n.dataset.adParams):{}}catch(T){S("data-ad-params non \xE8 JSON valido",n)}let h={instanceId:n.dataset.ualId,name:s,el:n,cfg:d,params:w,status:"idle",cleanup:[],tries:0,consentSkipped:!1};f.set(h.instanceId,h),Ve(h),r.emit("slotRegistered",C(h)),(d.lazy!==void 0?d.lazy:t.lazy.enabled)&&A?A.observe(n):J(h)}function Ve(n){let{el:s,cfg:d}=n;if(d.minHeight&&(s.style.minHeight=d.minHeight+"px"),s.classList.add("ual-slot"),d.label){let h=document.createElement("div");h.className="ual-label",h.textContent=d.label,h.style.cssText="font:10px/1.4 sans-serif;color:#888;text-align:center;text-transform:uppercase;letter-spacing:.05em",s.appendChild(h)}let w=document.createElement("div");w.className="ual-creative",s.appendChild(w),n.box=w}function Je(){"MutationObserver"in window&&(p=new MutationObserver(n=>{for(let s of n)s.removedNodes.forEach(d=>{if(d.nodeType===1)for(let w of[...f.values()])(d===w.el||d.contains(w.el))&&G(w)}),s.addedNodes.forEach(d=>{d.nodeType===1&&V(d)})}),p.observe(document.body||document.documentElement,{childList:!0,subtree:!0}))}function Xe(){"IntersectionObserver"in window&&(A=new IntersectionObserver(n=>{n.forEach(s=>{if(!s.isIntersecting)return;A.unobserve(s.target);let d=f.get(s.target.dataset.ualId);d&&J(d)})},{rootMargin:t.lazy.fetchMargin}))}function J(n){n.status!=="loading"&&(n.status="queued",v.add(n),clearTimeout(M),M=setTimeout(Ke,30))}function Ke(){let n=[...v];v=new Set,n.length&&se(n,0)}async function se(n,s){let d=new Map,w=[];for(let h of n){let b=(h.cfg.providers||[])[s];if(!b){w.push(h);continue}let T=typeof b=="string"?b:b.id;d.has(T)||d.set(T,[]),d.get(T).push(h)}w.forEach(Ye),await Promise.all([...d.entries()].map(async([h,b])=>{let T=await Qe(h,b,s);T.length&&await se(T,s+1)}))}async function Ge(n){let s=t.providers[n];if(!s)throw new Error("Provider non definito: "+n);let d=e.get(s.adapter);if(!d)throw new Error("Adapter non registrato: "+s.adapter);return y.has(n)||y.set(n,Promise.resolve(d.init?d.init(s,z()):null)),await y.get(n),{adapter:d,pcfg:s}}async function Qe(n,s,d){let w=t.providers[n];if((!w||w.consent!=="contextual")&&await c,s=s.filter(m=>f.get(m.instanceId)===m),!s.length)return[];let h,b;try{({adapter:h,pcfg:b}=await Ge(n))}catch(m){return S(m.message),r.emit("error",{provider:n,error:m}),s}if(b.consent==="required"&&!a.granted)return I(`Provider ${n} saltato: consenso non concesso`),s.forEach(m=>{m.consentSkipped=!0}),s;let T=z(),O=s.map(m=>{m.status="loading",m.provider=n;let g=m.cfg.providers[d];return{id:m.instanceId,name:m.name,el:m.box,sizes:ve(m.cfg),params:{...typeof g=="object"?g.params:{},...m.params},cfg:m.cfg}});O.forEach(m=>r.emit("slotRequested",{slot:m.name,id:m.id,provider:n})),I(`Richiesta a ${n} (${b.adapter})`,O.map(m=>m.name));let le=b.timeoutMs||t.providerTimeoutMs,L=[];try{if(h.fill){let m=await R(h.fill(O,b,T),le+2e3,{});s.forEach((g,Q)=>{let x=m[O[Q].id];x&&x.filled?ae(g,{width:x.width,height:x.height,selfRendered:!0,meta:x.meta}):(N(g),P(g),L.push(g))})}else{let m=await R(h.request(O,b,T),le,{});s.forEach((g,Q)=>{let x=m[O[Q].id];if(!x||!x.html&&!x.src&&!x.url){L.push(g);return}let D=ze(x);if(!D.ok){S(`Annuncio scartato (${n}, slot ${g.name}): ${D.reason}`),r.emit("error",{provider:n,slot:g.name,error:new Error(D.reason)}),L.push(g);return}let j=D.ad,et=Ce(g.box,j,{slotId:g.instanceId,onClick:()=>r.emit("slotClick",C(g)),onClose:()=>{G(g),g.el.dataset.ualStatus="closed",X(g.el,g.cfg,!0)}});g.cleanup.push(et.destroy),q(j.trackers.impression),ae(g,{width:j.width,height:j.height,ad:j})})}}catch(m){S(`Errore provider ${n}`,m),r.emit("error",{provider:n,error:m}),s.forEach(g=>{g.status==="loading"&&(N(g),P(g),L.push(g))})}return L}function ae(n,s){n.status="filled",n.el.dataset.ualStatus="filled",n.el.classList.add("ual-filled"),n.el.style.display="",r.emit("slotRendered",{...C(n),width:s.width,height:s.height,meta:s.meta});let d={...t.viewability,...n.cfg.viewability};(s.width||0)*(s.height||0)>dt&&!(n.cfg.viewability&&n.cfg.viewability.threshold!==void 0)&&(d.threshold=Math.min(d.threshold,.3));let h=n.box.firstElementChild||n.box,b=Oe(h,d,()=>{s.ad&&q(s.ad.trackers.viewable),r.emit("slotViewable",C(n)),Ze(n)});n.cleanup.push(b)}function Ye(n){n.status="empty",n.el.dataset.ualStatus="empty",P(n),X(n.el,n.cfg),r.emit("slotEmpty",C(n))}function X(n,s,d){(d||(s.collapseEmpty!==void 0?s.collapseEmpty:t&&t.collapseEmpty))&&(n.style.display="none",n.style.minHeight="")}function P(n){n.cleanup.forEach(s=>{try{s()}catch(d){}}),n.cleanup=[],n.box&&(n.box.innerHTML="")}function N(n){let s=n.provider&&t.providers[n.provider],d=s&&e.get(s.adapter);if(d&&d.destroy)try{d.destroy({id:n.instanceId,el:n.box},s)}catch(w){}}function Ze(n){let s=n.cfg.refreshSec;if(!s||n.cfg.maxRefresh&&n.tries>=n.cfg.maxRefresh)return;let d=()=>{n.refreshTimer=setTimeout(()=>{if(!f.has(n.instanceId))return;let w=n.el.getBoundingClientRect();w.bottom>0&&w.top<window.innerHeight&&document.visibilityState==="visible"?(n.tries++,K(n)):d()},s*1e3)};d(),n.cleanup.push(()=>clearTimeout(n.refreshTimer))}function K(n){n.status==="loading"||n.status==="queued"||(N(n),P(n),n.status="idle",n.consentSkipped=!1,J(n))}function G(n){N(n),P(n),A&&A.unobserve(n.el),f.delete(n.instanceId)}function C(n){return{slot:n.name,id:n.instanceId,provider:n.provider,status:n.status,el:n.el}}return{init:We,isInitialized:()=>u!==null,whenReady:()=>u,on:r.on.bind(r),off:r.off.bind(r),registerAdapter:(n,s)=>e.set(n,s),setTargeting(n){Object.entries(n||{}).forEach(([s,d])=>{d==null?(delete i[s],t&&delete t.targeting[s]):(i[s]=d,t&&(t.targeting[s]=d))})},refresh(n){for(let s of f.values())(!n||n.includes(s.name))&&K(s)},pageView(){if(l){for(let n of[...f.values()])G(n);document.querySelectorAll("[data-ual-id]").forEach(ie),t=k(),V(document)}},getSlots:()=>[...f.values()].map(C),getConsent:()=>a,debug:Y}}var Pe={name:"json",async request(e,r,t){let o={site:t.site,page:t.page,device:t.device,viewport:t.viewport,targeting:t.targeting,consent:{gdprApplies:t.consent.gdprApplies,tcString:t.consent.tcString,granted:t.consent.granted},slots:e.map(l=>({id:l.id,name:l.name,sizes:l.sizes,params:l.params}))},i=await fetch(r.endpoint,{method:"POST",headers:{"Content-Type":"application/json",...r.headers},body:JSON.stringify(o),credentials:r.withCredentials&&t.consent.granted?"include":"omit",keepalive:!1});if(i.status===204)return{};if(!i.ok)throw new Error("decide HTTP "+i.status);let a=await i.json();r.map&&typeof window[r.map]=="function"&&(a=window[r.map](a,e));let c={};return(a.ads||[]).forEach(l=>{l&&l.slotId&&(c[l.slotId]=l)}),c}};var Le={name:"iframe",async request(e,r,t){let o={};return e.forEach(i=>{let[a,c]=i.sizes&&i.sizes[0]||[i.params.width||300,i.params.height||250],l=fe(r.url,{params:i.params,width:a,height:c,site:t.site,slot:i.name,device:t.device,cb:W(),page:t.page,consent:{tcString:t.consent.tcString,gdpr:t.consent.gdprApplies?1:0}});o[i.id]={type:"url",url:l,width:a,height:c,sandbox:r.sandbox||void 0}}),o}};function je(e){return e.server.replace(/\/$/,"")+(e.deliveryPath||"/www/delivery")}var qe={name:"revive",async request(e,r,t){let o={};return e.forEach(i=>{if(i.params.zoneid==null){S(`revive: zoneid mancante per lo slot "${i.name}", slot saltato`);return}let[a,c]=i.sizes&&i.sizes[0]||[300,250],l=new URLSearchParams({zoneid:i.params.zoneid,cb:W()});t.page.ref&&l.set("referer",t.page.ref),Object.entries(i.params.vars||{}).forEach(([u,f])=>l.set(u,f)),o[i.id]={type:"url",url:`${je(r)}/afr.php?${l}`,width:a,height:c}}),o}},Re={name:"revive-async",async fill(e,r){let t={},o=`${je(r)}/asyncjs.php`,i=e.filter(l=>l.params.zoneid!=null?!0:(S(`revive-async: zoneid mancante per lo slot "${l.name}", slot saltato`),t[l.id]={filled:!1},!1));if(!i.length)return t;let a=i.map(l=>{let u=document.createElement("ins");return u.setAttribute("data-revive-zoneid",l.params.zoneid),u.setAttribute("data-revive-id",r.reviveId),Object.entries(l.params.vars||{}).forEach(([f,y])=>u.setAttribute("data-revive-"+f,y)),l.el.appendChild(u),new Promise(f=>{let y=p=>{E.disconnect(),clearTimeout(A);let v=u.getBoundingClientRect();t[l.id]={filled:p,width:Math.round(v.width),height:Math.round(v.height)},f()},E=new MutationObserver(()=>{u.querySelector("img,iframe,a,div,embed")&&y(!0)});E.observe(u,{childList:!0,subtree:!0});let A=setTimeout(()=>y(u.children.length>0),r.fillTimeoutMs||2500)})}),c=window.reviveAsync&&window.reviveAsync[r.reviveId];return c&&typeof c.refresh=="function"?c.refresh():await $(o),await Promise.all(a),t}};var ut=0,ne=new Map;function ft(e,r){return e.replace(/\{([\w.]+)\}/g,(t,o)=>{let i=o.split(".").reduce((a,c)=>a==null?void 0:a[c],r);return i==null?"":String(i)})}var re=new Set;function pt(e,r){let t=r||{};re.forEach(o=>{if(!(o in t)){try{e.clearTargeting(o)}catch(i){}re.delete(o)}}),Object.entries(t).forEach(([o,i])=>{e.setTargeting(o,i),re.add(o)})}var _e={name:"gpt",async init(e,r){window.googletag=window.googletag||{cmd:[]};let t=window.googletag;t.cmd.push(()=>{let o=t.pubads();e.singleRequest!==!1&&o.enableSingleRequest(),o.disableInitialLoad(),o.collapseEmptyDivs(!1),e.nonPersonalizedWithoutConsent&&r.consent&&!r.consent.granted&&o.setPrivacySettings&&o.setPrivacySettings({nonPersonalizedAds:!0}),t.enableServices()}),await $(e.src||"https://securepubads.g.doubleclick.net/tag/js/gpt.js",{crossorigin:"anonymous"})},fill(e,r,t){return new Promise(o=>{let i=window.googletag,a={},c=e.length;i.cmd.push(()=>{let l=i.pubads();pt(l,t.targeting);let u=[],f={};if(e.forEach(p=>{let v=document.createElement("div");v.id="ual-gpt-"+ ++ut,p.el.appendChild(v);let M=p.params.adUnitPath||ft(r.adUnitPath,{network:r.network,site:t.site,slot:p.name,section:p.params.section,params:p.params}),z=p.sizes.length?p.sizes:["fluid"],k=i.defineSlot(M,z,v.id);if(!k){a[p.id]={filled:!1},c--;return}k.addService(l),Object.entries(p.params.targeting||{}).forEach(([_,U])=>k.setTargeting(_,U)),ne.set(p.id,k),f[v.id]=p.id,u.push(k),i.display(v.id)}),!c)return o(a);let y,E=()=>{clearTimeout(y),l.removeEventListener("slotRenderEnded",A),Object.values(f).forEach(p=>{a[p]||(a[p]={filled:!1})}),o(a)},A=p=>{let v=f[p.slot.getSlotElementId()];if(!v||a[v])return;let[M,z]=Array.isArray(p.size)?p.size:[0,0];a[v]={filled:!p.isEmpty,width:M,height:z,meta:{advertiserId:p.advertiserId,lineItemId:p.lineItemId,creativeId:p.creativeId}},--c===0&&E()};l.addEventListener("slotRenderEnded",A),y=setTimeout(E,r.fillTimeoutMs||4e3),l.refresh(u)})})},destroy(e){let r=ne.get(e.id);r&&window.googletag&&window.googletag.destroySlots&&(window.googletag.destroySlots([r]),ne.delete(e.id))}};var Ue={name:"adsense",async init(e){await $(`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${encodeURIComponent(e.client)}`,{crossorigin:"anonymous"})},fill(e,r){return Promise.all(e.map(t=>new Promise(o=>{let i=document.createElement("ins");i.className="adsbygoogle",i.setAttribute("data-ad-client",r.client),i.setAttribute("data-ad-slot",t.params.slot);let[a,c]=t.sizes[0]||[];t.params.format||!a?(i.style.display="block",i.setAttribute("data-ad-format",t.params.format||"auto"),t.params.responsive!==!1&&i.setAttribute("data-full-width-responsive","true")):i.style.cssText=`display:inline-block;width:${a}px;height:${c}px`,r.test&&i.setAttribute("data-adtest","on"),t.el.appendChild(i);let l=y=>{u.disconnect(),clearTimeout(f);let E=i.getBoundingClientRect();o([t.id,{filled:y,width:Math.round(E.width),height:Math.round(E.height)}])},u=new MutationObserver(()=>{let y=i.getAttribute("data-ad-status");y==="filled"?l(!0):y==="unfilled"&&l(!1)});u.observe(i,{attributes:!0,attributeFilter:["data-ad-status"]});let f=setTimeout(()=>l(!!i.querySelector("iframe")),r.fillTimeoutMs||4e3);try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(y){l(!1)}}))).then(t=>Object.fromEntries(t))}};function mt(e){let r=e.reduce((o,i)=>o+(i.weight||1),0),t=Math.random()*r;for(let o of e)if(t-=o.weight||1,t<=0)return o;return e[e.length-1]}var Ne={name:"house",async request(e,r,t){let o=Date.now(),i={};return e.forEach(a=>{let c=(r.creatives||[]).filter(l=>!(l.slots&&!l.slots.includes(a.name)||l.devices&&!l.devices.includes(t.device)||l.from&&o<Date.parse(l.from)||l.to&&o>Date.parse(l.to)+864e5||a.sizes.length&&!a.sizes.some(([u,f])=>u===l.width&&f===l.height)));if(c.length){let l=mt(c);i[a.id]={...l,type:l.type||(l.html?"html":"image")}}}),i}};var gt="0.1.1";function De(){let e=new Map(Object.entries({json:Pe,iframe:Le,revive:qe,"revive-async":Re,gpt:_e,adsense:Ue,house:Ne}));return{...$e(e),version:gt}}var Fe="ual";(function(){let r=window[Fe]||{};if(r.version)return;let o={...De(),cmd:{push:u=>i(u)}};function i(u){try{u(o)}catch(f){S("Errore in comando cmd",f)}}let a=Array.isArray(r.cmd)?r.cmd:[];window[Fe]=o;let c=document.currentScript||document.querySelector('script[data-ual-config],script[data-config][src*="ual"]'),l=c&&(c.getAttribute("data-ual-config")||c.getAttribute("data-config"));if(a.forEach(i),l){let u=()=>o.init(l).catch(f=>S("Init fallito",f));document.readyState==="loading"?document.addEventListener("DOMContentLoaded",u):u()}})();})();
|
|
31
|
+
})();<\/script>`}function re(e){return String(e).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function It(e,t){let n='<!doctype html><html><head><meta charset="utf-8"><base target="_blank"><style>html,body{margin:0;padding:0;overflow:hidden;background:transparent}img{display:block;border:0;max-width:100%}</style>'+Ct(t,e.clickUrl)+"</head><body>",r="";if(e.type==="image"){let o=`<img src="${re(e.src)}" width="${e.width}" height="${e.height}" alt="${re(e.alt||"Advertisement")}">`;r=e.clickUrl?`<a href="${re(e.clickUrl)}" rel="noopener sponsored" onclick="parent.postMessage({ual:'${t}',cmd:'click'},'*')">${o}</a>`:o}else r=e.html||"";return n+r+"</body></html>"}function Fe(e,t,{slotId:n,onClick:r,onClose:o}={}){zt();let s="ual"+ ++kt,a=document.createElement("iframe");a.title="Advertisement",a.setAttribute("scrolling","no"),a.setAttribute("frameborder","0"),a.setAttribute("loading","eager"),a.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),a.style.cssText=`border:0;display:block;margin:0 auto;width:${t.width}px;height:${t.height}px;max-width:100%`,a.width=t.width,a.height=t.height;let c=Tt(t);return c!==null&&a.setAttribute("sandbox",c),t.type==="url"?a.src=t.url:a.srcdoc=It(t,s),oe.set(s,{iframe:a,slotId:n,ad:t,original:{w:t.width,h:t.height},onClick:()=>{O(t.trackers&&t.trackers.click),r&&r()},onTrack:d=>{let f=t.trackers&&t.trackers.custom;typeof d=="string"&&f&&Object.hasOwn(f,d)&&O(f[d])},onClose:o}),e.innerHTML="",e.appendChild(a),{iframe:a,channel:s,destroy:()=>oe.delete(s)}}var He=!1;function zt(){He||(He=!0,window.addEventListener("message",Mt))}function Mt(e){let t=e.data;if(!t||typeof t!="object"||!t.ual)return;let n=oe.get(t.ual);if(!(!n||e.source!==n.iframe.contentWindow))switch(t.cmd){case"resize":{let r=Math.min(+t.w||n.original.w,Y),o=Math.min(+t.h||n.original.h,Y);n.iframe.style.width=r+"px",n.iframe.style.height=o+"px";break}case"collapse":n.iframe.style.width=n.original.w+"px",n.iframe.style.height=n.original.h+"px";break;case"close":n.onClose&&n.onClose();break;case"click":n.onClick();break;case"track":n.onTrack(t.name);break;default:}}var Lt=["bottom","top"];function Ve(e,t){return e>0&&t>0&&e<=t*.3}function We(e){if(!e)return null;let t=typeof e=="string"?e:e&&typeof e=="object"?e.position:"bottom";return Lt.includes(t)?t:"bottom"}function Qe(e,t,n){let r=e.style.cssText;e.style.cssText+=`;position:fixed;left:0;right:0;${t}:0;z-index:2147483000;text-align:center;margin:0;padding:0`;let o=document.createElement("button");return o.type="button",o.textContent="\xD7",o.setAttribute("aria-label","Close advertisement"),o.style.cssText=`position:absolute;right:6px;${t==="bottom"?"top":"bottom"}:-26px;width:26px;height:26px;border:0;border-radius:6px 6px 0 0;background:rgba(0,0,0,.7);color:#fff;font:16px/26px system-ui,sans-serif;cursor:pointer`,o.addEventListener("click",n),e.appendChild(o),()=>{e.style.cssText=r,o.remove()}}function Je(e,{threshold:t=.5,durationMs:n=1e3}={},r){if(!("IntersectionObserver"in window))return()=>{};let o=null,s=!1,a=!1,c=()=>{s||o||document.visibilityState!=="visible"||(o=setTimeout(()=>{s=!0,w(),r()},n))},d=()=>{clearTimeout(o),o=null},f=new IntersectionObserver(E=>{E.forEach(m=>{a=m.intersectionRatio>=t,a?c():d()})},{threshold:[0,t,1]}),p=()=>document.visibilityState==="visible"&&a?c():d();document.addEventListener("visibilitychange",p),f.observe(e);function w(){d(),f.disconnect(),document.removeEventListener("visibilitychange",p)}return w}var Ot=new Set(["unconfigured","disabled","closed"]),$t=242500;function Ye(e){let t=he(),n=null,r=null,o={},s={gdprApplies:void 0,tcString:"",purposes:{},granted:!1,source:"pending"},a=Promise.resolve(s),c=!1,d=null,f=new Map,p=new Map,w=0,E=null,m=null,x=new Set,z=null;function I(){return{site:n.site,page:{url:location.href,path:location.pathname,ref:document.referrer,title:document.title},device:be(),viewport:{w:window.innerWidth,h:window.innerHeight},targeting:{...n.targeting},consent:s,debug:ye()}}function h(){let i=ke(r);return Object.assign(i.targeting,o),i}function $(i){let l=s;if(!(l.granted===i.granted&&l.tcString===i.tcString&&l.source===i.source)&&(s=i,t.emit("consent",s),!l.granted&&i.granted))for(let u of[...f.values()])u.consentSkipped&&F(u)}function F(i,l=20){if(f.get(i.instanceId)===i){if(i.status==="loading"||i.status==="queued"){l>0&&setTimeout(()=>F(i,l-1),250);return}Z(i)}}function at(i){return d?(k("init gi\xE0 eseguito"),d):(d=st(i).catch(l=>{throw d=null,l}),d)}async function st(i){r=await xe(i),r.debug&&ie(!0),Ee(r,e),n=h(),L("Config",n),a=ze(n.consent,$).then(l=>($(l),l)),document.readyState==="loading"&&await new Promise(l=>document.addEventListener("DOMContentLoaded",l,{once:!0})),c=!0,ut(),K(document),dt(),t.emit("ready",{site:n.site})}function K(i){let l=[];i.nodeType===1&&i.matches&&i.matches("[data-ad-slot]")&&l.push(i),i.querySelectorAll&&i.querySelectorAll("[data-ad-slot]").forEach(u=>l.push(u)),l.forEach(lt)}function lt(i){let l=i.dataset.ualId;if(!l)return ce(i);f.has(l)||Ot.has(i.dataset.ualStatus)||(le(i),ce(i))}function le(i){delete i.dataset.ualId,delete i.dataset.ualStatus,i.querySelectorAll(":scope > .ual-label, :scope > .ual-creative").forEach(l=>l.remove()),i.classList.remove("ual-slot","ual-filled"),i.style.display="",i.style.minHeight=""}function ce(i){let l=i.getAttribute("data-ad-slot"),u=n.slots[l];if(i.dataset.ualId=l+"#"+ ++w,!u){L("Slot non configurato, ignorato:",l),i.dataset.ualStatus="unconfigured";return}if(u.enabled===!1){L("Slot disabilitato:",l),i.dataset.ualStatus="disabled",G(i,u);return}let v={};try{v=i.dataset.adParams?JSON.parse(i.dataset.adParams):{}}catch(T){k("data-ad-params non \xE8 JSON valido",i)}let b={instanceId:i.dataset.ualId,name:l,el:i,cfg:u,params:v,status:"idle",cleanup:[],tries:0,consentSkipped:!1};f.set(b.instanceId,b),ct(b),t.emit("slotRegistered",P(b)),(u.lazy!==void 0?u.lazy:n.lazy.enabled)&&E?E.observe(i):X(b)}function ct(i){let{el:l,cfg:u}=i;if(u.minHeight&&(l.style.minHeight=u.minHeight+"px"),l.classList.add("ual-slot"),u.label){let b=document.createElement("div");b.className="ual-label",b.textContent=u.label,b.style.cssText="font:10px/1.4 sans-serif;color:#888;text-align:center;text-transform:uppercase;letter-spacing:.05em",l.appendChild(b)}let v=document.createElement("div");v.className="ual-creative",l.appendChild(v),i.box=v}function dt(){"MutationObserver"in window&&(m=new MutationObserver(i=>{for(let l of i)l.removedNodes.forEach(u=>{if(u.nodeType===1)for(let v of[...f.values()])(u===v.el||u.contains(v.el))&&ee(v)}),l.addedNodes.forEach(u=>{u.nodeType===1&&K(u)})}),m.observe(document.body||document.documentElement,{childList:!0,subtree:!0}))}function ut(){"IntersectionObserver"in window&&(E=new IntersectionObserver(i=>{i.forEach(l=>{if(!l.isIntersecting)return;E.unobserve(l.target);let u=f.get(l.target.dataset.ualId);u&&X(u)})},{rootMargin:n.lazy.fetchMargin}))}function X(i){i.status!=="loading"&&(i.status="queued",x.add(i),clearTimeout(z),z=setTimeout(ft,30))}function ft(){let i=[...x];x=new Set,i.length&&de(i,0)}async function de(i,l){let u=new Map,v=[];for(let b of i){let S=(b.cfg.providers||[])[l];if(!S){v.push(b);continue}let T=typeof S=="string"?S:S.id;u.has(T)||u.set(T,[]),u.get(T).push(b)}v.forEach(ht),await Promise.all([...u.entries()].map(async([b,S])=>{let T=await mt(b,S,l);T.length&&await de(T,l+1)}))}async function pt(i){let l=n.providers[i];if(!l)throw new Error("Provider non definito: "+i);let u=e.get(l.adapter);if(!u)throw new Error("Adapter non registrato: "+l.adapter);return p.has(i)||p.set(i,Promise.resolve(u.init?u.init(l,I()):null)),await p.get(i),{adapter:u,pcfg:l}}async function mt(i,l,u){let v=n.providers[i];if((!v||v.consent!=="contextual")&&await a,l=l.filter(g=>f.get(g.instanceId)===g),!l.length)return[];let b,S;try{({adapter:b,pcfg:S}=await pt(i))}catch(g){return k(g.message),t.emit("error",{provider:i,error:g}),l}if(S.consent==="required"&&!s.granted)return L(`Provider ${i} saltato: consenso non concesso`),l.forEach(g=>{g.consentSkipped=!0}),l;let T=I(),_=l.map(g=>{g.status="loading",g.provider=i;let y=g.cfg.providers[u];return{id:g.instanceId,name:g.name,el:g.box,sizes:Ae(g.cfg),params:{...typeof y=="object"?y.params:{},...g.params},cfg:g.cfg}});_.forEach(g=>t.emit("slotRequested",{slot:g.name,id:g.id,provider:i})),L(`Richiesta a ${i} (${S.adapter})`,_.map(g=>g.name));let pe=S.timeoutMs||n.providerTimeoutMs,H=[];try{if(b.fill){let g=await B(b.fill(_,S,T),pe+2e3,{});l.forEach((y,te)=>{let C=g[_[te].id];C&&C.filled?ue(y,{width:C.width,height:C.height,selfRendered:!0,meta:C.meta}):(V(y),D(y),H.push(y))})}else{let g=await B(b.request(_,S,T),pe,{});l.forEach((y,te)=>{let C=g[_[te].id];if(!C||!C.html&&!C.src&&!C.url&&!C.native){H.push(y);return}let W=Be(C);if(!W.ok){k(`Annuncio scartato (${i}, slot ${y.name}): ${W.reason}`),t.emit("error",{provider:i,slot:y.name,error:new Error(W.reason)}),H.push(y);return}let M=W.ad,me=()=>{O(M.trackers.click),t.emit("slotClick",P(y))},yt=M.type==="native"?Oe(y.box,M,{onClick:me}):M.type==="video"?_e(y.box,M,{onClick:me,onEvent:ne=>t.emit("videoEvent",{...P(y),event:ne}),onError:ne=>t.emit("error",{provider:i,slot:y.name,error:ne})}):Fe(y.box,M,{slotId:y.instanceId,onClick:()=>t.emit("slotClick",P(y)),onClose:()=>fe(y)});y.cleanup.push(yt.destroy),O(M.trackers.impression),ue(y,{width:M.width,height:M.height,ad:M})})}}catch(g){k(`Errore provider ${i}`,g),t.emit("error",{provider:i,error:g}),l.forEach(y=>{y.status==="loading"&&(V(y),D(y),H.push(y))})}return H}function ue(i,l){i.status="filled",i.el.dataset.ualStatus="filled",i.el.classList.add("ual-filled"),i.el.style.display="",t.emit("slotRendered",{...P(i),width:l.width,height:l.height,meta:l.meta});let u={...n.viewability,...i.cfg.viewability};l.ad&&l.ad.type==="video"&&!(i.cfg.viewability&&i.cfg.viewability.durationMs!==void 0)&&(u.durationMs=Math.max(u.durationMs,2e3));let v=We(i.cfg.sticky);v&&l.height&&(Ve(l.height,window.innerHeight)?i.cleanup.push(Qe(i.el,v,()=>fe(i))):k(`Slot "${i.name}": sticky ignorato, l'annuncio (${l.height}px) supera il 30% dello schermo`)),(l.width||0)*(l.height||0)>$t&&!(i.cfg.viewability&&i.cfg.viewability.threshold!==void 0)&&(u.threshold=Math.min(u.threshold,.3));let S=i.box.firstElementChild||i.box,T=Je(S,u,()=>{l.ad&&O(l.ad.trackers.viewable),t.emit("slotViewable",P(i)),gt(i)});i.cleanup.push(T)}function ht(i){i.status="empty",i.el.dataset.ualStatus="empty",D(i),G(i.el,i.cfg),t.emit("slotEmpty",P(i))}function G(i,l,u){(u||(l.collapseEmpty!==void 0?l.collapseEmpty:n&&n.collapseEmpty))&&(i.style.display="none",i.style.minHeight="")}function D(i){i.cleanup.forEach(l=>{try{l()}catch(u){}}),i.cleanup=[],i.box&&(i.box.innerHTML="")}function V(i){let l=i.provider&&n.providers[i.provider],u=l&&e.get(l.adapter);if(u&&u.destroy)try{u.destroy({id:i.instanceId,el:i.box},l)}catch(v){}}function gt(i){let l=i.cfg.refreshSec;if(!l||i.cfg.maxRefresh&&i.tries>=i.cfg.maxRefresh)return;let u=()=>{i.refreshTimer=setTimeout(()=>{if(!f.has(i.instanceId))return;let v=i.el.getBoundingClientRect();v.bottom>0&&v.top<window.innerHeight&&document.visibilityState==="visible"?(i.tries++,Z(i)):u()},l*1e3)};u(),i.cleanup.push(()=>clearTimeout(i.refreshTimer))}function Z(i){i.status==="loading"||i.status==="queued"||(V(i),D(i),i.status="idle",i.consentSkipped=!1,X(i))}function fe(i){ee(i),i.el.dataset.ualStatus="closed",G(i.el,i.cfg,!0)}function ee(i){V(i),D(i),E&&E.unobserve(i.el),f.delete(i.instanceId)}function P(i){return{slot:i.name,id:i.instanceId,provider:i.provider,status:i.status,el:i.el}}return{init:at,isInitialized:()=>d!==null,whenReady:()=>d,on:t.on.bind(t),off:t.off.bind(t),registerAdapter:(i,l)=>e.set(i,l),setTargeting(i){Object.entries(i||{}).forEach(([l,u])=>{u==null?(delete o[l],n&&delete n.targeting[l]):(o[l]=u,n&&(n.targeting[l]=u))})},refresh(i){for(let l of f.values())(!i||i.includes(l.name))&&Z(l)},pageView(){if(c){for(let i of[...f.values()])ee(i);document.querySelectorAll("[data-ual-id]").forEach(le),n=h(),K(document)}},getSlots:()=>[...f.values()].map(P),getConsent:()=>s,debug:ie}}var Ke={name:"json",async request(e,t,n){let r={site:n.site,page:n.page,device:n.device,viewport:n.viewport,targeting:n.targeting,consent:{gdprApplies:n.consent.gdprApplies,tcString:n.consent.tcString,granted:n.consent.granted},slots:e.map(c=>({id:c.id,name:c.name,sizes:c.sizes,params:c.params}))},o=await fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json",...t.headers},body:JSON.stringify(r),credentials:t.withCredentials&&n.consent.granted?"include":"omit",keepalive:!1});if(o.status===204)return{};if(!o.ok)throw new Error("decide HTTP "+o.status);let s=await o.json();t.map&&typeof window[t.map]=="function"&&(s=window[t.map](s,e));let a={};return(s.ads||[]).forEach(c=>{c&&c.slotId&&(a[c.slotId]=c)}),a}};var Xe={name:"iframe",async request(e,t,n){let r={};return e.forEach(o=>{let[s,a]=o.sizes&&o.sizes[0]||[o.params.width||300,o.params.height||250],c=ve(t.url,{params:o.params,width:s,height:a,site:n.site,slot:o.name,device:n.device,cb:J(),page:n.page,consent:{tcString:n.consent.tcString,gdpr:n.consent.gdprApplies?1:0}});r[o.id]={type:"url",url:c,width:s,height:a,sandbox:t.sandbox||void 0}}),r}};function Ge(e){return e.server.replace(/\/$/,"")+(e.deliveryPath||"/www/delivery")}var Ze={name:"revive",async request(e,t,n){let r={};return e.forEach(o=>{if(o.params.zoneid==null){k(`revive: zoneid mancante per lo slot "${o.name}", slot saltato`);return}let[s,a]=o.sizes&&o.sizes[0]||[300,250],c=new URLSearchParams({zoneid:o.params.zoneid,cb:J()});n.page.ref&&c.set("referer",n.page.ref),Object.entries(o.params.vars||{}).forEach(([d,f])=>c.set(d,f)),r[o.id]={type:"url",url:`${Ge(t)}/afr.php?${c}`,width:s,height:a}}),r}},et={name:"revive-async",async fill(e,t){let n={},r=`${Ge(t)}/asyncjs.php`,o=e.filter(c=>c.params.zoneid!=null?!0:(k(`revive-async: zoneid mancante per lo slot "${c.name}", slot saltato`),n[c.id]={filled:!1},!1));if(!o.length)return n;let s=o.map(c=>{let d=document.createElement("ins");return d.setAttribute("data-revive-zoneid",c.params.zoneid),d.setAttribute("data-revive-id",t.reviveId),Object.entries(c.params.vars||{}).forEach(([f,p])=>d.setAttribute("data-revive-"+f,p)),c.el.appendChild(d),new Promise(f=>{let p=m=>{w.disconnect(),clearTimeout(E);let x=d.getBoundingClientRect();n[c.id]={filled:m,width:Math.round(x.width),height:Math.round(x.height)},f()},w=new MutationObserver(()=>{d.querySelector("img,iframe,a,div,embed")&&p(!0)});w.observe(d,{childList:!0,subtree:!0});let E=setTimeout(()=>p(d.children.length>0),t.fillTimeoutMs||2500)})}),a=window.reviveAsync&&window.reviveAsync[t.reviveId];return a&&typeof a.refresh=="function"?a.refresh():await R(r),await Promise.all(s),n}};var Pt=0,ae=new Map;function jt(e,t){return e.replace(/\{([\w.]+)\}/g,(n,r)=>{let o=r.split(".").reduce((s,a)=>s==null?void 0:s[a],t);return o==null?"":String(o)})}var se=new Set;function qt(e,t){let n=t||{};se.forEach(r=>{if(!(r in n)){try{e.clearTargeting(r)}catch(o){}se.delete(r)}}),Object.entries(n).forEach(([r,o])=>{e.setTargeting(r,o),se.add(r)})}var tt={name:"gpt",async init(e,t){window.googletag=window.googletag||{cmd:[]};let n=window.googletag;n.cmd.push(()=>{let r=n.pubads();e.singleRequest!==!1&&r.enableSingleRequest(),r.disableInitialLoad(),r.collapseEmptyDivs(!1),e.nonPersonalizedWithoutConsent&&t.consent&&!t.consent.granted&&r.setPrivacySettings&&r.setPrivacySettings({nonPersonalizedAds:!0}),n.enableServices()}),await R(e.src||"https://securepubads.g.doubleclick.net/tag/js/gpt.js",{crossorigin:"anonymous"})},fill(e,t,n){return new Promise(r=>{let o=window.googletag,s={},a=e.length;o.cmd.push(()=>{let c=o.pubads();qt(c,n.targeting);let d=[],f={};if(e.forEach(m=>{let x=document.createElement("div");x.id="ual-gpt-"+ ++Pt,m.el.appendChild(x);let z=m.params.adUnitPath||jt(t.adUnitPath,{network:t.network,site:n.site,slot:m.name,section:m.params.section,params:m.params}),I=m.sizes.length?m.sizes:["fluid"],h=o.defineSlot(z,I,x.id);if(!h){s[m.id]={filled:!1},a--;return}h.addService(c),Object.entries(m.params.targeting||{}).forEach(([$,F])=>h.setTargeting($,F)),ae.set(m.id,h),f[x.id]=m.id,d.push(h),o.display(x.id)}),!a)return r(s);let p,w=()=>{clearTimeout(p),c.removeEventListener("slotRenderEnded",E),Object.values(f).forEach(m=>{s[m]||(s[m]={filled:!1})}),r(s)},E=m=>{let x=f[m.slot.getSlotElementId()];if(!x||s[x])return;let[z,I]=Array.isArray(m.size)?m.size:[0,0];s[x]={filled:!m.isEmpty,width:z,height:I,meta:{advertiserId:m.advertiserId,lineItemId:m.lineItemId,creativeId:m.creativeId}},--a===0&&w()};c.addEventListener("slotRenderEnded",E),p=setTimeout(w,t.fillTimeoutMs||4e3),c.refresh(d)})})},destroy(e){let t=ae.get(e.id);t&&window.googletag&&window.googletag.destroySlots&&(window.googletag.destroySlots([t]),ae.delete(e.id))}};var nt={name:"adsense",async init(e){await R(`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${encodeURIComponent(e.client)}`,{crossorigin:"anonymous"})},fill(e,t){return Promise.all(e.map(n=>new Promise(r=>{let o=document.createElement("ins");o.className="adsbygoogle",o.setAttribute("data-ad-client",t.client),o.setAttribute("data-ad-slot",n.params.slot);let[s,a]=n.sizes[0]||[];n.params.format||!s?(o.style.display="block",o.setAttribute("data-ad-format",n.params.format||"auto"),n.params.responsive!==!1&&o.setAttribute("data-full-width-responsive","true")):o.style.cssText=`display:inline-block;width:${s}px;height:${a}px`,t.test&&o.setAttribute("data-adtest","on"),n.el.appendChild(o);let c=p=>{d.disconnect(),clearTimeout(f);let w=o.getBoundingClientRect();r([n.id,{filled:p,width:Math.round(w.width),height:Math.round(w.height)}])},d=new MutationObserver(()=>{let p=o.getAttribute("data-ad-status");p==="filled"?c(!0):p==="unfilled"&&c(!1)});d.observe(o,{attributes:!0,attributeFilter:["data-ad-status"]});let f=setTimeout(()=>c(!!o.querySelector("iframe")),t.fillTimeoutMs||4e3);try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch(p){c(!1)}}))).then(n=>Object.fromEntries(n))}};function _t(e){let t=e.reduce((r,o)=>r+(o.weight||1),0),n=Math.random()*t;for(let r of e)if(n-=r.weight||1,n<=0)return r;return e[e.length-1]}var it={name:"house",async request(e,t,n){let r=Date.now(),o={};return e.forEach(s=>{let a=(t.creatives||[]).filter(c=>!(c.slots&&!c.slots.includes(s.name)||c.devices&&!c.devices.includes(n.device)||c.from&&r<Date.parse(c.from)||c.to&&r>Date.parse(c.to)+864e5||s.sizes.length&&!s.sizes.some(([d,f])=>d===c.width&&f===c.height)));if(a.length){let c=_t(a);o[s.id]={...c,type:c.type||(c.html?"html":"image")}}}),o}};var Rt="0.2.0";function rt(){let e=new Map(Object.entries({json:Ke,iframe:Xe,revive:Ze,"revive-async":et,gpt:tt,adsense:nt,house:it}));return{...Ye(e),version:Rt}}var ot="ual";(function(){let t=window[ot]||{};if(t.version)return;let r={...rt(),cmd:{push:d=>o(d)}};function o(d){try{d(r)}catch(f){k("Errore in comando cmd",f)}}let s=Array.isArray(t.cmd)?t.cmd:[];window[ot]=r;let a=document.currentScript||document.querySelector('script[data-ual-config],script[data-config][src*="ual"]'),c=a&&(a.getAttribute("data-ual-config")||a.getAttribute("data-config"));if(s.forEach(o),c){let d=()=>r.init(c).catch(f=>k("Init fallito",f));document.readyState==="loading"?document.addEventListener("DOMContentLoaded",d):d()}})();})();
|
package/docs/cdn.md
CHANGED
|
@@ -1,41 +1,55 @@
|
|
|
1
|
-
# Publishing UAL:
|
|
1
|
+
# Publishing UAL: loader and configuration
|
|
2
2
|
|
|
3
|
-
With the `<script>` **tag**, or with the components in "On your CDN" mode (`src` + `config` as a URL), **two
|
|
3
|
+
With the `<script>` **tag**, or with the components in "On your CDN" mode (`src` + `config` as a URL), you need **two things**, and they come from different places. An HTML version with examples is in the configurator guide (`/docs/#pubblicare`).
|
|
4
4
|
|
|
5
5
|
## The files
|
|
6
6
|
|
|
7
|
-
|
|
|
7
|
+
| What | Where it comes from | Address |
|
|
8
8
|
|---|---|---|
|
|
9
|
-
| **The loader** |
|
|
10
|
-
| **The configuration** | the JSON downloaded from the configurator (*JSON* tab ▸ *Download*), named `<site-id>.json
|
|
9
|
+
| **The loader** | The npm package, served by [jsDelivr](https://www.jsdelivr.com/): **nothing to upload** (about 25 KB, 10 KB gzipped) | `https://cdn.jsdelivr.net/npm/universal-ad-loader@0.1.2/dist/ual.min.js` |
|
|
10
|
+
| **The configuration** | the JSON downloaded from the configurator (*JSON* tab ▸ *Download*), named `<site-id>.json`, uploaded to **your** CDN | `https://adcdn.yourdomain.net/config/<site-id>.json` |
|
|
11
11
|
|
|
12
|
-
One configuration file per site. In the configurator's *Snippet* tab you set the
|
|
12
|
+
One configuration file per site. In the configurator's *Snippet* tab you set the loader URL, the configuration CDN and the configuration path: the address it shows is the exact one and the generated snippet already points there.
|
|
13
13
|
|
|
14
14
|
```
|
|
15
15
|
cdn/
|
|
16
|
-
├── ual.min.js ← the loader: the same file for all sites
|
|
17
16
|
└── config/
|
|
18
17
|
├── mario-pizzeria.json ← the configuration: one per site
|
|
19
18
|
└── another-site.json
|
|
20
19
|
```
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
### Which loader URL
|
|
23
22
|
|
|
24
|
-
|
|
|
23
|
+
| URL | Cache | When |
|
|
25
24
|
|---|---|---|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
25
|
+
| `…/universal-ad-loader@0.1.2/dist/ual.min.js` | 1 year, immutable | **Production (recommended):** pinned version, the site never changes by itself |
|
|
26
|
+
| `…/universal-ad-loader@0/dist/ual.min.js` | 7 days in the browser, 12 hours on the CDN | Follows every 0.x automatically: handy for trying things, risky for client sites |
|
|
27
|
+
| `…/universal-ad-loader/dist/ual.min.js` | same | Always the latest: only for trying |
|
|
28
|
+
|
|
29
|
+
To move a site to a new loader version, change the number in the URL of its snippet. The configurator uses the version of the package it was built with. Do not put the configuration on jsDelivr: it is tied to the npm package and cached for a long time.
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
### Loader on your own domain (alternative)
|
|
32
|
+
|
|
33
|
+
If you do not want to depend on jsDelivr, upload `dist/ual.min.js` to your domain and put its address in *Loader URL*. A versioned path plus an alias for urgent releases works best:
|
|
30
34
|
|
|
31
35
|
```
|
|
32
36
|
cdn/
|
|
33
|
-
├── v0.1.
|
|
37
|
+
├── v0.1.2/ual.min.js ← long cache (public, max-age=31536000, immutable)
|
|
34
38
|
├── ual.min.js ← alias, short cache (public, max-age=300)
|
|
35
39
|
└── config/
|
|
36
40
|
└── mario-pizzeria.json
|
|
37
41
|
```
|
|
38
42
|
|
|
43
|
+
Serve it as `Content-Type: text/javascript` with gzip or brotli; no CORS needed (loaded with `<script src>`).
|
|
44
|
+
|
|
45
|
+
## Headers
|
|
46
|
+
|
|
47
|
+
| File | Headers | Why |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| Configuration | `Content-Type: application/json`, `Access-Control-Allow-Origin: *`, `Cache-Control: public, max-age=120` | The loader reads it with `fetch` from another domain (without cookies, so `*` is fine). Short cache (1–5 minutes) so changes go live quickly |
|
|
50
|
+
|
|
51
|
+
The loader on jsDelivr already has the right headers (CORS, cache, compression).
|
|
52
|
+
|
|
39
53
|
## What is not needed
|
|
40
54
|
|
|
41
55
|
- `index.mjs`, `react.mjs`, `vue.mjs` and the other files in `dist/` other than `ual.min.js`: they are for the npm package.
|
|
@@ -44,15 +58,16 @@ cdn/
|
|
|
44
58
|
|
|
45
59
|
## Special cases
|
|
46
60
|
|
|
47
|
-
- **Package with the config in the code** (`defineConfig`, component without `src`): nothing is needed
|
|
61
|
+
- **Package with the config in the code** (`defineConfig`, component without `src`): nothing is needed, neither jsDelivr nor a CDN: UAL and the configuration are in the site bundle.
|
|
48
62
|
- **Existing ad servers only** (`iframe` adapter, see `ad-server-esistenti.md`): the same two files apply; the IDs and URLs are already in the configuration.
|
|
49
63
|
- **House creative images** (e.g. `https://cdn.yourdomain.net/promo/728x90.webp`): they are a third type of file, uploaded wherever you like and referenced in the configuration. They are not part of UAL and need no CORS headers (they are shown in an isolated iframe).
|
|
50
64
|
|
|
51
65
|
## Publishing and updating
|
|
52
66
|
|
|
53
67
|
1. Download the JSON from the configurator.
|
|
54
|
-
2. Upload it to
|
|
68
|
+
2. Upload it to your CDN at the address shown in *Snippet*. The loader is not uploaded: jsDelivr serves it.
|
|
55
69
|
3. Paste the snippet (or the framework code) into the site.
|
|
56
70
|
4. **To change providers, slots or rules:** edit in the configurator, download the JSON again and upload it **to the same address**. Sites pick it up on the next visit, after the cache expires.
|
|
71
|
+
5. **To update the loader:** change the version in the URL of the sites' snippet.
|
|
57
72
|
|
|
58
73
|
In SPAs using the tag, `ual.pageView()` must be called on every page change (the components do it on their own). Before replacing the configuration of a live site, publish with a test ID and check the log with `?ual_debug=1`.
|
package/docs/esempio.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
```html
|
|
6
6
|
<head>
|
|
7
|
-
<script async src="https://
|
|
7
|
+
<script async src="https://cdn.jsdelivr.net/npm/universal-ad-loader@0.1.2/dist/ual.min.js"
|
|
8
8
|
data-config="https://adcdn.yourdomain.net/config/mario-pizzeria.json"></script>
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universal-ad-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Loader pubblicitario universale: un tag per sito, configurazione centralizzata, waterfall tra provider e consenso TCF. Componenti per React, Next.js, Vue e Astro.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "ArdensLab",
|
|
@@ -89,9 +89,9 @@
|
|
|
89
89
|
"prepack": "npm run build",
|
|
90
90
|
"lint": "oxlint src",
|
|
91
91
|
"pretest": "npm run build",
|
|
92
|
-
"test": "node test/run.mjs . && node test/regression.mjs . && node test/package.mjs . && node test/wrappers.mjs .",
|
|
92
|
+
"test": "node test/run.mjs . && node test/regression.mjs . && node test/formats.mjs . && node test/package.mjs . && node test/wrappers.mjs .",
|
|
93
93
|
"test:node": "npm run build && node test/package.mjs .",
|
|
94
|
-
"test:browser": "npm run build && node test/run.mjs . && node test/regression.mjs .",
|
|
94
|
+
"test:browser": "npm run build && node test/run.mjs . && node test/regression.mjs . && node test/formats.mjs .",
|
|
95
95
|
"test:frameworks": "npm run build && node test/wrappers.mjs ."
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
@@ -164,7 +164,15 @@
|
|
|
164
164
|
"refreshSec": { "type": "integer", "minimum": 5 },
|
|
165
165
|
"maxRefresh": { "type": "integer", "minimum": 1 },
|
|
166
166
|
"enabled": { "type": "boolean" },
|
|
167
|
-
"viewability": { "$ref": "#/definitions/viewability" }
|
|
167
|
+
"viewability": { "$ref": "#/definitions/viewability" },
|
|
168
|
+
"sticky": {
|
|
169
|
+
"description": "Banner ancorato al bordo dello schermo, solo se occupa al massimo il 30% dell'altezza.",
|
|
170
|
+
"oneOf": [
|
|
171
|
+
{ "type": "boolean" },
|
|
172
|
+
{ "enum": ["top", "bottom"] },
|
|
173
|
+
{ "type": "object", "additionalProperties": false, "properties": { "position": { "enum": ["top", "bottom"] } } }
|
|
174
|
+
]
|
|
175
|
+
}
|
|
168
176
|
}
|
|
169
177
|
},
|
|
170
178
|
"slot": {
|