if (typeof window.$4wReferral === "undefined") {
var win = window || window.parent;
var loc = '';
try {
loc = win.top.location.origin + win.top.location.pathname;
}
catch(err) {
loc = win.document.referrer;
}
window.$4wReferral = loc;
console.log("$4wReferral=" + window.$4wReferral);
}
if (typeof window.$4wUserAgent === "undefined") {
window.$4wUserAgent = ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : "");
}
if (typeof window.imp_cb === "undefined") {
window.imp_cb = "";
}
if (typeof window.$4w__tcfapi !== 'function') {
window.$4wCallbacks = window.$4wCallbacks || {};
function postMessageHandler(event) {
let json = {};
try {
json = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
}
catch (ignore) {}
if (json.__tcfapiReturn) {
const payload = json.__tcfapiReturn;
if (typeof window.$4wCallbacks[payload.callId] === 'function') {
window.$4wCallbacks[payload.callId](payload.returnValue, payload.success);
delete window.$4wCallbacks[payload.callId];
}
return;
}
}
window.addEventListener('message', postMessageHandler, false);
window.$4w__tcfapi = function(cmd, version, callback, arg) {
var frame = window;
var tcfFrame;
var wt = window.top;
while (frame) {
try {
if (!tcfFrame && frame.frames['__tcfapiLocator']) {
tcfFrame = frame;
break;
}
} catch(ignore) {}
if (frame === wt) break;
frame = frame.parent;
}
if (!tcfFrame) {
callback({msg: '__tcfapiLocator not found'}, false);
return;
}
const callId = Math.random() + '';
const msg = {
__tcfapiCall: {
command: cmd,
parameter: arg,
version: version,
callId: callId
}
};
window.$4wCallbacks[callId] = callback;
tcfFrame.postMessage(msg, '*');
};
}
var deliveryNative = function (simply_ad_height, simply_ad_width, simply_domain, fw_curl, gdpr, gdpr_consent, fw_isPassback, fw_isPassbackStill, fw_positionPBStill, gdpr_consent_purpose) {
window._4wDelivered = true;
if (typeof window.$4wTad === "undefined") {
window.$4wTad = true; // default value if missing = true (no consent)
}
console.log("[ads_native.js] GDPR=", gdpr);
console.log("[ads_native.js] GDPR_CONSENT=", gdpr_consent);
console.log("[ads_native.js] GDPR_PURPOSE=", gdpr_consent_purpose);
console.log("[ads_native.js] TAD=", (window.$4wTad)?"1":"0");
if (typeof window.fw_fz === "undefined") {
fw_fz = true;
}
if (typeof window.fw_fc === "undefined") {
fw_fc = true;
}
if (typeof window.fw_czi === "undefined") {
fw_czi = 805795;
}
if (typeof window.fw_mzi === "undefined") {
fw_mzi = 658374;
}
var pr = 'https:';
var url = pr + '//static.4wnetwork.com/js/native_new.js?v=6';
var iframe = document.createElement('iframe');
(iframe.frameElement || iframe).style.cssText =
"width: "+simply_ad_width+"px; height: "+simply_ad_height+"px; border: 0";
iframe.src = "about:blank";
iframe.style.height = simply_ad_height;
iframe.style.width = simply_ad_width;
//Passback Native 4w-IN: il controllo sottostante serve a centrare il passback nel div contenitore
//tramite le direttive CSS sottoscritte
if (typeof(fw_isPassback)!="undefined" && fw_isPassback) {
iframe.style.position = "absolute";
iframe.style.left = "50%";
iframe.style.transform = "translateX(-50%)";
}
//Passback Native 4w-Still: il controllo sottostante serve a rendere overlay il passback native del 4w-Still
if (typeof(fw_isPassbackStill)!="undefined" && fw_isPassbackStill) {
if (isMobile()){
iframe.classList.add("fw-total-bottom-pb-still");
} else {
if (!(simply_ad_width > 1 && simply_ad_height >1)) {
if ((Math.floor(parent.document.body.clientWidth/3)) >= 441 ) {
iframe.style.width = Math.floor(parent.document.body.clientWidth/3) + "px";
} else {
iframe.style.width = 441 + "px";
}
}
switch (fw_positionPBStill) {
case 'fw-bottom-right-if':
iframe.classList.add("fw-bottom-right-pb-still");
break;
case 'fw-top-right-if':
iframe.classList.add("fw-top-right-pb-still");
break;
default:
iframe.classList.add("fw-bottom-right-pb-still");
}
}
setTimeout(function () {
insertCloseBtnPBStill(iframe);
setTimeout(function () {
console.log("CLOSE PB")
iframe.style.display = "none";
}, 30000);
}, 3000);
}
iframe.setAttribute("scrolling", "no");
iframe.setAttribute("frameborder", "0");
//var where = document.getElementsByTagName('script')[0];
if (typeof window.FW_id != 'undefined' && typeof window.FW_cont != 'undefined') {
var id = window.FW_id + window.FW_cont;
} else {
var id = window.fw_anchor;
setTimeout(function () {
if (typeof window.frameElement != 'undefined' && window.frameElement != null && typeof window.frameElement.style != 'undefined')
window.frameElement.style.cssText = "width: 0px; height: 0px; border: 0 ";
},
1
)
}
try {
var where = document.getElementById(id) || parent.document.getElementById(id);
}
catch(err) {
var where = document.body;
}
where.appendChild(iframe);
var doc = iframe.contentWindow.document;
doc.open().write('\n' +
'
\n' +
'\n' +
'' +
'' +
' ' +
' ' +
'\n' +
'
');
doc.close();
};
// GESTIONE CONSENT FRAMEWORK 2.2
(function(win, simply_ad_height, simply_ad_width, simply_domain, fw_curl){
var timeout = 3000;
win.$4wConsentIsReady = win.$4wConsentIsReady || false;
win._4wDelivered = win._4wDelivered || false;
// se abbiamo già processato la cmp andiamo di delivery
if (win.$4wConsentIsReady) {
deliveryNative(simply_ad_height, simply_ad_width, simply_domain, fw_curl, win.$4wConsentGdprApplies, win.$4wConsentData, win.fw_isPassback, win.fw_isPassbackStill, win.fw_positionPBStill, win.$4wConsentPurpose);
}
else {
// se non abbiamo già registrato la funzione win.$4w__tcfapi
if (typeof win.$4w__tcfapi !== 'function') {
// coda di callback per tcf (versione 2.0 consent framework)
win.$4wCallbacks = {};
// Metodo che gestisce i messaggi ricevuti
// una volta inviato il messaggio all'iframe padre mettiamoci in
// ascolto per la ricezione
//
// NOTA BENE: poichè i messaggi possono essere di due tipi dobbiamo
// distinguere se la risposta è della funzione __cmp o della funzione
// __tcfapi
function postMessageHandler(event) {
// cerchiamo di ottenere un oggetto dal messaggio ricevuto, se
// fallisce va in errore e il blocco try catch lo ignora
let json = {};
try {
json = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
}
catch (ignore) {}
//console.log(json);
if (json.__tcfapiReturn) {
const payload = json.__tcfapiReturn;
if (typeof win.$4wCallbacks[payload.callId] === 'function') {
// qui facciamo la magia:
// eseguiamo la callback passando il valore di ritorno
win.$4wCallbacks[payload.callId](payload.returnValue, payload.success);
delete win.$4wCallbacks[payload.callId];
}
return;
}
}
// listener messaggi usato sia per CMP (1.1) che TCF (2.0)
if (win.addEventListener) {
win.addEventListener("message", postMessageHandler, false);
} else {
win.attachEvent("onmessage", postMessageHandler);
}
win.$4w__tcfapi = function(cmd, version, callback, arg) {
// frame corrente
var frame = win;
// frame TCF (2.0)
var tcfFrame;
// radice DOM
var wt = win.top;
// Problema: alcuni editori non ci chiamano in modo diretto...
// Quando ci chiamano in terza chiamata (esempio: OPQ) e c'è un altro
// iframe di mezzo (tra noi e il dominio del publisher) nel 99% dei casi
// non riusciamo a ottenere il consent.
//
// Per ovviare dobbiamo utilizzare la comunicazione tra iframe tramite
// postMessage e ovviamente un "trucchetto".
//
// scorriamo all'indietro il DOM partendo dalla finestra corrente
// alla ricerca degli iframe:
// __tcfapiLocator
while (frame) {
try {
if (!tcfFrame && frame.frames['__tcfapiLocator']) {
tcfFrame = frame;
break;
}
} catch(ignore) {}
// se siamo arrivati alla radice esci dal ciclo
if (frame === wt) break;
// in caso contrario prendi l'iframe padre e continua la ricerca
frame = frame.parent;
}
// se non abbiamo l'iframe dove inviare il messaggio esci
if (!tcfFrame) {
callback({msg: '__tcfapiLocator not found'}, false);
return;
}
const callId = Math.random() + '';
const msg = {
__tcfapiCall: {
command: cmd,
parameter: arg,
version: version,
callId: callId
}
};
win.$4wCallbacks[callId] = callback;
tcfFrame.postMessage(msg, '*');
};
}
// 2023-11-20: TCF v2.2 getTCData is deprecated
if (typeof win.__tcfapi === 'function') {
// check TCF version
win.__tcfapi('ping', 2, (pingReturn) => {
// since TCF 2.2 version, getTCData function is "deprecated"
var call_tcf_function = "getTCData";
// With the release of TCF v2.2, the policy version has been incremented to version 4.
if (("undefined" !== typeof pingReturn.tcfPolicyVersion) && (parseInt(pingReturn.tcfPolicyVersion)>=4)){
call_tcf_function = "addEventListener";
}
// read consent by API
win.__tcfapi(call_tcf_function, 2, (tcData, success) => {
if (success && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {
console.info("[ads_native.js] ("+tcData.eventStatus+") "+call_tcf_function);
win.$4wConsentData = tcData.tcString;
win.$4wConsentGdprApplies = tcData.gdprApplies == true || tcData.gdprApplies == 'true' || tcData.gdprApplies == 1 ? 1 : 0;
win.$4wConsentPurpose = typeof tcData.purpose !== 'undefined' && typeof tcData.purpose.consents !== 'undefined' && typeof tcData.purpose.consents[5] !== 'undefined' && tcData.purpose.consents[5] ? 0 : 1;
win.$4wTcData = tcData;
win.$4wConsentIsReady = true;
/*
* window.$4wTad
*
* Return true if:
* - user has skipped CMP
* - user has denied Google Vendor ID
* Return false if:
* - user has accepted Google Vendor ID
*
* TAD Google flag: https://support.google.com/admanager/answer/12767726?hl=it
*/
const GOOGLE_VENDOR_ID = "755";
var isConsentGiven = ((typeof tcData.purpose !== 'undefined') && Object.keys(tcData.purpose.consents).length>0) ? true : false;
var hasVendor = (((isConsentGiven) && (typeof tcData.vendor.consents[GOOGLE_VENDOR_ID] !== 'undefined'))? tcData.vendor.consents[GOOGLE_VENDOR_ID] : false);
win.$4wTad = !hasVendor;
deliveryNative(simply_ad_height, simply_ad_width, simply_domain, fw_curl, win.$4wConsentGdprApplies, win.$4wConsentData, win.fw_isPassback, win.fw_isPassbackStill, win.fw_positionPBStill, win.$4wConsentPurpose);
}
else if (!success){
console.info("[ads_native.js] (failed) ("+tcData.eventStatus+") "+call_tcf_function);
win.$4wConsentIsReady = true;
deliveryNative(simply_ad_height, simply_ad_width, simply_domain, fw_curl, win.$4wConsentGdprApplies, win.$4wConsentData, win.fw_isPassback, win.fw_isPassbackStill, win.fw_positionPBStill, win.$4wConsentPurpose);
}
});
});
}
else
{
// check TCF version
win.$4w__tcfapi('ping', 2, (pingReturn) => {
// since TCF 2.2 version, getTCData function is "deprecated"
var call_tcf_function = "getTCData";
// With the release of TCF v2.2, the policy version has been incremented to version 4.
if (("undefined" !== typeof pingReturn.tcfPolicyVersion) && (parseInt(pingReturn.tcfPolicyVersion)>=4)){
call_tcf_function = "addEventListener";
}
// read consent by postMessage
win.$4w__tcfapi(call_tcf_function, 2, (tcData, success) => {
if (success && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {
console.info("[ads_native.js] ("+tcData.eventStatus+") "+call_tcf_function);
win.$4wConsentData = tcData.tcString;
win.$4wConsentGdprApplies = tcData.gdprApplies == true || tcData.gdprApplies == 'true' || tcData.gdprApplies == 1 ? 1 : 0;
win.$4wConsentPurpose = typeof tcData.purpose !== 'undefined' && typeof tcData.purpose.consents !== 'undefined' && typeof tcData.purpose.consents[5] !== 'undefined' && tcData.purpose.consents[5] ? 0 : 1;
win.$4wTcData = tcData;
win.$4wConsentIsReady = true;
/*
* window.$4wTad
*
* Return true if:
* - user has skipped CMP
* - user has denied Google Vendor ID
* Return false if:
* - user has accepted Google Vendor ID
*
* TAD Google flag: https://support.google.com/admanager/answer/12767726?hl=it
*/
const GOOGLE_VENDOR_ID = "755";
var isConsentGiven = ((typeof tcData.purpose !== 'undefined') && Object.keys(tcData.purpose.consents).length>0) ? true : false;
var hasVendor = (((isConsentGiven) && (typeof tcData.vendor.consents[GOOGLE_VENDOR_ID] !== 'undefined'))? tcData.vendor.consents[GOOGLE_VENDOR_ID] : false);
win.$4wTad = !hasVendor;
deliveryNative(simply_ad_height, simply_ad_width, simply_domain, fw_curl, win.$4wConsentGdprApplies, win.$4wConsentData, win.fw_isPassback, win.fw_isPassbackStill, win.fw_positionPBStill, win.$4wConsentPurpose);
}
else if (!success){
console.info("[ads_native.js] (failed) ("+tcData.eventStatus+") "+call_tcf_function);
win.$4wConsentIsReady = true;
deliveryNative(simply_ad_height, simply_ad_width, simply_domain, fw_curl, win.$4wConsentGdprApplies, win.$4wConsentData, win.fw_isPassback, win.fw_isPassbackStill, win.fw_positionPBStill, win.$4wConsentPurpose);
}
});
});
}
// fallback after timeout if CMP doesn't call us: delivery with no consent
var readConsent = setInterval(function(){
clearInterval(readConsent);
if (!win._4wDelivered) {
console.info("[ads_native.js] delivery fallback");
win.$4wConsentIsReady = true;
deliveryNative(simply_ad_height, simply_ad_width, simply_domain, fw_curl, win.$4wConsentGdprApplies, win.$4wConsentData, win.fw_isPassback, win.fw_isPassbackStill, win.fw_positionPBStill, win.$4wConsentPurpose);
}
}, timeout);
}
})(window, simply_ad_height, simply_ad_width, simply_domain, fw_curl);
//Funzione che riconosce se il dispositivo è di tipo "mobile"
function isMobile() {
if (navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
) {
return true;
} else {
return false;
}
}
function insertCloseBtnPBStill(header) {
var x = 0;
var divBtn = document.createElement('div');
divBtn.id = 'fw-xmark_' + x;
divBtn.className = 'fw-sticky-close-button-pb';
divBtn.innerHTML = '';
header.contentDocument.body.appendChild(divBtn);
var cBtn = header.contentDocument.getElementById('fw-xmark_' + x);
divBtn.style.cssText = "top: -20px; width: 20px; height: 20px;z-index:999";
cBtn.onclick = function () {
header.parentNode.style.display = "none";
};
}
delete fw_fz;
delete fw_fc;
delete fw_czi;
delete fw_mzi;