Shopify recently introduced new feature Shareable Discount Links that allows discount codes to be shared using a link.
The most important thing to know is that right now you can't grab the applied discount with Liquid. As cool as that would be to have, there's just no object that reveals that. I think the perfect - or crazy - world for a front end dev would be to have access to:
That last one would be pure magic but can see how that breaks the flow of codes working during in the checkout - but not before. A perfect world doesn't mean it's a sound idea.
Anyway, back on topic!
One handy feature that shareable discounts has, is the redirect option. We can hijack that in a way to let us pull in some custom string data. The idea is very simple:
To make it clearer you'd start with standard shareable discount code...
...and then add the redirect code:
When used the page will redirect to the home page with the querystring (?code=fake-code) let in place. Use JS to grab it and do cool stuff. Do remember that just because you have the code doesn't mean that it's valid, nor that it can apply to the cart. Always be mindful of that so you don't end up adding confusion or setting wrong expectations on cart price for the customer.