document.addEventListener("DOMContentLoaded", function () { // 1. Lê as UTMs da URL atual const params = new URLSearchParams(window.location.search); const utmKeys = ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"]; const utmParts = []; utmKeys.forEach(function (key) { const value = params.get(key); if (value) { utmParts.push(key + "=" + value); } }); // 2. Se não tiver UTM nenhuma, não faz nada (mantém o link original) if (utmParts.length === 0) return; const utmString = utmParts.join(" | "); // 3. Monta a mensagem personalizada com as UTMs const mensagemBase = "Olá! Eu estava no costurese.com.br e gostaria de mais informações."; const mensagemCompleta = mensagemBase + " [" + utmString + "]"; const mensagemCodificada = encodeURIComponent(mensagemCompleta); // 4. Monta o novo link do WhatsApp const novoLink = "https://wa.me/5521994278993?text=" + mensagemCodificada; // 5. Encontra todos os links wa.me na página e atualiza const links = document.querySelectorAll('a[href*="wa.me"]'); links.forEach(function (link) { link.href = novoLink; }); });