• Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login
  • Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login

December 7, 2022

Google Tag Manager Form Tracking with GA4: 7 Ways To Reach Your Goal

Updated: December 7th, 2022

While talking with marketers, I noticed that one of the most popular topics among them is form tracking. Unfortunately, in some cases, form tracking might become a real pain in the butt (especially if a marketer has no clue what CSS or HTML is). But do not fear because, in this blog post, I’ll show you 7 Google Tag Manager form tracking techniques.

Spoiler: some of them will require the developer’s input, but I’ll try my best to put everything in plain English.

 

Table of contents

+ Show table of contents +

  • If this blog post looks complex to you
  • Basic Context
  • Tag + Trigger
  • Before We Continue: Ready-made Guides
  • Which Form Tracking Method Should You Choose?
  • Method #1. Google Tag Manager Form Submission Trigger
  • Method #2. “Thank you” Page Tracking with Google Tag Manager
  • Method #3. Track AJAX Form Submissions with Google Tag Manager
  • Method #4. Track Form Submissions with Element Visibility Trigger
  • Method #5. Write Your Own Form Auto-Event Listener
  • Method #6. Form Tracking with dataLayer Events
  • Method #7. Track Form Submissions with DOM Scraping
  • Final words

 

If this blog post looks complex to you

This article is a long one and some parts might be confusing, especially if you are just starting with Google Tag Manager. If you want a fast solution, I have a module in my GTM course for beginners that is dedicated solely to form tracking. You can learn more about the course here.

 

Google Tag Manager Form Tracking: Basic Context

In this wonderful thing called THE INTERNET, there are various types of forms. Some of them refresh after a successful submission, some of them don’t, some of them might redirect you to a “thank you” page, etc. The main problem with form tracking is that there are no global standards of how forms must be developed. Some developers may prefer one technology (e.g., AJAX) over another – and they have a full right to do so.

Since you are interested in form tracking, you have probably noticed the Form Submission trigger and built-in Form variables in Google Tag Manager. Have at least one Form Submission trigger active on a page (which listens to all form submissions), and you’ll turn on Google Tag Manager Form auto-event listener.

google tag manager form tracking

Form auto-event listener listens for a standard submit browser event. However, a vast majority of forms use other ways to send their data (e.g. jQuery’s $.ajax) thus, the submit event is prevented from working. In that case, Google Tag Manager never records a form submission. And that’s a pretty common problem (in fact, I’d say that in 99% of cases where I worked, I used a different tracking method).

If GTM’s form listener does not work in your situation, there are other alternatives for how you can reach the goal. In this blog post, I will explain both standard options and workarounds for Google Tag Manager form tracking.

Google Tag Manager Ebook Bundle

Tag + Trigger

You are probably already familiar with the main Google Tag Manager concept: every interaction you want to track needs a tag and a trigger. If you want to track all form submissions with Google Analytics 4, you’ll need to create a Google Analytics Tag and a Trigger (rule) when a tag must fire.

Creating a tag is the easy part of this process. Let’s make one – you’ll need it in the upcoming chapters of this blog post.

In this article, I presume you have already installed Google Analytics 4 and already have the GA4 configuration tag. If not, read this blog post first.

After you have a GA4 config tag in your GTM container, it’s time to create a GA4 event tag that will be used in all of the examples of this article.

  1. Go to Tags
  2. Press New button
  3. In Tag Configuration choose Google Analytics: GA4 Event
  4. In the Configuration Tag field, select your current GA4 configuration tag. The event tag that we are creating will reuse some of the settings from the configuration tag (e.g. Measurement ID)
  5. In the Event Name field, I enter generate_lead
  6. Leave the Triggering part empty (for now) and click Save. We’ll get back to it later. 80% of this blog post is dedicated to various types of triggers you can make use of. The choice of trigger type depends on the way a form was developed.

Let me quickly explain some of the choices. The reason why I used generate_lead as an event name is that it is in the list of GA4 Recommended events. But if you want, you can name it something else.

Also, in the upcoming chapters of this blog post, I might suggest adding some additional parameters to this tag, so keep an eye on that.

======

Every form tracking method that I am going to cover depends on different elements/events that occur on a website after the form submission:

  • Form auto-event listener
  • Thank you page
  • AJAX form tracking
  • Tracking with Element Visibility trigger
  • Writing your own form auto-event listener
  • Developer’s help (to ask for the dataLayer.push)
  • DOM scraping

An incorrectly configured trigger will result in false data and reports (leading to wrong insights and actions). So read everything carefully.

If you have any questions or if some parts of this blog post are misleading, let me know in the comment section below, Twitter or LinkedIn. I will be glad to help.

 

Before We Continue: Ready-made Guides

Now, before we dive deep into this guide, there’s something you should know. This entire guide is universal and covers probably around 95% of form-tracking cases that I have/had to deal with.

However, to save you some time, I’d like to ask this: are you using Contact Form 7, Caldera Forms, or Gravity Forms plugins?

If yes, then I have some good news for you. Here are three guides tailored to those popular form plugins (some of them are using Universal Analytics (GA3) so you might need to adapt):

  • How to track Contact Form 7 with Google Tag Manager
  • How to track Gravity Forms with Google Tag Manager

If your form is custom or built using another technology, don’t worry. I have covered all the tips in the next chapters.

 

Which Form Tracking Method Should You Choose?

Before diving into the pool of triggers and tracking techniques, we’ll need to inspect a form and decide which technique fits our needs the best. I have prepared a flow scheme to help you choose the right Google Tag Manager form tracking method. Google Tag Manager Form Tracking Flow

Open full scheme on a new window

 

I am sure that some parts of that scheme might look vague. Continue reading, and everything will become much clearer.

 

Method #1. Google Tag Manager Form Submission Trigger

First, let’s try GTM’s built-in form listener. Open a list of Variables in your Google Tag Manager account. By default, form variables are disabled, therefore, you need to enable them. Under built-in variables, click Configure, and in the right sidebar enable all Form variables (all changes are automatically saved).

google tag manager form variables

Then open a list of all your triggers (by clicking Triggers in the left sidebar of the GTM interface). Create a new trigger with the following settings:

A little about the Check validation checkbox. Once this is checked, Google Tag Manager will not activate the Trigger if the default action of the form (submit and redirect) is prevented.

If left unchecked, the Trigger will go off whenever a submit event is registered (even when a form is submitted with errors (e.g. several required fields are left blank)).

When that checkbox is enabled, an additional field “Enable this trigger when…” appears. In my case, I want this trigger to be active on all pages, that’s why I entered Page Path contains /. Why? Because Page Path will always contain at least one slash on any page.

Now, let’s use GTM’s Preview and Debug mode to find out whether the default form auto-event listener works for us. At the top-right corner of your Google Tag Manager account, click Preview.

Then a new browser tab will open, asking you to enter the URL of the page where the form is located. Enter it and click Start.

Then a new tab (or window) will open with your website. At the bottom of the screen, you should see a badge similar to this one (that says connected):

If the preview mode’s tab or the badge has not connected, read this guide on how to fix Google Tag Manager Preview and Debug mode.

After Preview and Debug mode is enabled, navigate to the site where the form is located. Fill in the form (try not to leave any fields blank):

  1. Hit the submit button. Did a Form Submit event appear in the Preview and Debug console? If not, then GTM’s Form auto-event listener will not work with this form, and you should skip to the next form tracking option described in this blog post.
  2. If the Form Submit event did appear in Preview and Debug console, then you should do another test – try leaving at least one required form field empty and submit the form again. This way, you’ll imitate an error in your form:
    1. If the Form Submit event is fired once again, then you should check other form tracking options mentioned in this blog post.
    2. If the Form Submit event did not fire – that’s great! It means that GTM will track only those form submissions were successfully completed (and this is exactly what you need).

If you are reading this paragraph, I’ll presume that the Form Submission trigger works as expected and fires the event in the preview mode ONLY when a form is submitted successfully.

Let’s create a trigger specifically for that form. Remember the Form Submit event that was previously mentioned? Click on it (in Preview and Debug mode), then click Variables.

Then scroll down and start looking for any Form variable that is unique for that form. Usually, it will be Form ID variable, on other occasions – Form Classes (but Form ID is a better option). As you can see in the image below, I have submitted a form (of which Form ID variable is wpdevart-forms-7).

This is a good identifier that is not used on any other elements in the website, so I’ll use it for my trigger:

  1. Go to Triggers and open that Form Submission trigger that you have previously created
  2. Instead of “All Forms”, select “Some Forms” and enter the condition to target only that particular form. In my case, that is Form ID equals wpdevarp-forms-7.
    1. If you don’t see the Form ID variable – Enable it in the list of Built-in variables of Google Tag Manager.
    2. Form ID may (and probably will) be different in your situation (compared to my example).

Save the trigger.

If you have more than one form that visitors/users can submit, then it might make sense to include an additional parameter in your GA4 event tag (that will help you distinguish which form was submitted).

In GTM, go to Tags and edit the GA4 event tag you created.

There is no strict requirement of how that parameter should be named, so I’ll name it form_id. And its value will be the value of the {{Form ID}} variable.

Save the tag.

 

Let’s Test + Register Custom Dimension in GA4

  1. Assign this new trigger to the Google Analytics 4 Event Tag that you created at the beginning of this blog post.
  2. Refresh a Preview and Debug mode (by clicking the Preview button in the GTM interface once again)
  3. Then fill in the form and submit it. If Google Analytics Tag fired, that’s good news! Also (if possible), try submitting a different form on your website: in case of a successful submission, a GA tag should not fire.
  4. You should also check the incoming events in Google Analytics 4 Debug View.
  5. If you plan to use the form_id (or some other custom parameter in GA4 reports), you have to register them as custom dimensions. Read this guide to learn more.

 

Method #2. “Thank you” Page Tracking with Google Tag Manager

If the standard form listener in Google Tag Manager does not work, you should check whether that form redirects a user after a successful submission to another page.

  • If yes, what URL (web address) does it redirect to?
    form success URL

    • Is that address unique?
    • If yes, can users just navigate to that page without actually submitting a form? If the answer to the last question is no, then you can create a pageview trigger that fires only on that success page. Your goal here is to avoid accidental visits to success (a.k.a. “Thank you” page) as much as possible.

Now let’s create a trigger that fires only on the “Thank You” page.

  1. Go to Triggers in Google Tag Manager
  2. Press New button
  3. Choose trigger type – Pageview and Some page views
  4. If the visitor is redirected to https://www.example.com/form/thankyou.html, then you can set one of the following rules for this trigger:
    1. Page Path equals /form/thankyou.html.
    2. or Page URL contains /form/thankyou.html. Try being as specific as possible. Setting just “thankyou” as a rule for this trigger might not be the best idea because there might be other pages, of which URLs can contain that word (and we don’t want that!).
  5. And do not forget to properly name the trigger, e.g. “Pageview – Successful Form Submission”. A title must be clear. Otherwise, you’ll have a mess in your Google Tag Manager account (in the long run). You can read more about naming tips (a.k.a. Naming Conventions) here.

Google tag manager form tracking - pageview success page

 

Let’s Test + Dimensions in GA4

  1. Assign this new trigger to the Google Analytics 4 Tag that you created at the beginning of this blog post.
  2. Open (or refresh) a Preview and Debug mode, and refresh a web page with a form you want to track.
  3. Then fill in the form and submit it. After successful submission, you’ll be redirected to a “Thank you” page – if Google Analytics Tag fired, good job! Also (if possible), try submitting a different form on your website (to see if the tag did not fire on accident).
  4. You should also check Google Analytics 4 Debug View.
  5. If you have multiple forms and all of them have different thank you pages, you don’t need to set any custom parameters to the GA4 event tag. GA4 already automatically tracks page_location, and you can distinguish form submissions with a dimension such as Page Path.
  6. If, on the other hand, you have multiple forms and one “Thank you” page, you will need to do this:
    1. Check all of these tips and see if you can get a variable that contains some form identifier (e.g., form id, form name, etc.) and use it in the next list item.
    2. And then include an additional parameter in the GA4 generate_lead event tag. It can be something like form_id, form_name, or whatever works for you, for example:
Subscribe and Get the Ebook - Real Book Img - GTM for Beginners

Method #3. Track AJAX Form Submissions with Google Tag Manager

If you are reading this part, your form is probably not sending valid form submit events and is not redirecting users to a “thank you” page. It probably just refreshes itself and then displays “You have successfully filled in the form” message without the actual page refresh.

There’s a big chance that this form is using AJAX. I suggest skipping all the technical details here. The only thing here you should know is AJAX listener.

Bounteous have shared an awesome AJAX listener for GTM everyone can use for free. Here we’ll borrow their code to track form submissions. Copy the code below and paste it in the Custom HTML tag on Google Tag Manager:

<script id="gtm-jq-ajax-listen" type="text/javascript">
 (function() {

 'use strict';
 var $;
 var n = 0;
 init();

 function init(n) {

 // Ensure jQuery is available before anything
 if (typeof jQuery !== 'undefined') {
 
 // Define our $ shortcut locally
 $ = jQuery;
 bindToAjax();

 // Check for up to 10 seconds
 } else if (n < 20) {
 
 n++;
 setTimeout(init, 500);

 }

 }

 function bindToAjax() {

 $(document).bind('ajaxComplete', function(evt, jqXhr, opts) {

 // Create a fake a element for magically simple URL parsing
 var fullUrl = document.createElement('a');
 fullUrl.href = opts.url;

 // IE9+ strips the leading slash from a.pathname because who wants to get home on time Friday anyways
 var pathname = fullUrl.pathname[0] === '/' ? fullUrl.pathname : '/' + fullUrl.pathname;
 // Manually remove the leading question mark, if there is one
 var queryString = fullUrl.search[0] === '?' ? fullUrl.search.slice(1) : fullUrl.search;
 // Turn our params and headers into objects for easier reference
 var queryParameters = objMap(queryString, '&', '=', true);
 var headers = objMap(jqXhr.getAllResponseHeaders(), '\n', ':');

 // Blindly push to the dataLayer because this fires within GTM
 dataLayer.push({
 'event': 'ajaxComplete',
 'attributes': {
 // Return empty strings to prevent accidental inheritance of old data
 'type': opts.type || '',
 'url': fullUrl.href || '',
 'queryParameters': queryParameters,
 'pathname': pathname || '',
 'hostname': fullUrl.hostname || '',
 'protocol': fullUrl.protocol || '',
 'fragment': fullUrl.hash || '',
 'statusCode': jqXhr.status || '',
 'statusText': jqXhr.statusText || '',
 'headers': headers,
 'timestamp': evt.timeStamp || '',
 'contentType': opts.contentType || '',
 // Defer to jQuery's handling of the response
 'response': (jqXhr.responseJSON || jqXhr.responseXML || jqXhr.responseText || '')
 }
 });

 });

 }

 function objMap(data, delim, spl, decode) {

 var obj = {};

 // If one of our parameters is missing, return an empty object
 if (!data || !delim || !spl) {

 return {};

 }

 var arr = data.split(delim);
 var i;

 if (arr) {

 for (i = 0; i < arr.length; i++) {

 // If the decode flag is present, URL decode the set
 var item = decode ? decodeURIComponent(arr[i]) : arr[i];
 var pair = item.split(spl);

 var key = trim_(pair[0]);
 var value = trim_(pair[1]);

 if (key && value) {

 obj[key] = value;

 }

 }

 }

 return obj;

 }

 // Basic .trim() polyfill
 function trim_(str) {

 if (str) {

 return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');

 }

 }


 })();
 /*
 * v0.1.0
 * Created by the Google Analytics consultants at http://www.lunametrics.com
 * Written by @notdanwilkerson
 * Documentation: http://www.lunametrics.com/blog/2015/08/27/ajax-event-listener-google-tag-manager/
 * Licensed under the Creative Commons 4.0 Attribution Public License
 */
</script>

Set that Custom HTML tag to fire on all pages.

Now, let’s check whether a form is built on AJAX:

  1. Enable (or refresh) Preview and Debug mode.
  2. Try submitting the form on your website (with no errors).
  3. Did the ajaxComplete event appear in the Preview and debug console?
    1. If yes, the form uses AJAX.
    2. If not, skip to the next chapter of this blog post.

If your answer to the previous questions was Yes, let’s take a look at what we can do with that AJAX form. Click ajaxComplete event in Preview and Debug mode, then expand the API call:

Looks difficult for a non-developer, right? But it’s easier than you think.

This data was passed to the data layer after the successful submission of the form. Each line is a separate dataLayer data point that can be used as a dataLayer variable in GTM.

Now you should look for something that helps identify successful form submissions. Scroll down and look for “response”.

Let’s take a closer look at it. Can you see the message “Thanks for contacting us! We will be in touch with you shortly”? Bingo! We can use it as a trigger.

First, let’s create a Data Layer variable in Google Tag Manager.

  1. Go to Variables
  2. Scroll down to User-Defined  variable and hit New
  3. Click Variable configuration and choose variable type – Data Layer Variable
  4. Enter Data Layer Variable Name – attributes.response.data.message

You’re probably guessing why I entered attributes.response.data.message as Data Layer Variable Name, instead of just response. Let’s take a closer look at Data Layer in Preview and Debug mode.

In line 2, you see the event named ajaxComplete – that’s the same name that appears in Preview and Debug console’s left side. Then we see attributes which is an object containing various data points (key-value pairs). And the response is one of those keys.

Within that response (2), we see data (3), and within that, we see message (4).

Think of this as accessing folders. First, you have to access the attributes, then you go to response, then you go do the data folder and then you access message.

IMPORTANT: in your case, the structure of the data can be different, and parameters can be named differently. It will always start with attributes.response, but after that, things might differ in every form. It might be attributes.response.message or something like that. You will need to adapt.

Another example: let’s say you’re interested in Server data (from that very exact AJAX response). In that case, the Data Layer Variable’s Name should be attributes.headers.Server  .

After we create the Data Layer variable in Google Tag Manager, let’s debug. Refresh Preview and Debug mode (by clicking the Preview button in the GTM interface).

Fill in the form and submit it. Click the most recent ajaxComplete event in Preview and Debug console, then navigate to the Variables tab and find the new variable dlv – attributes.response.data.message. If you did everything correctly, it should look like this:

That’s a message of the successfully submitted form. If the value of that variable is undefined, then you should start looking for mistakes. The most common ones are typos in the variable name or inaccurately defined variable’s path. Some people just try using response instead of attributes.response.data.message. 

Now let’s create a trigger that fires when the event is ajaxComplete, AND our new Data Layer variable contains “Thanks for contacting us”.

  1. Go to Triggers and click New
  2. Choose Trigger Type – Custom Event
  3. Enter Event name – ajaxComplete
  4. This trigger should fire on Some Custom Events.
  5. Define a condition when the trigger will fire – dlv – attributes.response.data.message contains Thanks for contacting us!

 

Let’s Test

  1. Assign this new trigger to the Google Analytics 4 Event Tag that you created at the beginning of this blog post.
  2. Open (or refresh) a Preview and Debug mode
  3. Then fill in the AJAX form and submit it. After successful submission, Google Analytics 4 Event Tag should fire (it will be displayed in Preview and Debug mode. You should also check Google Analytics 4 Debug View.

Things to keep in mind when tracking AJAX forms:

  1. The response of your form might look different, so you should adjust your Data Layer Variable and Custom Event trigger.
  2. If developers change the response’s data, your trigger will fail. Inform developers about your GTM implementation.
  3. If the page contains more than one AJAX form, try looking for more information in Data Layer, which can help Google Tag Manager tell the difference between those forms.
Google Tag Manager Ebook Bundle

 

Method #4. Track Form Submissions with Element Visibility Trigger

One of the most awesome triggers in GTM (in my opinion) is the Element Visibility trigger. It enables you to track when a particular element appears on the screen (due to scrolling or some other circumstances).

The same technique can be applied to forms when a particular message (e.g., “Thank you”)  appears after a form is successfully submitted.

I have a bit older tutorial about this technique that uses Universal Analytics, but if you have no problem with this, you can take a look at that video below.

The first thing we need to do here is to inspect the success message of a form. We’ll need to find a way how to instruct Google Tag Manager in which particular website element we are interested in.

After you submit the form successfully, right-click on the success message and choose Inspect Element.

Inspect Element - Form Success Message

You will then see the browser’s developer tools that contain various information about the message: its content, CSS class, etc.

In the example below, I see that the message has a class “thanks” which could be used as a condition in the Element Visibility trigger. It was even better if the success message had a parameter called “id,” but since it’s not available, we’ll use CSS class.

Thank you message of a form

Let’s go to your Google Tag Manager container and go to Triggers. Create a new trigger and choose Element Visibility as its type. The key ingredient here is the Selection Method that will help GTM understand what we are looking for.

selection method

The selection method has two options: Element ID and CSS Selector. Since the success message in my example has no id (but “class”), we’ll go with CSS Selector.

In the Element Selector field, we need to paste that class “thanks”. In CSS, every class is defined with a dot in front of it, so let’s do the same.

Finally, make sure you tick “Observe DOM changes”. This setting means that if an element appears on the screen not due to scrolling but under some other circumstances (e.g., “just simply pops in”), GTM will catch it (most likely).

Take a look at the screenshot below. If you want, you may do some other tweaks but what I did was a bare minimum.

Element Visibility Trigger in form tracking

Save the trigger.

If you have no idea what you are doing here with a CSS selector, I explain them in plain English here + I share some tips on how to learn the topic faster.

 

Let’s Test

  1. Assign this new trigger to Google Analytics Tag that you created at the beginning of this blog post.
  2. Open (or refresh) a Preview and Debug mode
  3. Then fill in the form and submit it. After successful submission, in the P&D console, you will see the Element Visibility event. Click it, and you will see that the GA4 tag has fired. If you don’t see the Element Visibility event, you probably made some mistake in the Selection method or CSS selector field. Or forgot to enable Observe DOM changes checkbox. Or that form is in the iFrame (in that case, my Intermediate/Advanced GTM course will help you solve the problem).

 

Method #5. Write Your Own Form Auto-Event Listener

Yes, I know that this sounds complicated. Actually, this can’t be further from the truth.

If no other tracking method (explained in this blog post) works, then you have nothing to lose. Where am I going with this?

There is a slight chance that you can write an auto-event listener on your own (without solid coding skills). And I have explained that in this blog post.

So before you dive into that article, first answer this question: Are you trying to track some custom-made form built by a developer specifically for your website? If yes, skip to Chapter #6 of this blog post. Otherwise, try this method. It is not directly related to forms but the idea can work and can be applied.

For example, the Gravity form tracking guide is basically the result of this method.

 

Method #6. Form Tracking with dataLayer Events

Disclaimer: Although this form tracking method is a very robust solution, I placed it as a No.6 option in this list for a reason.

When other marketers approach me for form tracking advice, they’re looking for a solution where the developer’s input can be avoided. “Manage your marketing tags without help from developers” is one of the main reasons why they start considering Google Tag Manager in the first place.

This statement was among GTM’s key “selling” points when it was launched, so it’s no surprise marketers expect this to be 100% true. Although we know that in many situations, the developer’s help is strongly advised. My position here:

  1. If you have access to developers and Google Tag Manager’s Form listener isn’t working for you, I recommend using dataLayer.push method, which I will describe further.
  2. If you don’t have access to developers or they are super busy (and they usually are), then it’s okay to track with other techniques mentioned in this blog post. Just be aware that other solutions have a bigger chance of breaking when developers constantly update a website. This especially applies to technique No. 7 – DOM scraping.

I hope I made my point clear and we can continue.

As it was mentioned above, if the built-in Google Tag Manager Form listener does not work with your form, the next best thing is to ask the developer to implement a custom dataLayer.push() into the callback function, which is activated upon successful form submission. The piece of code could be something like this (obviously, that dummy data like “Footer” should be replaced with the actual data of your form):

window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({
   'event': 'formSubmission',
   'formType': 'Contact us',
   'formPosition': 'Footer'
});

You’ll need to prepare a short but well-written and clear task for a developer:

  1. First, choose a name for the event. In the example above, I chose formSubmission.
  2. Then think of any additional data you may need. Write those data points down and try categorizing them.
    1. Let’s say that I have several types of forms – “Contact us” and “Newsletter Subscription”. So I decided to have a dataLayer variable formType.
    2. Another useful parameter (in my opinion) is form position because some forms are in the footer, and others are in the sidebar of a website. Why not make it another dataLayer variable?
  3. If a developer is new to dataLayer events and Google Tag Manager in general, hand them a link to this dataLayer.push guide with clear examples. Explain to them that you need an event with additional parameters pushed into dataLayer after the successful form submission. If developers still have questions, this blog post should enlighten them.
  4. But remember to emphasize that the values of parameters like formType and formPosition should be dynamically replaced by a developer. If X form was submitted, the data of that X form must be pushed to the Data Layer. It is your developer’s job to know and code a solution that inserts the actual values.

Done! After the developer implements dataLayer.push in all forms, you should test it:

  1. Open Preview and Debug mode.
  2. Try submitting the form:
    1. Leave at least one required field blank. In this case, the dataLayer event must not be pushed.
    2. Fill in all fields and try submitting again. Did the event appear in Preview and debug console? It should look like this:
    3. Check whether all data is correctly pushed to the dataLayer. Click formSubmission event and then the API call in the Preview console. Data should look like this:

Set up variables and triggers in GTM. In my dataLayer.push example, there are two data points I’d like to use as variables – formType and formPosition (I will include them in my GA4 event tag), so I need to include them in Google Tag Manager by creating Data Layer variables.

1st variable:
Title:
dlv – formType
Variable type: Data Layer Variable
Data Layer Variable Name: formType
Leave all other settings as they are

2nd variable:
Title:
dlv – formPosition
Variable type: Data Layer Variable
Data Layer Variable Name: formPosition
Leave all other settings as they are

Now, let’s create a trigger. Go to Triggers and click New. Enter the following settings:

Trigger Type: Custom event
Event name: formSubmission (it may differ depending on your situation. Just make sure you and your developer are using the same name).
This trigger fires on: All custom events. This means that all formSubmission events will be tracked.

 

Update the GA4 event tag

Since I have created two Data Layer variables (formType and formPosition), I can use them in my GA4 event tag. As I have said before in this blog post, there are no strict requirements for how those parameters should be named.

I decided to use form_type and form_position. Their values are those two Data Layer Variables I have just created.

Save the tag.

 

Let’s test + GA4 Custom Dimensions

  1. Assign this new trigger to Google Analytics Tag that you created at the beginning of this blog post.
  2. Open (or refresh) a Preview and Debug mode
  3. Then fill in the form and submit it. After successful submission, Google Analytics Tag should fire (it will be displayed in Preview and Debug mode).
  4. You should also check the incoming events in Google Analytics 4 Debug View.
  5. Register form_position and form_type as Custom Dimensions in GA4 (if you plan to use them in the reports). Read this guide to learn more.

 

Method #7. Track Form Submissions with DOM Scraping

This method should never be your first option. Try using all other Google Tag Manager Form tracking methods (described in this blog post) before you continue reading this chapter.

If developers often update the website’s code, you should treat DOM scraping as a last resort. It is risky and can break faster than you think.

Even a slight change committed by the developer might break your implementation. Also, it requires some knowledge of Javascript and DOM concepts (which is not a very common skill among marketers).

For this example, we’ll be using DOM Element Variable. It is a variable in Google Tag Manager that lets you scrape content directly from Document Object Model (in other words: with its help, you can transfer any text on your website into a Variable and pass it on to your Marketing tools (e.g., Google Analytics)).

As an example, I’ll use a Shopify demo store. There is a Signup up to our mailing list form at the bottom of their homepage.

email form
Quick off-topic note: If you haven’t, consider subscribing to my monthly email newsletter for more useful Google Tag Manager guides

Enter [email protected] in that Shopify form and hit Subscribe. A page will refresh, the web address will change to https://somewebsite.com/?customer_posted=true#contact_form, and that little form displays a “Thank you” message.
thank you for subscribing

In this case, we could easily track form submissions with the Pageview trigger of Thank you page, but let’s imagine that the page’s address (URL) did not change. This is not a common situation, but it’s possible. That’s where DOM Element Variable might come in handy. We could create a trigger that could scan a website and look for a success message “Thanks for subscribing”.

First, let’s create a DOM element variable looking for that particular success message. Hover your mouse cursor over the success message’s text, right-click and choose Inspect.

Right click - Inspect Element

A developer’s console will appear with a lot of HTML code. Note that success message’s code is already selected in that console. That message does not have any unique ID so we’ll need to utilize CSS Selectors.

Inspect element

At the bottom of the screenshot, you can see a line of CSS selectors, e.g. div.note.form-success. These selectors can help us identify the exact element of the website.

Let’s create a DOM Element variable and try to scrape the “Thanks for subscribing” text.

  1. Go to Variables
  2. Scroll down to user-defined variables and click New
  3. Choose Variable type – DOM Element Variable
  4. Selection method – CSS selector
  5. In Element selector field enter div.note.form-success
    CSS selectors - short
    See what I did there? I entered the last CSS selector from the screenshot above.
  6. In case there were more than one possible success messages on a website with a similar CSS selector, I would have used a longer CSS selector, for example, “#contact_form div div.note.form-success” (without quotation marks). If you want to learn CSS Selectors and how to apply them in GTM, take a look at this course.
    css selectors
  7. Leave the Attribute name empty.
  8. Variable’s title could be DOM – Form Success Message.
  9. Hit Save.

 

Let’s test

  1. Enable Preview and Debug mode
  2. Submit the form.
  3. Choose DOM Ready (not Container Loaded) event in Preview and Debug console and click Variables.
  4. If DOM – Form Success Message variable’s value is Thanks for subscribing, you did a good job.

Alright! We need to create a trigger that depends on our new DOM variable.

  1. Go to Triggers and click New
  2. Choose Trigger type – DOM Ready
  3. This trigger fires on Some Pages
  4. Enter the following condition: DOM – Form Success Message equals Thanks for subscribing. This means that the trigger will fire only on those pages where the Form success message is displayed to visitors.
  5. Save the trigger

 

Do not forget to test:

  1. Assign this new trigger to the Google Analytics 4 Event Tag you created at the beginning of this blog post.
  2. Open a Preview and Debug mode (or refresh)
  3. Fill in the form and submit it. After successful submission, Google Analytics Tag should fire (it will be displayed in Preview and Debug mode).
  4. You should also check the incoming events in Google Analytics 4 Debug View.
  5. Also, try submitting a form with an intentional error and see whether the tag fires (it shouldn’t).

 

Google Tag Manager Form Tracking: Final words

In this blog post, I described a bunch of form tracking methods with Google Tag Manager. This has been an intense ride, but  I hope you found it useful. You should now be able to track many more forms without a developer’s input.

But remember – it’s okay to ask for the developer’s help. If possible, choose dataLayer.push method over DOM scraping. Robust solutions should be your priority.

Did I skip something in this post? Is there some aspect of form tracking that you’d want more information on? Drop me a comment, and let’s see what we can come up with!

Julius Fedorovicius
In Form Tracking Google Tag Manager Tips
79 COMMENTS
Jesus
  • Aug 3 2017
  • Reply

Hi,
Not sure if your post will work for Ajax Forms.
I am using NinjaForms and the form shows a confirmation message in the same page.
You can check a test page here https://www.thefrenchcandle.com/contact
I would like to be able scrap when this confirmation message is showed but I haven't been able. I tried but the variable doens't populate on the pageview tag as the pageview tag has not this information when it's fired.
Thank you in advance,
Jesus

    Julius Fedorovicius
    • Aug 3 2017
    • Reply

    Hi, my post works with AJAX forms (I've already used it multiple times). However, there's something strange with your form. Whenever I submit it and go to Preview and Debug console's Data Layer tab, my browser just crashes and I cannot do anything about it.

    I believe you should consult with a developer about this unusual behavior.

Dirk
  • Dec 12 2017
  • Reply

Hi, thanks for your great advice. I've read this post: https://www.analyticsmania.com/thank-you-page-tracking-google-tag-manager/
I've implemented everything in my Google TM. But the question I have now is: How can I view this information in my Google Analytics? I want to see the following: X submissions on a specific landing page.

    Julius Fed
    • Dec 16 2017
    • Reply

    Hey Dirk,

    One of the possible answers is this: in Google Analytics, go to Behavior > Events > Pages. Click the page you're interested in and you'll which events occurred on that page.

    Cheers

Vlado
  • Jan 19 2018
  • Reply

Hi,

I implemented THANK YOU PAGE TRACKING in GTM but I can't find a way do push the data to Google Analytics. Where in analytics can I see these conversions?

Mine main goal is to later link this with Adwords

Thanks

    Julius Fed
    • Jan 22 2018
    • Reply

    Hey, You can push data to Google Analytics with help of Universal Analytics Tag. I've described it in the "TAG + TRIGGER" section of this blog post.

    Cheers

Aldébaran
  • Jan 22 2018
  • Reply

Hi Julius,
First of all, thanks for this amazing tutorial, I've been following it for my personal website.
Very complete, and very well explained.
But, I am curently working on a form made in AJAX with an auto refresh (I installed LunaMetrics Plugin so I can get the ajaxComplete code).
The thing is, my attributes.response is a very large piece of code which changes so I cant' use it.
I decided to use attribute.response.ajax.submit which calls my form button (I suppose).
But it doesn't work
Is it possible to get some advices ?
Here's the link : http://fr.esterline-connection-technologies.com/en-en/search?category=4596&active_tab=part-number
( you have to click on "click here to refine your results" ).
sorry for my approximate english

    Julius Fed
    • Jan 22 2018
    • Reply

    Hey, there are hundreds of attributes.response.ajax.submit parameters in the response. Honestly, that response is huge and it will take way too much time to dig in. I would suggest keeping digging deeper.

    Maybe this blog post will give you some ideas https://www.analyticsmania.com/post/pull-data-from-data-layer-google-tag-manager-tutorial/

    Sorry, but debugging this response will take too much time while this week is super busy :(

    I've added a bookmark regarding this issue but I'm not sure when I'll be able to spare more time.

      Aldébaran
      • Feb 9 2018
      • Reply

      Hi Julius,
      Thanks for the blog post i'll check it out.

      Don't worry about this it's not "super" important. The response is probably going to change anyway, I asked the devs about it.
      I'll check it after that some development have been done.

      Have a good weekend and keep going ;).

Byron
  • Feb 23 2018
  • Reply

Hi Guys,

Firstly, this tutorial is amazing - Wow, learnt so much in one tutorial. I'm trying this with the Divi Contact forms and the Lunar Metric Ajax script. The issue being is that I don't get a nice response code like you showed in your example, my response code appears to be the whole page.

If I use a basic submit form trigger in GTM then it works but it triggers regardless of successful submission or not. Then if I try putting the validation on it doesn't appear to ever fire. So the only way I've felt moving forward was to use the Lunar Metrics approach that you outlined below but the response code is literally the whole page in html rather than a nice response code like you guys got. Do you guys have any advice for that?

    Julius Fed
    • Feb 25 2018
    • Reply

    Hi, your case is not so rare, actually. Sometimes I see when the AJAX listener returns a huge chunk of code. Sometimes it returns another array of objects, etc. You'll have to find a way how to distinguish a regular AJAX response with the response of a successful form submission. Dig into that very long response code and find something useful.

    Sometimes, this blog post helps (check method 2 or 3) https://www.analyticsmania.com/post/pull-data-from-data-layer-google-tag-manager-tutorial/
    Cheers

Andrea
  • Feb 28 2018
  • Reply

I rarely give praise comments, but this article is simply awesome. Navigated through each step and managed to implement a custom solution for my client. Thank you!!

    Julius Fed
    • Mar 1 2018
    • Reply

    Glad to hear that!

Mike
  • May 17 2018
  • Reply

Hello, what do i do when after form submits the response is blank?

Response: ' '

    Julius Fed
    • May 17 2018
    • Reply

    Hey, in that case forget about the AJAX listener because an empty response is unreliable. Instead, try using Element Visibility Trigger (when a success message appears, fire a tag) or ask a developer to use dataLayer.push when the form is successfully submitted.

    Read more on dataLayer.push here - https://www.analyticsmania.com/post/datalayer-push/

julien muret
  • Jun 8 2018
  • Reply

Hi Julius

I still can't figure which tech should work for my site as the form is in overlay.
The developer just added : dataLayer.push({'event':'formSubmission','formType':'Registration'});

but I don't have any event in my preview mode gtm.submissionform
thanks for your help

    Julius Fed
    • Jun 8 2018
    • Reply

    Hey Julien,
    If a developer has added that code snippet, you should see "formSubmission" event in the preview mode after the form is successfully submitted. If it does not appear, ask him to add this one:

    window.dataLayer = window.dataLayer || []
    window.dataLayer.push({‘event’:’formSubmission’,’formType’:’Registration’});

    If it still does not appear, then the developer did not properly add the code and you should ask him/her to fix it.

      julien muret
      • Jun 8 2018
      • Reply

      Thanks Julius, don't you think is because I don't use the good event and formType name ? I put formSubmission and Registration because I found it on another explanations but this is no how our form is called.
      All I can see from "inspect element" is :
      form id
      register-modal-get-quotes
      button id
      register-modal-get-quotes-done

      Thanks,

      Julien

luvstuss
  • Jun 21 2018
  • Reply

Hello again,
I returned to the same issue with another client already.
I created variable "Form Submission Message" where use ID as selection method and specified element ID. Btw should I put element ID with # or without #? Does it make a difference?
Then by your previous recommendation, I created new trigger the type of Element Visibility, where as selection method specified the ID; "Minimum Percent Visible" = 100%; the condition for trigger fires on "Some Visibility Events" is "Form Submission Message" which is start from "Thank you for contacting us".

But it doesn't work, gtm.elementVisibility doesn't load.

https://versapak-anti-doping.com/contact-us/

What am I doing wrong?
Thank you in advance.

    Julius Fed (Fedorovicius)
    • Jun 21 2018
    • Reply

    Hey, if you chose selection method: ID, then # is not needed. # is needed if selection method is CSS Selector.

    Now, regarding your form. Since you form reloads the page and the success message is displayed on the page right away, I suggest using DOM Scraping method instead of Element Visibility. It's a bit risky, but if no one changes the ID, you should be good. Here's a guide how to track with DOM scraping https://www.analyticsmania.com/form-tracking-dom-scraping-google-tag-manager/

      luvstuss
      • Jun 22 2018
      • Reply

      Hi Julius,

      Thank you for the prompt response.

      Because the Variable "Form Submit Successfully" belongs to DOM Element type but Trigger used Page View type, therefore the value of the Variable didn't transfer earlier. As soon as I changed Trigger type from PV to DOM Ready, Tag started to fire on the page and receive the value of the variable. Now, this event can be tracked in the appropriate GA report, but it doesn't appear in Conversions/Goals report. However, that is another story.

Matthias Kley
  • Jun 29 2018
  • Reply

Hi Julius,
thanks for this great post. i've implemented the ajax listener and It seems to work fine, but I don't get a form submission event in GA Real Time. I tried with attributes.respones.message and attributes.response.status. The website is https://www.erhardt-leimer.de/produkt/drehrahmensystem-drs07/

Do you have any idea whats wrong?

Thanks
Matthias

    Julius Fed (Fedorovicius)
    • Jun 29 2018
    • Reply

    Could you elaborate what do you mean "don't get a form submission event". You don't see any event? Or see something but it is undefined? Does the GA event tag fire after the form submission?

    You need to check what is the value of that Data Layer variable on ajaxComplete event.

    You can use attributes.response.status variable and it must be equal to "success". That should work fine.

      Matthias Kley
      • Jun 30 2018
      • Reply

      Thank you for your reply. Today I checked it again. All the form submissions I tested on Friday can now be seen in the behaviour-event report. But still I don't see any events in the real-time report (checked it again today).

        Julius
        • Jun 30 2018
        • Reply

        Check the tip #5 https://www.analyticsmania.com/post/google-analytics-real-time-reports-not-working/

        Also, check other suggestions.

Tanner
  • Nov 17 2018
  • Reply

I'm having the weirdest problem and maybe you can help. I am in the middle of setting up the form submission tracking, but before it's even live, I see gtm.formSubmit showing up in the Summary for the GTM Preview... any advice on why this is would be appreciated.

    Julius Fedorovicius
    • Nov 17 2018
    • Reply

    Hey,

    Facebook pixel is causing that. If you check the dataLayer on that gtm.formSubmit event, you'll see the Facebook URL. Make sure you actual Form Submission trigger is precise so that FB pixel's fake submission is not included.

Andrea
  • Dec 20 2018
  • Reply

Julius, yours is the best tutorial I read online. However, I can't get my Thrive Leads forms to work with either method #3 or #4. Would you be willing to check the form in question? It's on this page: https://travelhonestly.com/free-stuff/
thanks so much
Andrea

    Julius Fedorovicius
    • Dec 20 2018
    • Reply

    I see that those popups are using AJAX, however, all of them return the same success message meaning that you cannot distinguish which form was submitted. In this case, I'd go with developer's help and ask him/her to push the form submission information to the dataLayer.

Anton Gesmundo
  • May 22 2019
  • Reply

Hi Julius!

I followed #4. Track Forms with Element Visibility Trigger and the tag and trigger is set up fine. gtm.elementVisibility is firing right after DOM Ready, but the Google Analytics Tag fired only once after some delay of scrolling up and down the page (not immediately on the page load) and I couldn't get it to fire again after submitting another form.

    Julius Fedorovicius
    • May 27 2019
    • Reply

    Hey, Enable the "Observe DOM changes" checkbox and try again.

Julien VDC
  • May 22 2019
  • Reply

Hey Julius,

Like everyone else I'd like to thank you for posting publicly this guide, it's been a great help to understand further how GTM works and what you can do with it.

I currently testing the different approaches your suggesting (I think I might have to resort to #6 in my case...)... but I had questions concerning the DOM scraping which seems like you say a very weak solution:

- How would you proceed (if using DOM Scraping), if your site was multi-lingual and would thus display success messages in different languages depending on the user's preferred language?
- Also, would refreshing the page and thus display the message once again trigger it once again, thus counting twice..? How would you solve that?

Cheers,
Julien

    Julius Fedorovicius
    • May 27 2019
    • Reply

    Hey, your DOM scraping should depend on element classes, IDs, etc., not text. Therefore page translation should not have negative effects.

    As for the prevention of duplicate tracking, read this for inspiration https://www.simoahava.com/analytics/prevent-google-analytics-duplicate-transactions-with-customtask/

Marko
  • Jul 9 2019
  • Reply

I recently had to modify Lunametrics script to work on a single page app.
If anybody is interested then feel free to use it: https://gtm.marxdev.com/.

It works exactly like Lunametrics script but doesn't depend on jQuery and so should work on all websites.

Gabriel
  • Jul 11 2019
  • Reply

Dear Julius,

thanks for great content that you are sharing on this site and through your courses!

I've implemented successfully a lot of form tracking through element visibility trigger. However I'm struggling with one website. They don't have a permanent element that is visible after submitting the contact form. Just a 2 second pop-up appears at the top of the page, then it disappears. Is it possible to track it somehow?

    Julius Fedorovicius
    • Jul 12 2019
    • Reply

    Here's the guide I've just published. Inspired by your comment.
    https://www.analyticsmania.com/post/how-to-pause-javascript-and-inspect-an-element-that-quickly-disappears/

    Thanks!

Marco Villasenor
  • Aug 1 2019
  • Reply

Hi Julius

I am trying to track cross domain from a link embedded in a button, but it is not working url: https://www.lillyplay.com.br

The link is in the button CADASTRE-SE JÁ

Your inputs Will be most appreciated

Regards,

Marco

    Julius Fedorovicius
    • Aug 2 2019
    • Reply

    That button is not a regular link. I suggest you talk with developers and ask them to decorate the link with the linker parameter.
    Or you need to know how to write JavaScript in order to find a way around.

Gus
  • Aug 18 2019
  • Reply

Can you set a visibility trigger with an alert box? The form I'm trying to track only displays it after successful submit ( but I can't find the way to inspect it) I tried right-clicking on it to no avail.

The alert box looks like the one on this page (first alert box):

w3schools.com/js/js_popup.asp

    Julius Fedorovicius
    • Aug 18 2019
    • Reply

    Hey, no. That default browser array is not a part of the DOM (document object model), therefore, element visibility trigger cannot track it. Such form would require developer's input.

    As far as I saw on Stackoverflow, it would be possible to try to track the appearance of such alert with some custom JS, but it would not be guaranteed to work properly and also solutions I saw were tested just on Chrome.

    All in all, I'd go with developer's help on this one.

Drew Griffiths
  • Nov 13 2019
  • Reply

I'm also seeing the weird issue with facebook.com/tr/ as the Click URL for a form

    Julius Fedorovicius
    • Nov 13 2019
    • Reply

    Read this https://www.analyticsmania.com/post/why-is-there-a-gtm-formsubmit-event-on-every-page-view/

Matthew
  • Jan 22 2020
  • Reply

Hi Julius!

Thanks so much for an awesome post - I've come back to reference it often.

I'm curious - do you know which if any of these methods would work with embedded Pipedrive web forms? I've worked my way through the list and nothing seems to do the trick. Am I doing something wrong or is Pipedrive just hard to work with?

Thanks!

    Julius
    • Jan 22 2020
    • Reply

    If none of these, tips helped, then you should either keep googling or crybin the corner :)

    I havem't worked with pipedrive but I have heard that people have tough times with it

Barb Davids
  • Jan 29 2020
  • Reply

I used the 2nd method and have the page path as the label so I can see which form was filled out. I have multiple thank you pages for one client and this was super helpful seeing which ones came through and being able to tie them to source. Do you have a reference on how to determine which forms convert more?

    Julius Fedorovicius
    • Jan 31 2020
    • Reply

    You could ask a developer to add ?form-id=xxxx parameter to the thank you page's URL. Instead of XXX, a form ID should be used. Then you could distinguish from which form did a visitor land on a "thank you" page.

Pierre
  • Feb 10 2020
  • Reply

hello,

I too am having a tough time tracking Pipedrive form submission.

But even tracking the button...

What trigger would fit here please ?


Submit

    Julius Fedorovicius
    • Feb 10 2020
    • Reply

    As far as I know, the Pipedrive form is in the iframe and you cannot track it with GTM.

Damien
  • Feb 17 2020
  • Reply

Hi Julius, I've recently discovered your web and I found it really useful. I am trying to track form submissions for my website and the auto-event listener method works fine for me except for 1 thing: Although it only fires when the form is valid, when I preview my variables with GTM, all my form variables are undefined, so I cannot make the tag exclusive to that form (if I had another form in the same URL, it would also fire the tag). Maybe you know a fix for this issue? Thanks!

    Julius
    • Feb 17 2020
    • Reply

    Hi, at your current stage of GTM knowledge, I would contact a developer of that form and ask to add an ID to it.

Stef
  • Feb 26 2020
  • Reply

Wow, very in depth Julius. Thank you. I had a question that I didn't see answered here. Is it possible to have multiple thank you pages added as one trigger?

Right now I have a client that has 12 forms and each one has a unique page and so I added all 12 under one trigger. I'm not getting an error, but I'm not seeing conversions either.

Should I setup 12 different triggers?

Thanks in advance

    Julius
    • Feb 26 2020
    • Reply

    12 triggers is on of the ways. A more optimal way is to learn regex fundamentals and use them in a single trigger.

Tom Mercik
  • Jul 1 2020
  • Reply

Greetings! Great to be back on the tutorials - always something to learn! Followed the steps in #2. “Thank you” Page Tracking with Google Tag Manager. Result? Did not work - "Tags Not Fired".Is there a troubleshooting protocol (process?) for finding out what variable is not working properly? Thanbks in advance, Tom

    Julius
    • Jul 1 2020
    • Reply

    Hi, click on the tag that did not fire on pageview in the preview mode and check the variables.

Dee
  • Jul 16 2020
  • Reply

This is a great reference tutorial. This is my go-to while I learn about forms. Thank you!
I am using Drupal Webforms, I have a search form that, and I would like to know if it is possible along with click events, to also track the user input from text input and select fields. Currently, all I'm able to track is if user engaged (true or false). Am I correct in saying that what I need involves the use javascript in a data layer?

    Julius Fedorovicius
    • Jul 17 2020
    • Reply

    Hi, this would require JavaScript.

      Dee
      • Jul 17 2020
      • Reply

      Where can I learn more about this?

        Julius
        • Jul 17 2020
        • Reply

        There are many resources. Enter "javascript course" in Google aearch and you can start there.

Wilco
  • Jul 28 2020
  • Reply

Would be nice to have guide specific to Formidable Forms also. I notice there are a few crucial steps missing from this guide: https://formidableforms.com/google-tag-manager-form-submit-tracking/

I'm getting hits for forms that have been "submitted" but receive an error for example.

Your guides seem to be more complete.

    Julius Fedorovicius
    • Jul 28 2020
    • Reply

    Oh wow, that Formidable guide is terrible. I mean the method that they offer is terribly incorrect and will cause a lot of false positives. I added your idea to my backlog, however, I have no idea when it will go live.

Ellen Thompson
  • Aug 23 2020
  • Reply

Your site is the best resource for GTM, but I'm interested in knowing when you more advanced courses are going to be live and not on waitlist. Any first date yet?

    Julius
    • Aug 23 2020
    • Reply

    Hi, I am planning to open enrollment of the intermediate/advanced course in a week or so. Those who are on the waiting list will be notified via email.

Ashish
  • Dec 10 2020
  • Reply

Hello.
Thank you for the video. I have a question regarding the class. What is the solution if there are more than 1 element (two element) with the same class on the page?

Thank you in advance.

    Julius
    • Dec 10 2020
    • Reply

    Then you should learn CSS selectors and create advanced solutions.

Furqan Tariq
  • Apr 21 2021
  • Reply

I went with method 4 i.e. setting up an element visibility trigger

The weird and frustrating problem I am running into is that I have configured the trigger to fire on some visibility events, and specified the conditions (Page Path equals /contact)

Still, in debug and preview mode, the event fires on different pages where there is the same CSS selector.

Even if I put weird conditions like Click ID equals xyz, the trigger fires.

Is this just a debug/preview problem and that the Tag in reality would only be fired on the right page OR am I doing something wrong in the set up.

    Julius
    • Apr 21 2021
    • Reply

    Sounds like you are doing something wrong. You should learn CSS selectors. My intermediate/advanced gtm course can help with that.

      Furqan Tariq
      • Apr 21 2021
      • Reply

      I am not sure the problem is the misuse of the CSS selector (since I have a development background)

Thomas
  • May 20 2021
  • Reply

Thx a lot for your tuto Julius !
i use this with forminator and it's perfect
Good job

kibria
  • May 30 2021
  • Reply

Hi, Julius
i have done this ajax form on Google Universal analytics. but if i do track on GA4 then should i html listener code again on tag for GA4 platform?

    Julius Fedorovicius
    • May 31 2021
    • Reply

    No, use the same listener and create a GA4 tag

Carlos M. Díaz Honrado
  • Dec 29 2021
  • Reply

Hi Julius
A possible alternative for the second method (when redirecting a thank you page) is to add a new condition, that the referrer is the page, or pages, that contains contact form(s).
In my case contact form is hosted in /contact/ and redirects to /thank-you/, what I have done is define in the trigger the URL of the page contains /thank-you/ and Referrer contains /contact/
That way I prevent accidental visits to the thank you page from being sent to GA4

Amira
  • Feb 21 2022
  • Reply

Hello! Thank you very much for the very clear explanation. I would like to ask for advice: It has been 2 months since I added tags on GTM to aggregate data on GA4. As our site is not an e-commerce site, our conversions are mainly "form submissions". However, I did not respect the naming recommended by Google for the "event name" of each tag created. At the moment, I realize that there is a big difference between the data on GA4 and on Analytics Universal for the same events (we can find 16 on Analytics Universal and 34 on GA4). Is it due to non-compliance with the naming of events? How can I resolve this problem? Is it enough to rename the tags already created? Thanks very much !

Sylvia
  • Apr 14 2022
  • Reply

Hi Julius. My contact us form submission google ads and GA4 tags fired successfully by using method 4, and reloading the success page did not recode a second conversion. This is good. However, GTM displays second element visibility and fired tag when I reopen the success page in another window. So I want to know how to avoid duplicate tracking for one submission. Is there any clue?

    Julius Fedorovicius
    • Apr 14 2022
    • Reply

    You would need to go more advanced and store a cookie in the browser to prevent duplicate form submission

Sylvia
  • Apr 21 2022
  • Reply

Users can navigate to the register success page without submitting a form, so every time I refresh the success page, the GTM tag will fire. Is there any method to set the success page can't load without actually submitting a form?

Jeroen Balk
  • Dec 2 2022
  • Reply

Hi! Great article. I have followed all the steps. In the GTM debugging view I see a 'Form submit' trigger when i complete my form. However, the tag does NOT fire. It is prevented by: '_triggers matches RegEx (....)'.

How can I solve this?

Jeroen Balk
  • Dec 2 2022
  • Reply

I have used method #1 btw :)

Igor
  • Dec 29 2022
  • Reply

Hey, thank you for the awesome content. But if I have multiple forms and I want to track unique form submissions, because for some forms 1 user can submit 3-4 forms. How to track that? Thank you

Eric
  • Feb 9 2023
  • Reply

Hi Julius, this is great! Thank you!

I am trying to capture donation amount and bring that into GA4. I see the following in the Tag Assistant. Any ideas on the steps I need to take to properly capture this?

dataLayer.push({
event: "gtm4wp.formElementLeave",
inputID: "other-amount",
inputName: "other-amount",
inputClass: "otherAmount valid required",
formID: "donation-form",
formName: "(no form name)",
formClass: "donation-form",
gtm.uniqueEventId: 197
})

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • How to Track Gravity Forms With Google Tag Manager: Complete Guide
  • Introduction to Google Tag Manager Server-side Tagging
  • 3 Ways to Pull Data from Data Layer with Google Tag Manager
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings