Affiliate links INSIDE a membership/affiliate website?

I have created a website where much of the information is membership only, and also has an affiliate referral program running.
What I'm wondering if if/how there's a way to create links inside the site that also relate to the affiliates? As an example, some of the products that are recommended on the site are sold on the individual affiliate's website, so if someone is referred to the site from an affiliate link by person 'A' then when they click on a particular link in the site the user would get sent to, or if they were referred originally by person 'B' then when they click on the same link they would instead be sent to
Any advice would be appreciated :slight_smile: