Tracking Form Submissions with Google Analytics

If you use Google Analytics to analyze web traffic on your site, I imagine you would like to track submissions through your contact forms as well. Contact Form 7 allows you to set up this type of tracking very simply. In this post, I’ll show you how to do it.


If you’ve set everything up correctly, Contact Form 7’s contact form behaves as an Ajax application and its form submission is an Ajax event. Google Analytics’ _trackEvent() method is able to track an Ajax event without a real page view or redirection.

For example, let’s say that the name of your page tracker object is _gaq, and you want to track the form submission as an event. In order to do this, you will need to run the following JavaScript code when the submission event occurs:

_gaq.push(['_trackEvent', 'Contact Form', 'Submit']);

Using on_sent_ok action hook

You don’t need to edit any JavaScript files for running the above _trackEvent() method. Contact Form 7 provides a JavaScript action hook named on_sent_ok, and by utilizing this action, you can specify a JavaScript code that you wish to run after the form is successfully submitted.

It is quite a straightforward process for you to specify the aforementioned _trackEvent() with the on_sent_ok hook. You will find the Additional Settings field at the bottom of the contact form management page; now simply insert the following line into it:

on_sent_ok: "_gaq.push(['_trackEvent', 'Contact Form', 'Submit']);"

Note that you need to quote the codes properly and the code must be in one line.

on_sent_ok in Additional Settings

Now, if you have set everything up correctly, when someone makes a submission via your contact form, Google Analytics will track it as an event with Contact Form as the Category, and Submit as the Action.

To verify that this is working correctly, you can check the Content > Events > Overview report page on Google Analytics 24-48 hours after a submission. At that point, you should be able to find the Contact Form category there.

External links

Just another contact form plugin for WordPress. Simple but flexible.