Articles on: Page Editor

How to install UTMs in GreatPages TRIGGERED BY A BUTTON

  1. Go to the page editor;



  1. Click the gear icon in the top right corner of the screen;



  1. Then click "Javascript & CSS";



  1. Click to "To add" a new code;



  1. Choose a name for your code, select the "Funcionamento" option and add the entire code below in the text field;


<script>
function URLToArray(url) {
var request = {};
if (url.indexOf('?') !== -1) {
url = encodeURI(url);
var pairs = url.substring(url.indexOf('?') + 1).split('&');
for (var i = 0; i < pairs.length; i++) {
if (!pairs[i]) continue;
var pair = pairs[i].split('=');
if(pair[1] == undefined || pair[1] == '') {
request[decodeURIComponent(pair[0])] = '';
} else {
try {
request[decodeURIComponent(pair[0])] = decodeURIComponent(unescape(pair[1]));
} catch (e) {
request[decodeURIComponent(pair[0])] = pair[1];
}
}
}
}
return request;
}
/* Campos para integração */
function CamposUTM(modal) {
if (modal == undefined) { modal = false; }
/* Formulários */
let formularios = Array.from(document.querySelectorAll((modal ? '.gpc_modal ' : '') + 'form'));
utm = URLToArray(window.location.href);
let link_usar = '';
if (Object.entries(utm).length) {
for (var [key, value] of Object.entries(utm)) { link_usar += key + '=' + value + '&'; }
if (link_usar.length) { link_usar = link_usar.substr(0, (link_usar.length - 1)); }
}
formularios.map(formulario => {
/* Controle de get utm_source */
$(formulario).find('.gpc_campo').each(function (i, campo) {
let valor = $(campo).val();
if (valor.indexOf('{') != -1 && valor.indexOf('}') != -1) {
let valor_limpo = valor.replace('{', '').replace('}', '');
utm.hasOwnProperty(valor_limpo) ? $(campo).val(utm[valor_limpo]) : $(campo).val('');
}
});
let botao = $(formulario).find('.gpc_botao');
if (
botao.attr('gpc-link') !== undefined &&
botao.attr('gpc-link') !== ''
) {
let concatenar = '?';
if (botao.attr('gpc-link').indexOf('?') !== -1) { concatenar = '&'; }
botao.attr('gpc-link', botao.attr('gpc-link') + concatenar + link_usar);
}
});
/* Botões */
if (link_usar != '') {
/* Habilitar para boões expecificos */
let botoes = Array.from(document.querySelectorAll((modal ? '.gpc_modal ' : '') + '.link_externo'));
botoes.map(link => {
/* Controle de get utm_source */
$(link).each(function (i, href) {

if(href.href.indexOf('tel:') != -1 || href.href.indexOf('mailto:') != -1) { return; }
let concatenar = '?';
if ($(href).attr('href').indexOf('?') !== -1) { concatenar = '&'; }
$(href).attr('href', $(href).attr('href') + concatenar + link_usar);
});
});
}
}
CamposUTM();
$('body').on('click', '.link_popup', function () {
setTimeout(() => {
CamposUTM(true);
}, 200);
});
</script>


Then click "Save"!


Still have questions? Reach out to our team on Chat! We're always happy to help.

Updated on: 08/05/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!