Skip to main content

2.6.2 How to capture and parse the LeadJourney Click ID with Heyflow Forms

Jonas Strambach avatar
Written by Jonas Strambach
Updated this week
<script>
// LeadJourney - Heyflow Integration
document.addEventListener("DOMContentLoaded", function () {
function appendClickIdToAllHeyFlows(attempt = 0) {
const maxAttempts = 10;
const retryDelay = 500; // in ms

const clickId = localStorage.getItem('clickid');
if (!clickId) {
if (attempt < maxAttempts) {
setTimeout(() => appendClickIdToAllHeyFlows(attempt + 1), retryDelay);
}
return;
}

const wrappers = document.querySelectorAll('heyflow-wrapper');
if (!wrappers.length) return;

wrappers.forEach(wrapper => {
let tries = 0;
const maxTries = 30;

const interval = setInterval(() => {
if (!wrapper.shadowRoot) {
if (++tries >= maxTries) clearInterval(interval);
return;
}

const input = wrapper.shadowRoot.querySelector('input[data-label="lj_click_id"]');
if (input) {
input.value = clickId;
clearInterval(interval);
} else if (++tries >= maxTries) {
clearInterval(interval);
}
}, 300);
});
}

// Run on load and after Heyflow initializes
appendClickIdToAllHeyFlows();

window.addEventListener("heyflow-init", function () {
appendClickIdToAllHeyFlows();
});
});
</script>

🚨 More Information Coming Soon 🚨

Did this answer your question?