Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add To Cart Tracking support for Products (Beta) Block #2028

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions js/src/gtag-events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ document.defaultView.addEventListener( 'DOMContentLoaded', function () {
button.addEventListener( 'click', addToCartClick );
} );

/**
* Fix for Products (Beta) block
*
* Products (Beta) block doesn't trigger addAction events. Also it's not being queried by the previous query selector
* because we added :not( .wc-block-components-product-button__button ) to prevent tracking duplicates with
* other blocks that yes trigger addAction events.
Comment on lines +81 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can mention that Products (Beta) is rendered in the backend, which means the addAction(experimental__woocommerce_blocks--cart-add-item ...) won't work.

I think the "yes" could be omitted here: other blocks that ->yes<- trigger addAction events

*
* So the fix is to query again specifically the add to cart button in Products (Beta) block
*/
document
.querySelectorAll(
'[data-block-name="woocommerce/product-button"] > .add_to_cart_button:not( .product_type_variable ):not( .product_type_grouped )'
)
.forEach( ( button ) => {
button.addEventListener( 'click', addToCartClick );
} );

document
.querySelectorAll( '.single_add_to_cart_button' )
.forEach( ( button ) => {
Expand Down
Loading