1document.addEventListener("DOMContentLoaded", () => { 2 const phoneMask = (value) => { 3 if (!value) return ""; 4 value = value.replace(/\D/g, ""); 5 value = value.replace(/(\d{2})(\d)/, "($1) $2"); 6 value = value.replace(/(\d)(\d{4})$/, "$1-$2"); 7 return value; 8 }; 9 10 const inputNome = document?.getElementById("evg-form-nomeContato"); 11 const inputEmail = document?.getElementById("evg-form-email"); 12 const inputTelefone = document?.getElementById("evg-form-telefone"); 13 14 inputNome && inputNome.setAttribute("maxlength", 200); 15 inputEmail && inputEmail.setAttribute("maxlength", 200); 16 17 if (inputTelefone) { 18 inputTelefone.setAttribute("maxlength", 14); 19 inputTelefone.addEventListener("change", ({ target }) => { 20 phoneMask(target.value); 21 }); 22 } 23 24 async function sha256(message) { 25 const msgBuffer = new TextEncoder().encode(message); 26 const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); 27 const hashArray = Array.from(new Uint8Array(hashBuffer)); 28 const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); 29 return hashHex; 30 } 31 32 // Função para adicionar eventos 33 function addDataLayerEvents() { 34 let formEntradaId = ''; 35 36 document.querySelectorAll('.contact-form__content .evg-banner-container button').forEach((element) => { 37 const pageUrl = window.location.href; 38 39 element.addEventListener("click", function () { 40 setTimeout(async () => { 41 const elementName = element.textContent.trim(); 42 const form = this.closest('.contact-form__content'); 43 const formEntrada = form.querySelector('[id]').id; 44 formEntradaId = form.querySelector('[id]').id; 45 const formDataName = form.querySelector('#evg-form-nomeContato')?.value || ''; 46 const formDataEmail = form.querySelector('#evg-form-email')?.value || ''; 47 const formDataTelefone = form.querySelector('#evg-form-telefone')?.value || ''; 48 49 const formValid = form?.querySelector(".evg-popup-container")?.style?.display === "flex"; 50 51 let formData = {}; 52 53 if (typeof dataLayer !== 'undefined' && formValid) { 54 // Mapeia os produtos para um array de códigos 55 const produtosMap = { 56 'VRB': 'Gestão de BenefÃcios', 57 'VRG': 'Gestão de Pessoas', 58 'VRM': 'Gestão de Mobilidade' 59 }; 60 61 // Obtém checkboxes marcados e mapeia para códigos de produto 62 const checkedInputs = form.querySelectorAll('input[type="checkbox"]:checked'); 63 const produto = Array.from(checkedInputs) 64 .map(input => produtosMap[input.id]) 65 .filter(Boolean) 66 .join(', '); 67 68 // Prepara dados do formulário com hash 69 formData = { 70 produto, 71 nome_sobrenome: await sha256(formDataName), 72 email: await sha256(formDataEmail), 73 telefone: await sha256(formDataTelefone), 74 objetivo: form.querySelector('#evg-form-objetivo')?.value || '', 75 }; 76 77 // Envia para o dataLayer 78 dataLayer.push({ 79 event: "vr_working_lead", 80 location: pageUrl, 81 flow: "loja", 82 form_id: formEntrada, 83 form_data: formData, 84 lead_status: "in_progress", 85 data_consent: form.querySelector('#evg-optin-checkbox')?.checked || false, 86 category_element: "vr_form", 87 local_element: "bot_form", 88 element_name: elementName, 89 type_element: "modal", 90 type_interaction: "click" 91 }); 92 } 93 94 const formModal = document.getElementById('popupFormSubmit'); 95 96 if (formModal) { 97 formModal.addEventListener("click", function () { 98 const form = formModal.closest('form'); 99 const formDataEmpresa = form.querySelector('#evg-form-nomeEmpresa')?.value || ''; 100 const formDataCargo = form.querySelector('#evg-form-cargo')?.value || ''; 101 const formDataColaboradores = form.querySelector('#evg-form-numeroFuncionarios')?.value || ''; 102 103 const checkedInputs = form.querySelectorAll('input[type="checkbox"]:checked'); 104 105 const formFilled = Boolean(formDataEmpresa && formDataCargo && formDataColaboradores); 106 107 // Adiciona ao form data cargo, empresa e numero_colaboradores 108 formData.cargo = formDataCargo; 109 formData.empresa = formDataEmpresa; 110 formData.numero_colaboradores = formDataColaboradores; 111 112 if (typeof dataLayer !== 'undefined' && formFilled) { 113 dataLayer.push({ 114 event: "vr_generate_lead", 115 location: pageUrl, 116 flow: "loja", 117 form_id: formEntradaId, 118 form_data: formData, 119 lead_status: "generated", 120 data_consent: form.querySelector('#evg-optin-checkbox')?.checked || false, 121 category_element: "vr_form", 122 local_element: "bot_form", 123 element_name: elementName, 124 type_element: "modal", 125 type_interaction: "sent" 126 }); 127 } 128 }); 129 } 130 }, 500); 131 }); 132 }); 133 } 134 135 // Observador de mutação para detectar mudanças no DOM 136 const observer = new MutationObserver(function () { 137 addDataLayerEvents(); 138 }); 139 140 // Configuração do observador 141 const config = { childList: true, subtree: true }; 142 const targetNode = document.querySelector(".contact-form__content"); 143 144 // Iniciar observador, se o nó alvo existir 145 if (targetNode) { 146 observer.observe(targetNode, config); 147 } 148 149 // Adicionar eventos iniciais 150 addDataLayerEvents(); 151 152 // Função para ajustar a altura do iframe 153 function adjustIframeHeight(iframe, height) { 154 if (iframe && height) { 155 setTimeout(() => { 156 iframe.style.height = "0px"; // Reseta a altura 157 iframe.style.height = height + "px"; // Define a nova altura 158 }, 50); // Pequeno atraso para garantir o recálculo correto 159 } 160 } 161 162 // Verifica se o iframe de empresa parceira existe 163 const iframe = document.getElementById("form-empresa-parceira"); 164 165 if (iframe) { 166 window.addEventListener("message", (event) => { 167 // Se a mensagem for a altura do iframe, ajuste a altura 168 if (event.data.frameHeight) { 169 adjustIframeHeight(iframe, event.data.frameHeight); 170 } 171 }); 172 } 173});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.