Forum Academy Marketplace Showcase Pricing Features

Keeping Parameters during navigation, or saving them somewhere

Hello there!

I’m doing a Referral Program. So I want a user when they land my site with a referral link, if the user navigates around the site and signs up later, do avoid loosing the information of who referred that user

Process:

  1. User lands www.mysite.com/?referer=friendreferer
  2. Instead of signing up, navigates to home, other pages
  3. Comes back at sign-up, I need to have “somewhere” saved that the code of the user who referred this new one is friendreferer

What’s the best way to do that? Any ideas?

Thank you in advance!

Cookies are your friend here…

But the simplest way is just to save it to the Current User in some way. Then if they sign up within 3 days the ref link will still be assigned to them.

But that won’t work if they log in, or sign up more than 3 days later.

So the best bet is to set a cookie on their browser, then when they login or sign up, add the ref link stored in the cookie to the database.

I thought doing something like that… is there any cookie tutorial for this around?

1 Like

I found plugins like this

If you know any other (if it’s free even better) for doing this?

Yeah, there are several ways to set and read Cookies - there are a few plugins, or you can use standard JavaScript, or there are JS APIs that work well too (I use js-cookie GitHub - js-cookie/js-cookie at latest, which is very simple to use)

I’m pretty sure I’ve seen forum posts about how to do this in the past (although probably more to wo with shopping carts than referral links, although the process is basically the same).

But to briefly summarise, here’s how I do it (no doubt there are other ways).

  • Firstly, I have datatypes in my database for ‘Referral Link’ which contains data about the actual referral link itself (such as the User who created it, as well as the URL parameter value itself), and also a datatype for ‘User-Ref-Link’ which is a connecting datatype linking a User with a pre-existing ‘Referral Link’, including data like when it was set, when it expires, and the User it relates to etc.

  • When a new User lands on the page using the ‘Referral Link’ parameter value in the URL, if they are logged in and don’t already have a ‘User-Ref-Link’ for that particular ‘Referral Link’ in the DB, then I’ll simply create a new one for them. If they already have it then I won’t.

  • If they are not logged in, then I’ll create a new ‘User-Ref-Link’ and save its Unique ID in a cookie on their browser (assuming they don’t already have such a cookie saved). Then if/when they log in I’ll check to see if the logged in User has a ‘User-Ref-Link’ already containing that ‘Referral Link’, and if not I’ll modify the ‘User-Ref-Link’ stored in their cookies to link the the User.

That way I don’t have to keep passing URL parameters from page to page, I wont lose the referral if the user already has an account and I can set the expiry on the cookie to whatever i like, so can keep it valid for more than the 3-day standard Bubble cookie.

Update: here’s a more in-depth explanation of the process from an old thread: How to attach anonymous data to existing user after they log in? - Need help / Database - Bubble Forum

This topic was automatically closed after 70 days. New replies are no longer allowed.