WPForms is designed for simplicity, which is great for site owners and awkward for tracking: the form submits in the background and the page never changes. Most sites end up tracking the submit button, which counts every failed attempt.
WPForms fires a JavaScript event called wpformsAjaxSubmitSuccess when the server accepts a submission. This guide shows how to listen for it in Google Tag Manager and send the lead to GA4, Google Ads and Meta.
Prerequisites
- Google Tag Manager installed on the site.
- AJAX form submission enabled on the form, under Settings, then General, in the form builder.
- Your GA4 measurement ID, Google Ads conversion ID and label, and Meta pixel ID.
Step 1: The Listener
Create a Custom HTML tag named Listener - WPForms Success and fire it on All Pages:
<script>
(function () {
if (!window.jQuery) { return; }
jQuery(document).on('wpformsAjaxSubmitSuccess', function (event, json, formId, $form) {
var form = ($form && $form[0]) || event.target;
var email = form ? form.querySelector('input[type="email"]') : null;
var phone = form ? form.querySelector('input[type="tel"]') : null;
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'form_submit_success',
form_tool: 'wpforms',
form_id: String(formId || (form && form.getAttribute('data-formid')) || ''),
user_email: email && email.value ? email.value.trim().toLowerCase() : undefined,
user_phone: phone && phone.value ? phone.value.trim() : undefined
});
});
})();
</script>
Note the handler reads the fields from the form object passed with the event. WPForms clears the form after success, so reading from the page afterwards is unreliable.
Step 2: Variables and Trigger
Create Data Layer Variables for form_id, user_email and user_phone. Create a Custom Event trigger for form_submit_success, optionally with a condition on form_id.
Step 3: Tags
GA4 Event. Event name generate_lead, parameters form_id and form_tool. Mark generate_lead as a key event in GA4.
Google Ads Conversion. Conversion ID and label from the Google Ads conversion action, with a Conversion Linker tag on All Pages. For Enhanced Conversions, create a User-Provided Data variable from user_email and user_phone, attach it to the conversion tag, and turn Enhanced Conversions on in Google Ads.
Meta Lead. Fire the Lead event with email and phone as advanced matching parameters. If you use server-side GTM with the Conversions API, send the same event with a shared event ID.
Step 4: If AJAX Is Off
When AJAX is disabled, WPForms reloads the page and shows the confirmation message or redirects. Options:
- Turn AJAX on. This is the simplest fix and does not change the visitor experience.
- If you must keep it off, set the confirmation to redirect to a thank-you page, create a Page View trigger on that path, and add
noindexto the page.
Step 5: Test
- GTM Preview, submit the form with test data. Confirm
form_submit_successappears with the rightform_idand that email and phone are populated. - Confirm GA4, Google Ads and Meta tags fired once.
- Inspect the Google Ads request in a tag debugger such as the Insighter Debugger extension. You should see the conversion label and hashed user data.
- Submit with a missing required field. Nothing should fire.
- In GA4 DebugView, confirm
generate_leadarrives with its parameters.
Common Problems
- Nothing fires. AJAX is off, or jQuery is not available at the moment the listener runs. Try Window Loaded as the listener trigger.
- form_id empty. Older WPForms versions passed arguments in a different order. Use the
data-formidattribute fallback, which the code above already does. - Spam counted. Enable WPForms' anti-spam token and reCAPTCHA. Spam that passes those is accepted by the server and will count, so keep an eye on entries.
Result
One event, fired once, only when WPForms has accepted the submission, with the contact details available for Enhanced Conversions and Advanced Matching. That gives Google Ads and Meta the strongest possible signal from the smallest amount of code.
