Monday, April 13, 2009

Lead source codes - capturing with Javascript


In a recent post, we talked about using form profile fields to capture the most recent lead source code, as seen in the URL's query string, into a form. If, however, you want to manipulate the lead source prior to placing it in the form, or in any way work with the data, you may wish to use javascript directly.

This is a slightly more technical route, but once you are comfortable working with the javascript behind the form, many options become possible in your marketing efforts.

The javascript file here has the code that you see to the left. Essentially, the script looks for query strings in the URL of your page. In this case, we are looking for a query string called "c", so it will appear as "&c=****" where **** is the lead source code we are looking to track.

The script then puts that value in the "Campaign_ID" field (likely a hidden field) within your web form. The web form in this example is called "WhitepaperForm_data". To configure this for your web form, just add the javascript into the page with your web form, and configure the form name, form field, and query string, and you will have the query string value automatically populate your form field.

This technique is a very useful one to know, as it can be extended to do all sorts of interesting things with your web forms, and the content on your pages, based on the values passed in in a query string.

3 comments:

Tero Rantaruikka said...

If I have several parameters that track different lead sources (Google, Facebook, Banners) how do I add them to the JavaScript?

theGrieben said...

In the source I suggest changing


var strURL = document.location.href;

to

var strURL = decodeURIComponent(document.location.href);

This will allow special characters such as the @ in emails to be formatted properly.

theGrieben said...

In the source I suggest changing


var strURL = document.location.href;

to

var strURL = decodeURIComponent(document.location.href);

This will allow special characters such as the @ in emails to be formatted properly.