3

Note: Before marking it as duplicate please read description carefully

I am creating a module for Facebook pixel tracking and I am stuck at AddToCart event.

I have seen some 3rd party extensions, but the issue is they are tracking AddToCart after page load and my AddToCart event should based on ajax based.

So my question is, how can I trigger AddToCart facebook pixel code after ajax add to cart?

  • Are you using the standard magento 2 ajax functionality? – Dava Gordon May 10 at 8:52
  • Yes, most probably standard, I didn't use any plugin for this – Shoaib Munir May 10 at 8:53
  • If you know the ID/Class of the add to cart button why not just create a custom on page javascript something like $('.addtocart.btn').on('click', function() { // Do the Magic }); you may need to adjust the class – Dava Gordon May 10 at 9:00
  • I think this should work. I will surely try this. Please add it in answer, I will vote it anyways if it is working or not – Shoaib Munir May 10 at 9:02
2

If you know the ID/Class of the add to cart button why not just create a custom on page javascript something like

$('.addtocart.btn').on('click', function() { // Do the Magic });

you may need to adjust the class. i will create a extension for FB pixel very soon to include the ajax add to cart option. so fixes an issue a lot of people will be having

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.