Tracking Divi Forms in Google Tag Manager, GA4, and Facebook Pixel with Enhanced Conversions

Did you like this post? Share it!

Despite Divi being a popular WordPress builder, its built-in form solution lacks modern tracking capabilities. While you can set up a redirect to a thank-you page after submission, this approach is impractical for many reasons.

How can you track Ajax submissions in Divi forms?

Considering we’re in 2025 (or later), it’s also crucial to track enhanced conversions.

I’ve tested numerous tutorials, and only one solution worked seamlessly – visit on GitHub. I used and slightly modified this WordPress plugin from GitHub—it appears to be a functional solution. However, for my specific needs, I only wanted to send a dataLayer.push event in Google Tag Manager, and the plugin felt a bit too complex for that purpose.

<script>
jQuery(document).on("ajaxSuccess", function(_event, xhr, req, data) {
  var reqData = Object.fromEntries(new URLSearchParams(req.data));

  if (
    // check if this is a divi request
    req.url === window.location.href &&
    req.type === "POST" &&
    // check if the data sent is for a contact form
    Object.keys(reqData).some(function(key) { return key.startsWith("et_pb_contactform"); }) &&
    // check if the server response is valid
    xhr.status === 200 &&
    // check if the server didn't return an error message
    !jQuery(data).find(".et_pb_contact_error_text").length
  ) {
    var formmail = reqData.et_pb_contact_mail_0; // name of my field with email address
    dataLayer.push({ "event": "form_sent", "email": formmail  });
  }
});
</script>

How does the script work?

Unfortunately, it listens to all Ajax events on the site. When it detects a Divi form submission, it captures the event data, including field values, and then sends a dataLayer event containing the form details and email address.

You may set this script as custom HTML tag in your Google Tag Manager or in the footer of your WordPress site.

Happy tracking!

Subscribe to our newsletter
We send it 4 times a year.
Read more from our specialists