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.
_trackPageview()
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’ _trackPageview() JavaScript function 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 pageTracker, and you want to track the form submission as a virtual page view of the virtual URL /mysite/thank-you.html. In order to do this, you will need to run the following JavaScript code when the submission event occurs:
pageTracker._trackPageview('/mysite/thank-you.html');
Note that the /mysite/thank-you.html is not necessary for it to be a real URL. It can be any value, which will then be displayed as a page filename in your Analytics reports.
_gaq.push(['_trackPageview', '/mysite/thank-you.html']);
Using on_sent_ok action hook
You don’t need to edit any JavaScript files for running the above _trackPageview() function. 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 _trackPageview() 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: "pageTracker._trackPageview('/mysite/thank-you.html');"
Note that you need to quote the codes properly and the code must be in one line.

Now, if you have set everything up correctly, when someone makes a submission via your contact form, Google Analytics will track it as an access to /mysite/thank-you.html.
To verify that this is working correctly, you can check your Top Content report 24-48 hours after a submission. At that point, you should be able to see the assigned page name (/mysite/thank-you.html) in your report.
External resources
- Facebook conversion tracking with Contact Form 7 — Explains how to track facebook ads on your WordPress site using Contact Form 7.
