Skip to content

Instantly share code, notes, and snippets.

@leppert
Created April 30, 2012 21:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leppert/2562803 to your computer and use it in GitHub Desktop.
Save leppert/2562803 to your computer and use it in GitHub Desktop.
Parsing Svpply referrer links
var svpply = function(referrer){
var params = {};
if(referrer.substring(0, 17) === 'http://svpply.com'){
var e,
a = /\+/g,
r = /([^&=]+)=?([^&]*)/g,
d = function(s){ return decodeURIComponent(s.replace(a, " ")); },
q = referrer.split('?')[1];
while (e = r.exec(q))
params[d(e[1])] = d(e[2]) === 'true' ? true : d(e[2]) === 'false' ? false : d(e[2]);
delete params.redirect;
}
return params;
};
var svpply_user_info = svpply(document.referrer);
require 'cgi'
def svpply(referrer)
params = {}
if referrer[0..16] == 'http://svpply.com'
CGI::parse(referrer.split('?')[1]).each do |key, val|
params[key] = (val[0] === 'true' ? true : val[0] === 'false' ? false : val[0]) unless key == "redirect"
end
end
params
end
svpply_user_info = svpply(request.referer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment