I would like to use Google Ads to track conversions when a user successfully send a contact form with the SEND button.
I'm currently using "Modal Contact Form" which is based on the example you provided in your template, some example also shows a green box in a corner message when a user fill the required fields and press the SEND button, and there is a validation that show field borders as red (indicating those fields needs to be filled) also provided by you in some example.
According to Google I should include the following code and call it from the button I want to track (in my case the SEND button).
function gtag_report_conversion(url) {
var callback = function () {
if (typeof(url) != 'undefined') {
window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': 'AW-123456789/aBcDEPv9Ju5sTT3sT',
'event_callback': callback
});
return false;
}
For the header I already configured it like this (note that UA and AW IDs are sample IDs)
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456789-0');
gtag('config', 'AW-123456789');
function gtag_report_conversion(url) {
var callback = function () {
if (typeof(url) != 'undefined') {
window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': 'AW-123456789/aBcDEPv9Ju5sTT3sT',
'event_callback': callback
});
return false;
}
I'm not using a "thank you" page, and I don't want to redirect to any other page. I want the user to see how the modal contact form dissapeared, then see the message box appear but staying in the same page (without reloading or redirect).
When I use the following code, the page redirects to the URL (in the example mywebsite.com) and don't validate the fields, and don't show the success message window neither.
This is the header of my modal contact form:
This is the code for the button that is inside the form:SEND
I guess I will need to include somehow part of the code inside functions.js below contact form validation but I do not know where or how to do the call.
Also, I have the same contact form in every page, how can I do so the URL parameter for gtag_report_conversion function is always the current webpage url?
Please you help.
Thanks!
