Add to cart event not working
-
The add to cart event for UA/GA4 won’t fire on WordPress theme twenty twenty one. I have tested other themes and it is the same thing.
The add to cart event fires on product lists but not on the product detail pages.
The code from PDP page looks like this:
<form class="cart" action="/" method="post" enctype="multipart/form-data"> <div class="quantity"> <label class="screen-reader-text" for="quantity_615b69b500c71">Design Classic quantity</label> <input type="number" id="quantity_615b69b500c71" class="input-text qty text" step="1" min="1" max="" name="quantity" value="1" title="Qty" size="4" placeholder="" inputmode="numeric"> </div> <button type="submit" name="add-to-cart" value="135" class="single_add_to_cart_button button alt">Add to cart</button> </form>
And it should work with the following code that is in the plugin:
// track add to cart events for products on product detail pages jQuery( document ).on( 'click', '.single_add_to_cart_button:not(.disabled)', function() { var product_form = jQuery( this ).closest( 'form.cart' );
I added
alert('added_to_cart');
just to follow up if the button is working.Is there any other way to make this work? Thank you in advance.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Add to cart event not working’ is closed to new replies.