DuracellTomi's Google Tag Manager for WordPress - Version 1.16.2

Version Description

  • Fixed: server side GTM hostname did not work if domain name included a hyphen character
  • Fixed: user login and user registration data layer events were swapped, thanks danvy for the fix
  • Fixed: JavaScript error in Chrome around event.target.closest calls, thanks pinkasey for the fix
  • Fixed: cast _ga_tracked variable as integer to make the identical operator work correctly, thanks Irfan for the suggestion
  • Fixed: removed extra code added in 1.14 that reloads pages in Safari in WooCommerce integration. It broke some sites.
  • Updated: required PHP version raised to 7.4. Currently, this is not a hard requirement but from now I could include updates that will require this PHP version.
Download this release

Release Info

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

Code changes from version 1.16.1 to 1.16.2

admin/admin.php CHANGED
@@ -959,7 +959,7 @@ function gtm4wp_admin_init() {
959
  'description' => '<strong>Thomas Geiger</strong><br />
960
  Website: <a href="https://gtm4wp.com/" target="_blank" rel="noopener">gtm4wp.com</a><br />
961
  <a href="https://www.linkedin.com/in/duracelltomi" target="_blank" rel="noopener">Me on LinkedIn</a><br />
962
- <a href="http://www.linkedin.com/company/jabjab-online-marketing-ltd" target="_blank" rel="noopener">JabJab Online Marketing on LinkedIn</a>',
963
  )
964
  );
965
 
959
  'description' => '<strong>Thomas Geiger</strong><br />
960
  Website: <a href="https://gtm4wp.com/" target="_blank" rel="noopener">gtm4wp.com</a><br />
961
  <a href="https://www.linkedin.com/in/duracelltomi" target="_blank" rel="noopener">Me on LinkedIn</a><br />
962
+ <a href="https://www.linkedin.com/company/jabjab-online-marketing/" target="_blank" rel="noopener">JabJab Online Marketing on LinkedIn</a>',
963
  )
964
  );
965
 
duracelltomi-google-tag-manager-for-wordpress.php CHANGED
@@ -11,9 +11,9 @@
11
  * Plugin Name: GTM4WP
12
  * Plugin URI: https://gtm4wp.com/
13
  * Description: The first Google Tag Manager plugin for WordPress with business goals in mind
14
- * Version: 1.16.1
15
  * Requires at least: 3.4.0
16
- * Requires PHP: 5.6
17
  * Author: Thomas Geiger
18
  * Author URI: https://gtm4wp.com/
19
  * License: GPLv3
@@ -21,11 +21,11 @@
21
  * Text Domain: duracelltomi-google-tag-manager
22
  * Domain Path: /languages
23
 
24
- * WC requires at least: 3.2
25
- * WC tested up to: 6.6
26
  */
27
 
28
- define( 'GTM4WP_VERSION', '1.16.1' );
29
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
30
 
31
  global $gtp4wp_plugin_url, $gtp4wp_plugin_basename;
11
  * Plugin Name: GTM4WP
12
  * Plugin URI: https://gtm4wp.com/
13
  * Description: The first Google Tag Manager plugin for WordPress with business goals in mind
14
+ * Version: 1.16.2
15
  * Requires at least: 3.4.0
16
+ * Requires PHP: 7.4
17
  * Author: Thomas Geiger
18
  * Author URI: https://gtm4wp.com/
19
  * License: GPLv3
21
  * Text Domain: duracelltomi-google-tag-manager
22
  * Domain Path: /languages
23
 
24
+ * WC requires at least: 5.0
25
+ * WC tested up to: 7.1
26
  */
27
 
28
+ define( 'GTM4WP_VERSION', '1.16.2' );
29
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
30
 
31
  global $gtp4wp_plugin_url, $gtp4wp_plugin_basename;
integration/woocommerce.php CHANGED
@@ -285,7 +285,7 @@ function gtm4wp_map_eec_to_ga4( $productdata ) {
285
 
286
  $num_category_parts = min( 5, count( $category_parts ) );
287
  for ( $i = 1; $i < $num_category_parts; $i++ ) {
288
- $ga4_product[ 'item_category_' . (string) ( $i + 1 ) ] = $category_parts[ $i ];
289
  }
290
  }
291
 
@@ -840,7 +840,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $data_layer ) {
840
  );
841
  }
842
 
843
- if ( ( 1 === get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
844
  unset( $order );
845
  }
846
 
@@ -1012,7 +1012,7 @@ function gtm4wp_woocommerce_thankyou( $order_id ) {
1012
  }
1013
 
1014
  $do_not_flag_tracked_order = (bool) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG ] );
1015
- if ( ( 1 === get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
1016
  unset( $order );
1017
  }
1018
 
@@ -1653,35 +1653,6 @@ function gtm4wp_add_productdata_to_wc_block( $content, $data, $product ) {
1653
  return preg_replace( '/<li.+class=("|"[^"]+)wc-block-grid__product("|[^"]+")[^<]*>/i', '$0' . $product_data_tag, $content );
1654
  }
1655
 
1656
- /**
1657
- * Executed during wp_head with high priority.
1658
- * Adds a JavaScript code that reloads the page in Safari if the user landed on the page using the back button of the browser.
1659
- * Since the back button loads the previous state of the page instead of a new, clean state, some double tracking preventions
1660
- * break the functionality of GTM4WP.
1661
- *
1662
- * @return void
1663
- */
1664
- function gtm4wp_woocommerce_header_top() {
1665
- global $gtm4wp_options;
1666
-
1667
- $has_html5_support = current_theme_supports( 'html5' );
1668
- $add_cookiebot_ignore = $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_COOKIEBOT ];
1669
-
1670
- echo '<script' . ( $has_html5_support ? ' type="text/javascript"' : '' ) . ( $add_cookiebot_ignore ? ' data-cookieconsent="ignore"' : '' ) . ">
1671
- const gtm4wp_is_safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1672
- if ( gtm4wp_is_safari ) {
1673
- window.addEventListener('pageshow', function(event) {
1674
- if ( event.persisted ) {
1675
- // if Safari loads the page from cache usually by navigating with the back button
1676
- // it creates issues with product list click tracking
1677
- // therefore GTM4WP forces the page reload in this browser
1678
- window.location.reload();
1679
- }
1680
- });
1681
- }
1682
- </script>";
1683
- }
1684
-
1685
  // do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin.
1686
  if ( function_exists( 'WC' ) ) {
1687
  add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, 'gtm4wp_woocommerce_datalayer_filter_items' );
@@ -1719,7 +1690,5 @@ if ( function_exists( 'WC' ) ) {
1719
  add_action( 'woocommerce_shortcode_before_top_rated_products_loop', 'gtm4wp_before_top_rated_products_loop' );
1720
  add_action( 'woocommerce_shortcode_before_featured_products_loop', 'gtm4wp_before_featured_products_loop' );
1721
  add_action( 'woocommerce_shortcode_before_related_products_loop', 'gtm4wp_before_related_products_loop' );
1722
-
1723
- add_action( 'wp_head', 'gtm4wp_woocommerce_header_top', 1, 0 );
1724
  }
1725
  }
285
 
286
  $num_category_parts = min( 5, count( $category_parts ) );
287
  for ( $i = 1; $i < $num_category_parts; $i++ ) {
288
+ $ga4_product[ 'item_category' . (string) ( $i + 1 ) ] = $category_parts[ $i ];
289
  }
290
  }
291
 
840
  );
841
  }
842
 
843
+ if ( ( 1 === (int) get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
844
  unset( $order );
845
  }
846
 
1012
  }
1013
 
1014
  $do_not_flag_tracked_order = (bool) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG ] );
1015
+ if ( ( 1 === (int) get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
1016
  unset( $order );
1017
  }
1018
 
1653
  return preg_replace( '/<li.+class=("|"[^"]+)wc-block-grid__product("|[^"]+")[^<]*>/i', '$0' . $product_data_tag, $content );
1654
  }
1655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1656
  // do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin.
1657
  if ( function_exists( 'WC' ) ) {
1658
  add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, 'gtm4wp_woocommerce_datalayer_filter_items' );
1690
  add_action( 'woocommerce_shortcode_before_top_rated_products_loop', 'gtm4wp_before_top_rated_products_loop' );
1691
  add_action( 'woocommerce_shortcode_before_featured_products_loop', 'gtm4wp_before_featured_products_loop' );
1692
  add_action( 'woocommerce_shortcode_before_related_products_loop', 'gtm4wp_before_related_products_loop' );
 
 
1693
  }
1694
  }
js/gtm4wp-form-move-tracker.js CHANGED
@@ -1,33 +1,33 @@
1
- document.addEventListener("focusin", function(event) {
2
- const elem = event && event.target && event.target.closest("input,select,textarea,button,meter,progress");
3
- if ( elem ) {
4
- window[ gtm4wp_datalayer_name ].push({
5
- 'event' : 'gtm4wp.formElementEnter',
6
-
7
- 'inputID' : elem.getAttribute("id") || "(no input ID)",
8
- 'inputName' : elem.getAttribute("name") || "(no input name)",
9
- 'inputClass': elem.getAttribute("class") || "(no input class)",
10
-
11
- 'formID' : (elem.form && elem.form.getAttribute("id")) || "(no form ID)",
12
- 'formName' : (elem.form && elem.form.getAttribute("name")) || "(no form name)",
13
- 'formClass': (elem.form && elem.form.getAttribute("class")) || "(no form class)"
14
- });
15
- }
16
- }, false);
17
-
18
- document.addEventListener("focusout", function(event) {
19
- const elem = event && event.target && event.target.closest("input,select,textarea,button,meter,progress");
20
- if ( elem ) {
21
- window[ gtm4wp_datalayer_name ].push({
22
- 'event' : 'gtm4wp.formElementLeave',
23
-
24
- 'inputID' : elem.getAttribute("id") || "(no input ID)",
25
- 'inputName' : elem.getAttribute("name") || "(no input name)",
26
- 'inputClass': elem.getAttribute("class") || "(no input class)",
27
-
28
- 'formID' : (elem.form && elem.form.getAttribute("id")) || "(no form ID)",
29
- 'formName' : (elem.form && elem.form.getAttribute("name")) || "(no form name)",
30
- 'formClass': (elem.form && elem.form.getAttribute("class")) || "(no form class)"
31
- });
32
- };
33
- }, false);
1
+ document.addEventListener("focusin", function(event) {
2
+ const elem = event && event.target && event.target.closest && event.target.closest("input,select,textarea,button,meter,progress");
3
+ if ( elem ) {
4
+ window[ gtm4wp_datalayer_name ].push({
5
+ 'event' : 'gtm4wp.formElementEnter',
6
+
7
+ 'inputID' : elem.getAttribute("id") || "(no input ID)",
8
+ 'inputName' : elem.getAttribute("name") || "(no input name)",
9
+ 'inputClass': elem.getAttribute("class") || "(no input class)",
10
+
11
+ 'formID' : (elem.form && elem.form.getAttribute("id")) || "(no form ID)",
12
+ 'formName' : (elem.form && elem.form.getAttribute("name")) || "(no form name)",
13
+ 'formClass': (elem.form && elem.form.getAttribute("class")) || "(no form class)"
14
+ });
15
+ }
16
+ }, false);
17
+
18
+ document.addEventListener("focusout", function(event) {
19
+ const elem = event && event.target && event.target.closest && event.target.closest("input,select,textarea,button,meter,progress");
20
+ if ( elem ) {
21
+ window[ gtm4wp_datalayer_name ].push({
22
+ 'event' : 'gtm4wp.formElementLeave',
23
+
24
+ 'inputID' : elem.getAttribute("id") || "(no input ID)",
25
+ 'inputName' : elem.getAttribute("name") || "(no input name)",
26
+ 'inputClass': elem.getAttribute("class") || "(no input class)",
27
+
28
+ 'formID' : (elem.form && elem.form.getAttribute("id")) || "(no form ID)",
29
+ 'formName' : (elem.form && elem.form.getAttribute("name")) || "(no form name)",
30
+ 'formClass': (elem.form && elem.form.getAttribute("class")) || "(no form class)"
31
+ });
32
+ };
33
+ }, false);
js/gtm4wp-woocommerce-enhanced.js CHANGED
@@ -30,7 +30,7 @@ function gtm4wp_map_eec_to_ga4( productdata ) {
30
  } else if ( category_parts.length > 1 ) {
31
  ga4_product.item_category = category_parts[0];
32
  for( let i=1; i < Math.min( 5, category_parts.length ); i++ ) {
33
- ga4_product[ 'item_category_' + (i+1) ] = category_parts[i];
34
  }
35
  }
36
 
30
  } else if ( category_parts.length > 1 ) {
31
  ga4_product.item_category = category_parts[0];
32
  for( let i=1; i < Math.min( 5, category_parts.length ); i++ ) {
33
+ ga4_product[ 'item_category' + (i+1) ] = category_parts[i];
34
  }
35
  }
36
 
public/frontend.php CHANGED
@@ -680,12 +680,15 @@ function gtm4wp_get_the_gtm_tag() {
680
  $_gtm_env = '';
681
  }
682
 
683
- $_gtm_domain_name = 'www.googletagmanager.com';
684
- if (
685
- ( '' !== $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] ) &&
686
- ( preg_match( '/^[a-z0-9\.:]+$/', strtolower( $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] ) ) )
687
- ) {
688
- $_gtm_domain_name = $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ];
 
 
 
689
  }
690
 
691
  foreach ( $_gtm_codes as $one_gtm_id ) {
@@ -798,7 +801,7 @@ function gtm4wp_wp_footer() {
798
  $has_html5_support = current_theme_supports( 'html5' );
799
  $add_cookiebot_ignore = (bool) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_COOKIEBOT ];
800
 
801
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_NEWUSERREG ] ) {
802
  $user_logged_in = array_key_exists( 'gtm4wp_user_logged_in', $_COOKIE ) ?
803
  filter_var( wp_unslash( $_COOKIE['gtm4wp_user_logged_in'] ), FILTER_VALIDATE_INT )
804
  : 0;
@@ -817,7 +820,7 @@ function gtm4wp_wp_footer() {
817
  }
818
  }
819
 
820
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_USERLOGIN ] ) {
821
  $user_registered = array_key_exists( 'gtm4wp_user_registered', $_COOKIE ) ?
822
  filter_var( wp_unslash( $_COOKIE['gtm4wp_user_registered'] ), FILTER_VALIDATE_INT )
823
  : 0;
@@ -1087,12 +1090,15 @@ function gtm4wp_wp_header_begin( $echo = true ) {
1087
  continue;
1088
  }
1089
 
1090
- $_gtm_domain_name = 'www.googletagmanager.com';
1091
- if (
1092
- ( '' !== $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] ) &&
1093
- ( preg_match( '/^[a-z0-9\.:]+$/', strtolower( $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] ) ) )
1094
- ) {
1095
- $_gtm_domain_name = $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ];
 
 
 
1096
  }
1097
 
1098
  echo '
680
  $_gtm_env = '';
681
  }
682
 
683
+ // for PHP 7- compatibility.
684
+ if ( ! defined( 'FILTER_FLAG_HOSTNAME' ) ) {
685
+ define( 'FILTER_FLAG_HOSTNAME', 0 );
686
+ }
687
+
688
+ $_gtm_domain_test = ( '' === $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] ) ? 'www.googletagmanager.com' : strtolower( $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] );
689
+ $_gtm_domain_name = filter_var( $_gtm_domain_test, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME );
690
+ if ( false === $_gtm_domain_name ) {
691
+ $_gtm_domain_name = 'www.googletagmanager.com';
692
  }
693
 
694
  foreach ( $_gtm_codes as $one_gtm_id ) {
801
  $has_html5_support = current_theme_supports( 'html5' );
802
  $add_cookiebot_ignore = (bool) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_COOKIEBOT ];
803
 
804
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_USERLOGIN ] ) {
805
  $user_logged_in = array_key_exists( 'gtm4wp_user_logged_in', $_COOKIE ) ?
806
  filter_var( wp_unslash( $_COOKIE['gtm4wp_user_logged_in'] ), FILTER_VALIDATE_INT )
807
  : 0;
820
  }
821
  }
822
 
823
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_NEWUSERREG ] ) {
824
  $user_registered = array_key_exists( 'gtm4wp_user_registered', $_COOKIE ) ?
825
  filter_var( wp_unslash( $_COOKIE['gtm4wp_user_registered'] ), FILTER_VALIDATE_INT )
826
  : 0;
1090
  continue;
1091
  }
1092
 
1093
+ // for PHP 7- compatibility.
1094
+ if ( ! defined( 'FILTER_FLAG_HOSTNAME' ) ) {
1095
+ define( 'FILTER_FLAG_HOSTNAME', 0 );
1096
+ }
1097
+
1098
+ $_gtm_domain_test = ( '' === $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] ) ? 'www.googletagmanager.com' : strtolower( $gtm4wp_options[ GTM4WP_OPTION_GTMDOMAIN ] );
1099
+ $_gtm_domain_name = filter_var( $_gtm_domain_test, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME );
1100
+ if ( false === $_gtm_domain_name ) {
1101
+ $_gtm_domain_name = 'www.googletagmanager.com';
1102
  }
1103
 
1104
  echo '
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: duracelltomi
3
  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: 6.0.0
8
- Stable tag: 1.16.1
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
@@ -24,10 +24,7 @@ Google's official help pages includes [more details about the data layer](https:
24
 
25
  You can also add your Google Optimize container with the [recommended code setup](https://support.google.com/optimize/answer/7359264?hl=en)
26
 
27
- **Some parts of the plugin require PHP 5.6 newer.
28
- PHP 7.0 or newer is recommended.**
29
-
30
- Please note that PHP versions 7.2 or older already reached their end of life cycle thus it is recommended to upgrade. If you are not sure which version you are using, please contact your hosting provider for support.
31
 
32
  = GTM container code placement =
33
 
@@ -235,6 +232,15 @@ https://gtm4wp.com/how-to-articles/how-to-exclude-admin-users-from-being-tracked
235
 
236
  == Changelog ==
237
 
 
 
 
 
 
 
 
 
 
238
  = 1.16.1 =
239
 
240
  * Fixed: GTM ID not properly set in noscript tag (probably fixes some 403 errors with firewalls too)
@@ -811,6 +817,10 @@ Please report all bugs found in my plugin using the [contact form on my website]
811
 
812
  == Upgrade Notice ==
813
 
 
 
 
 
814
  = 1.16.1 =
815
 
816
  Bugfix release
3
  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: 7.4
7
+ Tested up to: 6.1.1
8
+ Stable tag: 1.16.2
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
24
 
25
  You can also add your Google Optimize container with the [recommended code setup](https://support.google.com/optimize/answer/7359264?hl=en)
26
 
27
+ **PHP 7.4 is required to use this plugin.**
 
 
 
28
 
29
  = GTM container code placement =
30
 
232
 
233
  == Changelog ==
234
 
235
+ = 1.16.2 =
236
+
237
+ * Fixed: server side GTM hostname did not work if domain name included a hyphen character
238
+ * Fixed: user login and user registration data layer events were swapped, thanks [danvy](https://github.com/danvy) for the fix
239
+ * Fixed: JavaScript error in Chrome around event.target.closest calls, thanks [pinkasey](https://github.com/pinkasey) for the fix
240
+ * Fixed: cast _ga_tracked variable as integer to make the identical operator work correctly, thanks [Irfan](https://github.com/in-codes) for the suggestion
241
+ * Fixed: removed extra code added in 1.14 that reloads pages in Safari in WooCommerce integration. It broke some sites.
242
+ * Updated: required PHP version raised to 7.4. Currently, this is not a hard requirement but from now I could include updates that will require this PHP version.
243
+
244
  = 1.16.1 =
245
 
246
  * Fixed: GTM ID not properly set in noscript tag (probably fixes some 403 errors with firewalls too)
817
 
818
  == Upgrade Notice ==
819
 
820
+ = 1.16.2 =
821
+
822
+ Bugfix release
823
+
824
  = 1.16.1 =
825
 
826
  Bugfix release