Hi Guys,
This tutorial can give you quick easy fix for setting up Google Analytics event tracking in Divi Contact form. Before going forward, I assumed your website is well set up with ga code and it’s working fine.
Here logic is to use jQuery(Javascript library) to track form submit an event and keeping validation to ensure there is no error. This solution may not cover all the cases but cover almost 99% use cases.
Kindly add this js script in your custom .js file or can use WP add_inline_script().
jQuery(document).ready(function($){ $('.et_pb_contact_form').submit(function(event){ let dcHasError = true; setTimeout(function() { // now wait 1000 milliseconds... $('.et_pb_contact_form input').each( function() { console.log($(this).hasClass('.et_contact_error')) if( false === $(this).hasClass('.et_contact_error') ) { dcHasError = false; return false; } }) if( true === dcHasError) { ga('send', { hitType: 'event', eventCategory: 'event category name', eventAction: 'Form Submit', eventLabel: 'event category name' }); } },1000); }) });
Hope this helps to anyone struggling to tracking Divi contact form.
Thanks