DuracellTomi's Google Tag Manager for WordPress - Version 1.7.2

Version Description

  • Fixed: in some cases, the remove item from cart link in a WooCommerce cart was not altered properly with additional tracking codes
  • Fixed: product categories were empty in the cart, on the checkout pages and on the order received page for product variations
  • Fixed: checkout option data included checkout step #1 if cart page was setup to be the first
  • Fixed: even more WooCommerce 3.x compatibility
  • Added: registration date of the logged in user can be added to the data layer
  • Updated: geoplugin.net has been replaced by freegeoip.net for weather tracking which has far better quota for free usage
  • Updated: AdWords dynamic remarketing data layer items on a WooCommerce product page will be shown for the root product as well on variable product pages
  • Updated: Selecting a product variation will include the price of the product in AdWords dynamic remarketing data layer items
  • Updated: minor code cleanup
Download this release

Release Info

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

Code changes from version 1.7.1 to 1.7.2

admin/admin.php CHANGED
@@ -103,6 +103,11 @@ $GLOBALS["gtm4wp_includefieldtexts"] = array(
103
  "description" => __( "Check this option to include the email address of the logged in user.", 'duracelltomi-google-tag-manager' ),
104
  "phase" => GTM4WP_PHASE_STABLE
105
  ),
 
 
 
 
 
106
  GTM4WP_OPTION_INCLUDE_REMARKETING => array(
107
  "label" => __( "Remarketing variable", 'duracelltomi-google-tag-manager' ),
108
  "description" => __( "Check this option to include a dataLayer variable where all dataLayer values are stored to be included in your AdWords remarketing tag as a custom variable field", 'duracelltomi-google-tag-manager' ),
@@ -438,7 +443,7 @@ $GLOBALS["gtm4wp_integratefieldtexts"] = array(
438
 
439
  GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => array(
440
  "label" => __( "Google Optimize page-hiding snippet ID list", 'duracelltomi-google-tag-manager' ),
441
- "description" => sprintf( __( "Enter a comma separated list of Google Optimizie container IDs that you would like to use on your site using Google Tag Manager. This plugin will add the <a href=\"%s\">page-hiding snippet</a> to your pages.", 'duracelltomi-google-tag-manager' ), 'https://developers.google.com/optimize/#the_page-hiding_snippet_code' ) .
442
  '<br /><span class="goid_validation_error">' . __( "This does not seems to be a valid Google Optimize ID! Valid format: GTM-XXXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile IDs.", 'duracelltomi-google-tag-manager' ) . '</span>',
443
  "phase" => GTM4WP_PHASE_EXPERIMENTAL
444
  ),
103
  "description" => __( "Check this option to include the email address of the logged in user.", 'duracelltomi-google-tag-manager' ),
104
  "phase" => GTM4WP_PHASE_STABLE
105
  ),
106
+ GTM4WP_OPTION_INCLUDE_USERREGDATE => array(
107
+ "label" => __( "Logged in user creation date", 'duracelltomi-google-tag-manager' ),
108
+ "description" => __( "Check this option to include the date of creation (registration) of the logged in user.", 'duracelltomi-google-tag-manager' ),
109
+ "phase" => GTM4WP_PHASE_STABLE
110
+ ),
111
  GTM4WP_OPTION_INCLUDE_REMARKETING => array(
112
  "label" => __( "Remarketing variable", 'duracelltomi-google-tag-manager' ),
113
  "description" => __( "Check this option to include a dataLayer variable where all dataLayer values are stored to be included in your AdWords remarketing tag as a custom variable field", 'duracelltomi-google-tag-manager' ),
443
 
444
  GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => array(
445
  "label" => __( "Google Optimize page-hiding snippet ID list", 'duracelltomi-google-tag-manager' ),
446
+ "description" => sprintf( __( "Enter a comma separated list of Google Optimize container IDs that you would like to use on your site using Google Tag Manager. This plugin will add the <a href=\"%s\">page-hiding snippet</a> to your pages.", 'duracelltomi-google-tag-manager' ), 'https://developers.google.com/optimize/#the_page-hiding_snippet_code' ) .
447
  '<br /><span class="goid_validation_error">' . __( "This does not seems to be a valid Google Optimize ID! Valid format: GTM-XXXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile IDs.", 'duracelltomi-google-tag-manager' ) . '</span>',
448
  "phase" => GTM4WP_PHASE_EXPERIMENTAL
449
  ),
common/readoptions.php CHANGED
@@ -9,6 +9,7 @@ define( 'GTM4WP_OPTION_INCLUDE_LOGGEDIN', 'include-loggedin' );
9
  define( 'GTM4WP_OPTION_INCLUDE_USERROLE', 'include-userrole' );
10
  define( 'GTM4WP_OPTION_INCLUDE_USERID', 'include-userid' );
11
  define( 'GTM4WP_OPTION_INCLUDE_USEREMAIL', 'include-useremail' );
 
12
  define( 'GTM4WP_OPTION_INCLUDE_POSTTYPE', 'include-posttype' );
13
  define( 'GTM4WP_OPTION_INCLUDE_CATEGORIES', 'include-categories' );
14
  define( 'GTM4WP_OPTION_INCLUDE_TAGS', 'include-tags' );
@@ -110,6 +111,7 @@ $gtm4wp_defaultoptions = array(
110
  GTM4WP_OPTION_INCLUDE_USERROLE => false,
111
  GTM4WP_OPTION_INCLUDE_USERID => false,
112
  GTM4WP_OPTION_INCLUDE_USEREMAIL => false,
 
113
  GTM4WP_OPTION_INCLUDE_POSTTYPE => true,
114
  GTM4WP_OPTION_INCLUDE_CATEGORIES => true,
115
  GTM4WP_OPTION_INCLUDE_TAGS => true,
9
  define( 'GTM4WP_OPTION_INCLUDE_USERROLE', 'include-userrole' );
10
  define( 'GTM4WP_OPTION_INCLUDE_USERID', 'include-userid' );
11
  define( 'GTM4WP_OPTION_INCLUDE_USEREMAIL', 'include-useremail' );
12
+ define( 'GTM4WP_OPTION_INCLUDE_USERREGDATE', 'include-userregdate' );
13
  define( 'GTM4WP_OPTION_INCLUDE_POSTTYPE', 'include-posttype' );
14
  define( 'GTM4WP_OPTION_INCLUDE_CATEGORIES', 'include-categories' );
15
  define( 'GTM4WP_OPTION_INCLUDE_TAGS', 'include-tags' );
111
  GTM4WP_OPTION_INCLUDE_USERROLE => false,
112
  GTM4WP_OPTION_INCLUDE_USERID => false,
113
  GTM4WP_OPTION_INCLUDE_USEREMAIL => false,
114
+ GTM4WP_OPTION_INCLUDE_USERREGDATE => false,
115
  GTM4WP_OPTION_INCLUDE_POSTTYPE => true,
116
  GTM4WP_OPTION_INCLUDE_CATEGORIES => true,
117
  GTM4WP_OPTION_INCLUDE_TAGS => true,
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.7.1
5
  Plugin URI: https://duracelltomi.com/google-tag-manager-for-wordpress/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
@@ -10,7 +10,7 @@ Text Domain: duracelltomi-google-tag-manager
10
  Domain Path: /languages
11
  */
12
 
13
- define( 'GTM4WP_VERSION', '1.7.1' );
14
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
15
 
16
  $gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
+ Version: 1.7.2
5
  Plugin URI: https://duracelltomi.com/google-tag-manager-for-wordpress/
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
 
13
+ define( 'GTM4WP_VERSION', '1.7.2' );
14
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
15
 
16
  $gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
integration/woocommerce.php CHANGED
@@ -3,10 +3,10 @@ define( 'GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY', 'gtm4wp_eec_product_array' );
3
 
4
  $gtm4wp_product_counter = 0;
5
  $gtm4wp_last_widget_title = "Sidebar Products";
6
- $gtm4wp_is_woocommerce3 = version_compare( $GLOBALS["woocommerce"]->version, "3.0", ">=" );
7
 
8
  function gtm4wp_woocommerce_addjs( $js ) {
9
- global $woocommerce;
10
 
11
  if ( version_compare( $woocommerce->version, "2.1", ">=" ) ) {
12
  wc_enqueue_js( $js );
@@ -29,15 +29,22 @@ function gtm4wp_prefix_productid( $product_id ) {
29
  }
30
  }
31
 
 
 
 
 
 
 
 
32
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
33
  global $woocommerce, $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter, $gtm4wp_is_woocommerce3;
34
 
35
  if ( is_product_category() || is_product_tag() || is_front_page() || is_shop() ) {
36
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
37
- $dataLayer["ecomm_prodid"] = array();
38
- $dataLayer["ecomm_pagetype"] = ( is_front_page() ? "home" : "category" );
39
- $dataLayer["ecomm_totalvalue"] = 0;
40
- }
41
  } else if ( is_product() ) {
42
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
43
  $postid = get_the_ID();
@@ -51,16 +58,17 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
51
  } else {
52
  $product_cat = "";
53
  }
54
-
55
- if ( "variable" != $product->get_type() ) {
56
- $product_price = $product->get_price();
57
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
58
- $product_sku = $product->get_sku();
59
- if ( "" != $product_sku ) {
60
- $product_id = $product_sku;
61
- }
62
  }
 
 
 
63
 
 
64
  $_temp_productdata = array(
65
  "name" => gtm4wp_woocommerce_html_entity_decode( get_the_title() ),
66
  "id" => $product_id,
@@ -70,8 +78,6 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
70
  $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "productdetail" );
71
 
72
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
73
- $remarketing_id = (string)$product_id;
74
-
75
  $dataLayer["ecomm_prodid"] = gtm4wp_prefix_productid( $remarketing_id );
76
  $dataLayer["ecomm_pagetype"] = "product";
77
  $dataLayer["ecomm_totalvalue"] = (float)$eec_product_array[ "price" ];
@@ -85,9 +91,9 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
85
  );
86
  }
87
  } else {
88
- $dataLayer["ecomm_prodid"] = array();
89
  $dataLayer["ecomm_pagetype"] = "product";
90
- $dataLayer["ecomm_totalvalue"] = 0;
91
 
92
  gtm4wp_woocommerce_addjs("
93
  var gtm4wp_use_sku_instead = " . (int)($gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ]) . ";
@@ -103,7 +109,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
103
  var current_product_detail_data = gtm4wp_product_detail_data;
104
  current_product_detail_data.id = product_variation.variation_id;
105
  if ( gtm4wp_use_sku_instead && product_variation.sku && ('' != product_variation.sku) ) {
106
- current_product_detail_data.id = product_variation.sku;
107
  }
108
  current_product_detail_data.price = product_variation.display_price;
109
 
@@ -123,7 +129,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
123
  },
124
  'ecomm_prodid': '".gtm4wp_prefix_productid("")."' + current_product_detail_data.id,
125
  'ecomm_pagetype': 'product',
126
- 'ecomm_totalvalue': 0
127
  });
128
  });
129
 
@@ -194,9 +200,15 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
194
  foreach( $woocommerce->cart->get_cart() as $cart_item_id => $cart_item_data) {
195
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data["data"], $cart_item_data, $cart_item_id );
196
 
197
- $product_id = $product->get_id();
 
198
 
199
- $_product_cats = get_the_terms($product_id, 'product_cat');
 
 
 
 
 
200
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
201
  $product_cat = array_pop( $_product_cats );
202
  $product_cat = $product_cat->name;
@@ -219,7 +231,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
219
  "quantity" => $cart_item_data["quantity"]
220
  );
221
 
222
- if ( "variation" == $product->get_type() ) {
223
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
224
  }
225
 
@@ -242,14 +254,14 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
242
  }
243
 
244
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
245
- $dataLayer["ecommerce"] = array(
246
- "checkout" => array(
247
- "actionField" => array(
248
- "step" => 1
249
- ),
250
- "products" => $gtm4wp_cart_products
251
- )
252
- );
253
  }
254
  }
255
  } else if ( is_order_received_page() ) {
@@ -318,14 +330,17 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
318
 
319
  if ( $order->get_items() ) {
320
  foreach ( $order->get_items() as $item ) {
321
- if ( $gtm4wp_is_woocommerce3 ) {
322
- $product = $item->get_product();
 
 
 
 
 
 
323
  } else {
324
- $product = $order->get_product_from_item( $item );
325
  }
326
-
327
- $product_id = $product->get_id();
328
- $_product_cats = get_the_terms($product_id, 'product_cat');
329
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
330
  $product_cat = array_pop( $_product_cats );
331
  $product_cat = $product_cat->name;
@@ -341,16 +356,16 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
341
 
342
  $product_price = $order->get_item_total( $item );
343
  $_temp_productdata = array(
344
- "id" => $remarketing_id,
345
- "name" => $item['name'],
346
- "sku" => $product_sku ? __( 'SKU:', 'duracelltomi-google-tag-manager' ) . ' ' . $product_sku : $product_id,
347
- "category" => $product_cat,
348
- "price" => $product_price,
349
- "currency" => get_woocommerce_currency(),
350
- "quantity" => $item['qty']
351
  );
352
 
353
- if ( "variation" == $product->get_type() ) {
354
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
355
  }
356
 
@@ -390,8 +405,14 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
390
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data["data"], $cart_item_data, $cart_item_id );
391
 
392
  $product_id = $product->get_id();
 
393
 
394
- $_product_cats = get_the_terms($product_id, 'product_cat');
 
 
 
 
 
395
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
396
  $product_cat = array_pop( $_product_cats );
397
  $product_cat = $product_cat->name;
@@ -413,7 +434,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
413
  "quantity" => $cart_item_data["quantity"]
414
  );
415
 
416
- if ( "variation" == $product->get_type() ) {
417
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
418
  }
419
 
@@ -431,44 +452,44 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
431
  }
432
 
433
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
434
- $dataLayer["ecommerce"] = array(
435
- "checkout" => array(
436
- "actionField" => array(
437
- "step" => 1 + (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ]
438
- ),
439
- "products" => $gtm4wp_checkout_products
440
- )
441
- );
442
-
443
- gtm4wp_woocommerce_addjs("
444
- $( 'form[name=checkout]' ).on( 'submit', function() {
445
- var _checkout_option = [];
446
-
447
- var _shipping_el = $( '#shipping_method input:checked' );
448
- if ( _shipping_el.length > 0 ) {
449
- _checkout_option.push( 'Shipping: ' + _shipping_el.val() );
450
- }
451
-
452
- var _payment_el = $( '.payment_methods input:checked' );
453
- if ( _payment_el.length > 0 ) {
454
- _checkout_option.push( 'Payment: ' + _payment_el.val() );
455
- }
456
-
457
- if ( _checkout_option.length > 0 ) {
458
- ". $gtm4wp_datalayer_name .".push({
459
- 'event': 'gtm4wp.checkoutOptionECC',
460
- 'ecommerce': {
461
- 'checkout_option': {
462
- 'actionField': {
463
- 'step': 1,
464
- 'option': _checkout_option.join( ', ' )
465
- }
466
- }
467
- }
468
- });
469
- }
470
- });");
471
- }
472
  }
473
  } else {
474
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
@@ -523,9 +544,16 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
523
  $cart_item = $woocommerce->cart->get_cart_item( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] );
524
  if ( !empty( $cart_item ) ) {
525
  $product = $cart_item["data"];
526
- $product_id = $product->get_id();
527
-
528
- $_product_cats = get_the_terms($product_id, 'product_cat');
 
 
 
 
 
 
 
529
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
530
  $product_cat = array_pop( $_product_cats );
531
  $product_cat = $product_cat->name;
@@ -539,15 +567,15 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
539
  $remarketing_id = $product_sku;
540
  }
541
 
542
- $dataLayer["ecommerce"]["add"]["products"][] = array(
543
- "name" => $product->get_title(),
544
- "id" => $remarketing_id,
545
- "price" => $product->get_price(),
546
- "category" => $product_cat,
547
- "quantity" => $cart_item["quantity"]
548
- );
549
-
550
- if ( "variation" == $product->get_type() ) {
551
  $dataLayer["ecommerce"]["add"][0][ "variant" ] = implode(",", $product->get_variation_attributes());
552
  }
553
  }
@@ -692,7 +720,7 @@ function gtm4wp_woocommerce_wp_footer() {
692
  ");
693
  }
694
 
695
- if ( ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) && ( ! is_cart() ) ) {
696
  echo "
697
  <script data-cfasync='false' type='text/javascript'>
698
  (function($) {
@@ -763,7 +791,7 @@ function gtm4wp_woocommerce_wp_footer() {
763
  });
764
  });
765
  }
766
- })(jQuery);
767
  </script>";
768
 
769
  gtm4wp_woocommerce_addjs("
@@ -861,76 +889,19 @@ function gtm4wp_woocommerce_enhanced_ecom_product_click() {
861
  ");
862
  }
863
 
864
- function gtm4wp_woocommerce_add_prod_data( $add_to_cart_link ) {
865
- global $product, $woocommerce_loop, $wp_query, $gtm4wp_options;
866
-
867
- $product_id = $product->get_id();
868
- $_product_cats = get_the_terms($product_id, 'product_cat');
869
- if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
870
- $product_cat = array_pop( $_product_cats );
871
- $product_cat = $product_cat->name;
872
- } else {
873
- $product_cat = "";
874
- }
875
-
876
- if ( is_search() ) {
877
- $list_name = __( "Search Results", "duracelltomi-google-tag-manager" );
878
- } else if ( isset( $woocommerce_loop[ "listtype" ] ) && ( $woocommerce_loop[ "listtype" ] != '' ) ) {
879
- $list_name = $woocommerce_loop[ "listtype" ];
880
- } else {
881
- $list_name = __( "General Product List", "duracelltomi-google-tag-manager" );
882
- }
883
-
884
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
885
- $posts_per_page = get_query_var('posts_per_page');
886
- if ( $posts_per_page < 1 ) {
887
- $posts_per_page = 1;
888
- }
889
-
890
- $remarketing_id = $product_id;
891
- $product_sku = $product->get_sku();
892
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
893
- $remarketing_id = $product_sku;
894
- }
895
-
896
- $_temp_productdata = array(
897
- "id" => $remarketing_id,
898
- "name" => $product->get_title(),
899
- "category" => $product_cat,
900
- "price" => $product->get_price(),
901
- "productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
902
- "listposition" => $woocommerce_loop[ "loop" ] + ( $posts_per_page * ($paged-1) ),
903
- "listname" => $list_name
904
- );
905
-
906
- if ( "variation" == $product->get_type() ) {
907
- $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
908
- } else {
909
- $_temp_productdata[ "variant" ] = "";
910
- }
911
-
912
- $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "addtocartproductlist" );
913
-
914
- $cartlink_with_data = sprintf('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_variant="%s" href="',
915
- esc_attr( $eec_product_array[ "id" ] ),
916
- esc_attr( $eec_product_array[ "name" ] ),
917
- esc_attr( $eec_product_array[ "price" ] ),
918
- esc_attr( $eec_product_array[ "category" ] ),
919
- esc_url( $eec_product_array[ "productlink" ] ),
920
- esc_attr( $eec_product_array[ "listposition" ] ),
921
- esc_attr( $eec_product_array[ "listname" ] ),
922
- esc_attr( $eec_product_array[ "variant" ] )
923
- );
924
-
925
- return str_replace( 'href="', $cartlink_with_data, $add_to_cart_link );
926
- }
927
-
928
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
929
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $cart_id="" ) {
930
- global $gtm4wp_options;
931
 
932
- $product_id = $product->get_id();
933
- $_product_cats = get_the_terms($product_id, 'product_cat');
 
 
 
 
 
 
 
934
  if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
935
  $product_cat = array_pop( $_product_cats );
936
  $product_cat = $product_cat->name;
@@ -949,13 +920,12 @@ function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $
949
  "name" => $product->get_title(),
950
  "price" => $product->get_price(),
951
  "category" => $product_cat,
952
- "productlink" => apply_filters( 'the_permalink', get_permalink(), 0)
 
953
  );
954
 
955
- if ( "variation" == $product->get_type() ) {
956
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
957
- } else {
958
- $_temp_productdata[ "variant" ] = "";
959
  }
960
 
961
  $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "cart" );
@@ -965,13 +935,13 @@ function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $
965
  }
966
 
967
  function gtm4wp_woocommerce_cart_item_remove_link_filter( $remove_from_cart_link ) {
968
- if ( ! isset( $GLOBALS["gtm4wp_cart_item_proddata"] ) ) {
969
- return $remove_from_cart_link;
970
- }
971
 
972
- if ( ! is_array( $GLOBALS["gtm4wp_cart_item_proddata"] ) ) {
973
- return $remove_from_cart_link;
974
- }
975
 
976
  $cartlink_with_data = sprintf('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" href="',
977
  esc_attr( $GLOBALS["gtm4wp_cart_item_proddata"]["id"] ),
@@ -983,7 +953,7 @@ function gtm4wp_woocommerce_cart_item_remove_link_filter( $remove_from_cart_link
983
  );
984
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
985
 
986
- return str_replace( 'href="', $cartlink_with_data, $remove_from_cart_link );
987
  }
988
 
989
  function gtp4wp_woocommerce_reset_loop() {
@@ -1000,6 +970,22 @@ function gtm4wp_woocommerce_add_related_to_loop( $arg ) {
1000
  return $arg;
1001
  }
1002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1003
  function gtm4wp_woocommerce_before_template_part( $template_name ) {
1004
  ob_start();
1005
  }
@@ -1164,9 +1150,9 @@ function gtm4wp_woocommerce_before_shop_loop_item() {
1164
  }
1165
 
1166
  function gtm4wp_woocommerce_cart_item_restored( $cart_item_key ) {
1167
- global $woocommerce;
1168
 
1169
- setcookie( "gtm4wp_product_readded_to_cart", $cart_item_key );
1170
  }
1171
 
1172
  // do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin
@@ -1177,7 +1163,6 @@ if ( isset ( $GLOBALS["woocommerce"] ) ) {
1177
 
1178
  add_action( "woocommerce_before_shop_loop_item", "gtm4wp_woocommerce_before_shop_loop_item" );
1179
 
1180
- // add_filter( "woocommerce_loop_add_to_cart_link", "gtm4wp_woocommerce_add_prod_data" );
1181
  add_action( "woocommerce_after_add_to_cart_button", "gtm4wp_woocommerce_single_add_to_cart_tracking" );
1182
  add_action( "wp_footer", "gtm4wp_woocommerce_wp_footer" );
1183
 
@@ -1187,10 +1172,13 @@ if ( isset ( $GLOBALS["woocommerce"] ) ) {
1187
  add_action( 'woocommerce_after_template_part', 'gtm4wp_woocommerce_after_template_part' );
1188
  add_filter( 'widget_title', 'gtm4wp_widget_title_filter' );
1189
 
1190
- add_filter( "woocommerce_cart_item_product", "gtm4wp_woocommerce_cart_item_product_filter" );
1191
  add_filter( "woocommerce_cart_item_remove_link", "gtm4wp_woocommerce_cart_item_remove_link_filter" );
1192
 
1193
- add_filter( "woocommerce_related_products_args", "gtm4wp_woocommerce_add_related_to_loop" );
 
 
 
1194
 
1195
  add_action( 'woocommerce_shortcode_before_recent_products_loop', 'gtm4wp_before_recent_products_loop' );
1196
  add_action( 'woocommerce_shortcode_before_sale_products_loop', 'gtm4wp_before_sale_products_loop' );
3
 
4
  $gtm4wp_product_counter = 0;
5
  $gtm4wp_last_widget_title = "Sidebar Products";
6
+ $GLOBALS["gtm4wp_is_woocommerce3"] = version_compare( $GLOBALS["woocommerce"]->version, "3.0", ">=" );
7
 
8
  function gtm4wp_woocommerce_addjs( $js ) {
9
+ global $woocommerce;
10
 
11
  if ( version_compare( $woocommerce->version, "2.1", ">=" ) ) {
12
  wc_enqueue_js( $js );
29
  }
30
  }
31
 
32
+ // from https://stackoverflow.com/questions/1252693/using-str-replace-so-that-it-only-acts-on-the-first-match
33
+ function gtm4wp_str_replace_first($from, $to, $subject) {
34
+ $from = '/'.preg_quote($from, '/').'/';
35
+
36
+ return preg_replace($from, $to, $subject, 1);
37
+ }
38
+
39
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
40
  global $woocommerce, $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter, $gtm4wp_is_woocommerce3;
41
 
42
  if ( is_product_category() || is_product_tag() || is_front_page() || is_shop() ) {
43
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
44
+ $dataLayer["ecomm_prodid"] = array();
45
+ $dataLayer["ecomm_pagetype"] = ( is_front_page() ? "home" : "category" );
46
+ $dataLayer["ecomm_totalvalue"] = 0;
47
+ }
48
  } else if ( is_product() ) {
49
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
50
  $postid = get_the_ID();
58
  } else {
59
  $product_cat = "";
60
  }
61
+
62
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
63
+ $product_sku = $product->get_sku();
64
+ if ( "" != $product_sku ) {
65
+ $product_id = $product_sku;
 
 
 
66
  }
67
+ }
68
+ $remarketing_id = (string)$product_id;
69
+ $product_price = $product->get_price();
70
 
71
+ if ( "variable" != $product->get_type() ) {
72
  $_temp_productdata = array(
73
  "name" => gtm4wp_woocommerce_html_entity_decode( get_the_title() ),
74
  "id" => $product_id,
78
  $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "productdetail" );
79
 
80
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
 
 
81
  $dataLayer["ecomm_prodid"] = gtm4wp_prefix_productid( $remarketing_id );
82
  $dataLayer["ecomm_pagetype"] = "product";
83
  $dataLayer["ecomm_totalvalue"] = (float)$eec_product_array[ "price" ];
91
  );
92
  }
93
  } else {
94
+ $dataLayer["ecomm_prodid"] = gtm4wp_prefix_productid( $remarketing_id );
95
  $dataLayer["ecomm_pagetype"] = "product";
96
+ $dataLayer["ecomm_totalvalue"] = $product_price;
97
 
98
  gtm4wp_woocommerce_addjs("
99
  var gtm4wp_use_sku_instead = " . (int)($gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ]) . ";
109
  var current_product_detail_data = gtm4wp_product_detail_data;
110
  current_product_detail_data.id = product_variation.variation_id;
111
  if ( gtm4wp_use_sku_instead && product_variation.sku && ('' != product_variation.sku) ) {
112
+ current_product_detail_data.id = product_variation.sku;
113
  }
114
  current_product_detail_data.price = product_variation.display_price;
115
 
129
  },
130
  'ecomm_prodid': '".gtm4wp_prefix_productid("")."' + current_product_detail_data.id,
131
  'ecomm_pagetype': 'product',
132
+ 'ecomm_totalvalue': current_product_detail_data.price
133
  });
134
  });
135
 
200
  foreach( $woocommerce->cart->get_cart() as $cart_item_id => $cart_item_data) {
201
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data["data"], $cart_item_data, $cart_item_id );
202
 
203
+ $product_id = $product->get_id();
204
+ $product_type = $product->get_type();
205
 
206
+ if ( "variation" == $product_type ) {
207
+ $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id);
208
+ $_product_cats = get_the_terms($parent_product_id, 'product_cat');
209
+ } else {
210
+ $_product_cats = get_the_terms($product_id, 'product_cat');
211
+ }
212
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
213
  $product_cat = array_pop( $_product_cats );
214
  $product_cat = $product_cat->name;
231
  "quantity" => $cart_item_data["quantity"]
232
  );
233
 
234
+ if ( "variation" == $product_type ) {
235
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
236
  }
237
 
254
  }
255
 
256
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
257
+ $dataLayer["ecommerce"] = array(
258
+ "checkout" => array(
259
+ "actionField" => array(
260
+ "step" => 1
261
+ ),
262
+ "products" => $gtm4wp_cart_products
263
+ )
264
+ );
265
  }
266
  }
267
  } else if ( is_order_received_page() ) {
330
 
331
  if ( $order->get_items() ) {
332
  foreach ( $order->get_items() as $item ) {
333
+ $product = ( $gtm4wp_is_woocommerce3 ? $item->get_product() : $order->get_product_from_item( $item ) ) ;
334
+
335
+ $product_id = $product->get_id();
336
+ $product_type = $product->get_type();
337
+
338
+ if ( "variation" == $product_type ) {
339
+ $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id);
340
+ $_product_cats = get_the_terms($parent_product_id, 'product_cat');
341
  } else {
342
+ $_product_cats = get_the_terms($product_id, 'product_cat');
343
  }
 
 
 
344
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
345
  $product_cat = array_pop( $_product_cats );
346
  $product_cat = $product_cat->name;
356
 
357
  $product_price = $order->get_item_total( $item );
358
  $_temp_productdata = array(
359
+ "id" => $remarketing_id,
360
+ "name" => $item['name'],
361
+ "sku" => $product_sku ? __( 'SKU:', 'duracelltomi-google-tag-manager' ) . ' ' . $product_sku : $product_id,
362
+ "category" => $product_cat,
363
+ "price" => $product_price,
364
+ "currency" => get_woocommerce_currency(),
365
+ "quantity" => $item['qty']
366
  );
367
 
368
+ if ( "variation" == $product_type ) {
369
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
370
  }
371
 
405
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data["data"], $cart_item_data, $cart_item_id );
406
 
407
  $product_id = $product->get_id();
408
+ $product_type = $product->get_type();
409
 
410
+ if ( "variation" == $product_type ) {
411
+ $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id);
412
+ $_product_cats = get_the_terms($parent_product_id, 'product_cat');
413
+ } else {
414
+ $_product_cats = get_the_terms($product_id, 'product_cat');
415
+ }
416
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
417
  $product_cat = array_pop( $_product_cats );
418
  $product_cat = $product_cat->name;
434
  "quantity" => $cart_item_data["quantity"]
435
  );
436
 
437
+ if ( "variation" == $product_type ) {
438
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
439
  }
440
 
452
  }
453
 
454
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
455
+ $dataLayer["ecommerce"] = array(
456
+ "checkout" => array(
457
+ "actionField" => array(
458
+ "step" => 1 + (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ]
459
+ ),
460
+ "products" => $gtm4wp_checkout_products
461
+ )
462
+ );
463
+
464
+ gtm4wp_woocommerce_addjs("
465
+ $( 'form[name=checkout]' ).on( 'submit', function() {
466
+ var _checkout_option = [];
467
+
468
+ var _shipping_el = $( '#shipping_method input:checked' );
469
+ if ( _shipping_el.length > 0 ) {
470
+ _checkout_option.push( 'Shipping: ' + _shipping_el.val() );
471
+ }
472
+
473
+ var _payment_el = $( '.payment_methods input:checked' );
474
+ if ( _payment_el.length > 0 ) {
475
+ _checkout_option.push( 'Payment: ' + _payment_el.val() );
476
+ }
477
+
478
+ if ( _checkout_option.length > 0 ) {
479
+ ". $gtm4wp_datalayer_name .".push({
480
+ 'event': 'gtm4wp.checkoutOptionECC',
481
+ 'ecommerce': {
482
+ 'checkout_option': {
483
+ 'actionField': {
484
+ 'step': 1 + " . (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ",
485
+ 'option': _checkout_option.join( ', ' )
486
+ }
487
+ }
488
+ }
489
+ });
490
+ }
491
+ });");
492
+ }
493
  }
494
  } else {
495
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
544
  $cart_item = $woocommerce->cart->get_cart_item( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] );
545
  if ( !empty( $cart_item ) ) {
546
  $product = $cart_item["data"];
547
+
548
+ $product_id = $product->get_id();
549
+ $product_type = $product->get_type();
550
+
551
+ if ( "variation" == $product_type ) {
552
+ $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id);
553
+ $_product_cats = get_the_terms($parent_product_id, 'product_cat');
554
+ } else {
555
+ $_product_cats = get_the_terms($product_id, 'product_cat');
556
+ }
557
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
558
  $product_cat = array_pop( $_product_cats );
559
  $product_cat = $product_cat->name;
567
  $remarketing_id = $product_sku;
568
  }
569
 
570
+ $dataLayer["ecommerce"]["add"]["products"][] = array(
571
+ "name" => $product->get_title(),
572
+ "id" => $remarketing_id,
573
+ "price" => $product->get_price(),
574
+ "category" => $product_cat,
575
+ "quantity" => $cart_item["quantity"]
576
+ );
577
+
578
+ if ( "variation" == $product_type ) {
579
  $dataLayer["ecommerce"]["add"][0][ "variant" ] = implode(",", $product->get_variation_attributes());
580
  }
581
  }
720
  ");
721
  }
722
 
723
+ if ( ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) && ( ! is_cart() ) && ( ! is_product() ) ) {
724
  echo "
725
  <script data-cfasync='false' type='text/javascript'>
726
  (function($) {
791
  });
792
  });
793
  }
794
+ })(jQuery);
795
  </script>";
796
 
797
  gtm4wp_woocommerce_addjs("
889
  ");
890
  }
891
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
892
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
893
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $cart_id="" ) {
894
+ global $gtm4wp_options, $gtm4wp_is_woocommerce3;
895
 
896
+ $product_id = $product->get_id();
897
+ $product_type = $product->get_type();
898
+
899
+ if ( "variation" == $product_type ) {
900
+ $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id);
901
+ $_product_cats = get_the_terms($parent_product_id, 'product_cat');
902
+ } else {
903
+ $_product_cats = get_the_terms($product_id, 'product_cat');
904
+ }
905
  if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
906
  $product_cat = array_pop( $_product_cats );
907
  $product_cat = $product_cat->name;
920
  "name" => $product->get_title(),
921
  "price" => $product->get_price(),
922
  "category" => $product_cat,
923
+ "productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
924
+ "variant" => ""
925
  );
926
 
927
+ if ( "variation" == $product_type ) {
928
  $_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
 
 
929
  }
930
 
931
  $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "cart" );
935
  }
936
 
937
  function gtm4wp_woocommerce_cart_item_remove_link_filter( $remove_from_cart_link ) {
938
+ if ( ! isset( $GLOBALS["gtm4wp_cart_item_proddata"] ) ) {
939
+ return $remove_from_cart_link;
940
+ }
941
 
942
+ if ( ! is_array( $GLOBALS["gtm4wp_cart_item_proddata"] ) ) {
943
+ return $remove_from_cart_link;
944
+ }
945
 
946
  $cartlink_with_data = sprintf('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" href="',
947
  esc_attr( $GLOBALS["gtm4wp_cart_item_proddata"]["id"] ),
953
  );
954
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
955
 
956
+ return gtm4wp_str_replace_first( 'href="', $cartlink_with_data, $remove_from_cart_link );
957
  }
958
 
959
  function gtp4wp_woocommerce_reset_loop() {
970
  return $arg;
971
  }
972
 
973
+ function gtm4wp_woocommerce_add_cross_sell_to_loop( $arg ) {
974
+ global $woocommerce_loop;
975
+
976
+ $woocommerce_loop[ "listtype" ] = __( "Cross-Sell Products", "duracelltomi-google-tag-manager" );
977
+
978
+ return $arg;
979
+ }
980
+
981
+ function gtm4wp_woocommerce_add_upsells_to_loop( $arg ) {
982
+ global $woocommerce_loop;
983
+
984
+ $woocommerce_loop[ "listtype" ] = __( "Upsell Products", "duracelltomi-google-tag-manager" );
985
+
986
+ return $arg;
987
+ }
988
+
989
  function gtm4wp_woocommerce_before_template_part( $template_name ) {
990
  ob_start();
991
  }
1150
  }
1151
 
1152
  function gtm4wp_woocommerce_cart_item_restored( $cart_item_key ) {
1153
+ global $woocommerce;
1154
 
1155
+ setcookie( "gtm4wp_product_readded_to_cart", $cart_item_key );
1156
  }
1157
 
1158
  // do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin
1163
 
1164
  add_action( "woocommerce_before_shop_loop_item", "gtm4wp_woocommerce_before_shop_loop_item" );
1165
 
 
1166
  add_action( "woocommerce_after_add_to_cart_button", "gtm4wp_woocommerce_single_add_to_cart_tracking" );
1167
  add_action( "wp_footer", "gtm4wp_woocommerce_wp_footer" );
1168
 
1172
  add_action( 'woocommerce_after_template_part', 'gtm4wp_woocommerce_after_template_part' );
1173
  add_filter( 'widget_title', 'gtm4wp_widget_title_filter' );
1174
 
1175
+ add_filter( "woocommerce_cart_item_product", "gtm4wp_woocommerce_cart_item_product_filter" );
1176
  add_filter( "woocommerce_cart_item_remove_link", "gtm4wp_woocommerce_cart_item_remove_link_filter" );
1177
 
1178
+ add_filter( "woocommerce_related_products_args", "gtm4wp_woocommerce_add_related_to_loop" );
1179
+ add_filter( "woocommerce_related_products_columns", "gtm4wp_woocommerce_add_related_to_loop" );
1180
+ add_filter( "woocommerce_cross_sells_columns", "gtm4wp_woocommerce_add_cross_sell_to_loop" );
1181
+ add_filter( "woocommerce_upsells_columns", "gtm4wp_woocommerce_add_upsells_to_loop" );
1182
 
1183
  add_action( 'woocommerce_shortcode_before_recent_products_loop', 'gtm4wp_before_recent_products_loop' );
1184
  add_action( 'woocommerce_shortcode_before_sale_products_loop', 'gtm4wp_before_sale_products_loop' );
js/admin-subtabs.js CHANGED
@@ -12,7 +12,7 @@ var adminsubtabs = {
12
  },
13
  "visitor": {
14
  tabtext: gtm4wp.visitortabtitle,
15
- numitems: 4
16
  },
17
  "adwords": {
18
  tabtext: gtm4wp.adwordstabtitle,
12
  },
13
  "visitor": {
14
  tabtext: gtm4wp.visitortabtitle,
15
+ numitems: 5
16
  },
17
  "adwords": {
18
  tabtext: gtm4wp.adwordstabtitle,
public/frontend.php CHANGED
@@ -55,7 +55,7 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
55
  }
56
  }
57
 
58
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] ) {
59
  $current_user = wp_get_current_user();
60
 
61
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] ) {
@@ -65,6 +65,10 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
65
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] ) {
66
  $dataLayer["visitorEmail"] = ( empty( $current_user->user_email ) ? "" : $current_user->user_email );
67
  }
 
 
 
 
68
  }
69
 
70
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERID ] ) {
@@ -378,6 +382,7 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
378
  $dataLayer[ "weatherPressure" ] = 0;
379
  $dataLayer[ "weatherWindSpeed" ] = 0;
380
  $dataLayer[ "weatherWindDeg" ] = 0;
 
381
 
382
  $gtm4wp_sessionid = array_key_exists( "gtm4wp_sessoionid", $_COOKIE ) ? $_COOKIE[ "gtm4wp_sessoionid" ] : "";
383
  // this is needed so that nobody can do a hack by editing our cookie
@@ -393,6 +398,9 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
393
  $dataLayer[ "weatherPressure" ] = $weatherdata->main->pressure;
394
  $dataLayer[ "weatherWindSpeed" ] = $weatherdata->wind->speed;
395
  $dataLayer[ "weatherWindDeg" ] = $weatherdata->wind->deg;
 
 
 
396
  }
397
  }
398
  }
@@ -416,22 +424,32 @@ function gtm4wp_wp_loaded() {
416
  $weatherdata = get_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid );
417
 
418
  if ( false === $weatherdata ) {
419
- $gtm4wp_geodata = wp_remote_get( 'http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'] );
 
420
 
421
  if ( is_array( $gtm4wp_geodata ) && ( 200 == $gtm4wp_geodata[ "response" ][ "code" ] ) ) {
422
- $gtm4wp_geodata = unserialize( $gtm4wp_geodata[ "body" ] );
 
423
 
424
- if ( array_key_exists( 'geoplugin_latitude', $gtm4wp_geodata ) && array_key_exists( 'geoplugin_longitude', $gtm4wp_geodata ) ) {
425
- $weatherdata = wp_remote_get( 'http://api.openweathermap.org/data/2.5/weather?appid=' . $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI ] . '&lat=' . $gtm4wp_geodata[ "geoplugin_latitude" ] . '&lon=' . $gtm4wp_geodata[ "geoplugin_longitude" ] . '&units=' . ($gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHERUNITS ] == 0 ? 'metric' : 'imperial') );
426
 
427
  if ( is_array( $weatherdata ) && ( 200 == $weatherdata[ "response" ][ "code" ] ) ) {
428
  $weatherdata = @json_decode( $weatherdata[ "body" ] );
429
 
430
  if ( is_object( $weatherdata ) ) {
431
  set_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid, $weatherdata, 60 * 60 );
 
 
432
  }
 
 
433
  }
 
 
434
  }
 
 
435
  }
436
  }
437
  }
55
  }
56
  }
57
 
58
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERREGDATE ] ) {
59
  $current_user = wp_get_current_user();
60
 
61
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] ) {
65
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] ) {
66
  $dataLayer["visitorEmail"] = ( empty( $current_user->user_email ) ? "" : $current_user->user_email );
67
  }
68
+
69
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERREGDATE ] ) {
70
+ $dataLayer["visitorRegistrationDate"] = ( empty( $current_user->user_registered ) ? "" : strtotime($current_user->user_registered) );
71
+ }
72
  }
73
 
74
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERID ] ) {
382
  $dataLayer[ "weatherPressure" ] = 0;
383
  $dataLayer[ "weatherWindSpeed" ] = 0;
384
  $dataLayer[ "weatherWindDeg" ] = 0;
385
+ $dataLayer[ "weatherDataStatus" ] = "Initialized with empty data";
386
 
387
  $gtm4wp_sessionid = array_key_exists( "gtm4wp_sessoionid", $_COOKIE ) ? $_COOKIE[ "gtm4wp_sessoionid" ] : "";
388
  // this is needed so that nobody can do a hack by editing our cookie
398
  $dataLayer[ "weatherPressure" ] = $weatherdata->main->pressure;
399
  $dataLayer[ "weatherWindSpeed" ] = $weatherdata->wind->speed;
400
  $dataLayer[ "weatherWindDeg" ] = $weatherdata->wind->deg;
401
+ $dataLayer[ "weatherDataStatus" ] = "Read from cache";
402
+ } else {
403
+ $dataLayer[ "weatherDataStatus" ] = "GTM4WP session active but no weather data in cache (" . $gtm4wp_sessionid . ")";
404
  }
405
  }
406
  }
424
  $weatherdata = get_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid );
425
 
426
  if ( false === $weatherdata ) {
427
+ // $gtm4wp_geodata = wp_remote_get( 'http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'] );
428
+ $gtm4wp_geodata = @wp_remote_get( 'https://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR'] );
429
 
430
  if ( is_array( $gtm4wp_geodata ) && ( 200 == $gtm4wp_geodata[ "response" ][ "code" ] ) ) {
431
+ // $gtm4wp_geodata = unserialize( $gtm4wp_geodata[ "body" ] );
432
+ $gtm4wp_geodata = @json_decode( $gtm4wp_geodata[ "body" ] );
433
 
434
+ if ( is_object( $gtm4wp_geodata ) ) {
435
+ $weatherdata = wp_remote_get( 'http://api.openweathermap.org/data/2.5/weather?appid=' . $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI ] . '&lat=' . $gtm4wp_geodata->latitude . '&lon=' . $gtm4wp_geodata->longitude . '&units=' . ($gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHERUNITS ] == 0 ? 'metric' : 'imperial') );
436
 
437
  if ( is_array( $weatherdata ) && ( 200 == $weatherdata[ "response" ][ "code" ] ) ) {
438
  $weatherdata = @json_decode( $weatherdata[ "body" ] );
439
 
440
  if ( is_object( $weatherdata ) ) {
441
  set_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid, $weatherdata, 60 * 60 );
442
+ } else {
443
+ echo "<!-- GTM4WP weather data status: Openweathermap.org did not return processable data: " . var_dump( $weatherdata, true ) . " -->";
444
  }
445
+ } else {
446
+ echo "<!-- GTM4WP weather data status: Openweathermap.org returned status code: " . $weatherdata[ "response" ][ "code" ] . " -->";
447
  }
448
+ } else {
449
+ echo "<!-- GTM4WP weather data status: freegeoip.net did not return lat-lng data: " . var_dump( $gtm4wp_geodata, true ) . " -->";
450
  }
451
+ } else {
452
+ echo "<!-- GTM4WP weather data status: freegeoip.net returned status code: " . $gtm4wp_geodata[ "response" ][ "code" ] . " -->";
453
  }
454
  }
455
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: duracelltomi
3
  Donate link: https://duracelltomi.com/
4
  Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, adwords remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel
5
  Requires at least: 3.4.0
6
- Tested up to: 4.8.1
7
- Stable tag: 1.7.1
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
@@ -271,6 +271,18 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So
271
 
272
  == Changelog ==
273
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  = 1.7.1 =
275
 
276
  * Fixed: PHP 5.3 compatible syntax in frontend.php
@@ -500,6 +512,10 @@ Please report all bugs found in my plugin using the [contact form on my website]
500
 
501
  == Upgrade Notice ==
502
 
 
 
 
 
503
  = 1.7.1 =
504
 
505
  Bugfix release: better PHP 5.3 and WooCommerce 2.6.x compatibility
3
  Donate link: https://duracelltomi.com/
4
  Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, adwords remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel
5
  Requires at least: 3.4.0
6
+ Tested up to: 4.9.0
7
+ Stable tag: 1.7.2
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
271
 
272
  == Changelog ==
273
 
274
+ = 1.7.2 =
275
+
276
+ * Fixed: in some cases, the remove item from cart link in a WooCommerce cart was not altered properly with additional tracking codes
277
+ * Fixed: product categories were empty in the cart, on the checkout pages and on the order received page for product variations
278
+ * Fixed: checkout option data included checkout step #1 if cart page was setup to be the first
279
+ * Fixed: even more WooCommerce 3.x compatibility
280
+ * Added: registration date of the logged in user can be added to the data layer
281
+ * Updated: geoplugin.net has been replaced by freegeoip.net for weather tracking which has far better quota for free usage
282
+ * Updated: AdWords dynamic remarketing data layer items on a WooCommerce product page will be shown for the root product as well on variable product pages
283
+ * Updated: Selecting a product variation will include the price of the product in AdWords dynamic remarketing data layer items
284
+ * Updated: minor code cleanup
285
+
286
  = 1.7.1 =
287
 
288
  * Fixed: PHP 5.3 compatible syntax in frontend.php
512
 
513
  == Upgrade Notice ==
514
 
515
+ = 1.7.2 =
516
+
517
+ Bugfix release: many little fixes, event better WooCommerce 3.x compatibility
518
+
519
  = 1.7.1 =
520
 
521
  Bugfix release: better PHP 5.3 and WooCommerce 2.6.x compatibility