function getCookie(name) { var value = "; " + document.cookie; var parts = value.split("; " + name + "="); if (parts.length >= 2) return parts.pop().split(";").shift(); } // Not only 24 hex: in Google parallel tracking the click id is the gclid, wbraid or gbraid. function rtkValidClickID(value) { return typeof value === 'string' && value !== 'undefined' && /^[A-Za-z0-9_-]{1,200}$/.test(value) ? value : null; } var rtPending = []; var rtRetryTimer = null; function rtResolveClickId() { var clickId = rtkValidClickID(getCookie('rtkclickid-store')); if (!clickId || clickId === 'undefined') { clickId = rtkValidClickID(sessionStorage.getItem("rtkclickid")); } if (!clickId || clickId === 'undefined') return null; return clickId; } function rtFireEvent(hostname, type, clickId) { if (hostname) { var url = `${hostname}/postback?clickid=${encodeURIComponent(clickId)}&type=${type}&eventid=${encodeURIComponent(clickId)}`; var sent = false; if (navigator.sendBeacon) { try { sent = navigator.sendBeacon(url); } catch (e) { sent = false; } } if (!sent) { var xhr = new XMLHttpRequest; xhr.open("GET", url); xhr.send(); } } if (type === 'viewcontent' || type === 'addtocart') { var xhr2 = new XMLHttpRequest; xhr2.open("POST", '/cart/update.js'); xhr2.setRequestHeader("Content-Type", "application/json"); xhr2.send( JSON.stringify({ attributes: { '__clickid': clickId, } }) ); } } function rtScheduleRetry() { if (rtRetryTimer) return; rtRetryTimer = setTimeout(function () { rtRetryTimer = null; rtFlushPending(); if (rtPending.length) rtScheduleRetry(); }, 1000); } function rtFlushPending() { var clickId = rtResolveClickId(); if (!clickId) return; while (rtPending.length) { var e = rtPending.shift(); rtFireEvent(e.hostname, e.type, clickId); } } function submitEvent(hostname, type) { console.log(type); var clickId = rtResolveClickId(); if (!clickId) { rtPending.push({ hostname: hostname, type: type }); rtScheduleRetry(); return; } rtFireEvent(hostname, type, clickId); } window.addEventListener('pagehide', rtFlushPending); document.addEventListener('visibilitychange', function () { if (document.visibilityState === 'hidden') rtFlushPending(); }); function detectProductByMeta() { try { return meta && meta.product; } catch (e) { return false; } } function detectProductByCartForm() { return document.querySelector("form[action='/cart/add']"); } var rtPathArray = (function () { var script = document.currentScript instanceof HTMLScriptElement ? document.currentScript : null; if (!script) { // A page element named "currentScript" shadows document.currentScript (DOM clobbering), a