Tracking for Divi
Ever wanted to track the built-in contact form from Divi? If you tried using Google Tag Manager’s built-in form submit events to do it you probably noticed an inflated number of events flowing. This is because the form submission event is triggered even if there are form validation errors or the ser
Ever wanted to track the built-in contact form from Divi? If you tried using Google Tag Manager’s built-in form submit events to do it you probably noticed an inflated number of events flowing.
This is because the form submission event is triggered even if there are form validation errors or the server returns another error.
Since Divi doesn’t provide any JavaScript events to hook into there is no straightforward way to find out if a message has actually been sent.
To get around this, this plugin listens to the network communication that is happening underneath. It’s based on the same mechanism Divi itself uses.
There are three options now:
- 01a dataLayer event
- 02a Google Analytics 4 event (using gtag.js)
- 03a Google Ads conversion (also using gtag.js)
You can use either one of them or event all of them together.
You’ll be able to customize the dataLayer variable if you’re not using the standard naming , and the event names, separately for dataLayer and gtag.
Data layer reporting
The structure of the object pushed to the dataLayer is the following, with the default naming:
{ event: "contact_form_submit", formId: string, postId: number, formData: { name: string, email: string, message: string, }, allFormData?: Record<string, unknown>, // when "Include all form data" is enabled }
It’s up to you to use or discard the form data.
Google Analytics 4 reporting
The Google Analytics event is sent with flattened parameters:
gtag( "event", "contact_form_submit", { form_id: "divi/contact-form-0", name: "John", email: "john@example.com", message: "Hello", // additional fields when "Include all form data" is enabled } );
Form data (name, email, message) is included by default. When “Include all form data” is enabled, all form fields are flattened into the event parameters.
This will only work if you have a Google Tag already deployed on the website i.e. the gtag() function is available. Otherwise, you will see a warning in your console like this:
Tracking for Divi: gtag event failed, gtag is not defined
Google Ads conversion reporting
The Google Ads conversion is sent like so:
gtag( "event", "conversion", { send_to: "<conversion_id>/<conversion_label>", } );