function waitForVwoUUID(callback, timeout = 3000, interval = 100) { const startTime = Date.now(); const checkUUID = () => { const cookieMatch = document.cookie.match(/_vwo_uuid=([^;]+)/); const uuid = (cookieMatch && cookieMatch[1]) || localStorage.getItem('_vwo_uuid') || sessionStorage.getItem('_vwo_uuid'); if (uuid) { callback(uuid); } else if (Date.now() - startTime < timeout) { setTimeout(checkUUID, interval); } else { console.warn('VWO UUID not found within the timeout period.'); callback(null); } }; checkUUID(); } waitForVwoUUID((vwoUUID) => { console.log('VWO UUID:', vwoUUID); if (vwoUUID) { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => updateLinks(vwoUUID)); } else { updateLinks(vwoUUID); } } else { console.warn('VWO UUID is not available, skipping link updates.'); } }); function updateLinks(vwoUUID) { const links = Array.from(document.getElementsByTagName('a')); links.forEach(link => { const href = link.getAttribute('href'); if (href && href.includes('flux_action')) { const url = new URL(href, window.location.origin); url.searchParams.append('vwo_cf_uuid', vwoUUID); link.setAttribute('href', url.href); } }); }