January 16, 2012 - 6 comments

Javascript Conditional Code for Conversion Tracking in Google Adwords

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:

[code lang="js"]
<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;
/* ]]> */

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.


January 23, 2013 at 12:35 pm

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

    January 23, 2013 at 5:34 pm

    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
February 28, 2013 at 4:42 pm

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.

    March 1, 2013 at 10:06 am

    Thanks Mario! I just emailed you about this.

    Mike Nelson
    March 13, 2013 at 3:20 pm

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

      March 14, 2013 at 4:57 am

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

Leave a Reply