Tuesday, March 27, 2007

Passing values into landing pages from a url

For those of you that are building out multiple landing pages I have a simple javascript that may help you with passing variables from campaign url strings into your landing pages.

For example, if you have landing pages that contain identical forms and only need unique "lead source" information you can use this javascript to pull a variable passed in a url string to change the lead source information.

Place the following code where you would normally put your hidden lead source fields.

<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}

</script>
<script type="text/javascript" language="JavaScript"><!--
document.write('<input ');
document.write(' type="hidden" ');
document.write(' name="lead_source" ');
document.write(' value="' + getQueryVariable("ls") + '">');
//--></script>

You can then access the page with the variable attached to the url:

www.yourwebpage.com/landingpage.html?ls=leadsource1

The variable populates the hidden form field with the lead source information.
<input name="lead_source" value="leadsource1" type="hidden">

When the user clicks submit the information will populate in salesforce.com eliminating the need for multiple landing pages.

You can also use this in correlation with you analytics link ids to maintain consistency in your reporting. Just change the variable in this line of code:
document.write(' value="' + getQueryVariable("change-this-value") + '">');

You can be creative and use this script to pass multiple values if needed...think about personalizing the landing page from a personalized url string in an email. You could pre-populate a form or even personalize the landing page with their name or any number of attributes in the email database!

Best of luck to you!

1 comments:

Jono Smith said...

Is it possible to associate leads to a campaign based on the fields in the lead form?

Spread the word!

Tag Cloud

Recent Articles

Translate This Page

Select Language:


Shared Articles

Favorite Books





www.flickr.com
This is a Flickr badge showing public photos from skatterbox. Make your own badge here.
-->