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.
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.
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.
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.