Get in touch
13 Aug 2014

How to Setup Goal tracking for Contact Form 7 in Google Analytics

by Dean Lynn 48

UPDATE 11/05/2015: Are you having issues with your Contact form 7 not working when using Google Analytic’s goal tracking?
I have noticed a lot of people have been experiencing problems when using Google Analytics by Yoast and Contact form 7 that the tracking wasn’t working or forms wouldn’t submit.

When assessing the sites with these 2 plugins installed – Very common 8/10 of the websites I have helped fix has these 2 plugins installed. All had the same issue where the when the form was filled out and submitted it would not send the message nor trigger the goal. After a few hours of analysing I noticed “ga is not defined” error in my browsers console. When I checked the analytics snipped it had been changed to __gaTracker() rather then ga(), When I changed this and tested a submit it worked perfectly.

I realised that Yoast had changed the global tracking function from the default ga() to the more unique __gaTracker(), so this was the reason why many people have been experiencing these issues.

The solution:
Please do follow the guide below for a full work though on how to setup Goal tracking with Contact form 7, but the snippet below is used if your using Google Analytics by Yoast plugin.
on_sent_ok: "__gaTracker('send', 'pageview', '/goals/contact-form/');"

Goal tracking with Contact form 7 Guide

I have created a step by step guide on how to setup goal tracking for your contact forms in WordPress.

Once you know the process it’s very easy to replicate across all forms that are setup in the Contact Form 7 plugin. Creating separate Goals for different forms, for example we track our eBook downloads through Google Analytics which the form is built with Contact form 7 plugin.

Step 1 – Login to Google Analytics

Once your login to your GA account head over to your dashboard, select Goals from within the View menu.

Step 2 – Create a New Goal

Simple choose a name for your goal. Example for a contact form on your contact us page I would name it “Contact Us”.
Now choose the option “Destination” from the type options.

Step 3 – Goal Destination

Choosing a URL destination for this process we will be choosing a URL that doesn’t exist. A good example would be: “/goals/contact-us/”
Complete the rest of the goal as necessary to finish the set-up of your new goal.

Conversion Tracking Code for Contact Form 7 (Universal/Classic)

Now depending on whether you’re using Classic (ga.js) or the new Universal (analytics.js) Google Analytics code, you’ll need either one of the following lines of tracking code to place in your contact form. You can find out more about which tracking you’re using here – https://support.google.com/analytics/answer/4457764?hl=en

Universal Analytics Code

on_sent_ok: "ga('send', 'pageview', '/goals/contact-us/');"

Classic Analytics Code

on_sent_ok: "_gaq.push(['_trackPageview', '/goals/contact-us/']);"

UPDATE: It seems a few people where having an issue with the sent notification not appearing. Please do try the following code:

on_sent_ok:”_gaq.push(['_trackPageview', '/goals/contact-us/', 'sent']);”

Step 4 – Contact Form 7 Tracking Code

Now head over to your contact form 7 form settings, scroll down to the section called “Additional Settings.
In this filed you need to paste in the tracking code (universal or classic) as shown above. Scroll back up to the top of the page and click save.
Now when your contact form is successfully complete, Google Analytics will display a new goal!

I have created a lovely infographic explaining the process:

Conversion Tracking For WordPress with Google Analytics Infographic

You can now repeat this same process for each contact form you have created, all you will need to do differently is change the Goal Name and the Goal URL.

You then need to give the goal a name and then select destination as the type.
You then need to add your URL (/goals/enquiry/) into the destination field.

Stay tuned for my new post on how to add a successful thank you page to your contact form.

Any questions Goal tracking with Contact form 7 fire away in the comments below.

Summary
Article Name
How to Setup Goal tracking for Contact Form 7 in Google Analytics
Description
Are you having issues with your Contact form 7 not working when using Google Analytics goal tracking?
Author
Publisher Name
Datify
Dean Lynn

Associate Director at Datify