Cookies work by storing a unique identifier when someone clicks on an affiliate link. If the user makes a purchase within a set period, after clicking, the system can attribute that sale to the affiliate. However, once the cookie expires, the tracking becomes ineffective. If a purchase happens after the cookie window has closed, the affiliate won't get credit, as the system can no longer link the sale to the original referral.