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?

4
  • Are you using the standard magento 2 ajax functionality? May 10, 2019 at 8:52
  • Yes, most probably standard, I didn't use any plugin for this May 10, 2019 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 May 10, 2019 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 May 10, 2019 at 9:02

1 Answer 1

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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