• 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)
  • Thread Starter engineerized

    (@engineerized)

    All the input fields below <button> is also added

    <input type="hidden" name="gtm4wp_id" value="130">
    <input type="hidden" name="gtm4wp_name" value="DESIGN">
    <input type="hidden" name="gtm4wp_sku" value="ME36W">
    <input type="hidden" name="gtm4wp_category" value="DESIGNFOR">
    <input type="hidden" name="gtm4wp_price" value="167">
    <input type="hidden" name="gtm4wp_stocklevel" value="6">

    That means that the woocommerce_after_add_to_cart_button is working but still the add to cart event won’t fire?

    • This reply was modified 3 years, 5 months ago by engineerized.
Viewing 1 replies (of 1 total)
  • The topic ‘Add to cart event not working’ is closed to new replies.