document.addEventListener("DOMContentLoaded", function () { const utmParams = { utm_source: "yourexpertnetwork", utm_medium: "referral", utm_campaign: "site-links", }; const currentHostname = window.location.hostname; document.querySelectorAll("a[href]").forEach((link) => { if ( link.hostname && link.hostname !== currentHostname && link.protocol.startsWith("http") ) { try { const url = new URL(link.href); for (const key in utmParams) { url.searchParams.append(key, utmParams[key]); } link.href = url.toString(); } catch (error) { console.error("Could not process URL:", link.href, error); } } }); });