Skip to content

Commit

Permalink
Fixed: decrease checkout step numbers 3 and 4 if shipping destination…
Browse files Browse the repository at this point in the history
… is set to 'Force shipping to the customer billing address' in WooCommerce. This way there will be no gap in Checkout behaviour report in Google Analytics.
  • Loading branch information
duracelltomi committed Mar 18, 2020
1 parent a3cab55 commit 784747b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion integration/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ function gtm4wp_woocommerce_addglobalvars( $return = '' ) {
var gtm4wp_eec = ' . gtm4wp_escjs_boolean( (bool) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) . ';
var gtm4wp_classicec = ' . gtm4wp_escjs_boolean( (bool) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) ) . ";
var gtm4wp_currency = '" . esc_js( get_woocommerce_currency() ) . "';
var gtm4wp_product_per_impression = " . (int) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION ] ) . ';';
var gtm4wp_product_per_impression = " . (int) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION ] ) . ';
var gtm4wp_needs_shipping_address = ' . gtm4wp_escjs_boolean( (bool) WC()->cart->needs_shipping_address() ) . ';';

return $return;
}
Expand Down
9 changes: 5 additions & 4 deletions js/gtm4wp-woocommerce-enhanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ jQuery(function() {
if ( is_checkout ) {
window.gtm4wp_checkout_step_offset = window.gtm4wp_checkout_step_offset || 0;
window.gtm4wp_checkout_products = window.gtm4wp_checkout_products || [];
var gtm4wp_shipping_payment_method_step_offset = window.gtm4wp_needs_shipping_address ? 0 : -1;
var gtm4wp_checkout_step_fired = []; // step 1 will be the billing section which is reported during pageload, no need to handle here

jQuery( document ).on( 'blur', 'input[name^=shipping_]:not(input[name^=shipping_method])', function() {
Expand Down Expand Up @@ -516,7 +517,7 @@ jQuery(function() {
'ecommerce': {
'checkout': {
'actionField': {
'step': 3 + window.gtm4wp_checkout_step_offset
'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset
},
'products': window.gtm4wp_checkout_products
}
Expand All @@ -542,7 +543,7 @@ jQuery(function() {
'ecommerce': {
'checkout': {
'actionField': {
'step': 4 + window.gtm4wp_checkout_step_offset
'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset
},
'products': window.gtm4wp_checkout_products
}
Expand Down Expand Up @@ -580,7 +581,7 @@ jQuery(function() {
'ecommerce': {
'checkout_option': {
'actionField': {
'step': 3 + window.gtm4wp_checkout_step_offset,
'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset,
'option': 'Shipping: ' + _shipping_el.val()
}
}
Expand All @@ -595,7 +596,7 @@ jQuery(function() {
'ecommerce': {
'checkout_option': {
'actionField': {
'step': 4 + window.gtm4wp_checkout_step_offset,
'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset,
'option': 'Payment: ' + _payment_el.val()
}
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So
= 1.11.4 =

* Fixed: fire gtm4wp.checkoutStepEEC and gtm4wp.checkoutOptionEEC events if there is only one shipping method available and it is hidden from the user
* Fixed: decrease checkout step numbers 3 and 4 if shipping destination is set to 'Force shipping to the customer billing address' in WooCommerce. This way there will be no gap in Checkout behaviour report in Google Analytics.
* Updated: tested version number for WooCommerce

= 1.11.3 =
Expand Down

0 comments on commit 784747b

Please sign in to comment.