How are referrals tracked?

Referrals are tracked when a user creates an account using an affiliate link or discount code provided by the affiliate