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; } function submitEvent(hostname, type) { var clickId = rtkValidClickID(getCookie('rtkclickid-store')); if (!clickId || clickId === 'undefined') { clickId = rtkValidClickID(sessionStorage.getItem("rtkclickid")); } if (!clickId || clickId === 'undefined') { setTimeout(function () { submitEvent(hostname, type); }, 1000); return; } console.log(type); if (hostname) { var xhr = new XMLHttpRequest; xhr.open("GET", `${hostname}/postback?clickid=${encodeURIComponent(clickId)}&type=${type}&eventid=${encodeURIComponent(clickId)}`); 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 detectProductByMeta() { try { return meta && meta.product; } catch (e) { return false; } } function detectProductByCartForm() { return document.querySelector("form[action='/cart/add']"); } var pathArray = (function () { var script = document.currentScript instanceof HTMLScriptElement ? document.currentScript : null; if (!script) { // A page element named "currentScript" shadows document.currentScript (DOM clobbering), a