Add to Cart firing twice, creating two FB Pixel events when should only be one (code snippet included)

New Member
1 0 1

When I click my add to cart button, then look at the FB Pixel Helper tool, as well as my FB events manager, I show that the add to cart button is firing twice. I have tried to mess around with the code but can not seem to get it right. Below is the code that I beleive is associated with this issue. Any help is greatly appreciated. Thank you.

/*============================================================================
  Cart
==============================================================================*/

var ajaxCart = {
  init: function(){
      $('body').on('submit', '.product_form', function(e) {
        e.preventDefault();
        var $addToCartForm = $(this);
        var $addToCartBtn = $addToCartForm.find('.add_to_cart');

        $.ajax({
          url: '/cart/add.js',
          dataType: 'json',
          type: 'post',
          data: $addToCartForm.serialize(),
          beforeSend: function() {
            $addToCartBtn.attr('disabled', 'disabled').addClass('disabled');
            $addToCartBtn.find('span').removeClass("zoomIn").addClass('animated zoomOut');
          },
          success: function(itemData) {
            $addToCartBtn.find('span').text({{ 'products.product.add_to_cart_success' | t | json }}).removeClass('zoomOut').addClass('fadeIn');
            $addToCartForm.find('.continue_shopping').show().addClass('animated fadeInUp');

            window.setTimeout(function(){
              $addToCartBtn.removeAttr('disabled').removeClass('disabled');
              $addToCartBtn.find('span').addClass("fadeOut").text($addToCartBtn.data('label')).removeClass('fadeIn').removeClass("fadeOut").addClass('zoomIn');
            }, 1000 );

            $.getJSON("/cart.js", function(cart) {
              refreshCart(cart);
            });
          },
          error: function(XMLHttpRequest) {
            var response = eval('(' + XMLHttpRequest.responseText + ')');
            response = response.description;
            $('.warning').remove();

            var warning = '<p class="warning animated bounceIn">' + response.replace('All 1 ', 'All ') + '</p>';
            $addToCartForm.after(warning);
            $addToCartBtn.removeAttr('disabled').removeClass('disabled');
            $addToCartBtn.find('span').text({{ 'products.product.add_to_cart' | t | json }}).removeClass('zoomOut').addClass('zoomIn');
          }
        });

        return false;
      });
  }
}

 

1 Like
Shopify Staff (Retired)
Shopify Staff (Retired)
269 1 20

Hey, Cody!

Stephanie here from Shopify support. 

I took a look at your site and there is only one Pixel installed; however, 2 add to cart events are firing. Typically, this is due to an app firing an additional pixel. 

I will reach out to you directly so we can dicuss this further! Keep an eye out for an email from me. ? 

Stephanie | Shopify Support
0 Likes
New Member
5 0 0

Hi, I'm having the same problem also. Can you also message me directly. Thanks!

0 Likes
New Member
2 0 1

Hi Stephanie, I'm having the same problem too. Can you maybe post how to look for the app that's causing the problem? Shopify should publish a list of apps that cause this problem.

1 Like
Tourist
6 0 1

I'm experiencing the same thing. Its happening for me without any apps so I know that's not it.

Were you able to figure it out?

I'm using the Debut theme.

0 Likes
Tourist
3 1 2

Any update to this?

1 Like
Tourist
12 0 1

Can we get an update?

1 Like
Highlighted
New Member
2 0 0

What template are you using?

0 Likes
Tourist
12 0 1
We are using Parallax theme.
0 Likes
Tourist
6 0 1

On the Debut theme it has been fixed but I suspect its not theme specific.

0 Likes