SEARCH MARKETING BLOG

How to set up goal tracking in Contact Form 7

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.

Contact Form 7 Analytics goal codeHow 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.

Goals in Analytics

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.

Contact Form 7 - Google Analytics goal tracking

In this case I have put the Match Type as Head Match. I could use Exact Match as well. For more on setting up goals, read Emily’s beginner’s guide and setting up goals.

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.

c

About

Steve started professional life as a magazine journalist, working on music magazines and women's titles before becoming a web editor in 1997, then joining MSN to work purely in online publishing. Since 1999 he has worked for and consulted to a broad range of businesses about their online marketing. He joined Vertical Leap as Campaign Delivery Manager in January 2012. Follow on Google Plus and Twitter.

6 thoughts on “How to set up goal tracking in Contact Form 7

  1. Hi. I completed the above as described and it works. However, Now i no longer see the “message sent successfully” when forms are sent. Any ideas why and how to get the message back? TY

    • Hello Guy, the most likely answer to this is that you have your Analytics code in the footer of your site, so the tracking code is breaking the form.

      The Analytics code needs to be in the so it is served before the goal tracking code is called.

      • In addition to Steve’s comment above, my testing has found two cases where the “success” message does not appear.

        1. If you copy and paste the code from above there may be a JavaScript error because of the curly quotes. Change the curly quotes to straight quotes to fix the error.
        2. Some WordPress Google Analytics plugins don’t include the tracking code if you are logged in to WordPress, causing a JavaScript error. Log out of WordPress to fix this error.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>