Track Referrals in Your Rails App
October 30th, 2008
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”
Sorry, comments are closed for this article.
November 3rd, 2008 at 01:01 PM
Ok, so this isn’t working as expected. Has anybody tried something similar with better results?
November 3rd, 2008 at 05:59 PM
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.