English Posts

Form tracking in Google Analytics 4

form tracking google analytics 4 and gtm

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:

form tracking google analytics 4
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

Create a new tag

Choose an Event tag

First of all, we have to create a new tag in GTM.

Go to Tag > New > Google Analytics 4: Event.

google analytics 4 event tag

Configuration Tag

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.

configuration tag google analytics 4

Choose the Event name

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:

events name google analytics 4

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:

event tag generate lead

Define Event parameters (optional)

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
event parameters google analytics 4

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.

Define User properties (optional)

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
user properties google analytics 4 tag manager

Create the trigger

Now we create the trigger in order to trigger the tag only for some specific Forms.

Select the Custom Event trigger

trigger custom event tag manager

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.

It’s easy:

  1. Open Google Tag Manager and enable the Preview Mode (top on the right)
preview mode google tag manager

2. Connect Preview Mode with your website:

connect website preview gtm

3. Let’s go on the website page where you have the Form you want to track, then fill in and submit it :

form submission

4. Let’s check the preview mode and what event is pushed into the Data Layer:

datalayer push form

Now I copy and paste the name “gtm4wp.formElementLeave” into our trigger:

custom event trigger gtm

We fire the trigger only on the page where there is the Form (A) and let’s enter a name for our trigger (B):

create trigger gtm

Save it.

Tag and Trigger

Here’s what the final result will look lik, i.e. our tag with its trigger:

tag and trigger gtm

Save it.

Test in Preview

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);
preview mode data layer gtm

Create Custom Dimension in Google Analytics 4

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

manage custom dimension google analytics 4

A new window will open, click on Create custom dimensions:

create custom dimension google analytics 4

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“:

create new custom dimension ga4

Save it.

Create User Property in Google Analytics 4

Now we’ve to register the User Property in GA4.

Let’s go into Configure > User Properties > New user property

create new user property in ga4

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):

new user property in google analytics 4

And save.

You can find a list of predefined user dimensions in the Google official Guide.

Publish the Container

If all testing went well, you can publish the container in Google Tag Manager to make the changes live on the website.

publish the container in gtm

Data Visualization in GA4

Once these steps have been completed, Google Analytics 4 will start collectiong 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.

debug mode google analytics 4

After 24 hours, all the values will be available in the Events > All Events Report:

event report google analytics 4

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:

custom parameters google analytics 4

Happy Analyzing!

You may also be interested by the following articles:

PII (Personally Identifiable Information): what is it?

What is GA4 Measurement ID?

How to filter internal traffic in Google Analytics 4

How to Link Google Analytics 4 to BigQuery

Regular Expression (RegEx): the Guidebook

How to delete gtm_debug=x in Google Analytics

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *