var campaignID = "6b075c2e2b497a31621b260b"; var cachebuster = Math.round(new Date().getTime() / 1000); var rtkClickID; function removeParam(key, sourceURL) { var rtn = sourceURL.split("?")[0], param, params_arr = [], queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : ""; if (queryString !== "") { params_arr = queryString.split("&"); for (var i = params_arr.length - 1; i >= 0; i -= 1) { param = params_arr[i].split("=")[0]; if (param === key) { params_arr.splice(i, 1); } } rtn = rtn + "?" + params_arr.join("&"); } return rtn; }; // 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; } // The page query forwarded with the click request: an rtkcid that fails the check counts // as absent, so it is dropped from the query as well. function rtkDropInvalidClickID(query) { var params = new URLSearchParams(query); if (!params.has('rtkcid') || rtkValidClickID(params.get('rtkcid'))) { return query; } return query.split('&').filter(function (p) { return !new URLSearchParams(p).has('rtkcid'); }).join('&'); } var urlParams = new URLSearchParams(window.location.search); var pixelParams = "&" + rtkDropInvalidClickID(window.location.search.substr(1)) if (campaignID == "") { campaignID = urlParams.get('rtkcmpid') } var initialSrc = "https://track.nationalwellnessbulletin.com/"+campaignID+"?format=json"; function stripTrailingSlash(str) { return str.replace(/\/$/, ""); } var rawData; setTimeout(function(){ if (!rtkValidClickID(urlParams.get('rtkcid'))) { xhr = new XMLHttpRequest; xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { rawData = JSON.parse(xhr.responseText); rtkClickID = rawData.clickid document.querySelectorAll('a').forEach(function(el) { if (el.href.indexOf("track.nationalwellnessbulletin.com/preclick")>-1) { if (el.href.indexOf('?')>-1) { el.href = stripTrailingSlash(el.href)+"&clickid="+rawData.clickid+"&rtkck="+cachebuster } else { el.href = stripTrailingSlash(el.href)+"?clickid="+rawData.clickid+"&rtkck="+cachebuster } } if (el.href.indexOf("clickid={clickid}")>-1) { el.href = el.href.replace(/{clickid}/, rawData.clickid)+"&rtkck="+cachebuster; } }); xhrr = new XMLHttpRequest; xhrr.open("GET", "https://track.nationalwellnessbulletin.com/preview?clickid="+encodeURIComponent(rawData.clickid)) xhrr.send(); } } xhr.open("GET", initialSrc+pixelParams) xhr.send(); } else { rtkClickID = rtkValidClickID(urlParams.get('rtkcid')) xhrTrack = new XMLHttpRequest; xhrTrack.open("GET", "https://track.nationalwellnessbulletin.com/preview?clickid="+encodeURIComponent(rtkClickID) ) xhrTrack.send(); document.querySelectorAll('a').forEach(function(el) { if (el.href.indexOf("track.nationalwellnessbulletin.com/preclick")>-1) { if (el.href.indexOf('?')>-1) { el.href = stripTrailingSlash(el.href)+"&clickid="+rtkClickID+"&rtkck="+cachebuster } else { el.href = stripTrailingSlash(el.href)+"?clickid="+rtkClickID+"&rtkck="+cachebuster } } if (el.href.indexOf("clickid={clickid}")>-1) { el.href = el.href.replace(/{clickid}/, rawData.clickid)+"&rtkck="+cachebuster; } }); } }, 5e1)