let ctagid; let uuid; let layer = containerLayer; let CTGID; layer.push({}); function uuidv4() { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); } if (!localStorage.getItem('CTUUID')) { uuid = uuidv4(); localStorage.setItem('CTUUID', uuid); } else { uuid = localStorage.getItem('CTUUID'); } layer[0].userid = uuid; layer[0].events = []; ctagid = localStorage.getItem('CTID'); if (window.location.search.split('CTGID=')[1]) { CTGID = window.location.search.split('CTGID=')[1]; localStorage.setItem('CTGID', CTGID); } else { if (localStorage.getItem('CTGID')) { CTGID = localStorage.getItem('CTGID'); } else { CTGID = ''; } } sendEventTracking = async (eventType) => { let position = layer[0].events.indexOf(eventType); let host = window.location.host; let path = window.location.pathname; if (position === -1) { await fetch(`https://ctag.containermedia.net/api/event?type=${eventType}&userid=${uuid}&host=${host}&path=${path}&account=${ctagid}&impressionId=${CTGID}`, { method: 'GET' }); layer[0].events.push(eventType); } else { if (eventType === 'Page View') { await fetch(`https://ctag.containermedia.net/api/event?type=${eventType}&userid=${uuid}&host=${host}&path=${path}&account=${ctagid}&impressionId=${CTGID}`, { method: 'GET' }); layer[0].events.push(eventType); } } }; function importables() {}; function initializer() { sendEventTracking("pageview"); }; function clickers() {window.addEventListener("click", function(event) { if (window.location.href.match('cart')) { if (event.target.innerText === 'Finalizar compra') { sendEventTracking("carrito"); } } if (window.location.href.match('email')) { if (event.target.outerText === 'Continuar') { sendEventTracking("sendEmail"); } } if (window.location.href.match('payment')) { if (event.target.outerText === 'COMPRAR AHORA') { let productos = document.querySelectorAll('.hproduct'); let products = []; for (const p of productos) { let product = {}; product.name = p.querySelector('.product-name').innerText; product.price = p.querySelector('.price').innerText; products.push(product); fetch(`https://ctag.containermedia.net/api/s2s/secure/?id=662c7a0ab59cd839f4d225c9&products${product.name}&price${product.price}`); } sendEventTracking("comprar"); } } });} importables(); initializer(); clickers(); sendEventTracking('Page View');