Skip to content

Commit

Permalink
Merge pull request #358 from duracelltomi/add/item_group_id
Browse files Browse the repository at this point in the history
Add/item group
  • Loading branch information
duracelltomi authored Jul 3, 2024
2 parents ecc7092 + baba5bf commit 7d97b15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integration/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
3 changes: 3 additions & 0 deletions js/gtm4wp-woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 7d97b15

Please sign in to comment.