If you run a WordPress site that uses the popular Contact Form 7 plugin, there is a way you can implement goal tracking to work with Google Analytics – without hacking the plugin code. Here’s the process.
Why track goals?
Tracking the number of people who fill in your enquiry form, or request a quote, is a good way to measure return on investment. You spend a lot of time and money getting people to your site and the number of enquiries helps you quantify the value of that work. Setting up an Analytics goal gives you a wealth of data about the people who “convert”, such as which pages they looked at first, how they arrived at your site, etc.
Requirements for this process
For these steps, I am assuming you are running WordPress with Contact Form 7 installed and that you have administrative rights to your site’s Google Analytics account. You must also have the newer asynchronous version of the code installed (this version of the code includes “_gaq.push” in some lines and shows that the asynchronous setting is true). The code must be in the header of the site, so it appears before the form.
Start by navigating in the WordPress admin to the Contact tab, then open the form you want to add tracking to.
In the form, scroll to the bottom, where you see an additional settings box, and paste this code into the box.
on_sent_ok: “_gaq.push(['_trackPageview', '/enquiry-thank-you.html']);”
It will then look like this image below – however, you can change the “enquiry-thank-you.html” to anything you like. Then save the form.
How the code works
When a person submits the form, this hidden piece of code sends a message to Google Analytics to count a page view for the virtual page “enquiry-thank-you.html”. With Analytics believing you have that as a page, and with the page only being viewed as a result of filling in the form, you can now link all views of that virtual page with goal conversions.
Setting up the goal in Analytics
Now you need to go to your Analytics account and navigate to the Admin section (click Admin in the top right of the main navigation bar). Click on Goals, in the middle of the screen, and create a new goal. Here, I have two goals already set up.
In the Goal URL field for the enquiry form goal you can see that I have put the same virtual URL that I used in the code for Contact Form 7 additional settings.
How to test that the virtual page works
The first thing to do is go and fill in your form to submit a test. Now, generally, you have to wait for a couple of days for Analytics to fully report on your page views and your goal conversions. However, there is a way to instantly test whether your virtual page is working.
Go to your form and fill it in. When you see the success message, leave the page as it is.
In a new browser window, go to Google Analytics, to your website profile, and click on the Home link in the left of the main navigation bar. In the left column you will see “Real Time”. Click that and then click “Overview”.
Wait a second and you should see at least one active user live on the site (you), currently viewing your virtual page. This is because you just submitted the form and still have the page open.