How to Add AdWords Conversion Tracking to Contact Form 7 in WordPress
Well, we never thought that adding an AdWords conversion tracking code to a Contact Form 7 form in WordPress would be the ridiculous polava it turned out to be.
To cut a long story short, WordPress gets funny about scripts on WordPress pages, and the AdWords code unfortunately falls into such a category.
You also need to make sure the code gets in-between the <body> </body> tags, otherwise it won’t register with AdWords.
To save you time and grey hair, here’s the quick fix:
- Create a thank you page (this should be a normal page from the Pages -> Add New menu item), and set the permalink to “thank-you” (or something similar, which will be used below).
- Create your Contact Form 7 form, and in the “Additional Settings” box at the very bottom, put: on_sent_ok: “location.replace(‘http://YourDomain.com/thank-you/’);”
- Go to Plugins -> Add New.
- Search for and install the Smart Google Analytics Code plugin. Activate plugin.
- Click the Smart Google Code option from the main side menu on the left.
- Add your AdWords tracking code to the AdWords Conversion Code Settings box at the bottom, pick your newly created Thank You page from the drop down list and complete the Caption box with something meaningful.
- Save Changes, run a test form submission, check the thank you page source code (right click -> view source code) to check the AdWords conversion tracking code is showing in-between the <body> tags.
Note: It can take up to 48 hours for customers who click your AdWords advert and then “convert”, to appear in your AdWords statistics.
Troubleshooting
- If your form does not send when you push the send button, you might be experiencing an “Uncaught SyntaxError: Unexpected token ILLEGAL” error when your form is submitted (error will not show on the page, and will only show as an error when you open the Inspect Element or Console part of Chrome). To resolve this, please make sure any code you copy from this article, (or from the Google AdWords conversion code section) is pasted into a plain text editor first to remove any formatting (use Notepad for PC’s, or TextEdit in plain text mode for Mac’s). This seems to be a problem with Chrome browsers in particular.
Robin Rico
Thank you so much for this post!! It’s exactly what I was looking for.
– Robin
Sara Thornton
My pleasure! Glad it helped, and thanks for the great feedback Robin,
Sara
Thomas
Hey,
Thank you very much 🙂 After I implemented your code, I saw that there is a new way to do it :
http://contactform7.com/tracking-form-submissions-with-google-analytics/
Might be useful for others…
Sara Thornton
Hey Thomas,
Thanks so much for your feedback! The link you provided is absolutely ideal for setting up Google Analytics, however I found that it was missing the final link in order to pop in the AdWords code required for tracking AdWords conversions. Did you find a user-friendly way to do this without using the the Smart Google Analytics Code plugin? If so, I’d love if you could post it in your reply, to hopefully provide an alternative method for anyone who stumbles across this article.
Many thanks in advance,
Sara
Lee
Am I being ‘stupid’ here.. or instead of populating WP with un-needed plugins.. this works:
1. create a new header1.php
2. create a new page template which calls header1.php
3. paste code into said header.
4. create your thankyou page using the new page template ?
Sara Thornton
Hello Lee,
Thanks for your post. Your suggestion is an excellent solution for any developers who wish to add the AdWords code with no additional plugins required.
It’s also an alternative solution for anyone wishing to track more than one type of AdWords conversion on the same website, or conversions on multiple pages, as the Smart Google Analytics Code plugin currently seems to have a few limitations in this area.
Thanks for your contribution!
Best wishes,
Sara
marius calude
Hi,
I have followed all the steps in your tutorial and it seems that when I click the send button from the contact form page, the site is not loading the thank-you page I have created. Can you please help me ?
Regards,
Marius
Sara Thornton
Hi Marius,
Can you double check that the URL of your thank you page is “/thank-you/”, and that the end “/” is included, so that it matches the code in point 2 (in the article above)?
Can you also post a link to your thank you page, and let me know what happens when you click your form send button?
Thanks,
Sara
Tim
Hiya,
I too had this problem. After reading the note Sara added i decided to retype the whole on_sent code into the additional settings area. It worked.
It seems the ” and the ‘ change when copy and pasted.
Its the solution I have been looking for!!
Thanks Sara,
Sara Thornton
Perfect – thanks for letting me know Tim! 🙂
Glad it helped,
Sara
IPM
The forms on our website utilize a confirmation message which appears on the same page as the form after submission, rather than a separate “thank you” page. How might these instructions be able to be modified to fit this situation?
Sara Thornton
Hi IPM,
Trying to hack the Javascript “in-page” thank you message would not really be a robust solution and could get rather messy if you want to track more than one conversion type.
To be honest, weighing up the time/cost benefit, the easiest way forward would be to switch to a “Thank You page” model, and then follow the instructions above.
I hope this helps,
Sara
Richard
Hi there,
I guess this doesnt work anymore – when you submit the button, the circle just continues. There’s no re-direction from my part. Any ideas? thank you
Sara Thornton
Hi Richard,
Thanks for your post. Did you follow the troubleshooting tip at the bottom of the article?
Dan Putnam
I figured it out I think using what they say here: http://contactform7.com/redirecting-to-another-url-after-submissions/
on_sent_ok: “location = ‘http://example.com/’;”
Looks like they changed the location replace code.
Sara Thornton
Thanks for your feedback Dan!
Dan Putnam
My tracking code is injected into the head.. not body. Any way to change that?
Sara Thornton
Hi Dan, if you use the solution in our article above, this should inject the code in-between the body tags.
Oussama Moursil
Just inserted the code, hope that will work. thx for your help.
Sara Thornton
Thanks for your post Oussama, I hope our solution works for you.