Referral program - cookies and more (Rails) -


I am creating a referral program for my Ruby on the Rails app, such that a user can share a link In which their User ID (app.com/?r=ID) is present if there is a referrer ID, when there is a visitor land on the app's homepage, there is a hidden field in the signup form on the homepage which is populated with Referrer ID it happens. The administrator then detects the ID and creates a new referral in the referral table if the referenced visitor indicates. This works, and here's the part of the code:

  @referrer = User.find (params [: r]) until @ referrer.nil will not rescue rescue? @referral = Referral.new (: referrer_id = & gt; @ referrer.id) end   

Pretty simple stuff, but it's very easy to break (Example: if visitors leave the homepage , Referrer id is lost). I think cookies can be a more robust method, where a cookie with referral ID is stored on the specified user's computer for day X. This is very common, especially with affiliate programs like GroupOn, but I have never worked with cookies and I do not know where it starts from.

Besides, is there a good way to mask or change the referrals URL system? Instead of app.com/?r=1842 , I like something like app.com/x39f3 & lt; - Randomly generated sequence of numbers related to a given user ? R = without part

Any help is greatly appreciated. Thanks!

To answer a cookie question, setting them is quite easy:

  Cookies ['AppRefer-id'] = Param [: R]   

And then there is only one format for reading them back (but without assignments). I would suggest putting this code in the first_filter in your application controller. In this way, the cookie will be set without regard to the page, on which your visitors are in the first place on your site.

Regarding changing the URL structure in the suggestion format, you referral code matches a specific pattern, otherwise you are likely to run in routing problems. If, for example, they matched with the format of three numbers, after three numbers, you can put your root files:

  match '/: referrer_id' = & gt; 'App # Index',: Barriers = & gt; {: Refer_id = & gt; The reference of App # Index should be changed in the controller in which you handle the referral. You can access referrer_id via params [: referrer_id].  

Hope this is some use.

Robin

Comments