(function () { tp = window["tp"] || []; /* window.PianoESPConfig = { id: 281, }; */ window.PianoESPConfig = { hashId: "C505DC52-1E1E-4340-987B-4984E70B5CFF" }; /* Checkout related */ /** * Event properties * * chargeAmount - amount of purchase * chargeCurrency * uid * email * expires * rid * startedAt * termConversionId * termId * promotionId * token_list * cookie_domain * user_token * */ function onCheckoutComplete(data) {} function onCheckoutExternalEvent() {} // definizione testata function pressWho() { const newspapers = [ "quotidiano", "ilrestodelcarlino", "localhost", "lanazione", "ilgiorno", "iltelegrafolivorno", ]; const urlPath = window.location !== window.parent.location ? document.referrer : document.location.href; let newspaper_is = ""; newspapers.forEach((paper) => { if (urlPath.includes(paper)) { newspaper_is = paper; } }); return newspaper_is; } // per aprire pagina fatturazione edicola function onCustomEvent(event, b, c, d) { console.debug("onCustomEvent", event); switch (event.eventName) { /* DA Verificare se cancellare con il nuovo form di fatturazione */ case "invoice-choice": var invoice = false; if ( typeof event.params.invoice != "undefined" && event.params.invoice.length > 0 ) { invoice = event.params.invoice; } console.debug(">*>*> final invoice choice: ", invoice); var newspaper = pressWho(); var baseUrl = "https://abbonati.quotidiano.net/" + newspaper; var finalUrl = baseUrl + "/invoice/index.html?wantsInvoice=" + invoice + "&tk=" + tp.pianoId.getToken(); console.debug("final redirect url", finalUrl); // redirect to invoice page location.href = finalUrl; break; } } //funzione per escludere l'alert di richiesta fattura function excludePage() { console.debug("initial parent location", window.parent.location); /**/ const urlWindow = window.location !== window.parent.location ? document.referrer : document.location.href; if (urlWindow.includes("ilrestodelcarlino.it/landing/break")) { window.parent.location.replace( "https://edicola.quotidiano.net/newsstand/ilrestodelcarlino" ); } /**/ console.debug("final parent location", window.parent.location); const excludeUrl = [ "/landing/ascom/carta-di-credito/", "https://www.google.com", ]; const urlPath = typeof iframe === "undefined" ? window.location !== window.parent.location ? document.referrer : document.location.href : window.location.href; excludeUrl.forEach((page) => { var urlPathIsExcluded = urlPath.includes(page); console.debug("page:", page, "isExcluded:", urlPathIsExcluded); return urlPathIsExcluded ? true : false; }); } function onCheckoutClose(event) { /* LG disabilitata funzionalità si usa il link alle fatture aggiunto alla fine della checkout /* Default behavior is to refresh the page on successful checkout * / if (event && event.state === "checkoutCompleted") { // location.reload(); /* Showing invoice form doesn't allow to use custom validation rules & other complex features */ // tp.pianoId.showForm({formName:"invoice_form"}); /* Show a template, and let the user choose between: askInvoice | skip * / //esclusione alert richiesta fattura if(excludePage() === false) { tp.offer.show({ offerId: 'OF4PX1JK0QX9', templateId: 'OT215MU5M48B', // we need only this part displayMode: "modal", width: '480', // TODO fix dialog width, not being processed with this setting height: '260', // // containerSelector: "#my-inline-offer", showCloseButton: false, // // close: function () {}, // // complete: function (params) {}, // // customEvent: function (params) { } }); } } */ } function onCheckoutCancel() {} function onCheckoutError() {} function onCheckoutSubmitPayment() {} /* Meter callback */ function onMeterExpired() {} /* Meter callback */ function onMeterActive() {} /* Callback executed when a user must login */ function onLoginRequired(params) { // Sets the cookie with the current state of the user document.cookie = "__pianoParams=" + encodeURIComponent(JSON.stringify(params)) + "; expires=" + new Date(new Date().getTime() + 60 * 60 * 1000).toGMTString() + "; path=/;"; } /* CookieManager */ function getCookie(name) { var v = document.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)"); return v ? v[2] : null; } function setCookie(name, value, days) { var d = new Date(); d.setTime(d.getTime() + 24 * 60 * 60 * 1000 * days); document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString(); } function deleteCookie(name) { setCookie(name, "", -1); } /* /CookieManager */ function onStartCheckout(params) { if (tp.user.isUserValid()) { var paramsCookie = tp.util.findCookieByName("__pianoParams"); if (params == null) { params = paramsCookie; } // Se il checkoutFlowId è CF63R8X3P28N, non applicare nessun form personalizzato if (params["checkoutFlowId"] === "CF63R8X3P28N") { // Rimuovi eventuale formNameByTermId per evitare che venga mostrato un form delete params["formNameByTermId"]; return; } var name_form="form-fatturazione"; if (params["offerType"]=="upgradeOffer"){ return; } if ( params["formNameByTermId"] && params["formNameByTermId"].indexOf("ordini-professionali") !== -1) { // console.error("TP Checkout" + params["formNameByTermId"]); return; } if (params.termId=="TM8FUUFMEMQE" ){ name_form="form-osservatori"; } if (params.termId=="TMZICH1G0V00" ){ name_form="evento-140-anni"; } /* aggiunto washing-machine */ if(params["formNameByTermId"].indexOf("washing-machine") !== -1){ tp.setCustomVariable("promoTerm","1"); } /* fine aggiunta washing-machine */ if ( params["formNameByTermId"] != '{"' + params.termId + '"' + ':"' + name_form +'"}' ) { setTimeout(() => { try { tp.offer.close(); var term_value = params.termId; var term_value_new = '{"' + term_value + '"' + ':"' + name_form +'"}'; params["formNameByTermId"] = term_value_new; tp.offer.startCheckout(params); } catch (error) { console.error(error); } }, 500); } setCookie("fonteML", "2"); } } /* Tracking */ function trackUser() { window.dataLayer = window.dataLayer || []; setTimeout(() => { try { const uStatus = window.dataLayer .filter((o) => "userStatus" in o && o) .at(-1); window.dataLayer.push({ event: "tracking", userStatus: uStatus.userStatus, userId: uStatus.userId, Id_Id: uStatus.Id_Id, }); } catch (error) { console.error(error); } }, 1000); } /* Tracking */ function onRegistrationSuccess(data) { /* aggiunta chimata a consensi * / var urlcons="https://pcon.monrif.net/cons.php?aid="+data.user.aud+"&uid="+data.user.sub; try { var xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", urlcons, false ); // false for synchronous request xmlHttp.send( null ); }catch(ex){} */ var fonteML = "reg-spontanea"; var regTerm = "TMLUDUTGVAAE"; var regTerm2 = "18ico1gzlzstd"; if (getCookie("fonteML") == "2") { fonteML = "reg-checkout"; // regTerm="TM9QMF15DEQ3"; } if (getCookie("_pc_reg_wall") == "1") { fonteML = "reg-wall"; //payWall // regTerm="TMKK4I3SC3BV"; } /*registration term try { if (tp.user.isUserValid() ){ console.log("TP REGTERM " + regTerm); // Create a conversion on registration term automatically tp.api.callApi("/conversion/registration/create", {term_id: regTerm}, function( conversionData ){ console.log("TP REGTERM CONV " + regTerm); }); console.log('TP Wait Reg Term'); }, 1000); } } catch(e){ console.log("TP Registration Term Error"); //console.log(e); } //registration term try { if (tp.user.isUserValid()){ console.log("TP CONVTERM " + regTerm2); // Create a conversion on registration term automatically tp.api.callApi("/conversion/registration/create", {term_id: regTerm2}, function( conversionData ){ console.log("TP CONVTERM CONV " + regTerm2); }); // 1 second wait setTimeout(function(){ console.log('TP Wait Conv'); }, 1000); } } catch(e){ console.log("TP Conv Term Error"); //console.log(e); } */ //newsletter try { regMlId(data, fonteML); // console.log ("TP COOKIE"+getCookie("fonteML")); } catch (e) { console.log("TP Params error2"); } //registration source try { regSource(tp.aid, tp.pianoId.getUser().sub, fonteML); } catch (e) { console.log("TP Params error3"); } const paywall = getCookie("_pc_piano_paywall"); if (paywall) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ userStatus: "registered", event: "visibility_blocked", visibility: "blocked", reason: "registered", }); } } /* Callback executed after a tinypassAccounts login */ function onLoginSuccess(data) { trackUser(); if (getCookie("addPassword") == "1") { window.location.href = "https://www.google.it"; } if (tp.localStorage.get("addPassword") == "1") { tp.localStorage.set("addPassword", ""); window.location.href = "https://dev.quotidiano.net/account"; } if (getCookie("_pc_piano_paywall") === "anonymous") { deleteCookie("_pc_piano_paywall"); } if (data.source == "OFFER") { tp.offer.close(); if (tp.user.isUserValid()) { // Get the stored cookie value var paramsCookie = tp.util.findCookieByName("__pianoParams"); var params; try { // Try to parse stored JSON data params = JSON.parse(paramsCookie); // Remove the old cookie document.cookie = "__pianoParams=null; expires=-1;" + " path=/;"; } catch (e) { params = false; } // If params object is valid - start checkout if (params ) { try { if(params["formNameByTermId"].indexOf("washing-machine") !== -1){ tp.setCustomVariable("promoTerm","1"); console.log("TP WASH CHECKOUT LOGIN"); } }catch(ex){} console.info(params); // Se il checkoutFlowId è CF63R8X3P28N, non applicare nessun form personalizzato if (params["checkoutFlowId"] === "CF63R8X3P28N") { // Rimuovi eventuale formNameByTermId per evitare che venga mostrato un form delete params["formNameByTermId"]; console.info("checkoutFlowId"); console.info(params); tp.offer.startCheckout(params); return; } // BLOCCO ordini-professionali: non modificare nulla if ( (params["formNameByTermId"] || "").indexOf("ordini-professionali") !== -1) { console.log("TP SKIP ORDINI PROFESSIONALI"); tp.offer.startCheckout(params); return; } var term_value = params.termId; var term_value_new = '{"' + term_value + '"' + ':"form-fatturazione"}'; params["formNameByTermId"] = term_value_new; tp.offer.startCheckout(params); } /*else { console.warn("freqcap params.offerId " +params.offerId); tp.experience.execute(); } */ } } } function onLogout() { trackUser(); setTimeout(location.reload(), 500); /*const paywall = getCookie('_pc_piano_paywall'); if(paywall === 'logged') { deleteCookie('_pc_piano_paywall') }*/ } /* Callback executed after an experience executed successfully */ function onExperienceExecute(event) {} /* Callback executed if experience execution has been failed */ function onExperienceExecutionFailed(event) {} /* Callback executed if external checkout has been completed successfully */ function onExternalCheckoutComplete(event) { /* Default behavior is to refresh the page on successful checkout */ //location.reload(); } tp.push(["setAid", "bC30V6YCpu"]); tp.push(["setCxenseSiteId", "1128466454647323938"]); tp.push(["setEndpoint", "https://buy.tinypass.com/api/v3"]); tp.push(["setUseTinypassAccounts", false]); tp.push(["setUsePianoIdUserProvider", true]); tp.push(['setPianoIdUrl', 'https://id.piano.io']); /* PRODUZIONE */ // tp.push(['setApplePayMerchantId','pmd_1NbM2QHasv0LOOMC4QPe6jUz']); tp.push(['setApplePayMerchantId','acct_14arygHasv0LOOMC']); /* TEST */ //tp.push(['setApplePayMerchantId','pmd_1PWe8NHasv0LOOMCONniVOiC']); /* checkout related events */ tp.push(["addHandler", "startCheckout", onStartCheckout]); tp.push(["addHandler", "checkoutComplete", onCheckoutComplete]); tp.push(["addHandler", "checkoutClose", onCheckoutClose]); tp.push(["addHandler", "checkoutCustomEvent", onCheckoutExternalEvent]); tp.push(["addHandler", "checkoutCancel", onCheckoutCancel]); tp.push(["addHandler", "checkoutError", onCheckoutError]); tp.push(["addHandler", "checkoutSubmitPayment", onCheckoutSubmitPayment]); /* user login events */ tp.push(["addHandler", "loginRequired", onLoginRequired]); tp.push(["addHandler", "loginSuccess", onLoginSuccess]); tp.push(["addHandler", "logout", onLogout]); tp.push(["addHandler", "registrationSuccess", onRegistrationSuccess]); /* meter related */ tp.push(["addHandler", "meterExpired", onMeterExpired]); tp.push(["addHandler", "meterActive", onMeterActive]); tp.push(["addHandler", "experienceExecute", onExperienceExecute]); tp.push([ "addHandler", "experienceExecutionFailed", onExperienceExecutionFailed, ]); /* external checkout related events */ tp.push([ "addHandler", "externalCheckoutComplete", onExternalCheckoutComplete, ]); //per aprire la form di fatturazione tp.push(["addHandler", "customEvent", onCustomEvent]); tp.push([ "init", function () { tp.experience.init(); console.log("INIZIALIZZO GA4 - G-7FMG8RRYMM"); tp.setGA4Config({ measurementId: "G-1QY0VE6NXY", eventParameters: { send_page_view: false, }, }); }, ]); tp.push([ "addHandler", "startCheckout", function (data) { try { console.log("tp startCheckout"); tp.setCustomVariable("termIdNl", data.termId); } catch (e) {} }, ]); tp.push([ "init", function () { tp.experience.init(); }, ]); })(); /* START NEWSLETTER */ function getMLId() { var uri = window.location.href; var mlid = "6521"; if (uri.indexOf("ancona") !== -1) { mlid = "3833"; } if (uri.indexOf("ascoli") !== -1) { mlid = "3834"; } if (uri.indexOf("cesena") !== -1) { mlid = "3836"; } if (uri.indexOf("civitanova") !== -1) { mlid = "3837"; } if (uri.indexOf("fano") !== -1) { mlid = "3838"; } if (uri.indexOf("fermo") !== -1) { mlid = "3839"; } if (uri.indexOf("ferrara") !== -1) { mlid = "3840"; } if (uri.indexOf("forli") !== -1) { mlid = "3841"; } if (uri.indexOf("imola") !== -1) { mlid = "3842"; } if (uri.indexOf("macerata") !== -1) { mlid = "3843"; } if (uri.indexOf("modena") !== -1) { mlid = "3844"; } if (uri.indexOf("padova") !== -1) { mlid = "3850"; } if (uri.indexOf("parma") !== -1) { mlid = "3852"; } if (uri.indexOf("pesaro") !== -1) { mlid = "3845"; } if (uri.indexOf("ravenna") !== -1) { mlid = "3846"; } if (uri.indexOf("reggio-emilia") !== -1) { mlid = "3847"; } if (uri.indexOf("rimini") !== -1) { mlid = "3848"; } if (uri.indexOf("rovigo") !== -1) { mlid = "3849"; } if (uri.indexOf("verona") !== -1) { mlid = "3851"; } if (uri.indexOf("venezia") !== -1) { mlid = "3853"; } return mlid; } function regMlId(data, fonte) { try { console.log("TP registrationMlID"); var dataForm = new FormData(); dataForm.append("email", data.user.email); dataForm.append("mlids", '["' + getMLId() + '"]'); dataForm.append("sub", true); dataForm.append("id", "RDC"); dataForm.append("fonte", fonte); dataForm.append("referer", window.location.href); var xhr = new XMLHttpRequest(); xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log("TP reg NL FONTE " + fonte + " " + this.responseText); } }); xhr.open( "POST", "https://newsletters.quotidiano.net/newsletter/sub/", false ); xhr.send(dataForm); } catch (e) { console.log(e); } } function regSource(aid, uid, fonte) { try { console.log("TP regSource"); var dataForm = new FormData(); dataForm.append("uid", uid); dataForm.append("id", aid); dataForm.append("fonte", fonte); dataForm.append("referer", window.location.href); var xhr = new XMLHttpRequest(); xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log("TP reg NL FONTE " + fonte + " " + this.responseText); } }); xhr.open( "POST", "https://newsletters.quotidiano.net/cons/setSource.php", false ); xhr.send(dataForm); } catch (e) { console.log(e); } } /* END NEWSLETTER */ /* CENTRO NOTIFICHE */ /* window.onmessage = (event) => { const currentUrl = window.location.href; let event_data = JSON.parse(event.data); if ( event_data.sender.startsWith("piano-id") && event_data.event == "closed" && currentUrl.includes("centro-notifiche") && !tp.user.isUserValid() ) { window.location.replace("/"); } }; */ // do not change this section // |BEGIN INCLUDE TINYPASS JS| (function (src) { var a = document.createElement("script"); a.type = "text/javascript"; a.async = true; a.src = src; var b = document.getElementsByTagName("script")[0]; b.parentNode.insertBefore(a, b); })("//cdn.tinypass.com/api/tinypass.min.js"); // |END INCLUDE TINYPASS JS|