function getRefQueryParam(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; var utmParamQueryString = '', utmParamQueryStringTrimmed = '', utm_source = '', utm_medium = '', utm_content = '', utm_campaign = '', utm_term = ''; (function() { utm_source = getRefQueryParam("utm_source"); utm_medium = getRefQueryParam("utm_medium"); utm_content = getRefQueryParam("utm_content"); utm_campaign = getRefQueryParam("utm_campaign"); utm_term = getRefQueryParam("utm_term"); if (utm_source) { utmParamQueryString += '&utm_source=' + utm_source; } if (utm_medium) { utmParamQueryString += '&utm_medium=' + utm_medium; } if (utm_content) { utmParamQueryString += '&utm_content=' + utm_content; } if (utm_campaign) { utmParamQueryString += '&utm_campaign=' + utm_campaign; } if (utm_term) { utmParamQueryString += '&utm_term=' + utm_term; } if(utmParamQueryString.length > 0) { utmParamQueryString = utmParamQueryString.substring(1); utmParamQueryStringTrimmed = utmParamQueryString; utmParamQueryString = utmParamQueryString; } if (!utmParamQueryString) return; var navLinks = document.querySelectorAll('a'); navLinks.forEach(function(item) { if (item.href.indexOf('/') === 0 || item.href.indexOf(location.host) !== -1) { if (item.href.indexOf('?') === -1) { item.href += '?'; } else { item.href += '&'; } item.href += utmParamQueryString; } }); })(); function ocard_redirect() { console.log('Redirect to ' + ocard_link); // test window.location.href = ocard_link; } // UTM -> Ocard var ocard_link = 'https://ocard.co/q?s=mkwbRm&qtk=bZ9nam&utm_source=web&utm_medium=booking&utm_campaign=booking&utm_content=booking'; if (utmParamQueryString) { ocard_link = 'https://ocard.co/q?s=mkwbRm&qtk=bZ9nam&' + utmParamQueryString; } console.log('link = ' + window.location.href); // test console.log('utmParamQueryString = ' + utmParamQueryString); // test console.log('ocard_link = ' + ocard_link); // test var reservation = document.getElementsByClassName('reservation-href'); for(var i = 0; i < reservation.length; i++) { reservation[i].addEventListener("click", ocard_redirect); }