How can I implement onclick data layer push for add to cart in Empire theme?

Hello,

I am trying to implement onclick data layer push. Basically, I want to get a datalayer push with product data after the add to cart button has been clicked. I implemented this to our product form liquid:


But this is firing at all times on a product page, and not waiting for the onclick, I can see it in the source code even before clicking on something. I would like to then send this data to GTM. The URL for preview of a product page is here:

https://n60ua4su0pqnir6h-19404561.shopifypreview.com/products/vintage-1906-led-55-7-5-w-2500k-e27?variant=41260710985909

Am I doing something wrong? Thank you all for your help.

Hi @MartinNovotny1 ,

I checked and you have one more code outside onclick, you just need to remove it, and everything will work fine.

Hope it helps!

where exactly did you past this code? thanks