Rack middleware for referral tracking