How can I trigger an event before adding a product to the cart?

HI guys,

I’m looking to build a feature that fires JUST before the user adds a product to the cart somewhat like CandyRack: https://apps.shopify.com/candyrack?search_id=9af07dd1-6824-4207-b138-28fabfc6139a&surface_detail=candy+rack&surface_inter_position=1&surface_intra_position=1&surface_type=search

I’m wondering how candy rack captures the add to cart event and then sends out the exact same event after closing out their window. I would like this exact behaviour.

The behaviour I’m talking about is that:
After you’ve installed the Candy rack app and created an offer.
When a user goes to the product page and clicks ADD TO CART.

Nothing is added to the cart YET.
FIRST CandyRack opens and AFTER you either made a selection or clicked the close button THEN the add to cart event is fired.

Any ideas on how to do this?

All help is appreciated.

Hey could you find any solution or figure out a way how they do it?