Created
April 30, 2012 21:23
-
-
Save leppert/2562803 to your computer and use it in GitHub Desktop.
Parsing Svpply referrer links
This file contains 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
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); |
This file contains 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
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