Saving HTTP Referer

I’m trying to save the site that a user came from when they sign up.
Right now I have a before_filter in my ApplicationController:

before_filter :save_referer

def save_referer
unless is_logged_in?
session[‘referer’] = request.env[“HTTP_REFERER”] unless
session[‘referer’]
end
end

def create
@user = User.new(params[:user])
if @user.save_with(session[:referer]) … end

User def save_with(referer) self.referer = referer unless referer ==
“null” self.save
end

Then when a user is created, it checks this session variable and sets
it to nil. This is buggy as it only works sometimes and I cannot seem
to figure out why. Any ideas what could be going on?

On Tue, Mar 2, 2010 at 5:30 PM, David [email protected] wrote:

I’m trying to save the site that a user came from when they sign up.
Right now I have a before_filter in my ApplicationController:

 session['referer'] = request.env["HTTP_REFERER"] unless

session[‘referer’]

Then when a user is created, it checks this session variable and sets
it to nil. This is buggy as it only works sometimes and I cannot seem
to figure out why. Any ideas what could be going on?

Because HTTP_REFERER is not a required header, and in fact
some security software blocks it for privacy reasons.

So you just can’t count on it being available.


Hassan S. ------------------------ [email protected]
twitter: @hassan

Aha, is there any way to figure out where a user comes from every
time?

On Mar 2, 5:53 pm, Hassan S. [email protected]

On Tue, Mar 2, 2010 at 6:42 PM, David [email protected] wrote:

Aha, is there any way to figure out where a user comes from every
time?

Short answer: no

Longer and probably not better answer: if by “every time” you mean
100% certainty, no BUT you could spend an interesting amount of
money approaching, on a very steep curve, that point.

Or so I’d think. But really, for the purposes of this discussion: no
:slight_smile:


Hassan S. ------------------------ [email protected]
twitter: @hassan

install google analytics… It has this functionality, and without
spending days/weeks/months on this problem, chances are they’ll do it
better.