(function () { function realUrlFromClkn(url) { var i = url.indexOf("/clkn/"); if (i === -1) return null; var tail = url.substring(i + 6); // after /clkn/ // Unbounce-style: "https/explore.bluwave.co.za/..." if (tail.startsWith("https/")) return "https://" + tail.substring(6); if (tail.startsWith("http/")) return "http://" + tail.substring(5); if (tail.startsWith("http")) return tail; return null; } function appendQs(dest, qs) { if (!qs || qs === "?") return dest; return dest + (dest.indexOf("?") >= 0 ? "&" : "?") + qs.replace(/^\?/, ""); } document.addEventListener( "click", function (e) { var qs = window.location.search; if (!qs || qs === "?") return; // Walk up the DOM from what was clicked (because button clicks often hit inner spans/divs) var el = e.target; var maxHops = 8; while (el && maxHops--) { // If it’s an anchor, grab its href if (el.tagName === "A" && el.href) { var href = el.href; // Only intercept trial/demo destinations if (href.includes("bluwave-crm-trial") || href.includes("bluwave-crm-demo")) { e.preventDefault(); e.stopPropagation(); var real = realUrlFromClkn(href) || href; window.location.href = appendQs(real, qs); return; } } // If it’s not an anchor, Unbounce button may store URL in data attributes // Check common attributes var attrs = ["data-href", "data-url", "href"]; for (var i = 0; i < attrs.length; i++) { var val = el.getAttribute && el.getAttribute(attrs[i]); if (val && (val.includes("bluwave-crm-trial") || val.includes("bluwave-crm-demo"))) { e.preventDefault(); e.stopPropagation(); var abs = val.startsWith("http") ? val : new URL(val, window.location.origin).toString(); var real2 = realUrlFromClkn(abs) || abs; window.location.href = appendQs(real2, qs); return; } } el = el.parentElement; } }, true // capture phase: runs BEFORE Unbounce handlers ); })();