How to call php code for ecommerce/store elements

I created a store using the “Commerce” element and “Store”. It displays about 10-12
products with their prices. When I click on an item, I want to invoke backend
php code that sets cookies and keeps track of what item the user viewed, how
do I ensure that my php code e.g “products.php” code is invoked when a user
views an item in the online store ?

Thanks for any pointers.