Skip to content

Instantly share code, notes, and snippets.

@rsoury
Last active November 29, 2016 05:53
Show Gist options
  • Save rsoury/9f376ae03652d5824036592c60120c04 to your computer and use it in GitHub Desktop.
Save rsoury/9f376ae03652d5824036592c60120c04 to your computer and use it in GitHub Desktop.
Referral Link For Sales Force Web To Lead
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.3/js.cookie.min.js"></script>
<script type="text/javascript">
(function($){
var getParameterByName = function(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
var appropriateRef = function(ref){
return (
ref == 'firstname.lastname' ||
ref == 'firstname1.lastname1' ||
ref == 'firstname2.lastname2' ||
);
};
var inputValue = 'Zippay Merchant Application';
var ref = (getParameterByName('ref') || "").toLowerCase();
while(ref.indexOf(' ') > -1){
ref = ref.replace(' ', '.');
}
if(appropriateRef(ref)){
var names = ref.split('.');
for(var i = 0; i < names.length; i ++){
names[i] = names[i][0].toUpperCase() + names[i].substring(1);
}
var formalname = names.join(' ');
inputValue = inputValue + ' - Ref: ' + formalname;
//Create the cookie.
if(Cookies){
Cookies.set('merchant_application_ref', formalname);
}
}else{
//Read a cookie.
if(Cookies){
var cookieRef = decodeURIComponent(Cookies.get('merchant_application_ref') || "");
cookieRef = cookieRef.toLowerCase();
while(cookieRef.indexOf(' ') > -1){
cookieRef = cookieRef.replace(' ', '.');
}
if(appropriateRef(cookieRef)){
var names = cookieRef.split('.');
for(var i = 0; i < names.length; i ++){
names[i] = names[i][0].toUpperCase() + names[i].substring(1);
}
var formalname = names.join(' ');
inputValue = inputValue + ' - Ref: ' + formalname;
}
}
}
$(window).load(function(){
$('<input />').attr({ type: 'hidden', id: 'lead_source', name: 'lead_source', value: inputValue }).prependTo('div.merchant-form form');
});
console.log(inputValue);
})(window.jQuery || window.$);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment