First of all, apologies for making another post on this issue, but I haven’t found any solutions that worked in the various other posts regarding this problem.
Basically, I’m trying to set up add to cart tracking as per the documentation, but have been unsuccessful. Our shopify site doesn’t have an ID, but instead uses class, so I’m using the alternate code snippet.
Things that have been done:
- Viewed product code has been put in the product.liquid file
- Viewed product code is successfully firing the viewed product events (for my email as well)
- Added the added to cart snippet below the viewed product code
Our Shopify site’s add to cart button code is here:
The code that I have inserted into product.liquid is here:
Different variations of the querySelector value I’ve tried to use:
All have not worked. I’ve tested each variant by adding to cart on our site after the change. Viewed product always fires correctly and instantly (meaning I am cookied already), but there is no add to cart metric added or event fired.
Best answer by Omar
The way I go about this normally is by opening up the browser developer tools and adding the 2 lines 37 and 38 of your last screenshot in the console and just testing with that. You can perfectly test this without adding it to the theme files.
If you can code a bit you could even send a alert message in your screen so you know it's working.
Another thing to check is if you're seeing errors in the console (when you click). Sometimes typos happen and cause an error to happen.
Not sure if this would be the best solution but you could add an ID to the button.
Last thing you want to check is to view the HTML of the product page and make sure all the data is being populated. Item, title, URL etc.
Hope this helps a bit