Saltar navegación

[Cerrado] Google Conversion Tag in Form Button

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Nigel 4 years, 4 months ago.

Autor
Mensajes
#2288665

Hi Team!
I trying to install a google conversion tag in toolset form.

This script:

---------------
<!-- Event snippet for Conversão de Contacto conversion page
In your html page, add the snippet and call gtag_report_conversion when someone clicks on the chosen link or button. -->

<script>
function gtag_report_conversion(url) {
var callback = function () {
if (typeof(url) != 'undefined') {
window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': 'AW-451504147/yYRiCP2pp_ABEJPQpdcC',
'event_callback': callback
});
return false;
}
</script>
---------------

I add script in HTML. How can i call gtag_report_conversion on form submit click?

#2288739

Nigel
Colaborador

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+01:00)

According to the comment in the existing code, for this to work you just need to add a click event handler to the submit button which calls the function gtag_report_conversion.

You need a way to identify the form submit button (allowing for the possibility there could be other forms—and submit buttons—on the page). The easiest way to do that is to edit the form and add your own custom class to the submit button, e.g. "gtag-submit".

Then you can update your code to add that event listener. You can add the following to your existing code, just before the closing /script tag:

    const submitButton = document.querySelector('.gtag-submit');
    submitButton.addEventListener( 'click', gtag_report_conversion );

El debate ‘[Cerrado] Google Conversion Tag in Form Button’ está cerrado y no admite más respuestas.