Preencha as informações abaixo para iniciar seu atendimento
jQuery(document).ready(function($) {
// Dispara sempre que QUALQUER popup do Elementor abrir
$(document).on('elementor/popup/show', function() {
const currentUrlParams = new URLSearchParams(window.location.search);
// Mapeamento dos IDs configurados no Elementor
const utmFields = {
utm_source: 'form-field-utm_source',
utm_medium: 'form-field-utm_medium',
utm_campaign: 'form-field-utm_campaign',
utm_content: 'form-field-utm_content',
utm_term: 'form-field-utm_term'
};
// Verifica se tem UTMs na URL
let utmPresent = false;
for (const utmKey of Object.keys(utmFields)) {
if (currentUrlParams.has(utmKey)) {
utmPresent = true;
break;
}
}
// Fallback para Orgânico se não tiver UTM
if (!utmPresent) {
currentUrlParams.set('utm_source', 'orgânico');
}
// Loop de preenchimento
for (const [utmKey, inputId] of Object.entries(utmFields)) {
const utmValue = currentUrlParams.get(utmKey);
if (utmValue) {
// O seletor [id="..."] força o navegador a pegar todos, contornando a regra de ID único
const inputElements = document.querySelectorAll(`[id="${inputId}"]`);
// Preenche todos os campos encontrados em todos os popups
inputElements.forEach(function(inputElement) {
inputElement.value = utmValue;
});
}
}
});
});