Search code examples
google-tag-managerfacebook-pixel

sometimes tag manager does not record facebook pixel code


my website is here i want to create facebook pixel event code with google tag manager but sometimes it's not working

my setup is:

trigger type : click all elements This trigger fires on : some clicks click classes == equals == cart-button btn btn-default btn-lg hvr-sweep-to-right

This trigger fires on : some clicks


Solution

  • You are facing quite common problem, basically GTM takes exact element that is clicked - which in your case is not only the button with classes you are looking for but also you can click on span or icon element(see highlighted below). In case you click on span,icon or outside of button area your trigger rules would not go through.

    enter image description here

    So you need to make sure your trigger takes into account all elements that are part of your button. There are multiple ways you can solve this. But looking at your html I think you can achieve this by simply using querySelector in GTM with this query: .product-util, #add_to_cart, #add_to_cart > *

    So your trigger can look like this: enter image description here

    This selector takes into account your wrapper div element, the button element and all children of this button. I didn't test this code of course and I am not sure if you use these class & id elsewhere on your website so do you testing. Hope this helps.