I have a reactJS web application, i would like my users to be able to refer other users to the application.
I have used URLSearchParams in the signup form so that users can share their personal link.
eg. app.com/signup?r=username
const queryParams = new URLSearchParams(window.location.search);
const r = queryParams.get('r');
console.log(r);
I can then save the referrer ID in the database when the user signs up, but i know this will not persist if the user views another page and then comes back to the signup form.
I think maybe setting a cookie that lasts for 30 days and then using this as the referrer ID on signup.
So my question is, how can i implement cookie based referrals in to a reactJS signup form?