DuracellTomi's Google Tag Manager for WordPress - Version 1.11

Version Description

WARNING! Please read the changelog very carefully as there are many important changes and removed features which could need your attention before updating!

  • Added Oxygen Builder and Beaver Builder Theme support - you can now use the codeless placement option without issues
  • Added ability to fix the Google Tag Manager ID and GTM Environment parameters in wp-config.php. To use it, create PHP constants with the names ** GTM4WP_HARDCODED_GTM_ID ** GTM4WP_HARDCODED_GTM_ENV_AUTH ** GTM4WP_HARDCODED_GTM_ENV_PREVIEW
  • Added support for WooCommerce Grouped Products
  • Added new WooCommerce option to add all order data into the data layer on the order reveived page ** This includes personal data of the customer -> you need to ensure this is used in a privacy friendly and compliant way! ** This order data will be always present on the order received page, even if the page is reloaded or later revisited!
  • Removed several unofficial data layer variables on the WooCommerce order received page as they can be read using the new order data option ** transactionDate ** transactionType ** transactionPaymentType ** transactionShippingMethod ** transactionPromoCode
  • Improved: price reporting with the WooCommerce enhanced ecommerce integration now follows the option set with the 'Display prices in the shop' option of WooCommerce
  • Improved: from WooCommerce 3.7 WC_Abstract_Order::get_used_coupons() was replaced with WC_Abstract_Order::get_coupon_codes() which is now used if WC 3.7+ is detected
  • Improved: use localStorage for WooCommerce duplicate transaction tracking prevention if available. Should be work with Safari at least for now.
  • Fixed: WooCommerce duplicate transaction tracking prevention's cookie was set to expire on session end, now adds 1 year.
  • Deprecated data layer variable productIsVariable. Use the new productType data layer variable which will equal to simple, variable, grouped or external depending on the type of the product shown
  • Fixed: Wrong lookup for product brand name if Use SKU instead of product ID option was turned on
  • Fixed: Wrong lookup for product brand name for variable products
  • Fixed: check if $woo->customer is initialized
  • Fixed: no checkout step reported on WooCommerce checkout page if the user has accepted the default selection of the payment and shipping methods

! Planned deprecation of support for WooCommerce 2.x-3.1.x with next plugin version ! ! Planned deprecation of support for WordPress 4.x with next plugin version !

Download this release

Release Info

Developer duracelltomi
Plugin Icon 128x128 DuracellTomi's Google Tag Manager for WordPress
Version 1.11
Comparing to
See all releases

Code changes from version 1.10.1 to 1.11

admin/admin.php CHANGED
@@ -515,6 +515,12 @@ $GLOBALS['gtm4wp_integratefieldtexts'] = array(
515
  'phase' => GTM4WP_PHASE_BETA,
516
  'plugintocheck' => 'woocommerce/woocommerce.php',
517
  ),
 
 
 
 
 
 
518
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => array(
519
  'label' => __( 'Exclude tax from revenue', 'duracelltomi-google-tag-manager' ),
520
  'description' => __( 'Enable this to exclude tax from the revenue variable while generating the purchase data', 'duracelltomi-google-tag-manager' ),
@@ -697,7 +703,18 @@ function gtm4wp_admin_output_field( $args ) {
697
 
698
  switch ( $args['label_for'] ) {
699
  case GTM4WP_ADMIN_GROUP_GTMID: {
700
- echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" value="' . $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] . '" /><br />' . $args['description'];
 
 
 
 
 
 
 
 
 
 
 
701
  echo '<br /><span class="gtmid_validation_error">' . __( 'This does not seems to be a valid Google Tag Manager ID! Valid format: GTM-XXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile container IDs.', 'duracelltomi-google-tag-manager' ) . '</span>';
702
 
703
  break;
@@ -720,14 +737,36 @@ function gtm4wp_admin_output_field( $args ) {
720
  }
721
 
722
  case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']': {
723
- echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']" value="' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] . '" /><br />' . $args['description'];
 
 
 
 
 
 
 
 
 
 
 
724
  echo '<br /><span class="gtmauth_validation_error">' . __( 'This does not seems to be a valid gtm_auth parameter! It should only contain letters, number and the &quot;-&quot; character. Please check and try again', 'duracelltomi-google-tag-manager' ) . '</span>';
725
 
726
  break;
727
  }
728
 
729
  case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']': {
730
- echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']" value="' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] . '" /><br />' . $args['description'];
 
 
 
 
 
 
 
 
 
 
 
731
  echo '<br /><span class="gtmpreview_validation_error">' . __( 'This does not seems to be a valid gtm_preview parameter! It should have the format &quot;env-NN&quot; where NN is an integer number. Please check and try again', 'duracelltomi-google-tag-manager' ) . '</span>';
732
 
733
  break;
@@ -1287,11 +1326,20 @@ function gtm4wp_admin_head() {
1287
  .ampid_validation_error,
1288
  .datalayername_validation_error,
1289
  .gtmauth_validation_error,
1290
- .gtmpreview_validation_error {
1291
- display: none;
1292
  color: #c00;
1293
  font-weight: bold;
1294
  }
 
 
 
 
 
 
 
 
 
1295
  </style>
1296
  <script type="text/javascript">
1297
  jQuery(function() {
515
  'phase' => GTM4WP_PHASE_BETA,
516
  'plugintocheck' => 'woocommerce/woocommerce.php',
517
  ),
518
+ GTM4WP_OPTION_INTEGRATE_WCORDERDATA => array(
519
+ 'label' => __( 'Order data in data layer', 'duracelltomi-google-tag-manager' ),
520
+ 'description' => __( 'Enable this to add all order attribute into the data layer on the order received page regardless and independently from classic and enhanced ecommerce tracking (WooCommerce 3.x required)', 'duracelltomi-google-tag-manager' ),
521
+ 'phase' => GTM4WP_PHASE_BETA,
522
+ 'plugintocheck' => 'woocommerce/woocommerce.php',
523
+ ),
524
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => array(
525
  'label' => __( 'Exclude tax from revenue', 'duracelltomi-google-tag-manager' ),
526
  'description' => __( 'Enable this to exclude tax from the revenue variable while generating the purchase data', 'duracelltomi-google-tag-manager' ),
703
 
704
  switch ( $args['label_for'] ) {
705
  case GTM4WP_ADMIN_GROUP_GTMID: {
706
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ID' ) ) {
707
+ $_gtm_id_value = GTM4WP_HARDCODED_GTM_ID;
708
+ $_input_readonly = ' readonly="readonly"';
709
+ $_warning_after = '<br /><span class="gtm_wpconfig_set">WARNING! Container ID was set and fixed in wp-config.php. If you wish to change this value, please edit your wp-config.php and change the container ID or remove the GTM4WP_HARDCODED_GTM_ID constant!</span>';
710
+ } else {
711
+ $_gtm_id_value = $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ];
712
+ $_input_readonly = '';
713
+ $_warning_after = '';
714
+ }
715
+
716
+ echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" value="' . $_gtm_id_value . '" ' . $_input_readonly . '/><br />' . $args['description'];
717
+ echo $_warning_after;
718
  echo '<br /><span class="gtmid_validation_error">' . __( 'This does not seems to be a valid Google Tag Manager ID! Valid format: GTM-XXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile container IDs.', 'duracelltomi-google-tag-manager' ) . '</span>';
719
 
720
  break;
737
  }
738
 
739
  case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']': {
740
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) ) {
741
+ $_gtm_auth_value = GTM4WP_HARDCODED_GTM_ENV_AUTH;
742
+ $_input_readonly = ' readonly="readonly"';
743
+ $_warning_after = '<br /><span class="gtm_wpconfig_set">WARNING! Environment auth parameter was set and fixed in wp-config.php. If you wish to change this value, please edit your wp-config.php and change the parameter value or remove the GTM4WP_HARDCODED_GTM_ENV_AUTH constant!</span>';
744
+ } else {
745
+ $_gtm_auth_value = $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ];
746
+ $_input_readonly = '';
747
+ $_warning_after = '';
748
+ }
749
+
750
+ echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']" value="' . $_gtm_auth_value . '" ' . $_input_readonly . '/><br />' . $args['description'];
751
+ echo $_warning_after;
752
  echo '<br /><span class="gtmauth_validation_error">' . __( 'This does not seems to be a valid gtm_auth parameter! It should only contain letters, number and the &quot;-&quot; character. Please check and try again', 'duracelltomi-google-tag-manager' ) . '</span>';
753
 
754
  break;
755
  }
756
 
757
  case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']': {
758
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) ) {
759
+ $_gtm_preview_value = GTM4WP_HARDCODED_GTM_ENV_PREVIEW;
760
+ $_input_readonly = ' readonly="readonly"';
761
+ $_warning_after = '<br /><span class="gtm_wpconfig_set">WARNING! Environment preview parameter was set and fixed in wp-config.php. If you wish to change this value, please edit your wp-config.php and change the parameter value or remove the GTM4WP_HARDCODED_GTM_ENV_PREVIEW constant!</span>';
762
+ } else {
763
+ $_gtm_preview_value = $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ];
764
+ $_input_readonly = '';
765
+ $_warning_after = '';
766
+ }
767
+
768
+ echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']" value="' . $_gtm_preview_value . '" ' . $_input_readonly . '/><br />' . $args['description'];
769
+ echo $_warning_after;
770
  echo '<br /><span class="gtmpreview_validation_error">' . __( 'This does not seems to be a valid gtm_preview parameter! It should have the format &quot;env-NN&quot; where NN is an integer number. Please check and try again', 'duracelltomi-google-tag-manager' ) . '</span>';
771
 
772
  break;
1326
  .ampid_validation_error,
1327
  .datalayername_validation_error,
1328
  .gtmauth_validation_error,
1329
+ .gtmpreview_validation_error,
1330
+ .gtm_wpconfig_set {
1331
  color: #c00;
1332
  font-weight: bold;
1333
  }
1334
+ .gtmid_validation_error,
1335
+ .goid_validation_error,
1336
+ .goid_ga_validation_error,
1337
+ .ampid_validation_error,
1338
+ .datalayername_validation_error,
1339
+ .gtmauth_validation_error,
1340
+ .gtmpreview_validation_error {
1341
+ display: none;
1342
+ }
1343
  </style>
1344
  <script type="text/javascript">
1345
  jQuery(function() {
common/readoptions.php CHANGED
@@ -108,6 +108,7 @@ define( 'GTM4WP_OPTION_INTEGRATE_WCUSESKU', 'integrate-woocommerce-remarketing-u
108
  define( 'GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH', 'integrate-woocommerce-use-full-category-path' );
109
  define( 'GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX', 'integrate-woocommerce-remarketing-productidprefix' );
110
  define( 'GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA', 'integrate-woocommerce-customer-data' );
 
111
  define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX', 'integrate-woocommerce-exclude-tax' );
112
  define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING', 'integrate-woocommerce-exclude-shipping' );
113
  define( 'GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG', 'integrate-woocommerce-do-not-use-order-tracked-flag' );
@@ -125,6 +126,8 @@ define( 'GTM4WP_PLACEMENT_BODYOPEN', 1 );
125
  define( 'GTM4WP_PLACEMENT_BODYOPEN_AUTO', 2 );
126
  define( 'GTM4WP_PLACEMENT_OFF', 3 );
127
 
 
 
128
  $gtm4wp_options = array();
129
 
130
  $gtm4wp_defaultoptions = array(
@@ -235,6 +238,7 @@ $gtm4wp_defaultoptions = array(
235
  GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH => false,
236
  GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => '',
237
  GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA => false,
 
238
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => false,
239
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING => false,
240
  GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG => false,
@@ -265,7 +269,21 @@ function gtm4wp_reload_options() {
265
  unset( $storedoptions[ GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE ] );
266
  }
267
 
268
- return array_merge( $gtm4wp_defaultoptions, $storedoptions );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  }
270
 
271
  function gtp4wp_debug_file( $debug_data ) {
108
  define( 'GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH', 'integrate-woocommerce-use-full-category-path' );
109
  define( 'GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX', 'integrate-woocommerce-remarketing-productidprefix' );
110
  define( 'GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA', 'integrate-woocommerce-customer-data' );
111
+ define( 'GTM4WP_OPTION_INTEGRATE_WCORDERDATA', 'integrate-woocommerce-order-data' );
112
  define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX', 'integrate-woocommerce-exclude-tax' );
113
  define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING', 'integrate-woocommerce-exclude-shipping' );
114
  define( 'GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG', 'integrate-woocommerce-do-not-use-order-tracked-flag' );
126
  define( 'GTM4WP_PLACEMENT_BODYOPEN_AUTO', 2 );
127
  define( 'GTM4WP_PLACEMENT_OFF', 3 );
128
 
129
+ global $gtm4wp_options, $gtm4wp_defaultoptions;
130
+
131
  $gtm4wp_options = array();
132
 
133
  $gtm4wp_defaultoptions = array(
238
  GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH => false,
239
  GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => '',
240
  GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA => false,
241
+ GTM4WP_OPTION_INTEGRATE_WCORDERDATA => false,
242
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => false,
243
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING => false,
244
  GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG => false,
269
  unset( $storedoptions[ GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE ] );
270
  }
271
 
272
+ $return_options = array_merge( $gtm4wp_defaultoptions, $storedoptions );
273
+
274
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ID' ) ) {
275
+ $return_options[ GTM4WP_OPTION_GTM_CODE ] = GTM4WP_HARDCODED_GTM_ID;
276
+ }
277
+
278
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) ) {
279
+ $return_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] = GTM4WP_HARDCODED_GTM_ENV_AUTH;
280
+ }
281
+
282
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) ) {
283
+ $return_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] = GTM4WP_HARDCODED_GTM_ENV_PREVIEW;
284
+ }
285
+
286
+ return $return_options;
287
  }
288
 
289
  function gtp4wp_debug_file( $debug_data ) {
duracelltomi-google-tag-manager-for-wordpress.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
- Version: 1.10.1
5
  Plugin URI: https://gtm4wp.com/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
@@ -10,12 +10,13 @@ Text Domain: duracelltomi-google-tag-manager
10
  Domain Path: /languages
11
 
12
  WC requires at least: 2.6
13
- WC tested up to: 3.6.5
14
  */
15
 
16
- define( 'GTM4WP_VERSION', '1.10.1' );
17
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
18
 
 
19
  $gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
20
  $gtp4wp_plugin_basename = plugin_basename( __FILE__ );
21
  require_once GTM4WP_PATH . '/common/readoptions.php';
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
+ Version: 1.11
5
  Plugin URI: https://gtm4wp.com/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
10
  Domain Path: /languages
11
 
12
  WC requires at least: 2.6
13
+ WC tested up to: 3.8
14
  */
15
 
16
+ define( 'GTM4WP_VERSION', '1.11' );
17
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
18
 
19
+ global $gtp4wp_plugin_url, $gtp4wp_plugin_basename;
20
  $gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
21
  $gtp4wp_plugin_basename = plugin_basename( __FILE__ );
22
  require_once GTM4WP_PATH . '/common/readoptions.php';
integration/woocommerce.php CHANGED
@@ -6,10 +6,13 @@ define( 'GTM4WP_WPFILTER_EEC_ORDER_ITEM', 'gtm4wp_eec_order_item' );
6
  $gtm4wp_product_counter = 0;
7
  $gtm4wp_last_widget_title = 'Sidebar Products';
8
  if ( function_exists( 'WC' ) ) {
9
- $GLOBALS['gtm4wp_is_woocommerce3'] = version_compare( WC()->version, '3.0', '>=' );
 
10
  } else {
11
- $GLOBALS['gtm4wp_is_woocommerce3'] = false;
 
12
  }
 
13
 
14
  function gtm4wp_woocommerce_addjs( $js ) {
15
  $woo = WC();
@@ -110,6 +113,100 @@ function gtm4wp_woocommerce_getproductterm( $product_id, $taxonomy ) {
110
  return "";
111
  }
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  function gtm4wp_woocommerce_addglobalvars( $return = '' ) {
114
  global $gtm4wp_options;
115
 
@@ -126,39 +223,41 @@ function gtm4wp_woocommerce_addglobalvars( $return = '' ) {
126
  }
127
 
128
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
129
- global $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter, $gtm4wp_is_woocommerce3;
130
 
131
  $woo = WC();
132
 
133
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA ] && $gtm4wp_is_woocommerce3 ) {
134
- // we need to use this instead of $woo->customer as this will load proper total order number and value from the database instead of the session
135
- $woo_customer = new WC_Customer( $woo->customer->get_id() );
136
-
137
- $dataLayer['customerTotalOrders'] = $woo_customer->get_order_count();
138
- $dataLayer['customerTotalOrderValue'] = $woo_customer->get_total_spent();
139
-
140
- $dataLayer['customerFirstName'] = $woo_customer->get_first_name();
141
- $dataLayer['customerLastName'] = $woo_customer->get_last_name();
142
-
143
- $dataLayer['customerBillingFirstName'] = $woo_customer->get_billing_first_name();
144
- $dataLayer['customerBillingLastName'] = $woo_customer->get_billing_last_name();
145
- $dataLayer['customerBillingCompany'] = $woo_customer->get_billing_company();
146
- $dataLayer['customerBillingAddress1'] = $woo_customer->get_billing_address_1();
147
- $dataLayer['customerBillingAddress2'] = $woo_customer->get_billing_address_2();
148
- $dataLayer['customerBillingCity'] = $woo_customer->get_billing_city();
149
- $dataLayer['customerBillingPostcode'] = $woo_customer->get_billing_postcode();
150
- $dataLayer['customerBillingCountry'] = $woo_customer->get_billing_country();
151
- $dataLayer['customerBillingEmail'] = $woo_customer->get_billing_email();
152
- $dataLayer['customerBillingPhone'] = $woo_customer->get_billing_phone();
153
-
154
- $dataLayer['customerShippingFirstName'] = $woo_customer->get_shipping_first_name();
155
- $dataLayer['customerShippingLastName'] = $woo_customer->get_shipping_last_name();
156
- $dataLayer['customerShippingCompany'] = $woo_customer->get_shipping_company();
157
- $dataLayer['customerShippingAddress1'] = $woo_customer->get_shipping_address_1();
158
- $dataLayer['customerShippingAddress2'] = $woo_customer->get_shipping_address_2();
159
- $dataLayer['customerShippingCity'] = $woo_customer->get_shipping_city();
160
- $dataLayer['customerShippingPostcode'] = $woo_customer->get_shipping_postcode();
161
- $dataLayer['customerShippingCountry'] = $woo_customer->get_shipping_country();
 
 
162
  }
163
 
164
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL ] && version_compare( $woo->version, "3.2", ">=" ) ) {
@@ -179,40 +278,10 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
179
  continue;
180
  }
181
 
182
- $product_id = $product->get_id();
183
- $product_type = $product->get_type();
184
-
185
- if ( "variation" == $product_type ) {
186
- $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id);
187
- $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
188
- } else {
189
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
190
- }
191
-
192
- $remarketing_id = $product_id;
193
- $product_sku = $product->get_sku();
194
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
195
- $remarketing_id = $product_sku;
196
- }
197
-
198
- $_temp_productdata = array(
199
- "id" => $remarketing_id,
200
- "name" => $product->get_title(),
201
- "price" => $product->get_price(),
202
- "category" => $product_cat,
203
- "stocklevel" => $product->get_stock_quantity(),
204
- "quantity" => $cart_item_data["quantity"]
205
- );
206
-
207
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
208
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
209
- }
210
 
211
- if ( "variation" == $product_type ) {
212
- $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
213
- }
214
-
215
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "cart" );
216
  $dataLayer["cartContent"]["items"][] = $eec_product_array;
217
  }
218
  }
@@ -234,58 +303,51 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
234
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
235
  $postid = get_the_ID();
236
  $product = wc_get_product( $postid );
237
- $product_id = $product->get_id();
238
 
239
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
240
-
241
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
242
- $product_sku = $product->get_sku();
243
- if ( '' != $product_sku ) {
244
- $product_id = $product_sku;
245
- }
246
- }
247
- $remarketing_id = (string) $product_id;
248
- $product_price = floatval( $product->get_price() );
249
 
250
  $dataLayer['productRatingCounts'] = $product->get_rating_counts();
251
  $dataLayer['productAverageRating'] = (float) $product->get_average_rating();
252
  $dataLayer['productReviewCount'] = (int) $product->get_review_count();
 
253
 
254
- if ( 'variable' != $product->get_type() ) {
255
- $dataLayer['productIsVariable'] = 0;
 
256
 
257
- $_temp_productdata = array(
258
- 'name' => gtm4wp_woocommerce_html_entity_decode( get_the_title() ),
259
- 'id' => $product_id,
260
- 'price' => $product_price,
261
- 'category' => $product_cat,
262
- 'stocklevel' => $product->get_stock_quantity(),
263
- );
264
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
265
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
266
- }
267
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'productdetail' );
268
-
269
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
270
- $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $remarketing_id );
271
  $dataLayer['ecomm_pagetype'] = 'product';
272
- $dataLayer['ecomm_totalvalue'] = (float) $eec_product_array['price'];
 
 
273
  }
274
 
275
- if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
276
- $dataLayer['ecommerce'] = array(
277
- 'currencyCode' => get_woocommerce_currency(),
278
- 'detail' => array(
279
- 'products' => array( $eec_product_array ),
280
- ),
281
- );
282
  }
283
- } else {
284
- $dataLayer['productIsVariable'] = 1;
285
 
286
- $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $remarketing_id );
287
- $dataLayer['ecomm_pagetype'] = 'product';
288
- $dataLayer['ecomm_totalvalue'] = $product_price;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  }
290
  }
291
  } elseif ( is_cart() ) {
@@ -300,45 +362,15 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
300
  continue;
301
  }
302
 
303
- $product_id = $product->get_id();
304
- $product_type = $product->get_type();
305
-
306
- if ( 'variation' == $product_type ) {
307
- $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id );
308
- $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
309
- } else {
310
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
311
- }
312
-
313
- $remarketing_id = $product_id;
314
- $product_sku = $product->get_sku();
315
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
316
- $remarketing_id = $product_sku;
317
- }
318
 
319
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
320
- $_temp_productdata = array(
321
- 'id' => $remarketing_id,
322
- 'name' => $product->get_title(),
323
- 'price' => $product->get_price(),
324
- 'category' => $product_cat,
325
- 'stocklevel' => $product->get_stock_quantity(),
326
- 'quantity' => $cart_item_data['quantity'],
327
- );
328
-
329
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
330
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
331
- }
332
-
333
- if ( 'variation' == $product_type ) {
334
- $_temp_productdata['variant'] = implode( ',', $product->get_variation_attributes() );
335
- }
336
-
337
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'cart' );
338
  $gtm4wp_cart_products[] = $eec_product_array;
339
  }
340
 
341
- $gtm4wp_cart_products_remarketing[] = gtm4wp_prefix_productid( $remarketing_id );
342
  }
343
 
344
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
@@ -392,6 +424,72 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
392
  }
393
  }
394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  if ( ( 1 == get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
396
  unset( $order );
397
  }
@@ -402,15 +500,15 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
402
 
403
  if ( isset( $order ) ) {
404
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX ] ) {
405
- $order_revenue = floatval( $order->get_total() - $order->get_total_tax() );
406
  } else {
407
- $order_revenue = floatval( $order->get_total() );
408
  }
409
 
410
  if ( $gtm4wp_is_woocommerce3 ) {
411
- $order_shipping_cost = floatval( $order->get_shipping_total() );
412
  } else {
413
- $order_shipping_cost = floatval( $order->get_total_shipping() );
414
  }
415
 
416
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING ] ) {
@@ -418,106 +516,48 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
418
  }
419
 
420
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
 
421
  $dataLayer['transactionId'] = $order->get_order_number();
422
- $dataLayer['transactionDate'] = date( 'c' );
423
- $dataLayer['transactionType'] = 'sale';
424
  $dataLayer['transactionAffiliation'] = '';
425
  $dataLayer['transactionTotal'] = $order_revenue;
426
  $dataLayer['transactionShipping'] = $order_shipping_cost;
427
- $dataLayer['transactionTax'] = floatval( $order->get_total_tax() );
428
- $dataLayer['transactionPaymentType'] = ( $gtm4wp_is_woocommerce3 ? $order->get_payment_method_title() : $order->payment_method_title );
429
- $dataLayer['transactionCurrency'] = get_woocommerce_currency();
430
- $dataLayer['transactionShippingMethod'] = $order->get_shipping_method();
431
- $dataLayer['transactionPromoCode'] = implode( ', ', $order->get_used_coupons() );
432
  }
433
 
434
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
 
435
  $dataLayer['ecommerce'] = array(
436
- 'currencyCode' => get_woocommerce_currency(),
437
  'purchase' => array(
438
  'actionField' => array(
439
  'id' => $order->get_order_number(),
440
  'affiliation' => '',
441
  'revenue' => $order_revenue,
442
- 'tax' => floatval( $order->get_total_tax() ),
443
- 'shipping' => floatval( $gtm4wp_is_woocommerce3 ? $order->get_shipping_total() : $order->get_total_shipping() ),
444
- 'coupon' => implode( ', ', $order->get_used_coupons() ),
445
  ),
446
  ),
447
  );
448
  }
449
 
450
- $_products = array();
451
- $_sumprice = 0;
452
- $_product_ids = array();
453
-
454
- if ( $order->get_items() ) {
455
- foreach ( $order->get_items() as $item ) {
456
-
457
- if ( ! apply_filters( GTM4WP_WPFILTER_EEC_ORDER_ITEM, true, $item ) ) {
458
- continue;
459
- }
460
-
461
- $product = ( $gtm4wp_is_woocommerce3 ? $item->get_product() : $order->get_product_from_item( $item ) );
462
-
463
- $product_id = $product->get_id();
464
- $product_type = $product->get_type();
465
-
466
- if ( 'variation' == $product_type ) {
467
- $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id );
468
- $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
469
- } else {
470
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
471
- }
472
-
473
- $remarketing_id = $product_id;
474
- $product_sku = $product->get_sku();
475
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
476
- $remarketing_id = $product_sku;
477
- }
478
-
479
- $product_price = floatval( $order->get_item_total( $item ) );
480
- $_temp_productdata = array(
481
- 'id' => $remarketing_id,
482
- 'name' => $product->get_title(),
483
- 'sku' => $product_sku ? $product_sku : $product_id,
484
- 'category' => $product_cat,
485
- 'price' => $product_price,
486
- 'currency' => get_woocommerce_currency(),
487
- 'stocklevel' => $product->get_stock_quantity(),
488
- 'quantity' => $item['qty'],
489
- );
490
-
491
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
492
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
493
- }
494
-
495
- if ( 'variation' == $product_type ) {
496
- $_temp_productdata['variant'] = implode( ',', $product->get_variation_attributes() );
497
- }
498
-
499
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'purchase' );
500
- $_products[] = $eec_product_array;
501
-
502
- $_sumprice += $product_price * $eec_product_array['quantity'];
503
- $_product_ids[] = gtm4wp_prefix_productid( $remarketing_id );
504
- }
505
  }
506
 
507
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
508
- $dataLayer['transactionProducts'] = $_products;
509
- $dataLayer['event'] = 'gtm4wp.orderCompleted';
510
  }
511
 
512
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
513
- $dataLayer['ecommerce']['purchase']['products'] = $_products;
514
- $dataLayer['event'] = 'gtm4wp.orderCompletedEEC';
515
  }
516
 
517
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
518
- $dataLayer['ecomm_prodid'] = $_product_ids;
519
  $dataLayer['ecomm_pagetype'] = 'purchase';
520
- $dataLayer['ecomm_totalvalue'] = (float) $_sumprice;
521
  }
522
 
523
  if ( ! $do_not_flag_tracked_order ) {
@@ -537,43 +577,13 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
537
  continue;
538
  }
539
 
540
- $product_id = $product->get_id();
541
- $product_type = $product->get_type();
542
-
543
- if ( 'variation' == $product_type ) {
544
- $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id );
545
- $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
546
- } else {
547
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
548
- }
549
-
550
- $remarketing_id = $product_id;
551
- $product_sku = $product->get_sku();
552
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
553
- $remarketing_id = $product_sku;
554
- }
555
 
556
- $_temp_productdata = array(
557
- 'id' => $remarketing_id,
558
- 'name' => $product->get_title(),
559
- 'price' => $product->get_price(),
560
- 'category' => $product_cat,
561
- 'stocklevel' => $product->get_stock_quantity(),
562
- 'quantity' => $cart_item_data['quantity'],
563
- );
564
-
565
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
566
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
567
- }
568
-
569
- if ( 'variation' == $product_type ) {
570
- $_temp_productdata['variant'] = implode( ',', $product->get_variation_attributes() );
571
- }
572
-
573
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'checkout' );
574
  $gtm4wp_checkout_products[] = $eec_product_array;
575
 
576
- $gtm4wp_checkout_products_remarketing[] = gtm4wp_prefix_productid( $remarketing_id );
577
  $gtm4wp_totalvalue += $eec_product_array['quantity'] * $eec_product_array['price'];
578
  } // end foreach cart item
579
 
@@ -594,8 +604,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
594
  ),
595
  );
596
 
597
- gtm4wp_woocommerce_addjs(
598
- '
599
  window.gtm4wp_checkout_products = ' . json_encode( $gtm4wp_checkout_products ) . ';
600
  window.gtm4wp_checkout_step_offset = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ';'
601
  );
@@ -612,39 +621,18 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
612
  if ( ! empty( $cart_item ) ) {
613
  $product = $cart_item['data'];
614
 
615
- $product_id = $product->get_id();
616
- $product_type = $product->get_type();
617
-
618
- if ( 'variation' == $product_type ) {
619
- $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id );
620
- $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
621
- } else {
622
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
623
- }
624
-
625
- $remarketing_id = $product_id;
626
- $product_sku = $product->get_sku();
627
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
628
- $remarketing_id = $product_sku;
629
- }
630
-
631
- $dataLayer['ecommerce']['currencyCode'] = get_woocommerce_currency();
632
- $dataLayer['ecommerce']['add']['products'][] = array(
633
- 'name' => $product->get_title(),
634
- 'id' => $remarketing_id,
635
- 'price' => $product->get_price(),
636
- 'category' => $product_cat,
637
- 'stocklevel' => $product->get_stock_quantity(),
638
- 'quantity' => $cart_item['quantity'],
639
  );
640
-
641
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
642
- $dataLayer["ecommerce"]["add"]["products"][0][ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
643
- }
644
-
645
- if ( 'variation' == $product_type ) {
646
- $dataLayer['ecommerce']['add'][0]['variant'] = implode( ',', $product->get_variation_attributes() );
647
- }
648
  }
649
 
650
  gtm4wp_woocommerce_addjs( "document.cookie = 'gtm4wp_product_readded_to_cart=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';" );
@@ -662,29 +650,7 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
662
  return;
663
  }
664
 
665
- $product_id = $product->get_id();
666
-
667
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
668
-
669
- $remarketing_id = $product_id;
670
- $product_sku = $product->get_sku();
671
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
672
- $remarketing_id = $product_sku;
673
- }
674
-
675
- $_temp_productdata = array(
676
- 'id' => $remarketing_id,
677
- 'name' => $product->get_title(),
678
- 'sku' => $product_sku ? $product_sku : $product_id,
679
- 'category' => $product_cat,
680
- 'price' => $product->get_price(),
681
- 'currency' => get_woocommerce_currency(),
682
- 'stocklevel' => $product->get_stock_quantity(),
683
- );
684
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
685
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
686
- }
687
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'addtocartsingle' );
688
 
689
  foreach ( $eec_product_array as $eec_product_array_key => $eec_product_array_value ) {
690
  echo '<input type="hidden" name="gtm4wp_' . esc_attr( $eec_product_array_key ) . '" value="' . esc_attr( $eec_product_array_value ) . '" />' . "\n";
@@ -695,43 +661,10 @@ $GLOBALS['gtm4wp_cart_item_proddata'] = '';
695
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item = '', $cart_id = '' ) {
696
  global $gtm4wp_options, $gtm4wp_is_woocommerce3;
697
 
698
- $product_id = $product->get_id();
699
- $product_type = $product->get_type();
 
700
 
701
- if ( 'variation' == $product_type ) {
702
- $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id );
703
- $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
704
- } else {
705
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
706
- }
707
-
708
- $remarketing_id = $product_id;
709
- $product_sku = $product->get_sku();
710
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
711
- $remarketing_id = $product_sku;
712
- }
713
-
714
- $_temp_productdata = array(
715
- 'id' => $remarketing_id,
716
- 'name' => $product->get_title(),
717
- 'price' => $product->get_price(),
718
- 'category' => $product_cat,
719
- 'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 ),
720
- 'variant' => '',
721
- 'stocklevel' => $product->get_stock_quantity(),
722
- );
723
-
724
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
725
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
726
- } else {
727
- $_temp_productdata[ "brand" ] = "";
728
- }
729
-
730
- if ( 'variation' == $product_type ) {
731
- $_temp_productdata['variant'] = implode( ',', $product->get_variation_attributes() );
732
- }
733
-
734
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'cart' );
735
  $GLOBALS['gtm4wp_cart_item_proddata'] = $eec_product_array;
736
 
737
  return $product;
@@ -746,6 +679,10 @@ function gtm4wp_woocommerce_cart_item_remove_link_filter( $remove_from_cart_link
746
  return $remove_from_cart_link;
747
  }
748
 
 
 
 
 
749
  $cartlink_with_data = sprintf(
750
  'data-gtm4wp_product_id="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_product_variant="%s" data-gtm4wp_product_stocklevel="%s" data-gtm4wp_product_brand="%s" href="',
751
  esc_attr( $GLOBALS['gtm4wp_cart_item_proddata']['id'] ),
@@ -803,31 +740,11 @@ function gtm4wp_woocommerce_after_template_part( $template_name ) {
803
  ob_end_clean();
804
 
805
  if ( 'content-widget-product.php' == $template_name ) {
806
- $product_id = $product->get_id();
807
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
808
-
809
- $remarketing_id = $product_id;
810
- $product_sku = $product->get_sku();
811
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
812
- $remarketing_id = $product_sku;
813
- }
814
-
815
- $_temp_productdata = array(
816
- 'id' => $remarketing_id,
817
- 'name' => $product->get_title(),
818
- 'price' => $product->get_price(),
819
- 'category' => $product_cat,
820
  'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 ),
821
  'listname' => $gtm4wp_last_widget_title,
822
- 'listposition' => $gtm4wp_product_counter,
823
- 'stocklevel' => $product->get_stock_quantity(),
824
- );
825
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
826
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
827
- } else {
828
- $_temp_productdata[ "brand" ] = "";
829
- }
830
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'widgetproduct' );
831
 
832
  $productlink_with_data = sprintf(
833
  'data-gtm4wp_product_id="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_productlist_name="%s" data-gtm4wp_product_listposition="%s" data-gtm4wp_product_stocklevel="%s" data-gtm4wp_product_brand="%s" href="',
@@ -931,28 +848,11 @@ function gtm4wp_woocommerce_before_shop_loop_item() {
931
  $posts_per_page = 1;
932
  }
933
 
934
- $remarketing_id = $product_id;
935
- $product_sku = $product->get_sku();
936
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
937
- $remarketing_id = $product_sku;
938
- }
939
-
940
- $_temp_productdata = array(
941
- 'id' => $remarketing_id,
942
- 'name' => $product->get_title(),
943
- 'price' => $product->get_price(),
944
- 'category' => $product_cat,
945
  'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 ),
946
  'listname' => $list_name,
947
- 'listposition' => $woocommerce_loop['loop'] + ( $posts_per_page * ( $paged - 1 ) ),
948
- 'stocklevel' => $product->get_stock_quantity(),
949
- );
950
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
951
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $remarketing_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
952
- } else {
953
- $_temp_productdata[ "brand" ] = "";
954
- }
955
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'productlist' );
956
 
957
  printf(
958
  '<span class="gtm4wp_productdata" style="display:none; visibility:hidden;" data-gtm4wp_product_id="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_product_listposition="%s" data-gtm4wp_productlist_name="%s" data-gtm4wp_product_stocklevel="%s" data-gtm4wp_product_brand="%s"></span>',
@@ -996,52 +896,51 @@ function gtm4wp_wc_quick_view_before_single_product() {
996
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
997
  $postid = get_the_ID();
998
  $product = wc_get_product( $postid );
999
- $product_id = $product->get_id();
1000
 
1001
- $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
1002
 
1003
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
1004
- $product_sku = $product->get_sku();
1005
- if ( '' != $product_sku ) {
1006
- $product_id = $product_sku;
1007
- }
1008
- }
1009
- $remarketing_id = (string) $product_id;
1010
- $product_price = floatval( $product->get_price() );
1011
-
1012
- if ( 'variable' != $product->get_type() ) {
1013
- $_temp_productdata = array(
1014
- 'name' => gtm4wp_woocommerce_html_entity_decode( get_the_title() ),
1015
- 'id' => $product_id,
1016
- 'price' => $product_price,
1017
- 'category' => $product_cat,
1018
- 'stocklevel' => $product->get_stock_quantity(),
1019
- );
1020
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
1021
- $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
1022
- } else {
1023
- $_temp_productdata[ "brand" ] = "";
1024
- }
1025
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, 'productdetail' );
1026
 
1027
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
1028
- $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $remarketing_id );
 
 
 
1029
  $dataLayer['ecomm_pagetype'] = 'product';
1030
- $dataLayer['ecomm_totalvalue'] = (float) $eec_product_array['price'];
 
 
1031
  }
1032
 
1033
- if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
1034
- $dataLayer['ecommerce'] = array(
1035
- 'currencyCode' => get_woocommerce_currency(),
1036
- 'detail' => array(
1037
- 'products' => array( $eec_product_array ),
1038
- ),
1039
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1040
  }
1041
- } else {
1042
- $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $remarketing_id );
1043
- $dataLayer['ecomm_pagetype'] = 'product';
1044
- $dataLayer['ecomm_totalvalue'] = $product_price;
1045
  }
1046
  }
1047
 
@@ -1051,6 +950,41 @@ function gtm4wp_wc_quick_view_before_single_product() {
1051
  </script>';
1052
  }
1053
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1054
  // do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin
1055
  if ( function_exists( 'WC' ) ) {
1056
  add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, 'gtm4wp_woocommerce_datalayer_filter_items' );
@@ -1069,6 +1003,7 @@ if ( function_exists( 'WC' ) ) {
1069
  add_action( 'woocommerce_after_template_part', 'gtm4wp_woocommerce_after_template_part' );
1070
  add_filter( 'widget_title', 'gtm4wp_widget_title_filter' );
1071
  add_action( 'wc_quick_view_before_single_product', 'gtm4wp_wc_quick_view_before_single_product' );
 
1072
 
1073
  add_filter( 'woocommerce_cart_item_product', 'gtm4wp_woocommerce_cart_item_product_filter' );
1074
  add_filter( 'woocommerce_cart_item_remove_link', 'gtm4wp_woocommerce_cart_item_remove_link_filter' );
6
  $gtm4wp_product_counter = 0;
7
  $gtm4wp_last_widget_title = 'Sidebar Products';
8
  if ( function_exists( 'WC' ) ) {
9
+ $GLOBALS['gtm4wp_is_woocommerce3'] = version_compare( WC()->version, '3.0', '>=' );
10
+ $GLOBALS['gtm4wp_is_woocommerce3_7'] = version_compare( WC()->version, '3.7', '>=' );
11
  } else {
12
+ $GLOBALS['gtm4wp_is_woocommerce3'] = false;
13
+ $GLOBALS['gtm4wp_is_woocommerce3_7'] = false;
14
  }
15
+ $GLOBALS['gtm4wp_grouped_product_ix'] = 1;
16
 
17
  function gtm4wp_woocommerce_addjs( $js ) {
18
  $woo = WC();
113
  return "";
114
  }
115
 
116
+ function gtm4wp_process_product( $product, $additional_product_attributes, $attributes_used_for ) {
117
+ global $gtm4wp_options, $gtm4wp_is_woocommerce3;
118
+
119
+ if ( ! $product ) {
120
+ return false;
121
+ }
122
+
123
+ if ( ! ( $product instanceof WC_Product ) ) {
124
+ return false;
125
+ }
126
+
127
+ $product_id = $product->get_id();
128
+ $product_type = $product->get_type();
129
+ $remarketing_id = $product_id;
130
+ $product_sku = $product->get_sku();
131
+
132
+ if ( 'variation' == $product_type ) {
133
+ $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id );
134
+ $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
135
+ } else {
136
+ $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
137
+ }
138
+
139
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( '' != $product_sku ) ) {
140
+ $remarketing_id = $product_sku;
141
+ }
142
+
143
+ $_temp_productdata = array(
144
+ 'id' => $remarketing_id,
145
+ 'name' => $product->get_title(),
146
+ 'sku' => $product_sku ? $product_sku : $product_id,
147
+ 'category' => $product_cat,
148
+ 'price' => (float) wc_get_price_to_display( $product ),
149
+ 'stocklevel' => $product->get_stock_quantity()
150
+ );
151
+
152
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] != "" ) {
153
+ if ( isset( $parent_product_id ) && ( $parent_product_id !== 0 ) ) {
154
+ $product_id_to_query = $parent_product_id;
155
+ } else {
156
+ $product_id_to_query = $product_id;
157
+ }
158
+
159
+ $_temp_productdata[ "brand" ] = gtm4wp_woocommerce_getproductterm( $product_id_to_query, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] );
160
+ }
161
+
162
+ if ( 'variation' == $product_type ) {
163
+ $_temp_productdata['variant'] = implode( ',', $product->get_variation_attributes() );
164
+ }
165
+
166
+ $_temp_productdata = array_merge( $_temp_productdata, $additional_product_attributes );
167
+
168
+ return apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, $attributes_used_for );
169
+ }
170
+
171
+ function gtm4wp_process_order_items( $order ) {
172
+ global $gtm4wp_options, $gtm4wp_is_woocommerce3;
173
+
174
+ $return_data = array(
175
+ 'products' => [],
176
+ 'sumprice' => 0,
177
+ 'product_ids' => []
178
+ );
179
+
180
+ if ( ! $order ) {
181
+ return $return_data;
182
+ }
183
+
184
+ $order_items = $order->get_items();
185
+
186
+ if ( $order_items ) {
187
+ foreach ( $order_items as $item ) {
188
+ if ( ! apply_filters( GTM4WP_WPFILTER_EEC_ORDER_ITEM, true, $item ) ) {
189
+ continue;
190
+ }
191
+
192
+ $product = ( $gtm4wp_is_woocommerce3 ? $item->get_product() : $order->get_product_from_item( $item ) );
193
+ $product_price = (float) $order->get_item_total( $item );
194
+ $eec_product_array = gtm4wp_process_product( $product, array(
195
+ 'quantity' => $item->get_quantity(),
196
+ 'price' => $product_price
197
+ ), 'purchase' );
198
+
199
+ if ( $eec_product_array ) {
200
+ $return_data['products'][] = $eec_product_array;
201
+ $return_data['sumprice'] += $product_price * $eec_product_array['quantity'];
202
+ $return_data['product_ids'][] = gtm4wp_prefix_productid( $eec_product_array['id'] );
203
+ }
204
+ }
205
+ }
206
+
207
+ return $return_data;
208
+ }
209
+
210
  function gtm4wp_woocommerce_addglobalvars( $return = '' ) {
211
  global $gtm4wp_options;
212
 
223
  }
224
 
225
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
226
+ global $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter, $gtm4wp_is_woocommerce3, $gtm4wp_is_woocommerce3_7;
227
 
228
  $woo = WC();
229
 
230
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA ] && $gtm4wp_is_woocommerce3 ) {
231
+ if ( $woo->customer instanceof WC_Customer ) {
232
+ // we need to use this instead of $woo->customer as this will load proper total order number and value from the database instead of the session
233
+ $woo_customer = new WC_Customer( $woo->customer->get_id() );
234
+
235
+ $dataLayer['customerTotalOrders'] = $woo_customer->get_order_count();
236
+ $dataLayer['customerTotalOrderValue'] = $woo_customer->get_total_spent();
237
+
238
+ $dataLayer['customerFirstName'] = $woo_customer->get_first_name();
239
+ $dataLayer['customerLastName'] = $woo_customer->get_last_name();
240
+
241
+ $dataLayer['customerBillingFirstName'] = $woo_customer->get_billing_first_name();
242
+ $dataLayer['customerBillingLastName'] = $woo_customer->get_billing_last_name();
243
+ $dataLayer['customerBillingCompany'] = $woo_customer->get_billing_company();
244
+ $dataLayer['customerBillingAddress1'] = $woo_customer->get_billing_address_1();
245
+ $dataLayer['customerBillingAddress2'] = $woo_customer->get_billing_address_2();
246
+ $dataLayer['customerBillingCity'] = $woo_customer->get_billing_city();
247
+ $dataLayer['customerBillingPostcode'] = $woo_customer->get_billing_postcode();
248
+ $dataLayer['customerBillingCountry'] = $woo_customer->get_billing_country();
249
+ $dataLayer['customerBillingEmail'] = $woo_customer->get_billing_email();
250
+ $dataLayer['customerBillingPhone'] = $woo_customer->get_billing_phone();
251
+
252
+ $dataLayer['customerShippingFirstName'] = $woo_customer->get_shipping_first_name();
253
+ $dataLayer['customerShippingLastName'] = $woo_customer->get_shipping_last_name();
254
+ $dataLayer['customerShippingCompany'] = $woo_customer->get_shipping_company();
255
+ $dataLayer['customerShippingAddress1'] = $woo_customer->get_shipping_address_1();
256
+ $dataLayer['customerShippingAddress2'] = $woo_customer->get_shipping_address_2();
257
+ $dataLayer['customerShippingCity'] = $woo_customer->get_shipping_city();
258
+ $dataLayer['customerShippingPostcode'] = $woo_customer->get_shipping_postcode();
259
+ $dataLayer['customerShippingCountry'] = $woo_customer->get_shipping_country();
260
+ }
261
  }
262
 
263
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL ] && version_compare( $woo->version, "3.2", ">=" ) ) {
278
  continue;
279
  }
280
 
281
+ $eec_product_array = gtm4wp_process_product( $product, array(
282
+ 'quantity' => $cart_item_data["quantity"]
283
+ ), 'cart' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
 
 
 
 
 
 
285
  $dataLayer["cartContent"]["items"][] = $eec_product_array;
286
  }
287
  }
303
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
304
  $postid = get_the_ID();
305
  $product = wc_get_product( $postid );
 
306
 
307
+ $eec_product_array = gtm4wp_process_product( $product, array(), 'productdetail' );
 
 
 
 
 
 
 
 
 
308
 
309
  $dataLayer['productRatingCounts'] = $product->get_rating_counts();
310
  $dataLayer['productAverageRating'] = (float) $product->get_average_rating();
311
  $dataLayer['productReviewCount'] = (int) $product->get_review_count();
312
+ $dataLayer['productType'] = $product->get_type();
313
 
314
+ switch ( $dataLayer['productType'] ) {
315
+ case 'variable': {
316
+ $dataLayer['productIsVariable'] = 1;
317
 
318
+ $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  $dataLayer['ecomm_pagetype'] = 'product';
320
+ $dataLayer['ecomm_totalvalue'] = $eec_product_array[ 'price' ];
321
+
322
+ break;
323
  }
324
 
325
+ case 'grouped': {
326
+ $dataLayer['productIsVariable'] = 0;
327
+
328
+ break;
 
 
 
329
  }
 
 
330
 
331
+ default: {
332
+ $dataLayer['productIsVariable'] = 0;
333
+
334
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
335
+ $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
336
+ $dataLayer['ecomm_pagetype'] = 'product';
337
+ $dataLayer['ecomm_totalvalue'] = $eec_product_array['price'];
338
+ }
339
+
340
+ if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
341
+ $dataLayer['ecommerce'] = array(
342
+ 'currencyCode' => get_woocommerce_currency(),
343
+ 'detail' => array(
344
+ 'products' => array(
345
+ $eec_product_array
346
+ ),
347
+ ),
348
+ );
349
+ }
350
+ }
351
  }
352
  }
353
  } elseif ( is_cart() ) {
362
  continue;
363
  }
364
 
365
+ $eec_product_array = gtm4wp_process_product( $product, array(
366
+ 'quantity' => $cart_item_data['quantity']
367
+ ), 'cart' );
 
 
 
 
 
 
 
 
 
 
 
 
368
 
369
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  $gtm4wp_cart_products[] = $eec_product_array;
371
  }
372
 
373
+ $gtm4wp_cart_products_remarketing[] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
374
  }
375
 
376
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
424
  }
425
  }
426
 
427
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCORDERDATA ] && $gtm4wp_is_woocommerce3 ) {
428
+ $order_items = gtm4wp_process_order_items( $order );
429
+
430
+ $dataLayer['orderData'] = array(
431
+ 'attributes' => array(
432
+ 'date' => $order->get_date_created()->date( 'c' ),
433
+
434
+ 'order_number' => $order->get_order_number(),
435
+ 'order_key' => $order->get_order_key(),
436
+
437
+ 'payment_method' => esc_js( $order->get_payment_method() ),
438
+ 'payment_method_title' => esc_js( $order->get_payment_method_title() ),
439
+
440
+ 'shipping_method' => esc_js( $order->get_shipping_method() ),
441
+
442
+ 'status' => esc_js( $order->get_status() ),
443
+
444
+ 'coupons' => implode( ', ', ( $gtm4wp_is_woocommerce3_7 ? $order->get_coupon_codes() : $order->get_used_coupons() ) )
445
+ ),
446
+ 'totals' => array(
447
+ 'currency' => esc_js( $order->get_currency() ),
448
+ 'discount_total' => esc_js( $order->get_discount_total() ),
449
+ 'discount_tax' => esc_js( $order->get_discount_tax() ),
450
+ 'shipping_total' => esc_js( $order->get_shipping_total() ),
451
+ 'shipping_tax' => esc_js( $order->get_shipping_tax() ),
452
+ 'cart_tax' => esc_js( $order->get_cart_tax() ),
453
+ 'total' => esc_js( $order->get_total() ),
454
+ 'total_tax' => esc_js( $order->get_total_tax() ),
455
+ 'total_discount' => esc_js( $order->get_total_discount() ),
456
+ 'subtotal' => esc_js( $order->get_subtotal() ),
457
+ 'tax_totals' => $order->get_tax_totals()
458
+ ),
459
+ 'customer' => array(
460
+ 'id' => $order->get_customer_id(),
461
+
462
+ 'billing' => array(
463
+ 'first_name' => esc_js( $order->get_billing_first_name() ),
464
+ 'last_name' => esc_js( $order->get_billing_last_name() ),
465
+ 'company' => esc_js( $order->get_billing_company() ),
466
+ 'address_1' => esc_js( $order->get_billing_address_1() ),
467
+ 'address_2' => esc_js( $order->get_billing_address_2() ),
468
+ 'city' => esc_js( $order->get_billing_city() ),
469
+ 'state' => esc_js( $order->get_billing_state() ),
470
+ 'postcode' => esc_js( $order->get_billing_postcode() ),
471
+ 'country' => esc_js( $order->get_billing_country() ),
472
+ 'email' => esc_js( $order->get_billing_email() ),
473
+ 'phone' => esc_js( $order->get_billing_phone() )
474
+ ),
475
+
476
+ 'shipping' => array(
477
+ 'first_name' => esc_js( $order->get_shipping_first_name() ),
478
+ 'last_name' => esc_js( $order->get_shipping_last_name() ),
479
+ 'company' => esc_js( $order->get_shipping_company() ),
480
+ 'address_1' => esc_js( $order->get_shipping_address_1() ),
481
+ 'address_2' => esc_js( $order->get_shipping_address_2() ),
482
+ 'city' => esc_js( $order->get_shipping_city() ),
483
+ 'state' => esc_js( $order->get_shipping_state() ),
484
+ 'postcode' => esc_js( $order->get_shipping_postcode() ),
485
+ 'country' => esc_js( $order->get_shipping_country() )
486
+ )
487
+
488
+ ),
489
+ 'items' => $order_items['products']
490
+ );
491
+ }
492
+
493
  if ( ( 1 == get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
494
  unset( $order );
495
  }
500
 
501
  if ( isset( $order ) ) {
502
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX ] ) {
503
+ $order_revenue = (float)( $order->get_total() - $order->get_total_tax() );
504
  } else {
505
+ $order_revenue = (float) $order->get_total();
506
  }
507
 
508
  if ( $gtm4wp_is_woocommerce3 ) {
509
+ $order_shipping_cost = (float) $order->get_shipping_total();
510
  } else {
511
+ $order_shipping_cost = (float) $order->get_total_shipping();
512
  }
513
 
514
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING ] ) {
516
  }
517
 
518
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
519
+ $dataLayer['event'] = 'gtm4wp.orderCompleted';
520
  $dataLayer['transactionId'] = $order->get_order_number();
 
 
521
  $dataLayer['transactionAffiliation'] = '';
522
  $dataLayer['transactionTotal'] = $order_revenue;
523
  $dataLayer['transactionShipping'] = $order_shipping_cost;
524
+ $dataLayer['transactionTax'] = (float) $order->get_total_tax();
525
+ $dataLayer['transactionCurrency'] = $order->get_currency();
 
 
 
526
  }
527
 
528
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
529
+ $dataLayer['event'] = 'gtm4wp.orderCompletedEEC';
530
  $dataLayer['ecommerce'] = array(
531
+ 'currencyCode' => $order->get_currency(),
532
  'purchase' => array(
533
  'actionField' => array(
534
  'id' => $order->get_order_number(),
535
  'affiliation' => '',
536
  'revenue' => $order_revenue,
537
+ 'tax' => (float) $order->get_total_tax(),
538
+ 'shipping' => (float)( $gtm4wp_is_woocommerce3 ? $order->get_shipping_total() : $order->get_total_shipping() ),
539
+ 'coupon' => implode( ', ', ( $gtm4wp_is_woocommerce3_7 ? $order->get_coupon_codes() : $order->get_used_coupons() ) ),
540
  ),
541
  ),
542
  );
543
  }
544
 
545
+ if ( ! $order_items ) {
546
+ $order_items = gtm4wp_process_order_items( $order );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  }
548
 
549
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
550
+ $dataLayer['transactionProducts'] = $order_items['products'];
 
551
  }
552
 
553
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
554
+ $dataLayer['ecommerce']['purchase']['products'] = $order_items['products'];
 
555
  }
556
 
557
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
558
+ $dataLayer['ecomm_prodid'] = $order_items['product_ids'];
559
  $dataLayer['ecomm_pagetype'] = 'purchase';
560
+ $dataLayer['ecomm_totalvalue'] = (float) $order_items['sumprice'];
561
  }
562
 
563
  if ( ! $do_not_flag_tracked_order ) {
577
  continue;
578
  }
579
 
580
+ $eec_product_array = gtm4wp_process_product( $product, array(
581
+ 'quantity' => $cart_item_data['quantity']
582
+ ), 'cart' );
 
 
 
 
 
 
 
 
 
 
 
 
583
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
  $gtm4wp_checkout_products[] = $eec_product_array;
585
 
586
+ $gtm4wp_checkout_products_remarketing[] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
587
  $gtm4wp_totalvalue += $eec_product_array['quantity'] * $eec_product_array['price'];
588
  } // end foreach cart item
589
 
604
  ),
605
  );
606
 
607
+ gtm4wp_woocommerce_addjs('
 
608
  window.gtm4wp_checkout_products = ' . json_encode( $gtm4wp_checkout_products ) . ';
609
  window.gtm4wp_checkout_step_offset = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ';'
610
  );
621
  if ( ! empty( $cart_item ) ) {
622
  $product = $cart_item['data'];
623
 
624
+ $eec_product_array = gtm4wp_process_product( $product, array(
625
+ 'quantity' => $cart_item['quantity']
626
+ ), 'readdedtocart' );
627
+
628
+ $dataLayer['ecommerce'] = array(
629
+ 'currencyCode' => get_woocommerce_currency(),
630
+ 'add' => array(
631
+ 'products' => array(
632
+ $eec_product_array
633
+ )
634
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
635
  );
 
 
 
 
 
 
 
 
636
  }
637
 
638
  gtm4wp_woocommerce_addjs( "document.cookie = 'gtm4wp_product_readded_to_cart=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';" );
650
  return;
651
  }
652
 
653
+ $eec_product_array = gtm4wp_process_product( $product, array(), 'addtocartsingle' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
654
 
655
  foreach ( $eec_product_array as $eec_product_array_key => $eec_product_array_value ) {
656
  echo '<input type="hidden" name="gtm4wp_' . esc_attr( $eec_product_array_key ) . '" value="' . esc_attr( $eec_product_array_value ) . '" />' . "\n";
661
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item = '', $cart_id = '' ) {
662
  global $gtm4wp_options, $gtm4wp_is_woocommerce3;
663
 
664
+ $eec_product_array = gtm4wp_process_product( $product, array(
665
+ 'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 )
666
+ ), 'cart' );
667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
  $GLOBALS['gtm4wp_cart_item_proddata'] = $eec_product_array;
669
 
670
  return $product;
679
  return $remove_from_cart_link;
680
  }
681
 
682
+ if ( ! isset( $GLOBALS['gtm4wp_cart_item_proddata']['variant'] ) ) {
683
+ $GLOBALS['gtm4wp_cart_item_proddata']['variant'] = '';
684
+ }
685
+
686
  $cartlink_with_data = sprintf(
687
  'data-gtm4wp_product_id="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_product_variant="%s" data-gtm4wp_product_stocklevel="%s" data-gtm4wp_product_brand="%s" href="',
688
  esc_attr( $GLOBALS['gtm4wp_cart_item_proddata']['id'] ),
740
  ob_end_clean();
741
 
742
  if ( 'content-widget-product.php' == $template_name ) {
743
+ $eec_product_array = gtm4wp_process_product( $product, array(
 
 
 
 
 
 
 
 
 
 
 
 
 
744
  'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 ),
745
  'listname' => $gtm4wp_last_widget_title,
746
+ 'listposition' => $gtm4wp_product_counter
747
+ ), 'widgetproduct' );
 
 
 
 
 
 
 
748
 
749
  $productlink_with_data = sprintf(
750
  'data-gtm4wp_product_id="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_productlist_name="%s" data-gtm4wp_product_listposition="%s" data-gtm4wp_product_stocklevel="%s" data-gtm4wp_product_brand="%s" href="',
848
  $posts_per_page = 1;
849
  }
850
 
851
+ $eec_product_array = gtm4wp_process_product( $product, array(
 
 
 
 
 
 
 
 
 
 
852
  'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 ),
853
  'listname' => $list_name,
854
+ 'listposition' => $woocommerce_loop['loop'] + ( $posts_per_page * ( $paged - 1 ) )
855
+ ), 'productlist' );
 
 
 
 
 
 
 
856
 
857
  printf(
858
  '<span class="gtm4wp_productdata" style="display:none; visibility:hidden;" data-gtm4wp_product_id="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_product_listposition="%s" data-gtm4wp_productlist_name="%s" data-gtm4wp_product_stocklevel="%s" data-gtm4wp_product_brand="%s"></span>',
896
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
897
  $postid = get_the_ID();
898
  $product = wc_get_product( $postid );
 
899
 
900
+ $eec_product_array = gtm4wp_process_product( $product, array(), 'productdetail' );
901
 
902
+ $dataLayer['productRatingCounts'] = $product->get_rating_counts();
903
+ $dataLayer['productAverageRating'] = (float) $product->get_average_rating();
904
+ $dataLayer['productReviewCount'] = (int) $product->get_review_count();
905
+ $dataLayer['productType'] = $product->get_type();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
906
 
907
+ switch ( $dataLayer['productType'] ) {
908
+ case 'variable': {
909
+ $dataLayer['productIsVariable'] = 1;
910
+
911
+ $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
912
  $dataLayer['ecomm_pagetype'] = 'product';
913
+ $dataLayer['ecomm_totalvalue'] = $eec_product_array[ 'price' ];
914
+
915
+ break;
916
  }
917
 
918
+ case 'grouped': {
919
+ $dataLayer['productIsVariable'] = 0;
920
+
921
+ break;
922
+ }
923
+
924
+ default: {
925
+ $dataLayer['productIsVariable'] = 0;
926
+
927
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
928
+ $dataLayer['ecomm_prodid'] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
929
+ $dataLayer['ecomm_pagetype'] = 'product';
930
+ $dataLayer['ecomm_totalvalue'] = $eec_product_array['price'];
931
+ }
932
+
933
+ if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
934
+ $dataLayer['ecommerce'] = array(
935
+ 'currencyCode' => get_woocommerce_currency(),
936
+ 'detail' => array(
937
+ 'products' => array(
938
+ $eec_product_array
939
+ ),
940
+ ),
941
+ );
942
+ }
943
  }
 
 
 
 
944
  }
945
  }
946
 
950
  </script>';
951
  }
952
 
953
+ function gtm4wp_woocommerce_grouped_product_list_column_label( $labelvalue, $product ) {
954
+ global $gtm4wp_options, $gtm4wp_grouped_product_ix;
955
+
956
+ if ( ! isset( $product ) ) {
957
+ return $labelvalue;
958
+ }
959
+
960
+ $list_name = __( 'Grouped Product Detail Page', 'duracelltomi-google-tag-manager' );
961
+
962
+ $eec_product_array = gtm4wp_process_product( $product, array(
963
+ 'productlink' => $product->get_permalink(),
964
+ 'listname' => $list_name,
965
+ 'listposition' => $gtm4wp_grouped_product_ix
966
+ ), 'groupedproductlist' );
967
+
968
+ $gtm4wp_grouped_product_ix++;
969
+
970
+ $labelvalue .=
971
+ sprintf(
972
+ '<span class="gtm4wp_productdata" style="display:none; visibility:hidden;" data-gtm4wp_product_id="%s" data-gtm4wp_product_sku="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_product_listposition="%s" data-gtm4wp_productlist_name="%s" data-gtm4wp_product_stocklevel="%s" data-gtm4wp_product_brand="%s"></span>',
973
+ esc_attr( $eec_product_array['id'] ),
974
+ esc_attr( $eec_product_array['sku'] ),
975
+ esc_attr( $eec_product_array['name'] ),
976
+ esc_attr( $eec_product_array['price'] ),
977
+ esc_attr( $eec_product_array['category'] ),
978
+ esc_url( $eec_product_array['productlink'] ),
979
+ esc_attr( $eec_product_array['listposition'] ),
980
+ esc_attr( $eec_product_array['listname'] ),
981
+ esc_attr( $eec_product_array['stocklevel'] ),
982
+ esc_attr( $eec_product_array['brand'] )
983
+ );
984
+
985
+ return $labelvalue;
986
+ }
987
+
988
  // do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin
989
  if ( function_exists( 'WC' ) ) {
990
  add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, 'gtm4wp_woocommerce_datalayer_filter_items' );
1003
  add_action( 'woocommerce_after_template_part', 'gtm4wp_woocommerce_after_template_part' );
1004
  add_filter( 'widget_title', 'gtm4wp_widget_title_filter' );
1005
  add_action( 'wc_quick_view_before_single_product', 'gtm4wp_wc_quick_view_before_single_product' );
1006
+ add_filter( 'woocommerce_grouped_product_list_column_label', 'gtm4wp_woocommerce_grouped_product_list_column_label', 10, 2 );
1007
 
1008
  add_filter( 'woocommerce_cart_item_product', 'gtm4wp_woocommerce_cart_item_product_filter' );
1009
  add_filter( 'woocommerce_cart_item_remove_link', 'gtm4wp_woocommerce_cart_item_remove_link_filter' );
js/admin-subtabs.js CHANGED
@@ -67,7 +67,7 @@ var adminsubtabs = {
67
  },
68
  "int-wc": {
69
  tabtext: gtm4wp.wctabtitle,
70
- numitems: 14
71
  },
72
  "int-google-optimize": {
73
  tabtext: gtm4wp.gotabtitle,
67
  },
68
  "int-wc": {
69
  tabtext: gtm4wp.wctabtitle,
70
+ numitems: 15
71
  },
72
  "int-google-optimize": {
73
  tabtext: gtm4wp.gotabtitle,
js/gtm4wp-woocommerce-classic.js CHANGED
@@ -15,12 +15,15 @@ jQuery(function() {
15
  var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
16
  var _product_name = jQuery( '[name=gtm4wp_name]', _product_form ).val();
17
  var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
 
18
 
19
- window[ gtm4wp_datalayer_name ].push({
20
- 'event': 'gtm4wp.addProductToCart',
21
- 'productName': _product_name,
22
- 'productSKU': _product_sku,
23
- 'productID': _product_id
24
- });
 
 
25
  });
26
- });
15
  var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
16
  var _product_name = jQuery( '[name=gtm4wp_name]', _product_form ).val();
17
  var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
18
+ var _product_is_grouped = jQuery( _product_form ).hasClass( 'grouped_form' );
19
 
20
+ if ( ! _product_is_grouped ) {
21
+ window[ gtm4wp_datalayer_name ].push({
22
+ 'event': 'gtm4wp.addProductToCart',
23
+ 'productName': _product_name,
24
+ 'productSKU': _product_sku,
25
+ 'productID': _product_id
26
+ });
27
+ }
28
  });
29
+ });
js/gtm4wp-woocommerce-enhanced.js CHANGED
@@ -177,14 +177,7 @@ jQuery(function() {
177
  jQuery( document ).on( 'click', '.single_add_to_cart_button', function() {
178
  var _product_form = jQuery( this ).closest( 'form.cart' );
179
  var _product_var_id = jQuery( '[name=variation_id]', _product_form );
180
- var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
181
- var _product_name = jQuery( '[name=gtm4wp_name]', _product_form ).val();
182
- var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
183
- var _product_category = jQuery( '[name=gtm4wp_category]', _product_form ).val();
184
- var _product_price = jQuery( '[name=gtm4wp_price]', _product_form ).val();
185
- var _product_currency = jQuery( '[name=gtm4wp_currency]', _product_form ).val();
186
- var _product_stocklevel = jQuery( '[name=gtm4wp_stocklevel]', _product_form ).val();
187
- var _product_brand = jQuery( '[name=gtm4wp_brand]', _product_form ).val();
188
 
189
  if ( _product_var_id.length > 0 ) {
190
  if ( gtm4wp_last_selected_product_variation ) {
@@ -193,27 +186,69 @@ jQuery(function() {
193
  window[ gtm4wp_datalayer_name ].push({
194
  'event': 'gtm4wp.addProductToCartEEC',
195
  'ecommerce': {
196
- 'currencyCode': _product_currency,
197
  'add': {
198
  'products': [gtm4wp_last_selected_product_variation]
199
  }
200
  }
201
  });
202
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  } else {
204
  window[ gtm4wp_datalayer_name ].push({
205
  'event': 'gtm4wp.addProductToCartEEC',
206
  'ecommerce': {
207
- 'currencyCode': _product_currency,
208
  'add': {
209
  'products': [{
210
- 'id': gtm4wp_use_sku_instead ? _product_sku : _product_id,
211
- 'name': _product_name,
212
- 'price': _product_price,
213
- 'category': _product_category,
214
- 'quantity': jQuery( 'form.cart:first input[name=quantity]' ).val(),
215
- 'stocklevel': _product_stocklevel,
216
- 'brand': _product_brand
217
  }]
218
  }
219
  }
@@ -264,7 +299,7 @@ jQuery(function() {
264
  });
265
 
266
  // track clicks in product lists
267
- jQuery( document ).on( 'click', '.products li:not(.product-category) a:not(.add_to_cart_button):not(.quick-view-button),.products>div:not(.product-category) a:not(.add_to_cart_button):not(.quick-view-button),.widget-product-item', function( event ) {
268
  // do nothing if GTM is blocked for some reason
269
  if ( 'undefined' == typeof google_tag_manager ) {
270
  return true;
@@ -287,8 +322,15 @@ jQuery(function() {
287
 
288
  if ( _productdata.length > 0 ) {
289
  productdata = _productdata.find( '.gtm4wp_productdata' );
 
290
  } else {
291
- productdata = jQuery( this );
 
 
 
 
 
 
292
  }
293
  }
294
  }
@@ -357,7 +399,6 @@ jQuery(function() {
357
  var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
358
  var _product_category = jQuery( '[name=gtm4wp_category]', _product_form ).val();
359
  var _product_price = jQuery( '[name=gtm4wp_price]', _product_form ).val();
360
- var _product_currency = jQuery( '[name=gtm4wp_currency]', _product_form ).val();
361
  var _product_stocklevel = jQuery( '[name=gtm4wp_stocklevel]', _product_form ).val();
362
  var _product_brand = jQuery( '[name=gtm4wp_brand]', _product_form ).val();
363
 
@@ -387,7 +428,7 @@ jQuery(function() {
387
  window[ gtm4wp_datalayer_name ].push({
388
  'event': 'gtm4wp.changeDetailViewEEC',
389
  'ecommerce': {
390
- 'currencyCode': _product_currency,
391
  'detail': {
392
  'products': [current_product_detail_data]
393
  },
@@ -515,16 +556,12 @@ jQuery(function() {
515
  if ( gtm4wp_checkout_step_fired.indexOf( 'shipping_method' ) == -1 ) {
516
  // shipping methods are not visible if only one is available
517
  // and if the user has already a pre-selected method, no click event will fire to report the checkout step
518
- jQuery( 'input[name^=shipping_method]:checked' ).trigger( 'click' );
519
-
520
- gtm4wp_checkout_step_fired.push( 'shipping_method' );
521
  }
522
 
523
  if ( gtm4wp_checkout_step_fired.indexOf( 'payment_method' ) == -1 ) {
524
  // if the user has already a pre-selected method, no click event will fire to report the checkout step
525
- jQuery( 'input[name=payment_method]:checked' ).trigger( 'click' );
526
-
527
- gtm4wp_checkout_step_fired.push( 'payment_method' );
528
  }
529
 
530
  var _shipping_el = jQuery( '#shipping_method input:checked' );
177
  jQuery( document ).on( 'click', '.single_add_to_cart_button', function() {
178
  var _product_form = jQuery( this ).closest( 'form.cart' );
179
  var _product_var_id = jQuery( '[name=variation_id]', _product_form );
180
+ var _product_is_grouped = jQuery( _product_form ).hasClass( 'grouped_form' );
 
 
 
 
 
 
 
181
 
182
  if ( _product_var_id.length > 0 ) {
183
  if ( gtm4wp_last_selected_product_variation ) {
186
  window[ gtm4wp_datalayer_name ].push({
187
  'event': 'gtm4wp.addProductToCartEEC',
188
  'ecommerce': {
189
+ 'currencyCode': gtm4wp_currency,
190
  'add': {
191
  'products': [gtm4wp_last_selected_product_variation]
192
  }
193
  }
194
  });
195
  }
196
+ } else if ( _product_is_grouped ) {
197
+ var _products_in_group = jQuery( '.grouped_form .gtm4wp_productdata' );
198
+ var _products_eec = [];
199
+
200
+ _products_in_group.each( function() {
201
+ var productdata = jQuery( this );
202
+
203
+ var product_qty_input = jQuery( 'input[name=quantity\\[' + productdata.data( 'gtm4wp_product_id' ) + '\\]]' );
204
+ if ( product_qty_input.length > 0 ) {
205
+ product_qty = product_qty_input.val();
206
+ } else {
207
+ return;
208
+ }
209
+
210
+ if ( 0 == product_qty ) {
211
+ return;
212
+ }
213
+
214
+ _products_eec.push({
215
+ 'id': gtm4wp_use_sku_instead ? productdata.data( 'gtm4wp_product_sku' ) : productdata.data( 'gtm4wp_product_id' ),
216
+ 'name': productdata.data( 'gtm4wp_product_name' ),
217
+ 'price': productdata.data( 'gtm4wp_product_price' ),
218
+ 'category': productdata.data( 'gtm4wp_product_cat' ),
219
+ 'quantity': product_qty,
220
+ 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
221
+ 'brand': productdata.data( 'gtm4wp_product_brand' )
222
+ });
223
+ });
224
+
225
+ if ( 0 == _products_eec.length ) {
226
+ return;
227
+ }
228
+
229
+ window[ gtm4wp_datalayer_name ].push({
230
+ 'event': 'gtm4wp.addProductToCartEEC',
231
+ 'ecommerce': {
232
+ 'currencyCode': gtm4wp_currency,
233
+ 'add': {
234
+ 'products': _products_eec
235
+ }
236
+ }
237
+ });
238
  } else {
239
  window[ gtm4wp_datalayer_name ].push({
240
  'event': 'gtm4wp.addProductToCartEEC',
241
  'ecommerce': {
242
+ 'currencyCode': gtm4wp_currency,
243
  'add': {
244
  'products': [{
245
+ 'id': gtm4wp_use_sku_instead ? jQuery( '[name=gtm4wp_sku]', _product_form ).val() : jQuery( '[name=gtm4wp_id]', _product_form ).val(),
246
+ 'name': jQuery( '[name=gtm4wp_name]', _product_form ).val(),
247
+ 'price': jQuery( '[name=gtm4wp_price]', _product_form ).val(),
248
+ 'category': jQuery( '[name=gtm4wp_category]', _product_form ).val(),
249
+ 'quantity': jQuery( 'form.cart:first input[name=quantity]' ).val(),
250
+ 'stocklevel': jQuery( '[name=gtm4wp_stocklevel]', _product_form ).val(),
251
+ 'brand': jQuery( '[name=gtm4wp_brand]', _product_form ).val()
252
  }]
253
  }
254
  }
299
  });
300
 
301
  // track clicks in product lists
302
+ jQuery( document ).on( 'click', '.products li:not(.product-category) a:not(.add_to_cart_button):not(.quick-view-button),.products>div:not(.product-category) a:not(.add_to_cart_button):not(.quick-view-button),.widget-product-item,.woocommerce-grouped-product-list-item__label a', function( event ) {
303
  // do nothing if GTM is blocked for some reason
304
  if ( 'undefined' == typeof google_tag_manager ) {
305
  return true;
322
 
323
  if ( _productdata.length > 0 ) {
324
  productdata = _productdata.find( '.gtm4wp_productdata' );
325
+
326
  } else {
327
+ _productdata = jQuery( this ).closest( '.woocommerce-grouped-product-list-item__label' );
328
+
329
+ if ( _productdata.length > 0 ) {
330
+ productdata = _productdata.find( '.gtm4wp_productdata' );
331
+ } else {
332
+ productdata = jQuery( this );
333
+ }
334
  }
335
  }
336
  }
399
  var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
400
  var _product_category = jQuery( '[name=gtm4wp_category]', _product_form ).val();
401
  var _product_price = jQuery( '[name=gtm4wp_price]', _product_form ).val();
 
402
  var _product_stocklevel = jQuery( '[name=gtm4wp_stocklevel]', _product_form ).val();
403
  var _product_brand = jQuery( '[name=gtm4wp_brand]', _product_form ).val();
404
 
428
  window[ gtm4wp_datalayer_name ].push({
429
  'event': 'gtm4wp.changeDetailViewEEC',
430
  'ecommerce': {
431
+ 'currencyCode': gtm4wp_currency,
432
  'detail': {
433
  'products': [current_product_detail_data]
434
  },
556
  if ( gtm4wp_checkout_step_fired.indexOf( 'shipping_method' ) == -1 ) {
557
  // shipping methods are not visible if only one is available
558
  // and if the user has already a pre-selected method, no click event will fire to report the checkout step
559
+ jQuery( 'input[name^=shipping_method]:checked' ).trigger( 'change' );
 
 
560
  }
561
 
562
  if ( gtm4wp_checkout_step_fired.indexOf( 'payment_method' ) == -1 ) {
563
  // if the user has already a pre-selected method, no click event will fire to report the checkout step
564
+ jQuery( 'input[name=payment_method]:checked' ).trigger( 'change' );
 
 
565
  }
566
 
567
  var _shipping_el = jQuery( '#shipping_method input:checked' );
public/frontend.php CHANGED
@@ -553,7 +553,7 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
553
  $dataLayer['weatherTemp'] = $weatherdata->main->temp;
554
  $dataLayer['weatherPressure'] = $weatherdata->main->pressure;
555
  $dataLayer['weatherWindSpeed'] = $weatherdata->wind->speed;
556
- $dataLayer['weatherWindDeg'] = ( $weatherdata->wind->deg ? $weatherdata->wind->deg : '' );
557
  $dataLayer['weatherFullWeatherData'] = $weatherdata;
558
  $dataLayer['weatherDataStatus'] = 'Read from cache';
559
  } else {
@@ -860,10 +860,15 @@ function gtm4wp_wp_header_begin( $echo = true ) {
860
  if ( dataLayer_content.transactionId || ( dataLayer_content.ecommerce && dataLayer_content.ecommerce.purchase ) ) {
861
  // read order id already tracked from cookies
862
  var gtm4wp_orderid_tracked = "";
863
- var gtm4wp_cookie = "; " + document.cookie;
864
- var gtm4wp_cookie_parts = gtm4wp_cookie.split( "; gtm4wp_orderid_tracked=" );
865
- if ( gtm4wp_cookie_parts.length == 2 ) {
866
- gtm4wp_orderid_tracked = gtm4wp_cookie_parts.pop().split(";").shift();
 
 
 
 
 
867
  }
868
 
869
  // check enhanced ecommerce
@@ -896,10 +901,14 @@ function gtm4wp_wp_header_begin( $echo = true ) {
896
  }
897
 
898
  if ( gtm4wp_orderid_tracked ) {
899
- var gtm4wp_orderid_cookie_expire = new Date();
900
- gtm4wp_orderid_cookie_expire.setTime( gtm4wp_orderid_cookie_expire.getTime() + (365*24*60*60*1000) );
901
- var gtm4wp_orderid_cookie_expires = "expires="+ gtm4wp_orderid_cookie_expire.toUTCString();
902
- document.cookie = "gtm4wp_orderid_tracked=" + gtm4wp_orderid_tracked + ";" + gtm4wp_orderid_cookie_expire + ";path=/";
 
 
 
 
903
  }
904
 
905
  }';
@@ -959,7 +968,7 @@ function gtm4wp_body_class( $classes ) {
959
 
960
  // solution is based on the code of Yaniv Friedensohn
961
  // http://www.affectivia.com/blog/placing-the-google-tag-manager-in-wordpress-after-the-body-tag/
962
- if ( GTM4WP_PLACEMENT_BODYOPEN_AUTO == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
963
  $classes[] = '">' . gtm4wp_get_the_gtm_tag() . '<br style="display:none;';
964
  }
965
 
@@ -1007,6 +1016,8 @@ add_action( 'body_open', 'gtm4wp_wp_body_open' );
1007
  add_action( 'genesis_before', 'gtm4wp_wp_body_open' ); // Genisis theme
1008
  add_action( 'generate_before_header', 'gtm4wp_wp_body_open', 0 ); // GeneratePress theme
1009
  add_action( 'elementor/page_templates/canvas/before_content', 'gtm4wp_wp_body_open' ); // Elementor
 
 
1010
 
1011
  // standard WP theme support for body open tags
1012
  add_action( 'wp_body_open', 'gtm4wp_wp_body_open' );
553
  $dataLayer['weatherTemp'] = $weatherdata->main->temp;
554
  $dataLayer['weatherPressure'] = $weatherdata->main->pressure;
555
  $dataLayer['weatherWindSpeed'] = $weatherdata->wind->speed;
556
+ $dataLayer['weatherWindDeg'] = ( isset($weatherdata->wind->deg) ? $weatherdata->wind->deg : '' );
557
  $dataLayer['weatherFullWeatherData'] = $weatherdata;
558
  $dataLayer['weatherDataStatus'] = 'Read from cache';
559
  } else {
860
  if ( dataLayer_content.transactionId || ( dataLayer_content.ecommerce && dataLayer_content.ecommerce.purchase ) ) {
861
  // read order id already tracked from cookies
862
  var gtm4wp_orderid_tracked = "";
863
+
864
+ if ( !window.localStorage ) {
865
+ var gtm4wp_cookie = "; " + document.cookie;
866
+ var gtm4wp_cookie_parts = gtm4wp_cookie.split( "; gtm4wp_orderid_tracked=" );
867
+ if ( gtm4wp_cookie_parts.length == 2 ) {
868
+ gtm4wp_orderid_tracked = gtm4wp_cookie_parts.pop().split(";").shift();
869
+ }
870
+ } else {
871
+ window.localStorage.getItem( "gtm4wp_orderid_tracked" );
872
  }
873
 
874
  // check enhanced ecommerce
901
  }
902
 
903
  if ( gtm4wp_orderid_tracked ) {
904
+ if ( !window.localStorage ) {
905
+ var gtm4wp_orderid_cookie_expire = new Date();
906
+ gtm4wp_orderid_cookie_expire.setTime( gtm4wp_orderid_cookie_expire.getTime() + (365*24*60*60*1000) );
907
+ var gtm4wp_orderid_cookie_expires_part = "expires=" + gtm4wp_orderid_cookie_expire.toUTCString();
908
+ document.cookie = "gtm4wp_orderid_tracked=" + gtm4wp_orderid_tracked + ";" + gtm4wp_orderid_cookie_expires_part + ";path=/";
909
+ } else {
910
+ window.localStorage.setItem( "gtm4wp_orderid_tracked", gtm4wp_orderid_tracked );
911
+ }
912
  }
913
 
914
  }';
968
 
969
  // solution is based on the code of Yaniv Friedensohn
970
  // http://www.affectivia.com/blog/placing-the-google-tag-manager-in-wordpress-after-the-body-tag/
971
+ if ( ( GTM4WP_PLACEMENT_BODYOPEN_AUTO == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) && ( !isset($_GET["ct_builder"]) ) ) {
972
  $classes[] = '">' . gtm4wp_get_the_gtm_tag() . '<br style="display:none;';
973
  }
974
 
1016
  add_action( 'genesis_before', 'gtm4wp_wp_body_open' ); // Genisis theme
1017
  add_action( 'generate_before_header', 'gtm4wp_wp_body_open', 0 ); // GeneratePress theme
1018
  add_action( 'elementor/page_templates/canvas/before_content', 'gtm4wp_wp_body_open' ); // Elementor
1019
+ add_action( 'ct_before_builder', 'gtm4wp_wp_body_open', 0 ); // Oxygen Builder
1020
+ add_action( 'fl_before_builder', 'gtm4wp_wp_body_open', 0 ); // Beaver Builder Theme
1021
 
1022
  // standard WP theme support for body open tags
1023
  add_action( 'wp_body_open', 'gtm4wp_wp_body_open' );
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: https://gtm4wp.com/
4
  Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, google ads, adwords remarketing, google ads remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel, google optimize, personalisation
5
  Requires at least: 3.4.0
6
  Requires PHP: 5.6
7
- Tested up to: 5.2.2
8
- Stable tag: 1.10.1
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
@@ -258,9 +258,44 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So
258
 
259
  == Changelog ==
260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  = 1.10.1 =
 
262
  * Fixed: wrong cookie name was used with the newly introduced double transaction tracking protection while setting the cookie
263
  * Fixed: double transaction tracking JavaScript code is now only included on the order received page
 
264
  * Fixed: replaced all references to AdWords to Google Ads
265
 
266
  = 1.10 =
@@ -602,6 +637,10 @@ Please report all bugs found in my plugin using the [contact form on my website]
602
 
603
  == Upgrade Notice ==
604
 
 
 
 
 
605
  = 1.10.1 =
606
 
607
  Bugfix release
4
  Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, google ads, adwords remarketing, google ads remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel, google optimize, personalisation
5
  Requires at least: 3.4.0
6
  Requires PHP: 5.6
7
+ Tested up to: 5.2.4
8
+ Stable tag: 1.11
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
258
 
259
  == Changelog ==
260
 
261
+ = 1.11 =
262
+
263
+ WARNING!
264
+ Please read the changelog very carefully as there are many important changes and removed features which could need your attention before updating!
265
+
266
+ * Added Oxygen Builder and Beaver Builder Theme support - you can now use the codeless placement option without issues
267
+ * Added ability to fix the Google Tag Manager ID and GTM Environment parameters in wp-config.php. To use it, create PHP constants with the names
268
+ ** GTM4WP_HARDCODED_GTM_ID
269
+ ** GTM4WP_HARDCODED_GTM_ENV_AUTH
270
+ ** GTM4WP_HARDCODED_GTM_ENV_PREVIEW
271
+ * Added support for WooCommerce Grouped Products
272
+ * Added new WooCommerce option to add all order data into the data layer on the order reveived page
273
+ ** This includes personal data of the customer -> you need to ensure this is used in a privacy friendly and compliant way!
274
+ ** This order data will be always present on the order received page, even if the page is reloaded or later revisited!
275
+ * Removed several unofficial data layer variables on the WooCommerce order received page as they can be read using the new order data option
276
+ ** transactionDate
277
+ ** transactionType
278
+ ** transactionPaymentType
279
+ ** transactionShippingMethod
280
+ ** transactionPromoCode
281
+ * Improved: price reporting with the WooCommerce enhanced ecommerce integration now follows the option set with the 'Display prices in the shop' option of WooCommerce
282
+ * Improved: from WooCommerce 3.7 WC_Abstract_Order::get_used_coupons() was replaced with WC_Abstract_Order::get_coupon_codes() which is now used if WC 3.7+ is detected
283
+ * Improved: use localStorage for WooCommerce duplicate transaction tracking prevention if available. Should be work with Safari at least for now.
284
+ * Fixed: WooCommerce duplicate transaction tracking prevention's cookie was set to expire on session end, now adds 1 year.
285
+ * Deprecated data layer variable productIsVariable. Use the new productType data layer variable which will equal to simple, variable, grouped or external depending on the type of the product shown
286
+ * Fixed: Wrong lookup for product brand name if Use SKU instead of product ID option was turned on
287
+ * Fixed: Wrong lookup for product brand name for variable products
288
+ * Fixed: check if $woo->customer is initialized
289
+ * Fixed: no checkout step reported on WooCommerce checkout page if the user has accepted the default selection of the payment and shipping methods
290
+
291
+ ! Planned deprecation of support for WooCommerce 2.x-3.1.x with next plugin version !
292
+ ! Planned deprecation of support for WordPress 4.x with next plugin version !
293
+
294
  = 1.10.1 =
295
+
296
  * Fixed: wrong cookie name was used with the newly introduced double transaction tracking protection while setting the cookie
297
  * Fixed: double transaction tracking JavaScript code is now only included on the order received page
298
+ * Fixed: product impressions not properly reported if Products per impressions were set to 0
299
  * Fixed: replaced all references to AdWords to Google Ads
300
 
301
  = 1.10 =
637
 
638
  == Upgrade Notice ==
639
 
640
+ = 1.11 =
641
+
642
+ Please read the changelog very carefully as there are many important changes and removed features which could need your attention before updating!
643
+
644
  = 1.10.1 =
645
 
646
  Bugfix release