Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanpraski/8277162f1b7f37f67d58bf96442305c6 to your computer and use it in GitHub Desktop.
Save ryanpraski/8277162f1b7f37f67d58bf96442305c6 to your computer and use it in GitHub Desktop.
Sample Salesforce web-to-lead form that captures Adwords GCLID in a hidden form field. Make sure to replace xxxxx and yyyyy with your specific Salesforce field values.
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
</head>
<body>
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
<script>
window.onload = function getGclid() {
document.getElementById("xxxxx").value = (name = new
RegExp('(?:^|;\\s*)gclid=([^;]*)').exec(document.cookie)) ?
name.split(",")[1] : "";}
</script>
<input type=hidden name="oid" value="yyyyy">
<input type=hidden name="retURL" value="http://">
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<input id="xxxxx" name="xxxxx" type="hidden" /><br>
<input type="submit" name="submit">
</form>
<script type="text/javascript">
function setCookie(name, value, days){
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires;
}
function getParam(p){
var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
var gclid = getParam('gclid');
if(gclid){
var gclsrc = getParam('gclsrc');
if(!gclsrc || gclsrc.indexOf('aw') !== -1){
setCookie('gclid', gclid, 90);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment