Module: Devise::Models::Referable
- Defined in:
- lib/devise_referable/model.rb
Overview
Referable tracks users that arrive at your site via an affiliate link. Currently this is hardcoded as /ref/:referrer_token/path/to/destination TODO: make url configurable
Classes that act as referrers are specified in the config, and must have a referrer_token column in the database. TODO: make column name configurable
When a visitor arrives at the site via the referral_landing_path, the following things happen:
- The referrer is looked up, by doing finds against the referrer_types in order.
- If found, a referral record is created with a unique referral_token.
- The referral_token is also stored in a cookie
- The visitor is then redirected to the path appended to the referral_landing_path (i.e. /path/to/destination above)
- If no path is given, they're redirected to the root path.
- If the visitor registers before the cookie expires, the referral record is updated with the new user id, and the cookie is cleared.
Configuration:
referrer_types: an array of symbols for classes that can refer users. i.e. [:blog, :customer, :user]
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/devise_referable/model.rb', line 25 def self.included(base) base.class_eval do has_one :referral, :foreign_key => :recipient_id extend ClassMethods end end |
Instance Method Details
#update_referral(token) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/devise_referable/model.rb', line 32 def update_referral(token) referral = Referral.find_by_referral_token(token) if referral referral.update_attributes( :recipient_id => self.id, :registered_at => self.created_at ) end end |