DuracellTomi's Google Tag Manager for WordPress - Version 1.5

Version Description

Lots of WooCommerce ecommerce codes has been changed and extended, please double check your measurement after upgrading to this version!

  • Added: warning message if you are using PHP 5.3 or older. Browser/OS/Device tracking needs 5.4 or newer
  • Added: Email address of the logged in user into the visitorEmail dataLayer variable. Remember: to comply with GTM TOS you are not allowed to pass this data towards any Google tag but you can use this in any other 3rd party tag.
  • Added: gtm4wp_eec_product_array WordPress filter so that plugin and theme authors can add their own data for enhanced ecommere product arrays
  • Fixed: JavaScript error in WooCommerce stores when enhanced ecommerce enabled and a product being clicked in a widget area
  • Fixed: Order data not present in some cases on the order received page
  • Changed: Extended "User SKUs instead of IDs for remarketing" option to be also applied to ecommerce product data arrays
  • Changed: Use wc_clean instead of the deprecated function woocommerce_clean
  • Changed: New, divided GTM container implemented - a fixed part in the and an iframe part placed using the container placement option you've set earlier
Download this release

Release Info

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

Code changes from version 1.4 to 1.5

admin/admin.php CHANGED
@@ -97,6 +97,11 @@ $GLOBALS["gtm4wp_includefieldtexts"] = array(
97
  "description" => __( "Check this option to include the ID of the logged in user.", 'duracelltomi-google-tag-manager' ),
98
  "phase" => GTM4WP_PHASE_STABLE
99
  ),
 
 
 
 
 
100
  GTM4WP_OPTION_INCLUDE_REMARKETING => array(
101
  "label" => __( "Remarketing variable", 'duracelltomi-google-tag-manager' ),
102
  "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' ),
@@ -418,9 +423,9 @@ $GLOBALS["gtm4wp_integratefieldtexts"] = array(
418
  "phase" => GTM4WP_PHASE_STABLE,
419
  "plugintocheck" => "woocommerce/woocommerce.php"
420
  ),
421
- GTM4WP_OPTION_INTEGRATE_WCREMARKETINGSKU => array(
422
  "label" => __( "Use SKU instead of ID", 'duracelltomi-google-tag-manager' ),
423
- "description" => __( "Check this to use product SKU in the dynamic remarketing variables instead of the ID of the products. Will fallback to ID if no SKU is set.", 'duracelltomi-google-tag-manager' ),
424
  "phase" => GTM4WP_PHASE_EXPERIMENTAL,
425
  "plugintocheck" => "woocommerce/woocommerce.php"
426
  )
@@ -440,6 +445,10 @@ function gtm4wp_admin_output_section( $args ) {
440
  _e( "Here you can check what data is needed to be included in the dataLayer to be able to access them in Google Tag Manager", 'duracelltomi-google-tag-manager' );
441
  echo "<br />";
442
  printf( __( '* Browser, OS and Device data is provided using <a href="%s">WhichBrowser</a> library.', 'duracelltomi-google-tag-manager' ), "http://whichbrowser.net/" );
 
 
 
 
443
 
444
  break;
445
  }
97
  "description" => __( "Check this option to include the ID of the logged in user.", 'duracelltomi-google-tag-manager' ),
98
  "phase" => GTM4WP_PHASE_STABLE
99
  ),
100
+ GTM4WP_OPTION_INCLUDE_USEREMAIL => array(
101
+ "label" => __( "Logged in user email", 'duracelltomi-google-tag-manager' ),
102
+ "description" => __( "Check this option to include the email address of the logged in user.", 'duracelltomi-google-tag-manager' ),
103
+ "phase" => GTM4WP_PHASE_STABLE
104
+ ),
105
  GTM4WP_OPTION_INCLUDE_REMARKETING => array(
106
  "label" => __( "Remarketing variable", 'duracelltomi-google-tag-manager' ),
107
  "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' ),
423
  "phase" => GTM4WP_PHASE_STABLE,
424
  "plugintocheck" => "woocommerce/woocommerce.php"
425
  ),
426
+ GTM4WP_OPTION_INTEGRATE_WCUSESKU => array(
427
  "label" => __( "Use SKU instead of ID", 'duracelltomi-google-tag-manager' ),
428
+ "description" => __( "Check this to use product SKU instead of the ID of the products for remarketing and ecommerce tracking. Will fallback to ID if no SKU is set.", 'duracelltomi-google-tag-manager' ),
429
  "phase" => GTM4WP_PHASE_EXPERIMENTAL,
430
  "plugintocheck" => "woocommerce/woocommerce.php"
431
  )
445
  _e( "Here you can check what data is needed to be included in the dataLayer to be able to access them in Google Tag Manager", 'duracelltomi-google-tag-manager' );
446
  echo "<br />";
447
  printf( __( '* Browser, OS and Device data is provided using <a href="%s">WhichBrowser</a> library.', 'duracelltomi-google-tag-manager' ), "http://whichbrowser.net/" );
448
+ if ( version_compare( PHP_VERSION, '5.4.0' ) < 0 ) {
449
+ echo "<br />";
450
+ _e( 'You are using an <strong>outdated</strong> version of PHP (5.3 or less). You <strong>should not turn on</strong> browser/device/os tracking as this can hurt your site. Please talk to your hosting and upgrade to PHP 5.4 or newer.', 'duracelltomi-google-tag-manager' );
451
+ }
452
 
453
  break;
454
  }
common/readoptions.php CHANGED
@@ -8,6 +8,7 @@ define( 'GTM4WP_OPTION_INCLUDE_REMARKETING', 'include-remarketing' );
8
  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_POSTTYPE', 'include-posttype' );
12
  define( 'GTM4WP_OPTION_INCLUDE_CATEGORIES', 'include-categories' );
13
  define( 'GTM4WP_OPTION_INCLUDE_TAGS', 'include-tags' );
@@ -83,7 +84,7 @@ define( 'GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE', 'integrate-woocommerce' );
83
  define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC', 'integrate-woocommerce-track-classic-ecommerce' );
84
  define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC', 'integrate-woocommerce-track-enhanced-ecommerce' );
85
  define( 'GTM4WP_OPTION_INTEGRATE_WCREMARKETING', 'integrate-woocommerce-remarketing' );
86
- define( 'GTM4WP_OPTION_INTEGRATE_WCREMARKETINGSKU', 'integrate-woocommerce-remarketing-usesku' );
87
 
88
  define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
89
 
@@ -103,6 +104,7 @@ $gtm4wp_defaultoptions = array(
103
  GTM4WP_OPTION_INCLUDE_LOGGEDIN => false,
104
  GTM4WP_OPTION_INCLUDE_USERROLE => false,
105
  GTM4WP_OPTION_INCLUDE_USERID => false,
 
106
  GTM4WP_OPTION_INCLUDE_POSTTYPE => true,
107
  GTM4WP_OPTION_INCLUDE_CATEGORIES => true,
108
  GTM4WP_OPTION_INCLUDE_TAGS => true,
@@ -178,7 +180,7 @@ $gtm4wp_defaultoptions = array(
178
  GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => false,
179
  GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC => false,
180
  GTM4WP_OPTION_INTEGRATE_WCREMARKETING => false,
181
- GTM4WP_OPTION_INTEGRATE_WCREMARKETINGSKU => false,
182
 
183
  GTM4WP_OPTION_INTEGRATE_WPECOMMERCE => false
184
  );
8
  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' );
84
  define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC', 'integrate-woocommerce-track-classic-ecommerce' );
85
  define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC', 'integrate-woocommerce-track-enhanced-ecommerce' );
86
  define( 'GTM4WP_OPTION_INTEGRATE_WCREMARKETING', 'integrate-woocommerce-remarketing' );
87
+ define( 'GTM4WP_OPTION_INTEGRATE_WCUSESKU', 'integrate-woocommerce-remarketing-usesku' );
88
 
89
  define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
90
 
104
  GTM4WP_OPTION_INCLUDE_LOGGEDIN => false,
105
  GTM4WP_OPTION_INCLUDE_USERROLE => false,
106
  GTM4WP_OPTION_INCLUDE_USERID => false,
107
+ GTM4WP_OPTION_INCLUDE_USEREMAIL => false,
108
  GTM4WP_OPTION_INCLUDE_POSTTYPE => true,
109
  GTM4WP_OPTION_INCLUDE_CATEGORIES => true,
110
  GTM4WP_OPTION_INCLUDE_TAGS => true,
180
  GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => false,
181
  GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC => false,
182
  GTM4WP_OPTION_INTEGRATE_WCREMARKETING => false,
183
+ GTM4WP_OPTION_INTEGRATE_WCUSESKU => false,
184
 
185
  GTM4WP_OPTION_INTEGRATE_WPECOMMERCE => false
186
  );
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.4
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.4' );
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.5
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.5' );
14
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
15
 
16
  $gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
integration/woocommerce.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  $gtm4wp_product_counter = 0;
3
  $gtm4wp_last_widget_title = "Sidebar Products";
4
 
5
  function gtm4wp_woocommerce_addjs( $js ) {
6
  global $woocommerce;
7
-
8
  if ( version_compare( $woocommerce->version, "2.1", ">=" ) ) {
9
  wc_enqueue_js( $js );
10
  } else {
@@ -28,6 +30,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
28
  } else if ( is_product() ) {
29
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
30
  $prodid = get_the_ID();
 
31
  $product = get_product( $prodid );
32
  $product_price = $product->get_price();
33
  $_product_cats = get_the_terms( $product->id, 'product_cat' );
@@ -37,30 +40,34 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
37
  } else {
38
  $product_cat = "";
39
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
42
  $remarketing_id = (string)$prodid;
43
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETINGSKU ] ) {
44
- $product_sku = $product->get_sku();
45
- if ( "" != $product_sku ) {
46
- $remarketing_id = $product_sku;
47
- }
48
- }
49
 
50
  $dataLayer["ecomm_prodid"] = $remarketing_id;
51
  $dataLayer["ecomm_pagetype"] = "product";
52
- $dataLayer["ecomm_totalvalue"] = (float)$product_price;
53
  }
54
-
55
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
56
  $dataLayer["ecommerce"] = array(
57
  "detail" => array(
58
- "products" => array(array(
59
- "name" => gtm4wp_woocommerce_html_entity_decode( get_the_title() ),
60
- "id" => $prodid,
61
- "price" => $product_price,
62
- "category" => $product_cat,
63
- ))
64
  )
65
  );
66
  }
@@ -124,8 +131,8 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
124
  $product_ids = array();
125
  foreach( $products as $oneproduct ) {
126
  $remarketing_id = $oneproduct['product_id'];
127
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETINGSKU ] ) {
128
- $product_sku = $oneproduct['product_sku'];
129
  if ( "" != $product_sku ) {
130
  $remarketing_id = $product_sku;
131
  }
@@ -144,8 +151,13 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
144
  $dataLayer["ecomm_totalvalue"] = (float)$cart_total;
145
  }
146
  } else if ( is_order_received_page() ) {
147
- $order_id = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET['order'] ) ? ($GLOBALS["wp"]->query_vars["order-received"] ? $GLOBALS["wp"]->query_vars["order-received"] : 0) : absint( $_GET['order'] ) );
148
- $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : woocommerce_clean( $_GET['key'] ) );
 
 
 
 
 
149
 
150
  if ( $order_id > 0 ) {
151
  $order = new WC_Order( $order_id );
@@ -213,19 +225,19 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
213
  $out[] = $category->name;
214
  }
215
  }
216
-
217
  $_category = implode( " / ", $out );
218
  }
219
 
220
  $remarketing_id = $_product->id;
221
  $product_sku = $_product->get_sku();
222
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETINGSKU ] && ( "" != $product_sku ) ) {
223
  $remarketing_id = $product_sku;
224
  }
225
 
226
  $_prodprice = $order->get_item_total( $item );
227
- $_products[] = array(
228
- "id" => $_product->id,
229
  "name" => $item['name'],
230
  "sku" => $product_sku ? __( 'SKU:', 'duracelltomi-google-tag-manager' ) . ' ' . $product_sku : $_product->id,
231
  "category" => $_category,
@@ -233,8 +245,10 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
233
  "currency" => get_woocommerce_currency(),
234
  "quantity" => $item['qty']
235
  );
236
-
237
- $_sumprice += $_prodprice * $item['qty'];
 
 
238
  $_product_ids[] = $remarketing_id;
239
  }
240
  }
@@ -262,7 +276,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
262
  $gtm4wp_checkout_products = array();
263
  $gtm4wp_checkout_products_remarketing = array();
264
  $gtm4wp_totalvalue = 0;
265
-
266
  foreach( $woocommerce->cart->get_cart() as $cart_item_id => $cart_item_data) {
267
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data["data"], $cart_item_data, $cart_item_id );
268
 
@@ -273,19 +287,25 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
273
  } else {
274
  $product_cat = "";
275
  }
276
-
277
- $gtm4wp_product_price = $product->get_price();
278
 
279
- $gtm4wp_checkout_products[] = array(
280
- "id" => $product->id,
 
 
 
 
 
 
281
  "name" => $product->post->post_title,
282
- "price" => $gtm4wp_product_price,
283
  "category" => $product_cat,
284
  "quantity" => $cart_item_data["quantity"]
285
  );
286
-
287
- $gtm4wp_checkout_products_remarketing[] = $product->id;
288
- $gtm4wp_totalvalue += $cart_item_data["quantity"] * $gtm4wp_product_price;
 
 
289
  } // end foreach cart item
290
 
291
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
@@ -331,8 +351,6 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
331
  }
332
  });
333
  }
334
-
335
- return false;
336
  });");
337
  }
338
  }
@@ -365,7 +383,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
365
  if ( 0 == qty ) {
366
  return true;
367
  }
368
-
369
  ". $gtm4wp_datalayer_name .".push({
370
  'event': 'gtm4wp.removeFromCartEEC',
371
  'ecommerce': {
@@ -391,30 +409,52 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
391
  if ( ! is_single() ) {
392
  return;
393
  }
 
 
 
 
 
394
 
395
  global $product, $woocommerce, $gtm4wp_datalayer_name, $gtm4wp_options;
396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
398
  gtm4wp_woocommerce_addjs("
399
  $( '.single_add_to_cart_button' ).click(function() {
400
  ". $gtm4wp_datalayer_name .".push({
401
  'event': 'gtm4wp.addProductToCart',
402
- 'productName': '". esc_js( $product->post->post_title ) ."',
403
- 'productSKU': '". esc_js( $product->get_sku() ) ."',
404
- 'productID': '". esc_js( $product->id ) ."'
405
  });
406
  });
407
  ");
408
  }
409
 
410
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
411
- $_product_cats = get_the_terms($product->id, 'product_cat');
412
- if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
413
- $product_cat = array_pop( $_product_cats );
414
- $product_cat = $product_cat->name;
415
- } else {
416
- $product_cat = "";
417
- }
418
 
419
  gtm4wp_woocommerce_addjs("
420
  $( '.single_add_to_cart_button' ).click(function() {
@@ -424,10 +464,10 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
424
  'currencyCode': '".get_woocommerce_currency()."',
425
  'add': {
426
  'products': [{
427
- 'name': '". esc_js( $product->post->post_title ) ."',
428
- 'id': '". esc_js( $product->id ) ."',
429
- 'price': '". esc_js( $product->get_price() ) ."',
430
- 'category': '". esc_js( $product_cat ) ."',
431
  'quantity': jQuery( 'form.cart:first input[name=quantity]' ).val()
432
  }]
433
  }
@@ -472,7 +512,7 @@ function gtm4wp_woocommerce_wp_footer() {
472
  i = 0;
473
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ] = [];
474
  }
475
-
476
  if ( typeof ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push == 'undefined' ) {
477
  return false;
478
  }
@@ -495,7 +535,7 @@ function gtm4wp_woocommerce_wp_footer() {
495
  if ( $( '.gtm4wp_productdata,.widget-product-item' ).length > 0 ) {
496
  for( var i=0; i<". $gtm4wp_datalayer_name .".length; i++ ) {
497
  if ( ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] ) {
498
-
499
  if ( ! ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] ) {
500
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = [];
501
  }
@@ -510,7 +550,7 @@ function gtm4wp_woocommerce_wp_footer() {
510
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] = {};
511
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = [];
512
  }
513
-
514
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'currencyCode' ] = '".get_woocommerce_currency()."';
515
 
516
  var productdata;
@@ -559,14 +599,10 @@ function gtm4wp_woocommerce_enhanced_ecom_product_click() {
559
 
560
  gtm4wp_woocommerce_addjs("
561
  $( '.products li:not(.product-category) a:not(.add_to_cart_button),.widget-product-item' ).click(function( event ) {
562
- var _productdata = $( this ).closest( '.product' ).length;
563
- if ( _productdata > 0 ) {
564
- var productdata = _productdata.find( '.gtm4wp_productdata' );
565
- }
566
-
567
- var ctrl_key_pressed = event.ctrlKey;
568
-
569
- if ( 0 == productdata.length ) {
570
  var productdata = jQuery( this );
571
 
572
  if ( '' == productdata.data( 'gtm4wp_product_id' ) ) {
@@ -574,6 +610,8 @@ function gtm4wp_woocommerce_enhanced_ecom_product_click() {
574
  }
575
  }
576
 
 
 
577
  event.preventDefault();
578
  if ( ctrl_key_pressed ) {
579
  // we need to open the new tab/page here so that popup blocker of the browser doesn't block our code
@@ -587,8 +625,8 @@ function gtm4wp_woocommerce_enhanced_ecom_product_click() {
587
  'click': {
588
  'actionField': {'list': productdata.data( 'gtm4wp_productlist_name' )},
589
  'products': [{
590
- 'name': productdata.data( 'gtm4wp_product_name' ),
591
  'id': productdata.data( 'gtm4wp_product_id' ),
 
592
  'price': productdata.data( 'gtm4wp_product_price' ),
593
  'category': productdata.data( 'gtm4wp_product_cat' ),
594
  'position': productdata.data( 'gtm4wp_product_listposition' )
@@ -601,16 +639,16 @@ function gtm4wp_woocommerce_enhanced_ecom_product_click() {
601
  } else {
602
  document.location.href = productdata.data( 'gtm4wp_product_url' )
603
  }
604
- }
 
605
  });
606
  });
607
  ");
608
  }
609
 
610
  function gtm4wp_woocommerce_add_prod_data( $add_to_cart_link ) {
611
- global $product, $woocommerce_loop;
612
-
613
- $product_price = $product->get_price();
614
  $_product_cats = get_the_terms($product->id, 'product_cat');
615
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
616
  $product_cat = array_pop( $_product_cats );
@@ -627,22 +665,46 @@ function gtm4wp_woocommerce_add_prod_data( $add_to_cart_link ) {
627
  $list_name = __( "General Product List", "duracelltomi-google-tag-manager" );
628
  }
629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
630
  $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" href="',
631
- esc_attr( $product->id ),
632
- esc_attr( $product->get_title() ),
633
- esc_attr( $product_price ),
634
- esc_attr( $product_cat ),
635
- esc_url( get_permalink() ),
636
- esc_attr( $woocommerce_loop[ "loop" ] ),
637
- esc_attr( $list_name )
638
  );
639
 
640
  return str_replace( 'href="', $cartlink_with_data, $add_to_cart_link );
641
  }
642
 
643
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
644
- function gtm4wp_woocommerce_cart_item_product_filter($product) {
645
- $product_price = $product->get_price();
 
646
  $_product_cats = get_the_terms($product->id, 'product_cat');
647
  if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
648
  $product_cat = array_pop( $_product_cats );
@@ -651,13 +713,21 @@ function gtm4wp_woocommerce_cart_item_product_filter($product) {
651
  $product_cat = "";
652
  }
653
 
654
- $GLOBALS["gtm4wp_cart_item_proddata"] = array(
655
- "id" => $product->id,
656
- "name" => $product->get_title(),
657
- "price" => $product_price,
 
 
 
 
 
 
658
  "category" => $product_cat,
659
  "productlink" => get_permalink()
660
  );
 
 
661
 
662
  return $product;
663
  }
@@ -702,13 +772,12 @@ function gtm4wp_woocommerce_before_template_part( $template_name ) {
702
  }
703
 
704
  function gtm4wp_woocommerce_after_template_part( $template_name ) {
705
- global $product, $gtm4wp_product_counter, $gtm4wp_last_widget_title;
706
 
707
  $productitem = ob_get_contents();
708
  ob_end_clean();
709
 
710
  if ( "content-widget-product.php" == $template_name ) {
711
- $product_price = $product->get_price();
712
  $_product_cats = get_the_terms($product->id, 'product_cat');
713
  if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
714
  $product_cat = array_pop( $_product_cats );
@@ -717,14 +786,31 @@ function gtm4wp_woocommerce_after_template_part( $template_name ) {
717
  $product_cat = "";
718
  }
719
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
  $productlink_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_productlist_name="%s" data-gtm4wp_product_listposition="%s" class="widget-product-item" href="',
721
- esc_attr( $product->id ),
722
- esc_attr( $product->get_title() ),
723
- esc_attr( $product_price ),
724
- esc_attr( $product_cat ),
725
- esc_url( get_permalink() ),
726
- $gtm4wp_last_widget_title,
727
- esc_attr( $gtm4wp_product_counter )
728
  );
729
 
730
  $gtm4wp_product_counter++;
@@ -781,9 +867,8 @@ function gtm4wp_before_related_products_loop() {
781
  }
782
 
783
  function gtm4wp_woocommerce_before_shop_loop_item() {
784
- global $product, $woocommerce_loop;
785
-
786
- $product_price = $product->get_price();
787
  $product_cat = "";
788
  if ( is_product_category() ) {
789
  global $wp_query;
@@ -805,16 +890,37 @@ function gtm4wp_woocommerce_before_shop_loop_item() {
805
  $list_name = __( "General Product List", "duracelltomi-google-tag-manager" );
806
  }
807
 
808
- $productlink = get_permalink();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809
 
810
  printf('<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"></span>',
811
- esc_attr( $product->id ),
812
- esc_attr( $product->get_title() ),
813
- esc_attr( $product_price ),
814
- esc_attr( $product_cat ),
815
- esc_url( $productlink ),
816
- esc_attr( $woocommerce_loop[ "loop" ] ),
817
- esc_attr( $list_name )
818
  );
819
  }
820
 
@@ -829,7 +935,7 @@ if ( isset ( $GLOBALS["woocommerce"] ) ) {
829
  // add_filter( "woocommerce_loop_add_to_cart_link", "gtm4wp_woocommerce_add_prod_data" );
830
  add_action( "woocommerce_after_add_to_cart_button", "gtm4wp_woocommerce_single_add_to_cart_tracking" );
831
  add_action( "wp_footer", "gtm4wp_woocommerce_wp_footer" );
832
-
833
  if ( true === $GLOBALS[ "gtm4wp_options" ][ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
834
  add_action( 'wp_footer', 'gtm4wp_woocommerce_enhanced_ecom_product_click' );
835
  add_action( 'woocommerce_before_template_part', 'gtm4wp_woocommerce_before_template_part' );
1
  <?php
2
+ define( 'GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY', 'gtm4wp_eec_product_array' );
3
+
4
  $gtm4wp_product_counter = 0;
5
  $gtm4wp_last_widget_title = "Sidebar Products";
6
 
7
  function gtm4wp_woocommerce_addjs( $js ) {
8
  global $woocommerce;
9
+
10
  if ( version_compare( $woocommerce->version, "2.1", ">=" ) ) {
11
  wc_enqueue_js( $js );
12
  } else {
30
  } else if ( is_product() ) {
31
  if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
32
  $prodid = get_the_ID();
33
+
34
  $product = get_product( $prodid );
35
  $product_price = $product->get_price();
36
  $_product_cats = get_the_terms( $product->id, 'product_cat' );
40
  } else {
41
  $product_cat = "";
42
  }
43
+
44
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
45
+ $product_sku = $product->get_sku();
46
+ if ( "" != $product_sku ) {
47
+ $prodid = $product_sku;
48
+ }
49
+ }
50
+
51
+ $_temp_productdata = array(
52
+ "name" => gtm4wp_woocommerce_html_entity_decode( get_the_title() ),
53
+ "id" => $prodid,
54
+ "price" => $product_price,
55
+ "category" => $product_cat,
56
+ );
57
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "productdetail" );
58
 
59
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
60
  $remarketing_id = (string)$prodid;
 
 
 
 
 
 
61
 
62
  $dataLayer["ecomm_prodid"] = $remarketing_id;
63
  $dataLayer["ecomm_pagetype"] = "product";
64
+ $dataLayer["ecomm_totalvalue"] = (float)$eec_product_array[ "price" ];
65
  }
66
+
67
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
68
  $dataLayer["ecommerce"] = array(
69
  "detail" => array(
70
+ "products" => array($eec_product_array)
 
 
 
 
 
71
  )
72
  );
73
  }
131
  $product_ids = array();
132
  foreach( $products as $oneproduct ) {
133
  $remarketing_id = $oneproduct['product_id'];
134
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
135
+ $product_sku = isset( $oneproduct['product_sku'] ) ? $oneproduct['product_sku'] : "";
136
  if ( "" != $product_sku ) {
137
  $remarketing_id = $product_sku;
138
  }
151
  $dataLayer["ecomm_totalvalue"] = (float)$cart_total;
152
  }
153
  } else if ( is_order_received_page() ) {
154
+ $order_id = empty( $_GET[ "order" ] ) ? ( $GLOBALS[ "wp" ]->query_vars[ "order-received" ] ? $GLOBALS[ "wp" ]->query_vars[ "order-received" ] : 0 ) : absint( $_GET[ "order" ] );
155
+ $order_id_filtered = apply_filters( 'woocommerce_thankyou_order_id', $order_id );
156
+ if ( "" != $order_id_filtered ) {
157
+ $order_id = $order_id_filtered;
158
+ }
159
+
160
+ $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET[ "key" ] ) ? "" : wc_clean( $_GET[ "key" ] ) );
161
 
162
  if ( $order_id > 0 ) {
163
  $order = new WC_Order( $order_id );
225
  $out[] = $category->name;
226
  }
227
  }
228
+
229
  $_category = implode( " / ", $out );
230
  }
231
 
232
  $remarketing_id = $_product->id;
233
  $product_sku = $_product->get_sku();
234
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
235
  $remarketing_id = $product_sku;
236
  }
237
 
238
  $_prodprice = $order->get_item_total( $item );
239
+ $_temp_productdata = array(
240
+ "id" => $remarketing_id,
241
  "name" => $item['name'],
242
  "sku" => $product_sku ? __( 'SKU:', 'duracelltomi-google-tag-manager' ) . ' ' . $product_sku : $_product->id,
243
  "category" => $_category,
245
  "currency" => get_woocommerce_currency(),
246
  "quantity" => $item['qty']
247
  );
248
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "purchase" );
249
+ $_products[] = $eec_product_array;
250
+
251
+ $_sumprice += $eec_product_array[ "price" ] * $eec_product_array[ "quantity" ];
252
  $_product_ids[] = $remarketing_id;
253
  }
254
  }
276
  $gtm4wp_checkout_products = array();
277
  $gtm4wp_checkout_products_remarketing = array();
278
  $gtm4wp_totalvalue = 0;
279
+
280
  foreach( $woocommerce->cart->get_cart() as $cart_item_id => $cart_item_data) {
281
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data["data"], $cart_item_data, $cart_item_id );
282
 
287
  } else {
288
  $product_cat = "";
289
  }
 
 
290
 
291
+ $remarketing_id = $product->id;
292
+ $product_sku = $product->get_sku();
293
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
294
+ $remarketing_id = $product_sku;
295
+ }
296
+
297
+ $_temp_productdata = array(
298
+ "id" => $remarketing_id,
299
  "name" => $product->post->post_title,
300
+ "price" => $product->get_price(),
301
  "category" => $product_cat,
302
  "quantity" => $cart_item_data["quantity"]
303
  );
304
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "checkout" );
305
+ $gtm4wp_checkout_products[] = $eec_product_array;
306
+
307
+ $gtm4wp_checkout_products_remarketing[] = $remarketing_id;
308
+ $gtm4wp_totalvalue += $eec_product_array[ "quantity" ] * $eec_product_array[ "price" ];
309
  } // end foreach cart item
310
 
311
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
351
  }
352
  });
353
  }
 
 
354
  });");
355
  }
356
  }
383
  if ( 0 == qty ) {
384
  return true;
385
  }
386
+
387
  ". $gtm4wp_datalayer_name .".push({
388
  'event': 'gtm4wp.removeFromCartEEC',
389
  'ecommerce': {
409
  if ( ! is_single() ) {
410
  return;
411
  }
412
+
413
+ // exit early if there is nothing to do
414
+ if ( ( false === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) && ( false === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
415
+ return;
416
+ }
417
 
418
  global $product, $woocommerce, $gtm4wp_datalayer_name, $gtm4wp_options;
419
 
420
+ $_product_cats = get_the_terms($product->id, 'product_cat');
421
+ if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
422
+ $product_cat = array_pop( $_product_cats );
423
+ $product_cat = $product_cat->name;
424
+ } else {
425
+ $product_cat = "";
426
+ }
427
+
428
+ $remarketing_id = $product->id;
429
+ $product_sku = $product->get_sku();
430
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
431
+ $remarketing_id = $product_sku;
432
+ }
433
+
434
+ $_temp_productdata = array(
435
+ "id" => $remarketing_id,
436
+ "name" => $product->post->post_title,
437
+ "sku" => $product_sku ? __( 'SKU:', 'duracelltomi-google-tag-manager' ) . ' ' . $product_sku : $product->id,
438
+ "category" => $product_cat,
439
+ "price" => $product->get_price(),
440
+ "currency" => get_woocommerce_currency()
441
+ );
442
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "addtocartsingle" );
443
+
444
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
445
  gtm4wp_woocommerce_addjs("
446
  $( '.single_add_to_cart_button' ).click(function() {
447
  ". $gtm4wp_datalayer_name .".push({
448
  'event': 'gtm4wp.addProductToCart',
449
+ 'productName': '". esc_js( $eec_product_array[ "name" ] ) ."',
450
+ 'productSKU': '". esc_js( $eec_product_array[ "sku" ] ) ."',
451
+ 'productID': '". esc_js( $eec_product_array[ "id" ] ) ."'
452
  });
453
  });
454
  ");
455
  }
456
 
457
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
 
 
 
 
 
 
 
458
 
459
  gtm4wp_woocommerce_addjs("
460
  $( '.single_add_to_cart_button' ).click(function() {
464
  'currencyCode': '".get_woocommerce_currency()."',
465
  'add': {
466
  'products': [{
467
+ 'id': '". esc_js( $eec_product_array[ "id" ] ) ."',
468
+ 'name': '". esc_js( $eec_product_array[ "name" ] ) ."',
469
+ 'price': '". esc_js( $eec_product_array[ "price" ] ) ."',
470
+ 'category': '". esc_js( $eec_product_array[ "category" ] ) ."',
471
  'quantity': jQuery( 'form.cart:first input[name=quantity]' ).val()
472
  }]
473
  }
512
  i = 0;
513
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ] = [];
514
  }
515
+
516
  if ( typeof ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push == 'undefined' ) {
517
  return false;
518
  }
535
  if ( $( '.gtm4wp_productdata,.widget-product-item' ).length > 0 ) {
536
  for( var i=0; i<". $gtm4wp_datalayer_name .".length; i++ ) {
537
  if ( ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] ) {
538
+
539
  if ( ! ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] ) {
540
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = [];
541
  }
550
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] = {};
551
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = [];
552
  }
553
+
554
  ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'currencyCode' ] = '".get_woocommerce_currency()."';
555
 
556
  var productdata;
599
 
600
  gtm4wp_woocommerce_addjs("
601
  $( '.products li:not(.product-category) a:not(.add_to_cart_button),.widget-product-item' ).click(function( event ) {
602
+ var _productdata = $( this ).closest( '.product' );
603
+ if ( _productdata.length > 0 ) {
604
+ var productdata = _productdata.find( '.gtm4wp_productdata' );
605
+ } else {
 
 
 
 
606
  var productdata = jQuery( this );
607
 
608
  if ( '' == productdata.data( 'gtm4wp_product_id' ) ) {
610
  }
611
  }
612
 
613
+ var ctrl_key_pressed = event.ctrlKey;
614
+
615
  event.preventDefault();
616
  if ( ctrl_key_pressed ) {
617
  // we need to open the new tab/page here so that popup blocker of the browser doesn't block our code
625
  'click': {
626
  'actionField': {'list': productdata.data( 'gtm4wp_productlist_name' )},
627
  'products': [{
 
628
  'id': productdata.data( 'gtm4wp_product_id' ),
629
+ 'name': productdata.data( 'gtm4wp_product_name' ),
630
  'price': productdata.data( 'gtm4wp_product_price' ),
631
  'category': productdata.data( 'gtm4wp_product_cat' ),
632
  'position': productdata.data( 'gtm4wp_product_listposition' )
639
  } else {
640
  document.location.href = productdata.data( 'gtm4wp_product_url' )
641
  }
642
+ },
643
+ 'eventTimeout': 2000
644
  });
645
  });
646
  ");
647
  }
648
 
649
  function gtm4wp_woocommerce_add_prod_data( $add_to_cart_link ) {
650
+ global $product, $woocommerce_loop, $wp_query, $gtm4wp_options;
651
+
 
652
  $_product_cats = get_the_terms($product->id, 'product_cat');
653
  if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
654
  $product_cat = array_pop( $_product_cats );
665
  $list_name = __( "General Product List", "duracelltomi-google-tag-manager" );
666
  }
667
 
668
+ $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
669
+ $posts_per_page = get_query_var('posts_per_page');
670
+ if ( $posts_per_page < 1 ) {
671
+ $posts_per_page = 1;
672
+ }
673
+
674
+ $remarketing_id = $product->id;
675
+ $product_sku = $product->get_sku();
676
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
677
+ $remarketing_id = $product_sku;
678
+ }
679
+
680
+ $_temp_productdata = array(
681
+ "id" => $remarketing_id,
682
+ "name" => $product->post->post_title,
683
+ "category" => $product_cat,
684
+ "price" => $product->get_price(),
685
+ "productlink" => get_permalink(),
686
+ "listposition" => $woocommerce_loop[ "loop" ] + ( $posts_per_page * ($paged-1) ),
687
+ "listname" => $list_name
688
+ );
689
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "addtocartproductlist" );
690
+
691
  $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" href="',
692
+ esc_attr( $eec_product_array[ "id" ] ),
693
+ esc_attr( $eec_product_array[ "name" ] ),
694
+ esc_attr( $eec_product_array[ "price" ] ),
695
+ esc_attr( $eec_product_array[ "category" ] ),
696
+ esc_url( $eec_product_array[ "productlink" ] ),
697
+ esc_attr( $eec_product_array[ "listposition" ] ),
698
+ esc_attr( $eec_product_array[ "listname" ] )
699
  );
700
 
701
  return str_replace( 'href="', $cartlink_with_data, $add_to_cart_link );
702
  }
703
 
704
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
705
+ function gtm4wp_woocommerce_cart_item_product_filter( $product ) {
706
+ global $gtm4wp_options;
707
+
708
  $_product_cats = get_the_terms($product->id, 'product_cat');
709
  if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
710
  $product_cat = array_pop( $_product_cats );
713
  $product_cat = "";
714
  }
715
 
716
+ $remarketing_id = $product->id;
717
+ $product_sku = $product->get_sku();
718
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
719
+ $remarketing_id = $product_sku;
720
+ }
721
+
722
+ $_temp_productdata = array(
723
+ "id" => $remarketing_id,
724
+ "name" => $product->post->post_title,
725
+ "price" => $product->get_price(),
726
  "category" => $product_cat,
727
  "productlink" => get_permalink()
728
  );
729
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "cart" );
730
+ $GLOBALS["gtm4wp_cart_item_proddata"] = $eec_product_array;
731
 
732
  return $product;
733
  }
772
  }
773
 
774
  function gtm4wp_woocommerce_after_template_part( $template_name ) {
775
+ global $product, $gtm4wp_product_counter, $gtm4wp_last_widget_title, $gtm4wp_options;
776
 
777
  $productitem = ob_get_contents();
778
  ob_end_clean();
779
 
780
  if ( "content-widget-product.php" == $template_name ) {
 
781
  $_product_cats = get_the_terms($product->id, 'product_cat');
782
  if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
783
  $product_cat = array_pop( $_product_cats );
786
  $product_cat = "";
787
  }
788
 
789
+ $remarketing_id = $product->id;
790
+ $product_sku = $product->get_sku();
791
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
792
+ $remarketing_id = $product_sku;
793
+ }
794
+
795
+ $_temp_productdata = array(
796
+ "id" => $remarketing_id,
797
+ "name" => $product->post->post_title,
798
+ "price" => $product->get_price(),
799
+ "category" => $product_cat,
800
+ "productlink" => get_permalink(),
801
+ "listname" => $gtm4wp_last_widget_title,
802
+ "listposition" => $gtm4wp_product_counter
803
+ );
804
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "widgetproduct" );
805
+
806
  $productlink_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_productlist_name="%s" data-gtm4wp_product_listposition="%s" class="widget-product-item" href="',
807
+ esc_attr( $eec_product_array[ "id" ] ),
808
+ esc_attr( $eec_product_array[ "name" ] ),
809
+ esc_attr( $eec_product_array[ "price" ] ),
810
+ esc_attr( $eec_product_array[ "category" ] ),
811
+ esc_url( $eec_product_array[ "productlink" ] ),
812
+ esc_attr( $eec_product_array[ "listname" ] ),
813
+ esc_attr( $eec_product_array[ "listposition" ] )
814
  );
815
 
816
  $gtm4wp_product_counter++;
867
  }
868
 
869
  function gtm4wp_woocommerce_before_shop_loop_item() {
870
+ global $product, $woocommerce_loop, $wp_query, $gtm4wp_options;
871
+
 
872
  $product_cat = "";
873
  if ( is_product_category() ) {
874
  global $wp_query;
890
  $list_name = __( "General Product List", "duracelltomi-google-tag-manager" );
891
  }
892
 
893
+ $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
894
+ $posts_per_page = get_query_var('posts_per_page');
895
+ if ( $posts_per_page < 1 ) {
896
+ $posts_per_page = 1;
897
+ }
898
+
899
+ $remarketing_id = $product->id;
900
+ $product_sku = $product->get_sku();
901
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
902
+ $remarketing_id = $product_sku;
903
+ }
904
+
905
+ $_temp_productdata = array(
906
+ "id" => $remarketing_id,
907
+ "name" => $product->post->post_title,
908
+ "price" => $product->get_price(),
909
+ "category" => $product_cat,
910
+ "productlink" => get_permalink(),
911
+ "listname" => $list_name,
912
+ "listposition" => $woocommerce_loop[ "loop" ] + ( $posts_per_page * ($paged-1) )
913
+ );
914
+ $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "productlist" );
915
 
916
  printf('<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"></span>',
917
+ esc_attr( $eec_product_array[ "id" ] ),
918
+ esc_attr( $eec_product_array[ "name" ] ),
919
+ esc_attr( $eec_product_array[ "price" ] ),
920
+ esc_attr( $eec_product_array[ "category" ] ),
921
+ esc_url( $eec_product_array[ "productlink" ] ),
922
+ esc_attr( $eec_product_array[ "listposition" ] ),
923
+ esc_attr( $eec_product_array[ "listname" ] )
924
  );
925
  }
926
 
935
  // add_filter( "woocommerce_loop_add_to_cart_link", "gtm4wp_woocommerce_add_prod_data" );
936
  add_action( "woocommerce_after_add_to_cart_button", "gtm4wp_woocommerce_single_add_to_cart_tracking" );
937
  add_action( "wp_footer", "gtm4wp_woocommerce_wp_footer" );
938
+
939
  if ( true === $GLOBALS[ "gtm4wp_options" ][ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
940
  add_action( 'wp_footer', 'gtm4wp_woocommerce_enhanced_ecom_product_click' );
941
  add_action( 'woocommerce_before_template_part', 'gtm4wp_woocommerce_before_template_part' );
js/admin-subtabs.js CHANGED
@@ -12,7 +12,7 @@ var adminsubtabs = {
12
  },
13
  "visitor": {
14
  tabtext: gtm4wp.visitortabtitle,
15
- numitems: 3
16
  },
17
  "adwords": {
18
  tabtext: gtm4wp.adwordstabtitle,
12
  },
13
  "visitor": {
14
  tabtext: gtm4wp.visitortabtitle,
15
+ numitems: 4
16
  },
17
  "adwords": {
18
  tabtext: gtm4wp.adwordstabtitle,
public/frontend.php CHANGED
@@ -55,9 +55,16 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
55
  }
56
  }
57
 
58
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] ) {
59
  $current_user = wp_get_current_user();
60
- $dataLayer["visitorType"] = ( empty( $current_user->roles[0] ) ? "visitor-logged-out" : $current_user->roles[0] );
 
 
 
 
 
 
 
61
  }
62
 
63
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERID ] ) {
@@ -242,7 +249,7 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
242
  $dataLayer["postCountTotal"] = (int) $wp_query->found_posts;
243
  }
244
 
245
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTID ] ) {
246
  $dataLayer["postID"] = (int) get_the_ID();
247
  }
248
 
@@ -433,7 +440,8 @@ function gtm4wp_wp_loaded() {
433
  function gtm4wp_get_the_gtm_tag() {
434
  global $gtm4wp_options, $gtm4wp_datalayer_name, $gtm4wp_container_code_written;
435
 
436
- $_gtm_tag = '';
 
437
 
438
  if ( GTM4WP_PLACEMENT_OFF == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
439
  $gtm4wp_container_code_written = true;
@@ -445,16 +453,11 @@ function gtm4wp_get_the_gtm_tag() {
445
  foreach( $_gtm_codes as $one_gtm_code ) {
446
  $_gtm_tag .= '
447
  <noscript><iframe src="//www.googletagmanager.com/ns.html?id=' . $one_gtm_code . '"
448
- height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
449
- <script data-cfasync="false">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\':
450
- new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0],
451
- j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src=
452
- \'//www.googletagmanager.com/gtm.\''.'+\'js?id=\'+i+dl;f.parentNode.insertBefore(j,f);
453
- })(window,document,\'script\',\'' . $gtm4wp_datalayer_name . '\',\'' . $one_gtm_code . '\');</script>';
454
  }
455
 
456
  $_gtm_tag .= '
457
- <!-- End Google Tag Manager -->';
458
 
459
  $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag );
460
  $gtm4wp_container_code_written = true;
@@ -553,23 +556,7 @@ function gtm4wp_wp_header_begin() {
553
  var gtm4wp_scrollerscript_scannertime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_READERTIME ] . ';';
554
  }
555
 
556
- $_gtm_header_content .= '
557
- </script>
558
- <!-- End Google Tag Manager for WordPress by DuracellTomi -->';
559
-
560
- echo $_gtm_header_content;
561
- }
562
-
563
- function gtm4wp_wp_header_end() {
564
- global $gtm4wp_datalayer_name, $gtm4wp_options;
565
-
566
- $_gtm_tag = '';
567
-
568
  if ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != "" ) {
569
- $_gtm_tag .= '
570
- <!-- Google Tag Manager for WordPress by DuracellTomi -->
571
- <script data-cfasync="false" type="text/javascript">';
572
-
573
  $gtm4wp_datalayer_data = array();
574
  $gtm4wp_datalayer_data = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_DATALAYER, $gtm4wp_datalayer_data );
575
 
@@ -579,13 +566,13 @@ function gtm4wp_wp_header_end() {
579
 
580
  $gtm4wp_remarketing_tags = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_REMARKTING, $gtm4wp_datalayer_data );
581
 
582
- $_gtm_tag .= '
583
  var google_tag_params = ' . json_encode( $gtm4wp_remarketing_tags ) . ';';
584
  $gtm4wp_datalayer_data["google_tag_params"] = "-~-window.google_tag_params-~-";
585
  }
586
 
587
  if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DOWNLOADS ] ) {
588
- $_gtm_tag .= '
589
  jQuery( function() {
590
  gtm4wp_track_downloads( "' . str_replace( '"', '', $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DWLEXT ] ) . '" );
591
  });';
@@ -597,18 +584,41 @@ function gtm4wp_wp_header_end() {
597
  $dl_json_data = json_encode( $gtm4wp_datalayer_data );
598
  }
599
 
600
- $_gtm_tag .= '
601
  ' . $gtm4wp_datalayer_name . '.push(' . str_replace(
602
  array( '"-~-', '-~-"' ),
603
  array( "", "" ),
604
  str_replace( "�", "-", $dl_json_data )
605
  ) . ');';
 
606
 
607
- $_gtm_tag .= '
608
  </script>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
  }
610
 
611
- echo $_gtm_tag;
 
 
 
612
  }
613
 
614
  function gtm4wp_body_class( $classes ) {
@@ -624,8 +634,7 @@ function gtm4wp_body_class( $classes ) {
624
  }
625
 
626
  add_action( "wp_enqueue_scripts", "gtm4wp_enqueue_scripts" );
627
- add_action( "wp_head", "gtm4wp_wp_header_begin", 1 );
628
- add_action( "wp_head", "gtm4wp_wp_header_end", 100 );
629
  add_action( "wp_footer", "gtm4wp_wp_footer" );
630
  add_action( "wp_loaded", "gtm4wp_wp_loaded" );
631
  add_filter( "body_class", "gtm4wp_body_class", 10000 );
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 ] ) {
62
+ $dataLayer["visitorType"] = ( empty( $current_user->roles[0] ) ? "visitor-logged-out" : $current_user->roles[0] );
63
+ }
64
+
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 ] ) {
249
  $dataLayer["postCountTotal"] = (int) $wp_query->found_posts;
250
  }
251
 
252
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTID ] && is_singular() === true) {
253
  $dataLayer["postID"] = (int) get_the_ID();
254
  }
255
 
440
  function gtm4wp_get_the_gtm_tag() {
441
  global $gtm4wp_options, $gtm4wp_datalayer_name, $gtm4wp_container_code_written;
442
 
443
+ $_gtm_tag = '
444
+ <!-- Google Tag Manager (noscript) -->';
445
 
446
  if ( GTM4WP_PLACEMENT_OFF == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
447
  $gtm4wp_container_code_written = true;
453
  foreach( $_gtm_codes as $one_gtm_code ) {
454
  $_gtm_tag .= '
455
  <noscript><iframe src="//www.googletagmanager.com/ns.html?id=' . $one_gtm_code . '"
456
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
 
 
 
 
 
457
  }
458
 
459
  $_gtm_tag .= '
460
+ <!-- End Google Tag Manager (noscript) -->';
461
 
462
  $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag );
463
  $gtm4wp_container_code_written = true;
556
  var gtm4wp_scrollerscript_scannertime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_READERTIME ] . ';';
557
  }
558
 
 
 
 
 
 
 
 
 
 
 
 
 
559
  if ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != "" ) {
 
 
 
 
560
  $gtm4wp_datalayer_data = array();
561
  $gtm4wp_datalayer_data = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_DATALAYER, $gtm4wp_datalayer_data );
562
 
566
 
567
  $gtm4wp_remarketing_tags = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_REMARKTING, $gtm4wp_datalayer_data );
568
 
569
+ $_gtm_header_content .= '
570
  var google_tag_params = ' . json_encode( $gtm4wp_remarketing_tags ) . ';';
571
  $gtm4wp_datalayer_data["google_tag_params"] = "-~-window.google_tag_params-~-";
572
  }
573
 
574
  if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DOWNLOADS ] ) {
575
+ $_gtm_header_content .= '
576
  jQuery( function() {
577
  gtm4wp_track_downloads( "' . str_replace( '"', '', $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DWLEXT ] ) . '" );
578
  });';
584
  $dl_json_data = json_encode( $gtm4wp_datalayer_data );
585
  }
586
 
587
+ $_gtm_header_content .= '
588
  ' . $gtm4wp_datalayer_name . '.push(' . str_replace(
589
  array( '"-~-', '-~-"' ),
590
  array( "", "" ),
591
  str_replace( "�", "-", $dl_json_data )
592
  ) . ');';
593
+ }
594
 
595
+ $_gtm_header_content .= '
596
  </script>';
597
+
598
+ if ( ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != "" ) && ( GTM4WP_PLACEMENT_OFF != $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) ) {
599
+ $_gtm_codes = explode( ",", str_replace( array(";"," "), array(",",""), $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] ) );
600
+
601
+ $_gtm_tag = '';
602
+ foreach( $_gtm_codes as $one_gtm_code ) {
603
+ $_gtm_tag .= '
604
+ <script data-cfasync="false">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\':
605
+ new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0],
606
+ j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src=
607
+ \'//www.googletagmanager.com/gtm.\''.'+\'js?id=\'+i+dl;f.parentNode.insertBefore(j,f);
608
+ })(window,document,\'script\',\'' . $gtm4wp_datalayer_name . '\',\'' . $one_gtm_code . '\');</script>';
609
+ }
610
+
611
+ $_gtm_tag .= '
612
+ <!-- End Google Tag Manager -->';
613
+
614
+ $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag );
615
+ $_gtm_header_content .= $_gtm_tag;
616
  }
617
 
618
+ $_gtm_header_content .= '
619
+ <!-- End Google Tag Manager for WordPress by DuracellTomi -->';
620
+
621
+ echo $_gtm_header_content;
622
  }
623
 
624
  function gtm4wp_body_class( $classes ) {
634
  }
635
 
636
  add_action( "wp_enqueue_scripts", "gtm4wp_enqueue_scripts" );
637
+ add_action( "wp_head", "gtm4wp_wp_header_begin" );
 
638
  add_action( "wp_footer", "gtm4wp_wp_footer" );
639
  add_action( "wp_loaded", "gtm4wp_wp_loaded" );
640
  add_filter( "body_class", "gtm4wp_body_class", 10000 );
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.6
7
- Stable tag: 1.4
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
@@ -12,37 +12,26 @@ The first Google Tag Manager plugin for WordPress with business goals in mind.
12
 
13
  == Description ==
14
 
15
- Google Tag Manager (GTM) is Google's free tool to everyone to be able to manage your analyitcs, PPC and other code snipetts
16
- using an intuitive web UI.
17
 
18
- This plugin can place the necessary container code snippet into your website so that you do not need to edit your theme files.
19
  Multiple containers are supported!
20
 
21
- = Basic data included =
 
22
 
23
- Google Tag Manager for WordPress (aka GTM4WP or GTM 4 WP) builds a so called dataLayer variable for you. Using this you can manage your tags
24
- very easily since you can fire them using rules that include
25
 
26
- * post/page titles
27
- * post/page dates
28
- * post/page category names
29
- * post/page tag names
30
- * post/page author ID and names
31
- * post/page ID
32
- * post types
33
- * post count on the current page + in the current category/tag/taxonomy
34
- * logged in status
35
- * logged in user role
36
- * logged in user ID (to track cross device behavior in Google Analytics)
37
- * search data
38
 
39
- Use search data to generate Analytics events when an empty search result is being shown.
40
- This is useful to see what people are searching for that is not available on your site (for example a product).
41
 
42
- Use post count to generate Analytics events when an empty result is being shown.
43
- This can be useful to catch empty (product) categories.
44
-
45
- = Codeless container code injection =
46
 
47
  Yaniv Friedensohn showed me a solution that can add the GTM container code after the opening body tag
48
  for almost every theme without modifying the theme files:
@@ -54,6 +43,23 @@ I added this solution to the plugin, currently as an experimental option.
54
  Users of the Genisis Framework should use the "Custom" option but without altering the theme.
55
  The Google Tag Manager container code will be added automatically.
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  = Browser / OS / Device data =
58
 
59
  (beta)
@@ -88,16 +94,6 @@ Depending on your websites traffic, additional fees may be applied:
88
 
89
  http://www.geoplugin.com/premium
90
 
91
- = Tag Manager Events =
92
-
93
- This plugin can fire several Tag Manager event so that you can include special tags when
94
-
95
- * the visitor moves between elements of a form (comment, contact, etc.)
96
- * the visitor clicks on a Facebook like/share (limited feature) or Twitter button
97
- * the visitor clicks on an outbound link (deprecated)
98
- * the visitor clicks on a download link (deprecated)
99
- * the visitor clicks on an email link (deprecated)
100
-
101
  = Media player events =
102
 
103
  (experimental)
@@ -112,6 +108,7 @@ It fires dataLayer events when a media player was being loaded on the page, when
112
  It can fire dataLayer events when the user reaches 10, 20, 30, ..., 90, 100% of the media duration.
113
 
114
  Tracking should work with embedded media using the oEmbed feauture of WordPress and it should also work with other plugins or even with copy/pasted codes.
 
115
 
116
  = Scroll tracking =
117
 
@@ -161,6 +158,7 @@ Google Tag Manager for WordPress can integrate with several popular plugins.
161
  * Enhanced e-commerce (beta):
162
  * implementation of [Enhanced E-commerce](https://developers.google.com/tag-manager/enhanced-ecommerce)
163
  * Does not include tracking of promotions since WooCommerce does not have such a feature (yet)
 
164
 
165
  More integration to come!
166
 
@@ -273,6 +271,19 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So
273
 
274
  == Changelog ==
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  = 1.4 =
277
 
278
  * Fixed: WP CLI error message
@@ -455,6 +466,10 @@ Please report all bugs found in my plugin using the [contact form on my website]
455
 
456
  == Upgrade Notice ==
457
 
 
 
 
 
458
  = 1.4 =
459
 
460
  Several additions and fixes, breaking changes on media player tracking, please read changelog before upgrade
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.6.1
7
+ Stable tag: 1.5.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
12
 
13
  == Description ==
14
 
15
+ Google Tag Manager (GTM) is Google's free tool for everyone to be able to manage your analyitcs, PPC and other code snipets
16
+ using an intuitive web UI. To learn more about this tool, visit the [official website](https://www.google.com/analytics/tag-manager/).
17
 
18
+ This plugin can place the necessary container code snippet into your website so that you do not need to add this manually.
19
  Multiple containers are supported!
20
 
21
+ The plugin can support your GTM setups by adding lots of meta data about the visited page and about the user into the so called data layer.
22
+ GTM help center incluldes [more details about this data layer](https://developers.google.com/tag-manager/devguide#datalayer).
23
 
24
+ **Some parts of the plugin requires PHP 5.3 newer.
25
+ PHP 5.4 or newer is recommended.**
26
 
27
+ Please note that PHP 5.x is nearing its end of life cycle thus it is recommended to upgrade. If you are not sure which version you are using, please contact
28
+ your hosting provider for support.
 
 
 
 
 
 
 
 
 
 
29
 
30
+ = GTM container code placement =
 
31
 
32
+ GTM container code snippet is currently divided into two parts: the most important part will be added to the <head> tag of your website every time. The second part is
33
+ called the iframe tag and it is only being used when users do not have JavaScript enabled. Code placement option only controls this second code snippet. For best
34
+ performance this should be just after the opening body tag but it might be also safe to use the footer option in plugin settings as the worst case.
 
35
 
36
  Yaniv Friedensohn showed me a solution that can add the GTM container code after the opening body tag
37
  for almost every theme without modifying the theme files:
43
  Users of the Genisis Framework should use the "Custom" option but without altering the theme.
44
  The Google Tag Manager container code will be added automatically.
45
 
46
+ = Basic data included =
47
+
48
+ * post/page titles
49
+ * post/page dates
50
+ * post/page category names
51
+ * post/page tag names
52
+ * post/page author ID and names
53
+ * post/page ID
54
+ * post types
55
+ * post count on the current page + in the current category/tag/taxonomy
56
+ * logged in status
57
+ * logged in user role
58
+ * logged in user ID (to track cross device behavior in Google Analytics)
59
+ * logged in user email address (to comply with [GTM terms of service](https://www.google.com/analytics/tag-manager/use-policy/) do not pass this towards Google tags)
60
+ * search data
61
+ * site name and id for WordPress multisite instances
62
+
63
  = Browser / OS / Device data =
64
 
65
  (beta)
94
 
95
  http://www.geoplugin.com/premium
96
 
 
 
 
 
 
 
 
 
 
 
97
  = Media player events =
98
 
99
  (experimental)
108
  It can fire dataLayer events when the user reaches 10, 20, 30, ..., 90, 100% of the media duration.
109
 
110
  Tracking should work with embedded media using the oEmbed feauture of WordPress and it should also work with other plugins or even with copy/pasted codes.
111
+ Currently, players injected into the website after page load are not being tracked.
112
 
113
  = Scroll tracking =
114
 
158
  * Enhanced e-commerce (beta):
159
  * implementation of [Enhanced E-commerce](https://developers.google.com/tag-manager/enhanced-ecommerce)
160
  * Does not include tracking of promotions since WooCommerce does not have such a feature (yet)
161
+ * Does not currently support refunds
162
 
163
  More integration to come!
164
 
271
 
272
  == Changelog ==
273
 
274
+ = 1.5 =
275
+
276
+ Lots of WooCommerce ecommerce codes has been changed and extended, please double check your measurement after upgrading to this version!
277
+
278
+ * Added: warning message if you are using PHP 5.3 or older. Browser/OS/Device tracking needs 5.4 or newer
279
+ * Added: Email address of the logged in user into the visitorEmail dataLayer variable. Remember: to comply with GTM TOS you are not allowed to pass this data towards any Google tag but you can use this in any other 3rd party tag.
280
+ * Added: gtm4wp_eec_product_array WordPress filter so that plugin and theme authors can add their own data for enhanced ecommere product arrays
281
+ * Fixed: JavaScript error in WooCommerce stores when enhanced ecommerce enabled and a product being clicked in a widget area
282
+ * Fixed: Order data not present in some cases on the order received page
283
+ * Changed: Extended "User SKUs instead of IDs for remarketing" option to be also applied to ecommerce product data arrays
284
+ * Changed: Use wc_clean instead of the deprecated function woocommerce_clean
285
+ * Changed: New, divided GTM container implemented - a fixed part in the <head> and an iframe part placed using the container placement option you've set earlier
286
+
287
  = 1.4 =
288
 
289
  * Fixed: WP CLI error message
466
 
467
  == Upgrade Notice ==
468
 
469
+ = 1.5 =
470
+
471
+ Lots of WooCommerce ecommerce codes has been changed and extended, please double check your measurement after upgrading to this version!
472
+
473
  = 1.4 =
474
 
475
  Several additions and fixes, breaking changes on media player tracking, please read changelog before upgrade