Skip to content

Status: Open. #427 = Add and Remove events for wooCommerce Blocks#428

Open
zamartz wants to merge 2 commits intoduracelltomi:masterfrom
zamartz:master
Open

Status: Open. #427 = Add and Remove events for wooCommerce Blocks#428
zamartz wants to merge 2 commits intoduracelltomi:masterfrom
zamartz:master

Conversation

@zamartz
Copy link
Copy Markdown

@zamartz zamartz commented Nov 16, 2025

  • Adds a dedicated WooCommerce Blocks cart-tracking option that listens to Block DOM events, fetches the current cart via the Store API, and emits GA4-friendly add/remove events for simple, variable, grouped, and mini-cart interactions.

  • Supplies a custom REST/AJAX product endpoint so the frontend can enrich every cart item (categories, brand, stock, item_type, SKU-based item_group_id, etc.) exactly like the legacy integration.

  • Replaces the legacy inline add-to-cart tracking whenever the Blocks option is enabled, preventing page reloads and double-event issues while maintaining the same GA4 dataLayer payload structure.

  • New option scope: note that the Blocks cart tracking only runs when both “Track e-commerce” and the new toggle are enabled, and that it intentionally disables the legacy add-to-cart markup. Reviewers will want to know this is guarded and opt-in.

  • Endpoints/security: mention the new REST route /gtm4wp/v1/product/ (read-only, no auth) plus its AJAX fallback gtm4wp_product_data, and that both rely on the existing GA4 product-formatter. Helps security reviewers assess exposure.

  • Caching/perf considerations: highlight the 300 ms Store API fetch cache, client-side product detail caching, and the sessionStorage warm-start. Also note the fallback behavior when storage or REST isn’t available.

  • Edge cases covered: call out support for variations, grouped parents, mini-cart increments, DOM/store dedupe, and the defensive parsing for custom cart structures.

  • Testing done: list the scenarios you validated (PDP add, variable products, grouped adds, mini-cart +/- add/remove, cart page quantity changes, Store API failure, sessionStorage disabled).

-Potential follow-ups: optional mention that we rely on Woo Blocks scripts/Store API; if either is missing, we no-op but log a warning—so theme compatibility hinges on those assets being present.

…e Blocks

- Adds a dedicated WooCommerce Blocks cart-tracking option that listens to Block DOM events, fetches the current cart via the Store API, and emits GA4-friendly add/remove events for simple, variable, grouped, and mini-cart interactions.

- Supplies a custom REST/AJAX product endpoint so the frontend can enrich every cart item (categories, brand, stock, item_type, SKU-based item_group_id, etc.) exactly like the legacy integration.

- Replaces the legacy inline add-to-cart tracking whenever the Blocks option is enabled, preventing page reloads and double-event issues while maintaining the same GA4 dataLayer payload structure.

- New option scope: note that the Blocks cart tracking only runs when both “Track e-commerce” and the new toggle are enabled, and that it intentionally disables the legacy add-to-cart markup. Reviewers will want to know this is guarded and opt-in.

- Endpoints/security: mention the new REST route /gtm4wp/v1/product/<id> (read-only, no auth) plus its AJAX fallback gtm4wp_product_data, and that both rely on the existing GA4 product-formatter. Helps security reviewers assess exposure.

- Caching/perf considerations: highlight the 300 ms Store API fetch cache, client-side product detail caching, and the sessionStorage warm-start. Also note the fallback behavior when storage or REST isn’t available.

- Edge cases covered: call out support for variations, grouped parents, mini-cart increments, DOM/store dedupe, and the defensive parsing for custom cart structures.

- Testing done: list the scenarios you validated (PDP add, variable products, grouped adds, mini-cart +/- add/remove, cart page quantity changes, Store API failure, sessionStorage disabled).

-Potential follow-ups: optional mention that we rely on Woo Blocks scripts/Store API; if either is missing, we no-op but log a warning—so theme compatibility hinges on those assets being present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant