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

Conversation

puntope
Copy link
Contributor

@puntope puntope commented Jul 28, 2023

Changes proposed in this Pull Request:

Closes #2020

This PR adds a fix for triggering the Add To Cart event when it takes place on Products (Beta) Block.

Detailed test instructions:

  1. Install Google Analytics Debugger extension
  2. Install GLA, complete the setup and connect Google Ads as well
  3. Install a theme with Blocks support, for example Storefront
  4. Create a new page (Page 1), and insert the block "All Products"
  5. Crate a new page (Page 2), and insert the block "Products (beta)"
  6. Go to Shop page in the store, click on Add to cart, see the 'add_to_cart' event is logged once by Google Analytics Debugger
  7. Go to "Page 1", click on Add to cart, see the 'add_to_cart' event is logged once by Google Analytics Debugger
  8. Go to "Page 2", click on Add to cart, see the 'add_to_cart' event is logged once by Google Analytics Debugger

Additional details:

Changelog entry

Fix - Fix support for "add_to_cart" event in Products (Beta) block

@puntope puntope self-assigned this Jul 28, 2023
@github-actions github-actions bot added changelog: fix Took care of something that wasn't working. type: bug The issue is a confirmed bug. labels Jul 28, 2023
@puntope puntope requested a review from a team July 28, 2023 14:55
@puntope puntope marked this pull request as ready for review July 28, 2023 15:22
@puntope puntope changed the title Add Add To Cart Tracking support for Products (Beta) Block Add To Cart Tracking support for Products (Beta) Block Jul 28, 2023
Copy link
Contributor

@jorgemd24 jorgemd24 left a comment

Choose a reason for hiding this comment

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

Thanks, @puntope, for fixing this, it works as expected 👍 . It took me some time to figure out why the hook experimental__woocommerce_blocks--cart-add-item doesn't work with "Products Beta."

I noticed that in Products Beta, the "Add to the cart" button is rendered in the backend:

https://github.com/woocommerce/woocommerce-blocks/blob/e4e57d465419aa7901d171754bf6ef2fe3ce3dae/src/BlockTypes/ProductButton.php#L40-L117

On the other hand, "All products" are rendered using React, and the hook experimental__woocommerce_blocks--cart-add-item is attached in the click event:

https://github.com/woocommerce/woocommerce-blocks/blob/e4e57d465419aa7901d171754bf6ef2fe3ce3dae/assets/js/atomic/blocks/product-elements/button/block.tsx#L91-L95

So, do you think that a similar issue could be affecting the google-analytics extension?

https://github.com/woocommerce/woocommerce-google-analytics-integration/blob/730da93ae7820a7a8db4c719d2b7b5f2a2c46b7f/assets/js/src/actions.js#L114-L118

Comment on lines +81 to +83
* 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.
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

@puntope
Copy link
Contributor Author

puntope commented Aug 1, 2023

So, do you think that a similar issue could be affecting the google-analytics extension?

Yes, Google Analytics has the same issue. And all the plugins relying on that hook using Products (Beta) but this PR only achieves the fix for GLA

@puntope puntope merged commit f93294b into develop Aug 1, 2023
6 checks passed
@puntope puntope deleted the fix/products-beta-add-to-cart branch August 1, 2023 12:28
@martynmjones martynmjones mentioned this pull request Aug 1, 2023
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Took care of something that wasn't working. type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confirm compatibility with Blocks
2 participants