Gravity Form Event Tracking Via Tag Manager

in this blog, you will see how to add tracking in WordPress Gravity Form via Google Tag Manager (GTM)

Gravity Form Tracking

We can track gravity form by using google analytics event tracking and conversion tracking code in 2 different Ways.

  1. By using wp-admin.
  2. By Using Tag Manager.

Here we will see both ways. It is entirely up to you, whichever options do you like you can go with that.

Gravity forms

Gravity form Event Tracking by using wp-admin:

Steps to add Tracking Code using wp-admin:

  • Login to wp-admin.
  • Click on Forms(in left  menu)
  • Click on respective form where you want to add Tracking Code.
  • Click on Confirmation(setting->confirmation).
  • Click on TEXT option (Right-top of confirmation message box).
  • Add your event tracking or conversion tracking pixel code after message.
  • Check the checkbox of  ‘Disable auto formatting‘ .
  • Click on Save Confirmation Button.
Gravity Form Tracking Code Instruction
Gravity Form Tracking Code Instruction

Steps to add Tracking Code using Tag Manager (GTM):

By using Google Tag manager you can add any type of HTML code on your website without editing main source code of your webpage of your website. Only you have to add GTM Container code on your website.

I know you will be amazed by GTM because of it’s extensive feature. but here we are not going to discuss on GTM features/options. We will focus on how to add Tracking code on Gravity form using GTM.

There are 2 more ways to add tracking code by GTM.

  1. Add tracking code on default GTM form submit event (i.e gtm.formSubmit listener):
    By using this you can easily add your tracking code , just you have to enable some options in variables and create some Tags and triggers. But there is some problem with this, that it will track each form submission whether it is successful form submission or not.
    That is why I would suggest to go with Custom HTML code.
  2. Add tracking code by using Custom HTML Code: 
    Follow the below steps to add tracking code by using custom HTML code, This will help you to track successful form submission.

Steps to add tracking code by using custom code in GTM:

1) Create following new custom HTML tag, to push Gravity form states.
Tag Name: Gravity Form Custom Code
Configure Tag: Custom HTML Tag
Trigger on : DOM Ready

Gravity Form Event Tracking Custom Code
Gravity Form Event Tracking Custom Code

Custom Code:

 
<script>
  if(jQuery('.gform_confirmation_message').is(":visible"))/* page load */
  {
    var formId=jQuery('.gform_confirmation_message').attr('id').replace('gform_confirmation_message_','');
    dataLayer.push({'event':'gform.submit.success','formId':formId});
  }
  jQuery(document).on('submit','form[id*="gform_"]',function(){/* for Ajax Load */
  clearInterval(window.gsetInt);
    var formId=jQuery(this).attr('id').replace('gform_','');
    jQuery(this).find('.gfield').removeClass('gfield gfield_error ')
    window.gsetInt=setInterval(function(){
      if(jQuery('.gform_confirmation_message_'+formId+'.gforms_confirmation_message,.gform_confirmation_message_'+formId+'.gform_confirmation_message').is(":visible"))
      {
        clearInterval(window.gsetInt);
        dataLayer.push({'event':'gform.submit.success','formId':formId});
      }
      if(jQuery('#gform_fields_'+formId+' .gfield_error').is(":visible"))
      {
        clearInterval(window.gsetInt);
        dataLayer.push({'event':'gform.submit.error','formId':formId});
      }
    },200);
  });
</script>

2) Create Trigger:
Trigger Name: DOM Ready
Choose Event: Page View
Trigger Type: DOM Ready
Fire On: All Pages

DOM Ready Trigger
DOM Ready Trigger

3) Create Trigger For Success Form Submission: 
Tigger Name: gform.submit.success
Event Name: gform.submit.success

Gravity Form Successful Submission Event
Gravity Form Successful Submission Event

4) Create Variable to get form ID:
Variable Name: formId
Choose Type: Data Layer Variable
Data Layer Variable Name: formId

Form ID DataLayer Variable
Form ID DataLayer Variable

5) Create Lookup table variable to get Custom Label for Gravity form
Variable Name: Custom Label for Gravity Form
Choose Type: Lookup Table
Input Variable: {{formId}}
Lookup Table: As per Below Image

Lookup Table for Custom Label for Gravity form
Lookup Table for Custom Label for Gravity form

6) Create Event Tracking Tag For Gravity Form
Tag Name: Event Tracking Tag For Gravity Form
Trigger on: gform.submit.success
Label variable: {{Custom Label for Gravity Form}}

Event Tracking Tag For Gravity Form
Event Tracking Tag For Gravity Form

Result:

Gravity Form - Event Tracking Sample
Gravity Form - Event Tracking Sample

Likewise you can add Conversion Tracking Code and Change Conversion Label by using Lookup table Variable

Note: As I have tested, this code is working fine in almost all cases. Still you can modify the custom code, if it is not matching your requirement.
You can go for some of other my blogs, which might be useful for you. Also I would love to hear from you about some suggestions and help . You can contact me via contact us form or use blog comment form.

23 thoughts on “Gravity Form Event Tracking Via Tag Manager

  1. Pingback:Contact Form 7 Event Tracking Via GTM | Notes on Click

  2. YOU ARE THE BEST – spent many hours trying to get GTM/GA to stop counting false positives for gravity forms – this worked AND I don’t have to create a form submission tag for every single form on the site. Thanks for the detailed tutorial.

  3. Great! Congratulations. A very elegant solution for GTM. I tried to insert dataLayer.push in the thank you message but the event didn’t activate (I don’t know the reason). Furthermore, with your code it isn’t necessary to insert any code in the site.

  4. I appreciate your sharing this. I especially like how you use the lookup table. Do you know how I can implement this on a confirmation page and not on the confirmation text as the custom code your written watches for? Thank you for sharing your work with the world.

    1. Hi Paul,
      if you have different confirmation page then on the basis of URL you can trigger you code. But it won’t work if you have same confirmation page for multiple form, in this scenario you can use page referrer (from which page user is landing to you confirmation page) to trigger your code.
      Hope this might be useful.

  5. Hi this isn’t working for me.

    I have a Gravity Form with a text confirmation page, not a redirect confirmation. I would like to track this form through Google Tag Manager to display a goal conversion in Google Analytics (Universal Analytics).

    I’ve followed all the steps as you have listed above.

    No conversions are being recorded. However when using GTM-debug mode, all the triggers are firing, even the gform.submit.success tag is being fired after clicking the submit button.

    Could someone please help?

    1. Hi Ariel
      As you mentioned above, all the tag and trigger is working fine for you but you are not getting any conversion.
      Then I think there might be problem with your GOAL in google analytics, just go thorough goal set up and to confirm that goal is working fine or not check Realtime-> Conversion in google analytics.
      if you need more assitance you can leave message in Get in touch form.

  6. Thanks for creating this! It was extremely helpful. I modified the concept to use with another tracking pixel outside of GA that I had inserted as custom HTML in GTM. I just stopped after step 4 and then used the “gform.submit.success” trigger on my tag. I also used the formid variable to narrow down which form needed to count towards the trigger. Thanks again!

  7. Great, works like a charm. But why would you have to create the dataLayer Variable formId, and not use the built-in variable “Form ID”? Or which part of the code would you have to adapt accordingl?

    1. Since in this blog we are using a custom HTML code to check for both non-ajax and ajax form submission, the built-in variable isn’t “Form ID” which is used but as a predefined variable is ssetup by default. .

  8. you are really a good webmaster. The web site loading speed is incredible. It seems that you’re doing any unique trick. Also, The contents are masterpiece. you’ve done a great job on this topic!

  9. Hello,

    I just wanted to note that with Gravity Forms v2.2.2 (May 4th Update) the confirmation markup changed, note from changelog;
    “Fixed an issue with the confirmation message markup for AJAX enabled forms containing an extra gforms_confirmation_message div.”

    Anyway due to this change .gforms_confirmation_message is no longer present in the confirmation markup for AJAX which causes the success to never trigger.

    To fix this just remove the s, so it looks for .gform_confirmation_message as that is still present.

    Basically, they removed the outer .gforms_confirmation_message div that wrapped the wrapper. Which just leaves the .gform_confirmation_message div.

    Hope that helps those who’ve now found this code to no longer function.

    All the best,
    Cheers

  10. Hi, thank you very much for this post. I’d been looking for a solution for a while with no luck.

    I’m wondering whether it’s possible to set up form error tracking in a similar way?

  11. Thanks so much!
    But for some reason this is only working on some of my pages, and not others. I can’t figure out why it only works on some pages, as they all use the same form. Has anyone else encountered this problem? The confirmation message is the same on all pages, yet gform.submit.success only works on certain ones.

    Thanks!

    1. Hi Holly,
      I would love to help you, before giving any suggestion I wanted to your website so that I can try to figure out what’s going on and why it is not working

  12. Hi and thanks for this useful guide. I managed to follow her even if I’m not very experienced.
    I would also like to monitor the errors. Has anyone tried to capture the error label for each field?
    How can I proceed?
    Thanks in advance for your help

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.