Facebook-for-woocommerce: Add to Cart event is missing : Depending on redirect to cart page store setting

Created on 17 Jan 2018  路  24Comments  路  Source: facebookincubator/facebook-for-woocommerce

All necessary events seem to be working, but the add to cart event is not present.

We haven't detected the event AddToCart coming from your Pixel

Do this ASAP bug

Most helpful comment

I wrote up a quick function to get the 'AddToCart' event to fire on the 'woocommerce_after_cart' action without editing the plugin. https://gist.github.com/TimBHowe/40f7fe01db0e6546d9403a19fbaf34f1

The point @willgorham brought up is correct. The 'AddToCart' event fires every time that a non-empty cart page is visited with the total of all the items in the cart. This is probably why it was patched in 1.6.6

We are going to keep looking into it on our end.

All 24 comments

Hello @revendo, do you use another extension for the add to cart functionality?

The only extension we're using that could cause an issue is Enhanced Ecommerce Google Analytics Plugin for WooCommerce. Could that be a problem? If yes, could you recommend similar plugin for Google Analytics which is compatible to facebook-for-woocommerce?

@revendo Can you share your website url with us so we can debug the issue?

@revendo I did verify that AddToCart is not firing on your website. We will try to resolve it asap. Thanks for reporting

@revendo would you mind try deactivate _Enhanced Ecommerce Google Analytics Plugin for WooCommerce_ and then try adding a product to see whether AddToCart can be fired? This can help us understand on your side if it's indeed caused by incompatibility with this plug-in

I disabled the plugin Enhanced E-commerce for Woocommerce store but it doesn't seem to change the behavior.

seems similar to #192

Hi @revendo ,

Did you check "Enable AJAX add to cart buttons on archives" : Woocommerce -> settings ->display -> Add to cart behaviour?

Yes, I did enable this function. Should I disable it?

Hey,
I have run into the same issue myself.

I think the problem is that the inject_add_to_cart_event which handles the 'AddToCart' event is added to the woocommerce_add_to_cart action. This action fires when an item is added to the cart, but if you have your store set to Redirect to cart page upon adding a product to your cart this causes the action to be fired through ajax and redirect user to the cart before injecting the pixel code for the event.

This also could be causing issue with add-to-cart URLs. Example: https://www.yourwebsite.com/?add-to-cart=123.

You might want to revert it back to firing on 'woocommerce_after_cart' action to allow this option to work.

Hope this helps.

Hi @TimBHowe and @revendo ,

We use 'woocommerce_after_cart' before, however, there is another double firing problem. Thanks to a pull request which enable to fire this as soon as you hit the button. However, you need to disable 'Redirect to cart page upon adding a product to your cart'.

Hi @mengyingdu

Redirecting to the cart is a core feature of WooCommerce, and is important for many stores. I think FB for WC should be able to handle this action. Maybe raising an issue with WC core to make it easier to detect Add To Cart actions / redirects to the cart page could be helpful?

Hi @willgorham,

Thanks for your input and our team will consider that and talk to our product manager.

Hi @revendo and @TimBHowe ,

There is some workaround for you if you prefer using 'redirecting to cart' behavior:
In plugin editor, search for 'facebook-for-woocommerce', then change these line like this.

As I mentioned in #192, we can change it to be compatible in dual cases. However, this may add more db read which is performance unfriendly. We will consider @willgorham suggestion or figure out some other approach to fix it.

Let me if it works.

Thanks.

@mengyingdu Thanks for taking this into consideration.

Just to clarify your workaround: won't this fire the AddToCart event on every cart page view? (Even if a product hasn't just been added.)

I wrote up a quick function to get the 'AddToCart' event to fire on the 'woocommerce_after_cart' action without editing the plugin. https://gist.github.com/TimBHowe/40f7fe01db0e6546d9403a19fbaf34f1

The point @willgorham brought up is correct. The 'AddToCart' event fires every time that a non-empty cart page is visited with the total of all the items in the cart. This is probably why it was patched in 1.6.6

We are going to keep looking into it on our end.

@TimBHowe Nice fix!! Would you be willing to send us a pull request to incorporate it fully? I think there's something we can do here that accommodates both approaches, essentially detecting the store's add to cart setting, and firing add to cart in the right place based on that setting.

Hi there,

On my store now when I click Add to Cart, the pixel works for Add to Cart function. However, it only works when Add to Cart is clicked, and then an upsell pop up appears. If an upsell pop up does NOT appear, and the visitor is then re-directed to the cart, the pixel does NOT fire.

I have attached screen shots to show.
screen shot 2018-02-19 at 12 32 37 pm
screen shot 2018-02-19 at 12 33 07 pm

Notice the Add to Cart function missing from the cart page.

Also, please notice the View Content error. I checked the warning, and have attached a screen shot. It says there is an error in the url coding, but I am not sure how this is possible because the url is exactly the same and I am not sure how to fix this.
screen shot 2018-02-19 at 12 41 21 pm

Thanks for the additional report. Agree that's not good behavior. We'll prioritize a fix that works for both cases (upsell and no upsell). The ViewContent issue seems like a separate problem, I'd open a separate issue for that if you can.

Ok so we finally fixed this issue. Here's what we did:

  • If your store setting is redirect to cart, we fire the event on the Cart being viewed.
  • If your store setting is not redirect to cart, we fire the event via AJAX when the button is clicked.

The fix is in v1.8.4 and later versions available here. Thanks for your patience!

@dmitridr Thank you!

Hi, can you upload this update to woocommerce also so we can update via the wordpress dashboard aswell?

Thanks!

Was this page helpful?
0 / 5 - 0 ratings