Articles on: Client Side
This article is also available in:

Wordpress - Tracking Contactform7 & Gravity Forms through dataLayer events

To help you track your Gravity Forms and Contact Form 7 forms more accurately, you can use our WordPress plugin, which includes a special DataLayer event called "generate_lead." If you set it up to trigger based on a CSS element (like a thank-you message), form submission, or thank-you page, it may cause tracking errors. To avoid this, it's best to set it up using a DataLayer event in Google Tag Manager.

Here are the two situations you're in when setting this up:

You haven't set up tracking for your form yet

You've already set up tracking for your form

Let’s get started 🚀

You haven't set up tracking for your form yet



Setting up tracking for your forms helps you monitor how many visitors are filling them out, and whether your forms are functioning properly. Additionally, it provides insights into where your visitors come from, improving your website's performance.

Create a Trigger



To correctly track form submissions, you'll first need to set up a trigger in Google Tag Manager. A trigger activates when a specific event occurs, like submitting a form.

In this demonstration, we will guide you on how to create a trigger in Google Tag Manager.



Create a GA4 Event Tag



Once you have set up the trigger, now we will create a GA4 Event tag in Google Tag Manager (GTM). A tag helps send event data to Google Analytics when someone submits a form on your website.

In this demonstration, we will guide you through creating a GA4 Event Tag to send form submission data to Google Analytics.



Add Parameters for Visitor Data (Optional)



If you also want to send along data from your visitor who fills in the form (for enhanced conversions, for example), you can send that along as a parameter.

Under the DataLayer section in the GTM preview, you’ll see data about the form submission, such as:

form_data.your-name

form_data.your-email

form_data.your-message

form_data.your-subject

In this demonstration, we will guide you on how to add parameters to track visitor data.



These keys may vary based on your form fields. You need to test and identify the correct DataLayer Keys.

Create Data Layer Variables



To capture the values of the fields submitted in the form, (such as name, email, subject, or message), you need to create DataLayer Variables in GTM. These variables will help you capture user input and send it to Google Analytics.

For example, you can create a DataLayer variable for the form_data.your_name field to track the name entered by the user.

In this demonstration, we will guide you on creating Data Layer Variables in GTM



Configure the GA4 Event Tag with DataLayer Variables



Now that you have your variables set up, return to your GA4 event tag and include the DataLayer variables as parameters.

In this demonstration, we will guide you on how to configure the GA4 Event Tag with Data Layer Variables



For the other input fields, you can use the following parameter names:

Name of visitor = user_data.email_address

Form name = form_name

Form ID = form_id

Form thank-you page = form_destination

Completed message = free choice, as long as you do add this as a custom statistic in GA4

Preview Tag After Configuration



Before making the changes live, test everything using Preview Mode in Google Tag Manager. This allows you to ensure that everything is functioning correctly before publishing.

In Preview Mode, visit your website, fill out a form, and check if the GA4 - generate_lead tag fires when the form is submitted.

GA4 - generate_lead

You've already set up Tracking for your Form



If you already track your GravityForms or Contactform7 form and want to update it, all you have to do is change the trigger of your current tag and possibly adjust the parameters.

Modify the Trigger in Your Existing Tag



Start by removing your existing trigger, which is probably set to track using "CSS element visibility" or a "Thank You" page. These triggers are not the most accurate way to track form submissions. Next, create a new trigger called ‘trytagging_generate_lead’, and set it to ‘All Custom Events’. This custom trigger ensures that it fires specifically for GravityForms and Contact Form 7 submissions, providing more reliable tracking.

In this demonstration, we will guide you on how to update the trigger for your existing tag



Collect Form Data for Enhanced Conversions



Once the new trigger is set up, move on to configuring the GA4 event. Open your GTM container in Preview Mode and submit a form. After submission, check the DataLayer Event for ‘trytagging_generate_lead’.

Under the DataLayer section in the GTM preview, you’ll see data about the form submission, such as:

form_data.your-name

form_data.your-email

form_data.your-message

form_data.your-subject

These keys will depend on your form’s fields, so confirm them in your test.

Form Data in Data Layer

Create User-Defined Variables in GTM



Once you've identified the DataLayer keys, Now, create user-defined variables for each DataLayer key that corresponds to the form fields you want to track.

For example, create a variable for the name field by selecting Data Layer Variable and entering the DataLayer key, such as form_data.your-name. This ensures the form data will be available to use in the GA4 event.

In this demonstration, we will guide you on how to create user-defined variables in GTM



Modify the Existing GA4 Event Tag



After the variables are created, go back to the GA4 event setup and add parameters to capture the data. For the email address, use ‘user_data.email_address’ and link it to the email variable you created.

Similarly, add other parameters like form_data.you_name, form_data.your-message and form_data.your-subject to track additional form details.

In this demonstration, we will guide you on how to modify the existing GA4 Event Tag



For the other input fields, you can use the following parameter names:

Name of visitor = user_data.email_address

Form name = form_name

Form ID = form_id

Form thank-you page = form_destination

Completed message = free choice, as long as you do add this as a custom statistic in GA4

Finally, save your tag and test the entire setup to ensure everything is working correctly. Submit a form and check the event in GA4 to confirm that the submission and the associated data are tracked accurately.

Updated on: 06/02/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!