How to Add AdWords Conversion Tracking to Contact Form 7 in WordPress

Google Adwords Logo

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:

  1. 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).
  2. 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/’);”
  3. Go to Plugins -> Add New.
  4. Search for and install the Smart Google Analytics Code plugin.  Activate plugin.
  5. Click the Smart Google Code option from the main side menu on the left.
  6. 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.
  7. 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.
This entry was posted in WordPress on by .

About Sara Thornton

Sara is a Jack (or Jill) of many trades. A web designer and developer, an ethical SEO implementer, an AdWords advocate, as well as being our in house user-guide creator and trainer. In her spare time she loves a bendy/stretchy yoga session, and feels most happy when she's near the ocean (ideally with a ridiculously absorbing book).

Leave a Reply

Your email address will not be published. Required fields are marked *

20 thoughts on “How to Add AdWords Conversion Tracking to Contact Form 7 in WordPress

    1. Sara Thornton Post author

      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

      Reply
      1. 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 ?

        Reply
        1. Sara Thornton Post author

          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

          Reply
  1. 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

    Reply
    1. Sara Thornton Post author

      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

      Reply
      1. 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,

        Reply
  2. 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?

    Reply
    1. Sara Thornton Post author

      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

      Reply
  3. 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

    Reply