// Appendix A: Capture first-touch UTM values. (function () { const params = new URLSearchParams(window.location.search); const source = params.get('utm_source'); const medium = params.get('utm_medium'); const campaign = params.get('utm_campaign'); const content = params.get('utm_content'); function setCookie(name, value, days) { const expires = new Date(Date.now() + days * 86400000).toUTCString(); document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires + '; path=/; SameSite=Lax'; } function getCookie(name) { return document.cookie.split('; ').find(row => row.startsWith(name + '=')); } // Preserve the original first touch. Content alone does not establish it. if ((source || medium || campaign) && !getCookie('first_touch')) { const firstTouch = { source: source || '', medium: medium || '', campaign: campaign || '', content: content || '', capturedDate: new Date().toISOString() }; const firstTouchJson = JSON.stringify(firstTouch); // Cookies are used by both the form script and Lava workflow actions. setCookie('first_touch', firstTouchJson, 365); setCookie('utm_source', firstTouch.source, 365); setCookie('utm_medium', firstTouch.medium, 365); setCookie('utm_campaign', firstTouch.campaign, 365); setCookie('utm_content', firstTouch.content, 365); setCookie('first_touch_date', firstTouch.capturedDate.split('T')[0], 365); } })(); // Appendix B: Populate and hide Connection Request tracking fields. (function () { function getCookie(name) { const parts = ('; ' + document.cookie).split('; ' + name + '='); return parts.length === 2 ? decodeURIComponent(parts.pop().split(';').shift()) : ''; } function setControlValue(control, value) { if (!control || !value) return; const valueSetter = Object.getOwnPropertyDescriptor( Object.getPrototypeOf(control), 'value' )?.set; if (valueSetter) valueSetter.call(control, value); else control.value = value; control.dispatchEvent(new Event('input', { bubbles: true })); control.dispatchEvent(new Event('change', { bubbles: true })); } function populateTrackingFields() { const expectedLabels = [ 'UTM Source', 'UTM Medium', 'UTM Campaign', 'UTM Content', 'First Touch Date', 'First Form Date' ]; const labels = [...document.querySelectorAll('label')]; const controls = {}; // Wait until every expected tracking control has rendered. for (const labelText of expectedLabels) { const label = labels.find(el => el.textContent.trim() === labelText); if (!label) return false; const control = (label.htmlFor ? document.getElementById(label.htmlFor) : null) || label.closest('.form-group')?.querySelector('input, textarea, select'); if (!control) return false; controls[labelText] = { label, control }; } let firstTouch = {}; try { firstTouch = JSON.parse(getCookie('first_touch') || '{}') || {}; } catch (error) { console.warn('Could not parse first_touch cookie', error); } const values = { 'UTM Source': firstTouch.source || getCookie('utm_source'), 'UTM Medium': firstTouch.medium || getCookie('utm_medium'), 'UTM Campaign': firstTouch.campaign || getCookie('utm_campaign'), 'UTM Content': firstTouch.content || getCookie('utm_content'), 'First Touch Date': (firstTouch.capturedDate || getCookie('first_touch_date') || '').split('T')[0], 'First Form Date': new Date().toISOString().split('T')[0] }; Object.entries(values).forEach(([labelText, value]) => { const item = controls[labelText]; setControlValue(item.control, value); const wrapper = item.label.closest('.form-group'); if (wrapper) wrapper.style.setProperty('display', 'none', 'important'); }); document.querySelectorAll('h4').forEach(heading => { if (['Tracking', 'UTM Tracking'].includes(heading.textContent.trim())) { heading.style.setProperty('display', 'none', 'important'); } }); return true; } if (populateTrackingFields()) return; const observer = new MutationObserver(function () { if (populateTrackingFields()) observer.disconnect(); }); // Use documentElement because Page Header scripts may run before body exists. observer.observe(document.documentElement, { childList: true, subtree: true }); setTimeout(function () { observer.disconnect(); }, 15000); })();