From 1f14491f9a221f457bd85c1efc8f1a3448f7a24c Mon Sep 17 00:00:00 2001 From: Thomas Geiger Date: Fri, 5 Apr 2024 15:03:19 +0200 Subject: [PATCH 1/2] Add parent product ID of a variable product into the data layer --- integration/woocommerce.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration/woocommerce.php b/integration/woocommerce.php index 8b301adc..87194119 100755 --- a/integration/woocommerce.php +++ b/integration/woocommerce.php @@ -90,6 +90,10 @@ function gtm4wp_woocommerce_process_product( $product, $additional_product_attri 'google_business_vertical' => $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCBUSINESSVERTICAL ], ); + if ( 'variation' === $product_type ) { + $_temp_productdata['item_group_id'] = $parent_product_id; + } + if ( 1 === count( $product_cat_parts ) ) { $_temp_productdata['item_category'] = $product_cat_parts[0]; } elseif ( count( $product_cat_parts ) > 1 ) { From baba5bf8c3b95d47edc69391738f00e87fcbcf14 Mon Sep 17 00:00:00 2001 From: Thomas Geiger Date: Fri, 19 Apr 2024 14:34:43 +0200 Subject: [PATCH 2/2] Add item_group_id to view_item and add_to_cart without internal_id --- js/gtm4wp-woocommerce.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/gtm4wp-woocommerce.js b/js/gtm4wp-woocommerce.js index a3f24369..306bf752 100644 --- a/js/gtm4wp-woocommerce.js +++ b/js/gtm4wp-woocommerce.js @@ -513,6 +513,7 @@ function gtm4wp_woocommerce_process_pages() { current_product_detail_data.price = gtm4wp_make_sure_is_float( current_product_detail_data.price ); + current_product_detail_data.item_group_id = current_product_detail_data.id; current_product_detail_data.id = product_variation.variation_id; current_product_detail_data.item_id = product_variation.variation_id; current_product_detail_data.sku = product_variation.sku; @@ -529,6 +530,8 @@ function gtm4wp_woocommerce_process_pages() { current_product_detail_data.variant = product_variation_attribute_values.join(','); gtm4wp_last_selected_product_variation = current_product_detail_data; + delete current_product_detail_data.internal_id; + // fire ga4 version gtm4wp_push_ecommerce( 'view_item', [ current_product_detail_data ], { 'currency': gtm4wp_currency,