// CRO Enhancements - Sticky Bar, Exit Intent, Tracking (function() { // Only run on blog articles if (!window.location.pathname.includes("/blog/articles/")) return; // Check if user already converted or dismissed var hasConverted = localStorage.getItem("ukds_converted"); var hasDismissed = localStorage.getItem("ukds_dismissed"); var dismissedAt = localStorage.getItem("ukds_dismissed_at"); // Reset dismissal after 7 days if (dismissedAt && Date.now() - parseInt(dismissedAt) > 7 * 24 * 60 * 60 * 1000) { localStorage.removeItem("ukds_dismissed"); localStorage.removeItem("ukds_dismissed_at"); hasDismissed = null; } // === STICKY CTA BAR === var stickyBar = document.createElement("div"); stickyBar.className = "sticky-cta-bar"; stickyBar.setAttribute("role", "complementary"); stickyBar.setAttribute("aria-label", "Contact prompt"); stickyBar.innerHTML = '

Need expert help with your data project?

' + 'Get Free Consultation' + '×'; document.body.appendChild(stickyBar); // Show sticky bar after scrolling 40% var stickyShown = false; window.addEventListener("scroll", function() { var scrollPercent = (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100; if (scrollPercent > 40 && !stickyShown && !hasDismissed) { stickyBar.classList.add("visible"); stickyShown = true; } }); window.closeStickyBar = function() { stickyBar.classList.remove("visible"); localStorage.setItem("ukds_dismissed", "sticky"); localStorage.setItem("ukds_dismissed_at", Date.now().toString()); }; // === EXIT INTENT POPUP === if (!hasConverted && !hasDismissed) { var popup = document.createElement("div"); popup.className = "exit-popup-overlay"; popup.innerHTML = '
' + '×' + '

Wait! Before you go...

' + '
' + '
📊
' + 'Free Data Project Checklist' + '

' + 'The same checklist we use for enterprise projects

' + '
' + '
' + '' + '' + '
' + 'No thanks, I will figure it out myself' + '
'; document.body.appendChild(popup); var exitShown = false; document.addEventListener("mouseout", function(e) { if (e.clientY < 10 && !exitShown && !hasConverted && !hasDismissed) { popup.classList.add("active"); exitShown = true; trackCTA("exit_popup_shown"); } }); window.closeExitPopup = function() { popup.classList.remove("active"); localStorage.setItem("ukds_dismissed", "popup"); localStorage.setItem("ukds_dismissed_at", Date.now().toString()); }; window.submitExitForm = function(e) { e.preventDefault(); var email = e.target.email.value; trackCTA("exit_popup_converted", email); localStorage.setItem("ukds_converted", "true"); popup.querySelector(".exit-popup").innerHTML = '

🎉 Check your inbox!

' + '

We sent the checklist to ' + email + '

' + '

' + 'Or talk to us now →' + '

'; // Send to endpoint fetch("/api/lead-capture.php", { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({ email: email, source: "exit_popup", page: window.location.pathname }) }).catch(function(err) { console.error(err); }); }; } // === CTA TRACKING === window.trackCTA = function(action, label) { if (typeof gtag !== "undefined") { gtag("event", action, { event_category: "CRO", event_label: label || window.location.pathname }); } console.log("CTA tracked:", action, label); }; // Track all quote links document.querySelectorAll('a[href*="/quote"]').forEach(function(link) { link.addEventListener("click", function() { var isInlineCta = this.closest(".inline-cta") ? "inline_cta" : "other"; trackCTA("quote_click", isInlineCta); }); }); })(); // Social Proof Notification (function() { if (localStorage.getItem("ukds_social_proof_dismissed")) return; var messages = [ "3 businesses requested quotes today", "A London fintech just enquired about data scraping", "New project started: competitor price monitoring", "5 quotes sent this week" ]; var notification = document.createElement("div"); notification.id = "social-proof"; notification.style.cssText = "position:fixed;bottom:80px;left:20px;background:#fff;padding:15px 20px;border-radius:8px;box-shadow:0 4px 20px rgba(0,0,0,0.15);z-index:9998;display:none;max-width:280px;font-size:14px;border-left:4px solid #00cc66;"; notification.innerHTML = '
🔔
×'; document.body.appendChild(notification); window.closeSocialProof = function() { notification.style.display = "none"; localStorage.setItem("ukds_social_proof_dismissed", Date.now()); }; function showNotification() { var msg = messages[Math.floor(Math.random() * messages.length)]; document.getElementById("social-proof-text").textContent = msg; notification.style.display = "block"; setTimeout(function() { notification.style.display = "none"; }, 6000); } // Show after 20 seconds, then every 45 seconds setTimeout(showNotification, 20000); setInterval(showNotification, 45000); })();