How to keep referral information until user signup

406 views Asked by At

I would like to add referral program to my website. The user is taken from some other page to my homepage with referral url parameter like:

www.example.com?referral=refCode

The thing is, the only time I care about the referral code is at the signup page.

www.example.com/signup

Is there a way to retain the referral code through user journey on my website?

2

There are 2 answers

0
Jan Horčička On BEST ANSWER

I solved the issue using cookies. Spring Boot provides easy access to cookie operations as described for example in this article.

When an user reaches my home page, I check for the referral parameter and if it exists, I store it in the cookie. I set cookie expiry date for 14 days for example. In the POST controller for the sign-up, I check their cookie and if it contains the referral info, I store it in the DB for the user.

0
monotype On

I faced the same dilemma recently, and after some thought, I decided to use cookies. In my system when user hits /login, they are redirected to an external API for social login. By setting cookies from the query on the homepage, I can retrieve them on the backend from the client's cookies. Initially, I thought of using localStorage, but it turns out it's impossible to retrieve from it and attach to a query on redirect, partitialy it can be resolved by using a separate login page, but what if I want to redirect a user who hits a protected route or tries to buy something without being logged in? Therefore, cookies are an excellent and straightforward solution in this case.