(function() { const url = 'https://api.apparell.com/api/tracking/product/8579169321302/collect' const getCookie = function() { const name = '_apparell' + '='; const cDecoded = decodeURIComponent(document.cookie); const cArr = cDecoded.split('; '); let res; cArr.forEach(val => { if (val.indexOf(name) === 0) res = val.substring(name.length); }) return res }; const cookie = getCookie() || '9409b81d-0a95-48ed-a73f-0ee0a6c23444'; const expires = 'expires=' + new Date(Date.now() + 31536000000); document.cookie = '_apparell' + '=' + cookie + '; ' + expires + '; path=/'; const getDefaultParams = function() { let x = 'connection=' + encodeURI(navigator.userAgent); x = x + '&lang=' + encodeURI(navigator.language); x = x + '&referer=' + encodeURI(document.referrer); x = x + '&url=' + encodeURI(window.location.href); x = x + '&cookie=' + cookie; return x }; const sendData = function(data) { const r = new window.XMLHttpRequest; r.open('POST', url, true); r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); r.send(getDefaultParams() + data); }; const initListeners = function() { sendData('&live=1'); document.onvisibilitychange = function() { if (document.visibilityState === 'hidden') { sendData('&live=0'); } else { sendData('&live=1'); } }; }; sendData('&live=1'); }).call(this);