How to track conversions through Gravity Forms in Google Analytics

Google Analytics goal overview

Tracking conversions is something that I’ve only recently started doing, in an effort to better understand how these conversions are taking place and to then tailor my site to improve conversions. Most of my conversions are through forms, for which I use Gravity Forms.

When I looked into how to build a goal in Google Analytics that tracked when a form was completed (like a contact form, order form or mailing list signup form), the general advice was to change the confirmation type on your Gravity Form to “page”, so that you could build your goal in Google Analytics based on when anyone viewed the “confirmation page”.

I didn’t like this for a few reasons. I had made a conscious decision to use the text confirmation because it best met my needs. I also didn’t want to have to maintain another page because of a technical issue. And I don’t like doing things a different way just because it’s easier – I want it the way I want it, the way it should be. So I set about researching how to do it with a text confirmation.

As it turns out, the end solution is fairly simple, but the prevailing information about how to do it is spotty, hence me creating this post for others to use. The general idea is to use the gform_submit_button filter to add an onclick event that sends the conversion data to Analytics. Note that because we’re using the gform_submit_button filter, this will work regardless of your confirmation method (text, page or redirect).

Firstly, this assumes that you have Google Analytics installed on your site using the Universal system (if not, go and install/update it now).

Secondly, it assumes that you are not interested in assigning a dynamic monetary value to your conversion (like an order total). If you are, then you’ll want to modify this snippet to add that data to the event.

Paste this snippet into your functionality plugin:

You’ll need to tweak a few things in this code. In lines 8 & 10 you need to set the Category, Action and Label for the event that you want to track. For a better understanding of what these values should be, checking out Google’s Event Tracking docs.

Then, change line 15 to apply the event to the correct form (in my example, the form ID is 6).

Lastly, you need to make sure that your form is not using AJAX. My implementation stumped me for a while, because it was using AJAX. Once I turned that off, it was registering the events in GA nicely.

Your form should now be sending the event to GA when you use the submit button (check using Inspector Tools if you know how, else you’ll have to wait to set up your GA goal and see the data arrive in the dashboard). Now it’s time to set up the goal in Google Analytics to actually track it.

Go to the Administration section of GA and to View > Goals. Click on New Goal and give it a name (Sign Up To Mailing List in my case). For the Type, select Event.

New GA Event Goal

On the next screen, add the Category, Action and Label that you configured in your snippet. Leave the Value field blank. If you want to assign an arbitrary value to each conversion, set “Use the Event value as the Goal Value for the conversion” to No and enter a value in the field that appears.

ga-goal-details

Once you create your goal, you should start seeing data come in to GA. Data does not appear in real-time, and in my case it took about 30 minutes to start seeing the data in Google Analytics, though some have reported that it can take many hours, so be patient.

Google Analytics goal overview

With that, you should be able to start tracking your important Gravity Forms events and seeing where your customers are coming from and get a better feel for how to refine that process for them.

Need Gravity Forms?

16 thoughts on “How to track conversions through Gravity Forms in Google Analytics”

  1. Jodi says:

    This is just what I’ve been looking for … I’ve read so many different tutorials, my head is spinning, so it’s nice to see one that’s up-to-date and specific to Gravity Forms! Had you tried just tracking pageviews instead of events using something like this in the confirmation?

    on_sent_ok: “ga(‘send’, ‘pageview’, ‘/contact-us/thank-you’);”

    It seems like it’d be easier, but I wondered the pros and cons (or if it even works … I haven’t confirmed it yet, but I had something similar working with CF7).

    1. Well, no, because I don’t redirect to a different page after submitting the form. I wanted to use the text redirect, so tracking a pageview would not work in my case.

  2. Dave G says:

    Hi, thanks for the tutorial, but I have been looking for how to track the product value and have found no help. I am using the stripe addon, is there anyway you could add a section to explain how you would track the total shopping cart cost? Thanks.

    1. Dave,

      I’m not able to really look into this, but you can pull the get the form total using the payment_amount value. Since this value is empty until the payment is received, you may not be able to use the submit button filter to do this (since this happens before the payment is confirmed as submitted. You may need quite a different approach, instead hooking into the gform_post_payment_status action instead. Let us know if you do get this working.

  3. Jodi says:

    The method I mentioned is for virtual pageviews, not a redirect. You set up a goal with the corresponding virtual page.

  4. Wesley says:

    Instead of using the Functionality plugin, I just added the code to a custom functions file that was created with my Child Theme. Using your method I successfully created a goal in GA using one of my gravity forms. Now I’d like to add tracking code to another one of my forms. I assumed I would just copy and paste the same code as the first, change the eventCategory and the form ID and everything should work? But when I update the Functions file with the new code below the first, it freezes up the backend and I have to use FTP to delete the new code and get things working again. Some sort of php error perhaps? Any help would be greatly appreciated.

    1. Did you change the function name? Each function must have a unique name, so try renaming it to function add_conversion_tracking_code_2($button, $form) for the second form.

  5. Wesley says:

    That seemed to do the trick! Thanks so much.

  6. Thanks for writing the article. The biggest issue I see with this approach is that it tracks a goal submission even if there are errors in the form and the visitor chooses to abandons the form entirely. This happens because the code doesn’t check for a completed submission, but instead just checks if the button was clicked.

    There is a way to track conversions using the text confirmation by doing a virtual pageview or event directly within the text box. You can see code examples of how to do this with both Classic and Universal Analytics at https://gist.github.com/jg314/5430f002c7be986d5f9c.

    I hope that’s helpful.

  7. Scott says:

    Dave, I’m a little confused. Once you upload the functionality plug-in within WordPress, where do you find the area to paste the snippet? Please assume that I’m pretty much a novice. Thanks for your help.

    1. You can edit the files in the plugin from the Plugins > Editor menu, but you should really use FTP or SFTP to do this instead. The files will be located in wp-content/plugins/functionality-plugin/

  8. jamieakhtar says:

    For AJAX support, simply add this code on the confirmation screen:
    if( !document.body.className.match(‘GF_AJAX_POSTBACK’) ) ga(‘send’, ‘event’, { eventCategory: ‘Forms’, eventAction: ‘Mailing List Subscription’, eventLabel: ‘Sidebar’});

    1. do not need the link tracking as above
    2. only occurs after the user views the confirmation screen (so all validation is passed0
    3. prevents firing twice by checking against GF_AJAX_POSTBACK

  9. Amadeo says:

    Couldn’t you also first check if there is post data via php and if so execute the ga code? This would make sure it fires only after a form has been submitted. Unless I’m missing something.

  10. https://nl.wordpress.org/plugins/gravity-forms-google-analytics-addon/ This is a plugin that will do this for you with custom page URLs, it even supports multipage forms and GTM implementations.

  11. Renee says:

    What if you’re using the same form for multiple landing pages, but want to track those conversions separately? Is there a way to associate a path or page id in that code? For example I’d like the goal to be tracked like “Complimentary Audit” and “Sales Audit” even though I am using the same form ID for both.

    1. In Google Analytics, you should be able to break these down by the pages on which the events were registered. Otherwise, you could use some conditionals in the snippet above to check what page you’re on and register it as different events to suit your needs.

Leave a Reply