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.

Previous post:

Next post: