Is there a way to use coupon codes to track affiliate

Is there a way to use coupon codes to track affiliate referrals?

After purchase with coupon code the buyer gets a discount and affiliate gets credit, e.g. a coupon code distributed on a website or flyer. No referral url, just a coupon code.