You’re using WordPress and Contact Form 7 and everything seems great. But one day, you need to track in Google AdWords how many people use the contact form to see the conversion rates.
Unlike some contact form plugins, Contact Form 7 does not generate a thank you page after submitting the form. This will make it hard to embed Google AdWords Conversion Tracking Code.
The good news is Contact Form 7 allows you to attach a function call after form submission. It means that we can apply the tracking code on that function call.
On your header.php of your current WordPress template, add the following code:
var img = document.createElement("img");
var goalId = "94216xxxx"; // Your Google Conversion ID
var randomNum = new Date().getMilliseconds();
var value = 0;
var label = "Dwn0CMig0xxxxxxxxxx"; // Your Google Conversion Label
var url = encodeURI(location.href);
var trackUrl = "http://www.googleadservices.com/pagead/conversion/"+goalId+"/?random="+randomNum+"&value="+value+"&label="+label+"&guid=ON&script=0&url="+url;
img.src = trackUrl;
Don’t forget to replace the
label to your AdWords ID and LABEL.
On Contact Form 7 – Additional Settings tab, add the following:
Your Additional Settings tab should look like below:
Like how it was mentioned, this function will be called when the form has been submitted. The function will create an image tag that links to Google AdWords Conversion Tracker.