Here’s a quick and easy way to track exactly where your signups are coming from, and who referred any given customer, without having to cross-reference your analytics program.

1
2
3
4
5
before_filter: set_referer

def set_referer
  cookies[:referer] = request.env['HTTP_REFERER'] if cookies[:referer].nil?
end

The set_referer method sets up a session variable that keeps the original referrer with your customer, no matter how many pages they click through before signing up.

You can email this variable to yourself when they sign up, or store it in the database to keep track of who came from where.


2 Responses to “Track Referrals in Your Rails App”

  1. Ryan Says:

    Ok, so this isn’t working as expected. Has anybody tried something similar with better results?

  2. Ryan Says:

    I had a ton of trouble getting this to work properly, and I finally traced it down to the session variable not getting passed correctly. I’m still not sure why session[:referer] would not persist between requests. I finally achieved the result I was looking for by setting a cookie instead of a session variable.

Sorry, comments are closed for this article.