(function () { console.group('EMBED__2'); const botonesSinFiltrar = document.getElementsByTagName('a'); const botones = Array.from(botonesSinFiltrar).filter((boton) => { const href = boton.getAttribute('href'); return href && href.includes('origen.io/'); }); document.addEventListener('click', function (event) { if (event.target.id == 'boton_cerrar') { document.getElementById('iframe').contentWindow.postMessage('clickCerrar', '*'); setTimeout(() => { document.getElementById('modal_origen').remove(); const urlParams = new URLSearchParams(window.location.search); const origenHash = urlParams.get('origen'); const cleanedUrl = window.location.href.replace(`origen=${origenHash}`, ''); history.replaceState('', '', cleanedUrl); const canonicalUrl = document.querySelector('link[rel="canonical"]'); if (canonicalUrl !== null) { canonicalUrl.href = cleanedUrl; } }, 150); } }, false); for (let i = 0; i < botones.length; i++) { botones[i].addEventListener('click', function (event) { event.preventDefault(); const direccionUrl = event.currentTarget.getAttribute('href') + '?iframe=true&boton=true'; const hash = event.currentTarget.getAttribute('href').split('/').pop(); history.pushState({ state: 'origen' }, '1', `?origen=${hash}`); const canonicalUrl = document.querySelector('link[rel="canonical"]'); if (canonicalUrl !== null) { canonicalUrl.href = window.location.href; }; if (direccionUrl) { insertOrigen(direccionUrl); } else { } }, false); } const urlParams = new URLSearchParams(window.location.search); const myParam = urlParams.get('origen'); if (myParam) { const direccionUrl = `https://qr.origen.io/${myParam}?iframe=true`; insertOrigen(direccionUrl); }; window.addEventListener('popstate', () => { // TODO aqui esta la movida // console.log('opstate'); // console.log(history.state); // if(!history.state || history.state.state!='origen'){ // } document.getElementById('boton_cerrar').click(); }); const canonical0 = document.querySelector('link[rel="canonical"]'); if (canonical0 !== null) { canonical0.href = window.location.href; } // GTM para iframe // (function () { // /// // SET COOKIE PROPIA // function setCookie (cname, exdays) { // const d = new Date(); // d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); // const expires = 'expires=' + d.toUTCString(); // const cvalue = Math.random() * 10000000; // document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; // }; // function getCookie (cname) { // const gaCookie = checkIfGaCookie(); // console.log('gaCookie________'); // console.log(gaCookie); // if (gaCookie) { // return gaCookie; // } else { // const name = cname + '='; // const ca = document.cookie.split(';'); // for (let i = 0; i < ca.length; i++) { // let c = ca[i]; // while (c.charAt(0) == ' ') { // c = c.substring(1); // } // if (c.indexOf(name) == 0) { // return c.substring(name.length, c.length); // } // } // return ''; // } // }; // function checkCookie () { // let user = getCookie('_origen'); // // console.log('(Checking cookie) value is:') // // console.log(user) // if (user != '') { // // alert("Welcome again to Origen: " + user); // return user; // } else { // setCookie('_origen', 365); // user = getCookie('_origen'); // if (user != '') { // return user; // } else { // return '11111111.22222222'; // } // } // }; // function checkIfGaCookie () { // try { // console.log('checkeandoCookies_1!'); // const trackers = ga.getAll(); // console.log('checkeandoCookies_3!'); // let i, len; // for (i = 0, len = trackers.length; i < len; i += 1) { // console.log(i); // console.log(trackers[i].get('trackingId')); // const clientId = trackers[i].get('clientId'); // if (clientId) { // return clientId; // } else { // throw new Error('ga no va'); // } // } // } catch (e) { // console.log('hay catch'); // console.log(document.cookie); // const match = document.cookie.match(/_ga=(.+?);/); // const gaUserId = match ? match[1].split('.').slice(-2).join('.') : false; // console.log('gaUserId ___(catch pillando por javascript)'); // console.log(gaUserId); // return gaUserId || false; // } // }; // // Set to the origin ("https://www.domain.com") of the iframe you want to communicate with // const childOriginDev = 'https://dev.origen.io'; // const childOrigin = 'https://origen.io'; // const possibleOrigins = ['https://qrkit.es', 'https://dev.origen.io', 'https://origen.io', 'https://origen.link', 'https://qr.dev.origen.io', 'https://qr.origen.io', 'https://qr.origen.link']; // const postCallback = function (event) { // console.log('PARENT: mensaje recibido'); // console.log('PARENT: event'); // console.log(event); // // if (event.origin !== childOrigin && event.origin !== childOriginDev ){ // if (!possibleOrigins.includes(event.origin)) { // console.log('not a valid Origin!'); // } else if (typeof event.data === 'string' && event.data.includes('internalHistory')) { // switch (event.data.split('_')[1]) { // case 'back': // history.back(); // break; // default: // break; // } // } else if (event.data !== 'childReady' && !event.data.event) { // } else if (event.data === 'childReady') { // // console.log('PARENT: child is ready!'); // event.source.postMessage('parentReady', event.origin); // const cookieValue = checkCookie('_origen'); // if (cookieValue) { // console.log('PARENT: Mandando mensaje con id a child'); // console.log('clientId: ' + cookieValue); // // console.log(event.origin); // event.source.postMessage({ // event: 'clientId', // clientId: cookieValue // }, event.origin); // } else { // /// XXXX que hacer en este caso? // } // } // }; // // Start listening for messages from child frame // window.addEventListener('message', postCallback); // })(); console.groupEnd('EMBED__2'); async function insertOrigen (direccionUrl) { const myRequest = new Request('https://qr.origen.io/check', { mode: 'cors' }); let _direccionUrl = direccionUrl; if (!direccionUrl.includes('qr.')) { _direccionUrl = direccionUrl.replace('origen', 'qr.origen'); } fetch(myRequest).then(function (response) { if (response.status != '222') { } else { document.body.insertAdjacentHTML('beforeend', `