From 8e71bec45c1b0be71c092e2d598832531cdba4dd Mon Sep 17 00:00:00 2001 From: Thomas Geiger Date: Tue, 2 Apr 2024 16:32:19 +0200 Subject: [PATCH] Fix: add_to_cart tracked with variable and grouped products in lists --- integration/woocommerce.php | 1 + js/gtm4wp-woocommerce.js | 8 ++++++-- readme.txt | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/integration/woocommerce.php b/integration/woocommerce.php index fa038acb..a85aaa86 100755 --- a/integration/woocommerce.php +++ b/integration/woocommerce.php @@ -1256,6 +1256,7 @@ function gtm4wp_woocommerce_get_product_list_item_extra_tag( $product, $listtype 'productlink' => $permalink, 'item_list_name' => $list_name, 'index' => (int) $itemix + ( $posts_per_page * ( $paged - 1 ) ), + 'product_type' => $product->get_type(), ), 'productlist' ); diff --git a/js/gtm4wp-woocommerce.js b/js/gtm4wp-woocommerce.js index 7d25ed23..525c2b33 100644 --- a/js/gtm4wp-woocommerce.js +++ b/js/gtm4wp-woocommerce.js @@ -224,11 +224,15 @@ function gtm4wp_woocommerce_process_pages() { if ( !productdata ) { return true; } - + + if ( "variable" === productdata.product_type || "grouped" === productdata.product_type ) { + return true; + } + if ( productdata.productlink ) { delete productdata.productlink; } - + delete productdata.product_type; productdata.quantity = 1; gtm4wp_push_ecommerce( 'add_to_cart', [ productdata ], { diff --git a/readme.txt b/readme.txt index 02d5b74a..13a89524 100644 --- a/readme.txt +++ b/readme.txt @@ -227,6 +227,7 @@ to report micro conversions and/or to serve ads only to visitors who spend more = 1.20.2 = * Fix: Wrong ID parameter used tracking product variations (id instead of item_id). Thanks [micmaf](https://github.com/micmaf) +* Fix: do not track add_to_cart in product lists when 'Select options' or 'View products' buttons are clicked = 1.20.1 =