Here are the rules of the McDonald's Coffee Rewards Program which was available in the USA as of 2020.
Customers can get a 6th free McCafé drink when they buy 5, if they purchase via McCafe App. It works like a digital version of a punch card. Once a customer had 5 drinks, a code + QR voucher code will appear on their app that they can scan at the counter to get their reward. The free drink voucher is valid 90 days after the issuing. The discounted drink does not “earn” a stamp for the app.
If you get the discounted drink you don’t get a stamp for it.