Why is my Facebook Pixel add to cart event not working?

This happens to some themes. Add this to your theme’s theme.liquid file to correct it:


<script>
  function bcpoDone() {
    $(document).on('bcpo:add', function (e, e2) {
      if (!window.bcpo_product) return;
      var id = Number($('form[action="/cart/add"] [name="id"]').val());
      var variant;
      for (var i = 0; i < bcpo_product.variants.length; i += 1) {
        if (bcpo_product.variants[i].id === id) {
          variant = bcpo_product.variants[i];
          break;
        }
      }
      if (!variant) return;
      fbq('track', 'AddToCart', {
        content_type: 'product_group',
        content_ids: [bcpo_product.id],
        currency: bcpo.currentCurrency,
        value: bcpo_product.price / 100,
        num_items: $('form[action="/cart/add"] [name="quantity"]').val() || 1,
        content_name: variant.title,
        content_category: bcpo_product.type,
      });
    });
  }
  </script>
Was this article helpful?
Dislike 0

Pin It on Pinterest