Created
October 21, 2010 20:37
-
-
Save cschmidt/639301 to your computer and use it in GitHub Desktop.
How to pass the Google Adwords gclid parameter onto your form confirmation page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
<!-- | |
(function() { | |
function getQueryParam(paramName) { | |
var query = window.location.search; | |
var paramValue = null; | |
var pos = query.indexOf(paramName + '='); | |
if (pos > -1) { | |
var start = pos + paramName.length + 1; | |
var end = query.indexOf('&', start); | |
end = end > -1 ? end : query.length; | |
paramValue = query.substring(start, end); | |
} | |
return paramValue; | |
} | |
var gclid = getQueryParam("gclid"); | |
if (gclid != null) { | |
var previous_form_url = | |
window.module.lp.form.data['confirmData']; | |
window.module.lp.form.data['confirmData'] = | |
previous_form_url + "?gclid=" + gclid; | |
} | |
}) (); | |
--> | |
</script> |
Yeah, that's certainly more compact and covers more cases. Is window.location.href more widely supported than window.location.search?
Good question - I can't see any reason not to use location.search instead of location.href -- no difference in support across browsers as far as I know.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A shorter alternative to getQueryParam that I use sometimes is: