In this post, I’m going to show you how to track a Form with Google Analytics 4 and Google Tag Manager.
If you want to track the Lead of a user who fills out the Form on your website, firstly you must have created a new Property for GA4 and secondly created a tag in Google Tag Manager to pass the information to Analytics.
This is the path we’ll follow:
Table of content: - Create a new tag - Choose an Event tag - Configuration tag - Choose the Event name - Define Event Parameters (optional) - Define User Properties (optional) - Create the Trigger - Tag and trigger - Test in Preview - Create Custom Dimension in Google Analytics 4 - Create User Property in Google Analytics 4 - Publish the Container - Data Visualization in GA4
First of all, we have to create a new tag in GTM.
Go to Tag > New > Google Analytics 4: Event.
In the Configuration tag box (A) we select the Google Analytics tag (you can read this post if you want to know how create the GA tag easily) in order to pass the information on our GA4 Property.
Now we need to give the Event a name. I suggest you not to type a random name, but you should follow the Google Official Guide.
Since we are tracking a fill out of a Form, so the user is generating a Lead, we’ll use the Event name ‘generate_lead’ as suggested by the Google team:
The reason why I suggest you use this name instead of a random one, is related to the continuos implementation of Google Analytics 4 and its reports. In the future, Google may develop reports to collect these event names and it will be easier for you to measure it, just because it will fit directly into the report.
At this point, our tag will look like this:
We can now add some event parameters.
With these we can collect additional information.
Let’s add several values as you can see below (B):
- Parameter name: lead_type
- Value: newsletter_subscription
Why enter event parameters? It is useful if we have different types of Form on our website. In this case could only have one event name (called “generate_lead”) and then several parameters that identify the type of Form, for example:
- Newsletter subscription form: we can enter a parameter value such as “newsletter_subscription”;
- Information request form: we can type the parameter value “information_subscription”;
- Estimate request form: we could insert the value “estimate_subscription”;
The choise of tag names and structure depends on your measurement plan.
The Event tag for GA4 gives us the possibility to add the user property.
If wi fill in this field, all the users who have filled out the Form, according to the rules we’ve inserted in the tag, will be recognized as subscribers of this type of lead.
Let’s type the following values (C):
- Property name: newsletter_subscriber
- Value: true
Now we create the trigger in order to trigger the tag only for some specific Forms.
Select the Custom Event trigger
And inspect the page of our website where there is the Form. The aim is to see what is the event name that triggers when the Form is submitted.
- Open Google Tag Manager and enable the Preview Mode (top on the right)
2. Connect Preview Mode with your website:
3. Let’s go on the website page where you have the Form you want to track, then fill in and submit it :
4. Let’s check the preview mode and what event is pushed into the Data Layer:
Now I copy and paste the name “gtm4wp.formElementLeave” into our trigger:
We fire the trigger only on the page where there is the Form (A) and let’s enter a name for our trigger (B):
Here’s what the final result will look lik, i.e. our tag with its trigger:
Now we have to check if our tag and trigger fire correctly before publishing the container.
As described in the previous steps:
- Enable the Preview Mode;
- Connect our website to begin previewing our container;
- Fill in the Form and send it;
- Check the Preview: if everything is correct, we’ll see the Tag that is activated (A), as soon as the Form has been pushed into the Data Layer(B);
Now we’ve to create a new custom dimension in GA4, so that we can see the value of the parameter we previously put in our tag (what we called “lead_type“).
Let’s go into Events > All Events > Manage Custom Definitions
A new window will open, click on Create custom dimensions:
Then we’ll type the name of the parameter that we wrote in Google Tag Manager, that’s ‘lead_type‘ (A) and, if you want, you can change the name that will appear in your Reports giving a clearer name (B), which I called “Lead Type“:
Now we’ve to register the User Property in GA4.
Let’s go into Configure > User Properties > New user property
We need to type the same name we used in our tag in GTM: ‘newsletter_subscriber’ (remember that, once the name of the user property has been entered, it can be no longer be changed; you can change the description at any time):
You can find a list of predefined user dimensions in the Google official Guide.
If all testing went well, you can publish the container in Google Tag Manager to make the changes live on the website.
Once these steps have been completed, Google Analytics 4 will start collecting the information.
For each user who fills the Form, according to the rules set in the tag, you’ll be able to see the event that is collected (A), the parameter (B) and the user property set (C), as well as a series of other parameters that are associated with the event.
After 24 hours, all the values will be available in the Events > All Events Report:
If we click on the event previously created, i.e. ‘generate_lead‘, it’s possible to see custom parameters (A) that we typed in our tag in GTM: