From e5c7106e36ecc9d5b15e238f3a0cdea8dbd91f4f Mon Sep 17 00:00:00 2001 From: Emre Erkan Date: Fri, 10 Feb 2023 13:06:18 +0300 Subject: [PATCH 1/3] feat: new filter for capability override --- admin/admin.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/admin/admin.php b/admin/admin.php index 3a3ae31c..042c0e1c 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -1006,16 +1006,18 @@ function gtm4wp_show_admin_page() { /** * Hook function for admin_menu. Adds the plugin options page into the Settings menu of the WordPress admin. + * The capability can be changed with the gtm4wp_admin_page_capability filter. * * @see https://developer.wordpress.org/reference/hooks/admin_menu/ * * @return void */ function gtm4wp_add_admin_page() { + $capability = apply_filters( 'gtm4wp_admin_page_capability', 'manage_options' ); add_options_page( esc_html__( 'Google Tag Manager for WordPress settings', 'duracelltomi-google-tag-manager' ), esc_html__( 'Google Tag Manager', 'duracelltomi-google-tag-manager' ), - 'manage_options', + $capability, GTM4WP_ADMINSLUG, 'gtm4wp_show_admin_page' ); From 5289fcd7df8a64da05680af39db0fd8d80b2c3b9 Mon Sep 17 00:00:00 2001 From: Thomas Geiger Date: Mon, 28 Aug 2023 16:34:50 +0200 Subject: [PATCH 2/3] Added changelog --- admin/admin.php | 1 + readme.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/admin/admin.php b/admin/admin.php index 042c0e1c..6342e934 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -1014,6 +1014,7 @@ function gtm4wp_show_admin_page() { */ function gtm4wp_add_admin_page() { $capability = apply_filters( 'gtm4wp_admin_page_capability', 'manage_options' ); + add_options_page( esc_html__( 'Google Tag Manager for WordPress settings', 'duracelltomi-google-tag-manager' ), esc_html__( 'Google Tag Manager', 'duracelltomi-google-tag-manager' ), diff --git a/readme.txt b/readme.txt index 86d29e76..d3fbe7ae 100644 --- a/readme.txt +++ b/readme.txt @@ -250,6 +250,8 @@ Instead of the above events, you can use the new GA4 ecommerce events (add_to_ca In the Universal Analytics GTM tag now you have an option to use the GA4 ecommerce data in the data layer. If you are on GA360 and still collecting ecommerce data, you need to update your GTM setup to use that option firing on the GA4 ecommerce events. +* Updated: use the gtm4wp_admin_page_capability filter to modify the capability needed to use the admin page (thanks [emreerkan](https://github.com/emreerkan)) + = 1.18.1 = * Fixed: PHP notice about Undefined variable: blocking_cookie From e056441ec030bc6b3e8d42abccc92cd8ee6c31cb Mon Sep 17 00:00:00 2001 From: Thomas Geiger Date: Wed, 6 Sep 2023 15:20:22 +0200 Subject: [PATCH 3/3] Force .00 postfix for integers in the add_to_cart --- integration/woocommerce.php | 2 +- js/gtm4wp-woocommerce-enhanced.js | 31 ++++++++++++++++++++++++++----- readme.txt | 1 + 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/integration/woocommerce.php b/integration/woocommerce.php index 95b8f6de..a526210c 100755 --- a/integration/woocommerce.php +++ b/integration/woocommerce.php @@ -214,7 +214,7 @@ function gtm4wp_process_product( $product, $additional_product_attributes, $attr 'name' => $product->get_title(), 'sku' => $product_sku ? $product_sku : $product_id, 'category' => $product_cat, - 'price' => round( (float) wc_get_price_to_display( $product ), 2 ), + 'price' => round( (float) wc_get_price_to_display( $product ), 2 ), // Unfortunately this does not force a .00 postfix for integers. 'stocklevel' => $product->get_stock_quantity(), ); diff --git a/js/gtm4wp-woocommerce-enhanced.js b/js/gtm4wp-woocommerce-enhanced.js index 580a21ad..8b5a5f7b 100644 --- a/js/gtm4wp-woocommerce-enhanced.js +++ b/js/gtm4wp-woocommerce-enhanced.js @@ -519,11 +519,12 @@ function gtm4wp_process_woocommerce_pages() { }); // fire ga4 version + const variant_value = gtm4wp_last_selected_product_variation.price * gtm4wp_last_selected_product_variation.quantity; window[ gtm4wp_datalayer_name ].push({ 'event': 'add_to_cart', 'ecommerce': { 'currency': gtm4wp_currency, - 'value': gtm4wp_last_selected_product_variation.price * gtm4wp_last_selected_product_variation.quantity, + 'value': variant_value.toFixed(2), 'items': [ gtm4wp_map_eec_to_ga4( gtm4wp_last_selected_product_variation ) ] } }); @@ -546,10 +547,15 @@ function gtm4wp_process_woocommerce_pages() { return true; } + let group_product_price = parseFloat(dom_productdata.getAttribute( 'data-gtm4wp_product_price' )); + if ( isNaN(group_product_price) ) { + group_product_price = 0; + } + const product_data = { 'id': gtm4wp_use_sku_instead ? dom_productdata.getAttribute( 'data-gtm4wp_product_sku' ) : dom_productdata.getAttribute( 'data-gtm4wp_product_id' ), 'name': dom_productdata.getAttribute( 'data-gtm4wp_product_name' ), - 'price': dom_productdata.getAttribute( 'data-gtm4wp_product_price' ), + 'price': group_product_price.toFixed(2), 'category': dom_productdata.getAttribute( 'data-gtm4wp_product_cat' ), 'quantity': product_qty, 'stocklevel': dom_productdata.getAttribute( 'data-gtm4wp_product_stocklevel' ), @@ -581,16 +587,25 @@ function gtm4wp_process_woocommerce_pages() { 'event': 'add_to_cart', 'ecommerce': { 'currency': gtm4wp_currency, - 'value': sum_value, + 'value': sum_value.toFixed(2), 'items': ga4_products } }); } else { const product_id_el = gtm4wp_use_sku_instead ? product_form.querySelector( '[name=gtm4wp_sku]' ) : product_form.querySelector( '[name=gtm4wp_id]' ); + + let product_price = 0; + if ( product_form.querySelector( '[name=gtm4wp_price]' ) ) { + product_price = parseFloat(product_form.querySelector( '[name=gtm4wp_price]' ).value); + if ( isNaN(product_price) ) { + product_price = 0; + } + } + const product_data = { 'id': product_id_el && product_id_el.value, 'name': product_form.querySelector( '[name=gtm4wp_name]' ) && product_form.querySelector( '[name=gtm4wp_name]' ).value, - 'price': product_form.querySelector( '[name=gtm4wp_price]' ) && product_form.querySelector( '[name=gtm4wp_price]' ).value, + 'price': product_price.toFixed(2), 'category': product_form.querySelector( '[name=gtm4wp_category]' ) && product_form.querySelector( '[name=gtm4wp_category]' ).value, 'quantity': product_form.querySelector( '[name=quantity]' ) && product_form.querySelector( '[name=quantity]' ).value, 'stocklevel': product_form.querySelector( '[name=gtm4wp_stocklevel]' ) && product_form.querySelector( '[name=gtm4wp_stocklevel]' ).value, @@ -852,7 +867,13 @@ function gtm4wp_process_woocommerce_pages() { if ( gtm4wp_use_sku_instead && product_variation.sku && ('' !== product_variation.sku) ) { current_product_detail_data.id = product_variation.sku; } - current_product_detail_data.price = product_variation.display_price; + const variant_price = parsefloat( product_variation.display_price ); + if ( isNaN( variant_price ) ) { + current_product_detail_data.price = 0; + } else { + current_product_detail_data.price = variant_price.toFixed(2); + } + let product_variation_attribute_values = []; for( let attrib_key in product_variation.attributes ) { diff --git a/readme.txt b/readme.txt index d3fbe7ae..7fe45784 100644 --- a/readme.txt +++ b/readme.txt @@ -251,6 +251,7 @@ In the Universal Analytics GTM tag now you have an option to use the GA4 ecommer If you are on GA360 and still collecting ecommerce data, you need to update your GTM setup to use that option firing on the GA4 ecommerce events. * Updated: use the gtm4wp_admin_page_capability filter to modify the capability needed to use the admin page (thanks [emreerkan](https://github.com/emreerkan)) +* Fixed: price did not include the .00 postfix for integers in the add_to_cart event = 1.18.1 =