The main reason to use codes is that each one is identifiable. When a partner, a creator or a segment gets its own code, redemption tells you what that relationship produced without relying on cookies, click attribution or a platform's modelling. For affiliate arrangements and gifted product, it is the most reliable record you will have.
Codes also let you control who receives an offer. Limits per customer, single-use codes generated per recipient, minimum order requirements and end dates all constrain the giveaway, which matters when the offer is meant for one audience rather than the whole internet.
The trade-off is that codes travel. Once a code exists it can be posted anywhere, and coupon aggregation sites collect them. Unique per-recipient codes and sensible usage limits contain that, at the cost of more setup than a single shared code.