Skip Navigation

[Closed] Google Conversion Tag in Form Button

This support ticket is created 3 years, 2 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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 3 years, 2 months ago.

Author
Posts
#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
Supporter

Languages: English (English ) Spanish (Español )

Timezone: 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 );

The topic ‘[Closed] Google Conversion Tag in Form Button’ is closed to new replies.