Javascript Conditional Code for Conversion Tracking in Google Adwords

by Bradley on January 16, 2012

I was working with a Squarespace site recently and needed to put some tracking code on the success page after a contact form.

I’m not as familiar with SquareSpace as WordPress and had to write some javascript code to run on a contact form tracking page.  Since no PHP was available to write, Eric and I did it strictly in Javascript.  Here’s the final code:

<script type="text/javascript">
if ((location.href)=="http:www.yoursite.com/trackingpage") {
/* <![CDATA[ */
var google_conversion_id = xxxxxxxx;
var google_conversion_language = "en";
var google_conversion_format = "1";
var google_conversion_color = "000000";
var google_conversion_label = "xxxxxxxxxxx";
var google_conversion_value = 0;
/* ]]> */
}
</script>

Naturally you’ll need to change these three values:

  1. Change http:www.yoursite.com/trackingpage to the exact URL of the transaction URL.
  2. Replace the xxxxxxxx after google_conversion_id to whatever your actual conversion is is.
  3. You’ll also need to change xxxxxxxx after google_conversion_label to whatever your actual label is, too.
That’s it!  Now this code can be included on every page but will still only trigger on the conversion page.

Want More out of WordPress?

I can show you how to get more traffic, make WordPress do amazing things, and how to make more money with your website by converting your visitors into customers. Click the button to the right to get a free estimate.

  • future7

    Hi Brad – Very interesting indeed! But what if the form is a widget and there isn’t a success page? 

    • rawwebdesign

      That would take some different code altogether, but the basic idea is to push an event to Google Analytics when the contact form is submitted. I’d be happy to work with you to make the code if you’d like. Just email me if you want to work together.

  • Mario Izquierdo

    I too am trying to do the same, but the problem we have encountered is there isn’t a separate url once the form is completed. I would like to know how exactly you did it because we want to invest in adwords conversion tracking.

    • rawwebdesign

      Thanks Mario! I just emailed you about this.

    • http://www.mnelson071799.com/ Mike Nelson

       How did this work out for you Mario? I’m curious about the same thing.

      • rawwebdesign

        Please email me and I’ll write the code for you. Thanks!

Previous post:

Next post: