DuracellTomi's Google Tag Manager for WordPress - Version 1.9.1

Version Description

  • Fixed: handle out of quota cases with ipstack queries properly
  • Fixed: proper YouTube tracking for WordPress sites and WordPress multisites installed in a subdirectory
  • Fixed: properly detect client IP address and also properly escape this data while using it
  • Fixed: WooCommerce checkout steps after page load did not include products in the cart
  • Fixed: checkout step events for payment mode and shipping type not always fired
  • Fixed: the CMD on Mac will be treated just like the Ctrl key on Windows while processing the product click event in the WooCommerce integration (thy for luzinis)
  • Fixed: add currencyCode to every ecommerce action in WooCommerce integration
  • Fixed: better WooCommere Quick View integration
  • Fixed: possible cross site scripting vulnerability if site search tracking was enabled due to not properly escaped referrer url tracking
  • Changed: code cleanup in WooCommerce integration
Download this release

Release Info

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

Code changes from version 1.9 to 1.9.1

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.9
5
  Plugin URI: https://gtm4wp.com/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
@@ -10,10 +10,10 @@ Text Domain: duracelltomi-google-tag-manager
10
  Domain Path: /languages
11
 
12
  WC requires at least: 2.6
13
- WC tested up to: 3.4.5
14
  */
15
 
16
- define( 'GTM4WP_VERSION', '1.9' );
17
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
18
 
19
  $gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
+ Version: 1.9.1
5
  Plugin URI: https://gtm4wp.com/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
10
  Domain Path: /languages
11
 
12
  WC requires at least: 2.6
13
+ WC tested up to: 3.5.4
14
  */
15
 
16
+ define( 'GTM4WP_VERSION', '1.9.1' );
17
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
18
 
19
  $gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
integration/woocommerce.php CHANGED
@@ -198,6 +198,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
198
 
199
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
200
  $dataLayer["ecommerce"] = array(
 
201
  "detail" => array(
202
  "products" => array($eec_product_array)
203
  )
@@ -212,72 +213,6 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
212
  }
213
  }
214
  } else if ( is_cart() ) {
215
- // moved to gtm4wp-woocommerce-enhanced.js
216
- /*
217
- if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
218
- gtm4wp_woocommerce_addjs("
219
- $( document ).on( 'click', '[name=update_cart]', function() {
220
- gtm4wp_handle_cart_qty_change();
221
- });
222
-
223
- $( document ).on( 'keypress', '.woocommerce-cart-form input[type=number]', function() {
224
- gtm4wp_handle_cart_qty_change();
225
- });
226
-
227
- function gtm4wp_handle_cart_qty_change() {
228
- $( '.product-quantity input.qty' ).each(function() {
229
- var _original_value = $( this ).prop( 'defaultValue' );
230
-
231
- var _current_value = parseInt( $( this ).val() );
232
- if ( isNaN( _current_value ) ) {
233
- _current_value = _original_value;
234
- }
235
-
236
- if ( _original_value != _current_value ) {
237
- var productdata = $( this ).closest( '.cart_item' ).find( '.remove' );
238
-
239
- if ( _original_value < _current_value ) {
240
- ". $gtm4wp_datalayer_name .".push({
241
- 'event': 'gtm4wp.addProductToCartEEC',
242
- 'ecommerce': {
243
- 'currencyCode': '".get_woocommerce_currency()."',
244
- 'add': {
245
- 'products': [{
246
- 'name': productdata.data( 'gtm4wp_product_name' ),
247
- 'id': productdata.data( 'gtm4wp_product_id' ),
248
- 'price': productdata.data( 'gtm4wp_product_price' ),
249
- 'category': productdata.data( 'gtm4wp_product_cat' ),
250
- 'variant': productdata.data( 'gtm4wp_product_variant' ),
251
- 'quantity': _current_value - _original_value
252
- }]
253
- }
254
- }
255
- });
256
- } else {
257
- ". $gtm4wp_datalayer_name .".push({
258
- 'event': 'gtm4wp.removeFromCartEEC',
259
- 'ecommerce': {
260
- 'currencyCode': '".get_woocommerce_currency()."',
261
- 'remove': {
262
- 'products': [{
263
- 'name': productdata.data( 'gtm4wp_product_name' ),
264
- 'id': productdata.data( 'gtm4wp_product_id' ),
265
- 'price': productdata.data( 'gtm4wp_product_price' ),
266
- 'category': productdata.data( 'gtm4wp_product_cat' ),
267
- 'variant': productdata.data( 'gtm4wp_product_variant' ),
268
- 'quantity': _original_value - _current_value
269
- }]
270
- }
271
- }
272
- });
273
- }
274
- } // end if qty changed
275
- }); // end each qty field
276
- }; // end gtm4wp_handle_cart_qty_change()
277
- ");
278
- }
279
- */
280
-
281
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
282
  $gtm4wp_cart_products = array();
283
  $gtm4wp_cart_products_remarketing = array();
@@ -339,6 +274,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
339
 
340
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
341
  $dataLayer["ecommerce"] = array(
 
342
  "checkout" => array(
343
  "actionField" => array(
344
  "step" => 1
@@ -551,6 +487,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
551
 
552
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
553
  $dataLayer["ecommerce"] = array(
 
554
  "checkout" => array(
555
  "actionField" => array(
556
  "step" => 1 + (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ]
@@ -560,143 +497,9 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
560
  );
561
 
562
  gtm4wp_woocommerce_addjs("
563
- var gtm4wp_checkout_products = " . json_encode($gtm4wp_checkout_products) . ";
564
- var gtm4wp_checkout_step_offset = " . (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ";");
565
-
566
- // moved to gtm4wp-woocommerce-enhanced.js
567
- /*
568
- gtm4wp_woocommerce_addjs("
569
- var gtm4wp_checkout_products = " . json_encode($gtm4wp_checkout_products) . ";
570
- var gtm4wp_checkout_step_offset = " . (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ";
571
- var gtm4wp_checkout_step_fired = []; // step 1 will be the billing section which is reported during pageload, no need to handle here
572
-
573
- $( document ).on( 'blur', 'input[name^=shipping_]:not(input[name=shipping_method])', function() {
574
- // do not report checkout step if already reported
575
- if ( gtm4wp_checkout_step_fired.indexOf( 'shipping' ) > -1 ) {
576
- return;
577
- }
578
-
579
- // do not report checkout step if user is traversing through the section without filling in any data
580
- if ( $( this ).val().trim() == '' ) {
581
- return;
582
- }
583
-
584
- ". $gtm4wp_datalayer_name .".push({
585
- 'event': 'gtm4wp.checkoutStepEEC',
586
- 'ecommerce': {
587
- 'checkout': {
588
- 'actionField': {
589
- 'step': 2 + gtm4wp_checkout_step_offset
590
- },
591
- 'products': gtm4wp_checkout_products
592
- }
593
- }
594
- });
595
-
596
- gtm4wp_checkout_step_fired.push( 'shipping' );
597
- });
598
-
599
- $( document ).on( 'click', 'input[name=shipping_method]', function() {
600
- // do not report checkout step if already reported
601
- if ( gtm4wp_checkout_step_fired.indexOf( 'shipping_method' ) > -1 ) {
602
- return;
603
- }
604
-
605
- // do not fire event during page load
606
- if ( 'complete' != document.readyState ) {
607
- return;
608
- }
609
-
610
- ". $gtm4wp_datalayer_name .".push({
611
- 'event': 'gtm4wp.checkoutStepEEC',
612
- 'ecommerce': {
613
- 'checkout': {
614
- 'actionField': {
615
- 'step': 3 + gtm4wp_checkout_step_offset
616
- },
617
- 'products': gtm4wp_checkout_products
618
- }
619
- }
620
- });
621
-
622
- gtm4wp_checkout_step_fired.push( 'shipping_method' );
623
- });
624
-
625
- $( document ).on( 'click', 'input[name=payment_method]', function() {
626
- // do not report checkout step if already reported
627
- if ( gtm4wp_checkout_step_fired.indexOf( 'payment_method' ) > -1 ) {
628
- return;
629
- }
630
-
631
- // do not fire event during page load
632
- if ( 'complete' != document.readyState ) {
633
- return;
634
- }
635
-
636
- ". $gtm4wp_datalayer_name .".push({
637
- 'event': 'gtm4wp.checkoutStepEEC',
638
- 'ecommerce': {
639
- 'checkout': {
640
- 'actionField': {
641
- 'step': 4 + gtm4wp_checkout_step_offset
642
- },
643
- 'products': gtm4wp_checkout_products
644
- }
645
- }
646
- });
647
-
648
- gtm4wp_checkout_step_fired.push( 'payment_method' );
649
- });
650
-
651
- $( 'form[name=checkout]' ).on( 'submit', function() {
652
- console.log('form submit');
653
-
654
- if ( gtm4wp_checkout_step_fired.indexOf( 'shipping_method' ) == -1 ) {
655
- // shipping methods are not visible if only one is available
656
- // and if the user has already a pre-selected method, no click event will fire to report the checkout step
657
- $( 'input[name=shipping_method]:checked' ).trigger( 'click' );
658
-
659
- gtm4wp_checkout_step_fired.push( 'shipping_method' );
660
- }
661
-
662
- if ( gtm4wp_checkout_step_fired.indexOf( 'payment_method' ) == -1 ) {
663
- // if the user has already a pre-selected method, no click event will fire to report the checkout step
664
- $( 'input[name=payment_method]:checked' ).trigger( 'click' );
665
-
666
- gtm4wp_checkout_step_fired.push( 'payment_method' );
667
- }
668
-
669
- var _shipping_el = $( '#shipping_method input:checked' );
670
- if ( _shipping_el.length > 0 ) {
671
- ". $gtm4wp_datalayer_name .".push({
672
- 'event': 'gtm4wp.checkoutOptionEEC',
673
- 'ecommerce': {
674
- 'checkout_option': {
675
- 'actionField': {
676
- 'step': 3 + gtm4wp_checkout_step_offset,
677
- 'option': 'Shipping: ' + _shipping_el.val()
678
- }
679
- }
680
- }
681
- });
682
- }
683
-
684
- var _payment_el = $( '.payment_methods input:checked' );
685
- if ( _payment_el.length > 0 ) {
686
- ". $gtm4wp_datalayer_name .".push({
687
- 'event': 'gtm4wp.checkoutOptionEEC',
688
- 'ecommerce': {
689
- 'checkout_option': {
690
- 'actionField': {
691
- 'step': 4 + gtm4wp_checkout_step_offset,
692
- 'option': 'Payment: ' + _payment_el.val()
693
- }
694
- }
695
- }
696
- });
697
- }
698
- });");
699
- */
700
  }
701
  }
702
  } else {
@@ -705,56 +508,10 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
705
  }
706
  }
707
 
708
- // moved to gtm4wp-woocommerce-enhanced.js
709
- /*
710
- if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
711
- gtm4wp_woocommerce_addjs("
712
- $( document ).on( 'click', '.mini_cart_item a.remove,.product-remove a.remove', function() {
713
- var productdata = $( this );
714
-
715
- var qty = 0;
716
- var qty_element = $( this ).closest( '.cart_item' ).find( '.product-quantity input.qty' );
717
- if ( 0 == qty_element.length ) {
718
- qty_element = $( this ).closest( '.mini_cart_item' ).find( '.quantity' );
719
- if ( qty_element.length > 0 ) {
720
- qty = parseInt( qty_element.text() );
721
-
722
- if ( isNaN( qty ) ) {
723
- qty = 0;
724
- }
725
- }
726
- } else {
727
- qty = qty_element.val();
728
- }
729
-
730
- if ( 0 == qty ) {
731
- return true;
732
- }
733
-
734
- ". $gtm4wp_datalayer_name .".push({
735
- 'event': 'gtm4wp.removeFromCartEEC',
736
- 'ecommerce': {
737
- 'remove': {
738
- 'products': [{
739
- 'name': productdata.data( 'gtm4wp_product_name' ),
740
- 'id': productdata.data( 'gtm4wp_product_id' ),
741
- 'price': productdata.data( 'gtm4wp_product_price' ),
742
- 'category': productdata.data( 'gtm4wp_product_cat' ),
743
- 'variant': productdata.data( 'gtm4wp_product_variant' ),
744
- 'quantity': qty
745
- }]
746
- }
747
- }
748
- });
749
- });
750
- ");
751
- }
752
- */
753
-
754
  if ( isset ( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] ) ) {
755
  $cart_item = $woo->cart->get_cart_item( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] );
756
  if ( !empty( $cart_item ) ) {
757
- $product = $cart_item["data"];
758
 
759
  $product_id = $product->get_id();
760
  $product_type = $product->get_type();
@@ -772,6 +529,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
772
  $remarketing_id = $product_sku;
773
  }
774
 
 
775
  $dataLayer["ecommerce"]["add"]["products"][] = array(
776
  "name" => $product->get_title(),
777
  "id" => $remarketing_id,
@@ -827,199 +585,6 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
827
  }
828
  }
829
 
830
- // moved to gtm4wp-woocommerce-enhanced.js
831
- /*
832
- function gtm4wp_woocommerce_wp_footer() {
833
- global $gtm4wp_options, $gtm4wp_datalayer_name;
834
-
835
- if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
836
- gtm4wp_woocommerce_addjs("
837
- $( '.add_to_cart_button:not(.product_type_variable, .product_type_grouped, .single_add_to_cart_button)' ).click(function() {
838
- var productdata = $( this ).closest( '.product' ).find( '.gtm4wp_productdata' );
839
-
840
- ". $gtm4wp_datalayer_name .".push({
841
- 'event': 'gtm4wp.addProductToCart',
842
- 'productName': productdata.data( 'gtm4wp_product_name' ),
843
- 'productSKU': $( this ).data( 'product_sku' ),
844
- 'productID': $( this ).data( 'product_id' ),
845
- });
846
- });
847
- ");
848
- }
849
-
850
- if ( ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) && ( ! is_cart() ) && ( ! is_product() ) ) {
851
- echo "
852
- <script data-cfasync='false' type='text/javascript'>
853
- (function($) {
854
- if ( $( '.gtm4wp_productdata' ).length > 0 ) {
855
- for( var i=0; i<". $gtm4wp_datalayer_name .".length; i++ ) {
856
- if ( ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ] ) {
857
- break;
858
- }
859
- }
860
-
861
- if ( i == ". $gtm4wp_datalayer_name .".length ) {
862
- // no existing dyn remarketing data found in the datalayer
863
- i = 0;
864
- ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ] = [];
865
- }
866
-
867
- if ( typeof ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push == 'undefined' ) {
868
- return false;
869
- }
870
-
871
- var productdata;
872
- $( '.gtm4wp_productdata' ).each( function() {
873
- productdata = jQuery( this );
874
-
875
- ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push( '".gtm4wp_prefix_productid("")."' + productdata.data( 'gtm4wp_product_id' ) );
876
- });
877
- }
878
- })(jQuery);
879
- </script>";
880
- }
881
-
882
- if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
883
- echo "
884
- <script data-cfasync='false' type='text/javascript'>
885
- (function($) {
886
- if ( $( '.gtm4wp_productdata,.widget-product-item' ).length > 0 ) {
887
- for( var i=0; i<". $gtm4wp_datalayer_name .".length; i++ ) {
888
- if ( ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] ) {
889
-
890
- if ( ! ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] ) {
891
- ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = [];
892
- }
893
-
894
- break;
895
- }
896
- }
897
-
898
- if ( i == ". $gtm4wp_datalayer_name .".length ) {
899
- // no existing ecommerce data found in the datalayer
900
- i = 0;
901
- ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] = {};
902
- ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = [];
903
- }
904
-
905
- ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'currencyCode' ] = '".get_woocommerce_currency()."';
906
-
907
- var productdata;
908
- $( '.gtm4wp_productdata,.widget-product-item' ).each( function() {
909
- productdata = jQuery( this );
910
-
911
- ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ].push({
912
- 'name': productdata.data( 'gtm4wp_product_name' ),
913
- 'id': productdata.data( 'gtm4wp_product_id' ),
914
- 'price': productdata.data( 'gtm4wp_product_price' ),
915
- 'category': productdata.data( 'gtm4wp_product_cat' ),
916
- 'position': productdata.data( 'gtm4wp_product_listposition' ),
917
- 'list': productdata.data( 'gtm4wp_productlist_name' )
918
- });
919
- });
920
- }
921
- })(jQuery);
922
- </script>";
923
-
924
- gtm4wp_woocommerce_addjs("
925
- $( '.add_to_cart_button:not(.product_type_variable, .product_type_grouped, .single_add_to_cart_button)' ).click(function() {
926
- var productdata = $( this ).closest( '.product' ).find( '.gtm4wp_productdata' );
927
-
928
- ". $gtm4wp_datalayer_name .".push({
929
- 'event': 'gtm4wp.addProductToCartEEC',
930
- 'ecommerce': {
931
- 'currencyCode': '".get_woocommerce_currency()."',
932
- 'add': {
933
- 'products': [{
934
- 'name': productdata.data( 'gtm4wp_product_name' ),
935
- 'id': productdata.data( 'gtm4wp_product_id' ),
936
- 'price': productdata.data( 'gtm4wp_product_price' ),
937
- 'category': productdata.data( 'gtm4wp_product_cat' ),
938
- 'quantity': 1
939
- }]
940
- }
941
- }
942
- });
943
- });
944
- ");
945
- }
946
- }
947
- */
948
-
949
- // moved to gtm4wp-woocommerce-enhanced.js
950
- /*
951
- function gtm4wp_woocommerce_enhanced_ecom_product_click() {
952
- global $gtm4wp_datalayer_name;
953
-
954
- gtm4wp_woocommerce_addjs("
955
- $( '.products li:not(.product-category) a:not(.add_to_cart_button),.widget-product-item' ).click(function( event ) {
956
- if ( 'undefined' == typeof google_tag_manager ) {
957
- return true;
958
- }
959
-
960
- var _productdata = $( this ).closest( '.product' );
961
-
962
- if ( _productdata.length > 0 ) {
963
- var productdata = _productdata.find( '.gtm4wp_productdata' );
964
-
965
- } else {
966
- var _productdata = $( this ).closest( 'ul.products li' );
967
-
968
- if ( _productdata.length > 0 ) {
969
- var productdata = _productdata.find( '.gtm4wp_productdata' );
970
-
971
- } else {
972
- var productdata = jQuery( this );
973
-
974
- }
975
- }
976
-
977
- if ( ( 'undefined' == typeof productdata.data( 'gtm4wp_product_id' ) ) || ( '' == productdata.data( 'gtm4wp_product_id' ) ) ) {
978
- return true;
979
- }
980
-
981
- // only act on links pointing to the product detail page
982
- if ( productdata.data( 'gtm4wp_product_url' ) != $( this ).attr( 'href' ) ) {
983
- return true;
984
- }
985
-
986
- var ctrl_key_pressed = event.ctrlKey;
987
-
988
- event.preventDefault();
989
- if ( ctrl_key_pressed ) {
990
- // we need to open the new tab/page here so that popup blocker of the browser doesn't block our code
991
- var _productpage = window.open( 'about:blank', '_blank' );
992
- }
993
-
994
- ". $gtm4wp_datalayer_name .".push({
995
- 'event': 'gtm4wp.productClickEEC',
996
- 'ecommerce': {
997
- 'currencyCode': '".get_woocommerce_currency()."',
998
- 'click': {
999
- 'actionField': {'list': productdata.data( 'gtm4wp_productlist_name' )},
1000
- 'products': [{
1001
- 'id': productdata.data( 'gtm4wp_product_id' ),
1002
- 'name': productdata.data( 'gtm4wp_product_name' ),
1003
- 'price': productdata.data( 'gtm4wp_product_price' ),
1004
- 'category': productdata.data( 'gtm4wp_product_cat' ),
1005
- 'position': productdata.data( 'gtm4wp_product_listposition' )
1006
- }]
1007
- }
1008
- },
1009
- 'eventCallback': function() {
1010
- if ( ctrl_key_pressed && _productpage ) {
1011
- _productpage.location.href= productdata.data( 'gtm4wp_product_url' );
1012
- } else {
1013
- document.location.href = productdata.data( 'gtm4wp_product_url' )
1014
- }
1015
- },
1016
- 'eventTimeout': 2000
1017
- });
1018
- });
1019
- ");
1020
- }
1021
- */
1022
-
1023
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
1024
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $cart_id="" ) {
1025
  global $gtm4wp_options, $gtm4wp_is_woocommerce3;
@@ -1334,6 +899,7 @@ function gtm4wp_wc_quick_view_before_single_product() {
1334
 
1335
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
1336
  $dataLayer["ecommerce"] = array(
 
1337
  "detail" => array(
1338
  "products" => array($eec_product_array)
1339
  )
@@ -1387,4 +953,4 @@ if ( function_exists ( "WC" ) ) {
1387
  add_action( "woocommerce_shortcode_before_featured_products_loop", "gtm4wp_before_featured_products_loop" );
1388
  add_action( "woocommerce_shortcode_before_related_products_loop", "gtm4wp_before_related_products_loop" );
1389
  }
1390
- }
198
 
199
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
200
  $dataLayer["ecommerce"] = array(
201
+ "currencyCode" => get_woocommerce_currency(),
202
  "detail" => array(
203
  "products" => array($eec_product_array)
204
  )
213
  }
214
  }
215
  } else if ( is_cart() ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
217
  $gtm4wp_cart_products = array();
218
  $gtm4wp_cart_products_remarketing = array();
274
 
275
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
276
  $dataLayer["ecommerce"] = array(
277
+ "currencyCode" => get_woocommerce_currency(),
278
  "checkout" => array(
279
  "actionField" => array(
280
  "step" => 1
487
 
488
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
489
  $dataLayer["ecommerce"] = array(
490
+ "currencyCode" => get_woocommerce_currency(),
491
  "checkout" => array(
492
  "actionField" => array(
493
  "step" => 1 + (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ]
497
  );
498
 
499
  gtm4wp_woocommerce_addjs("
500
+ window.gtm4wp_checkout_products = " . json_encode($gtm4wp_checkout_products) . ";
501
+ window.gtm4wp_checkout_step_offset = " . (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ";"
502
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  }
504
  }
505
  } else {
508
  }
509
  }
510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  if ( isset ( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] ) ) {
512
  $cart_item = $woo->cart->get_cart_item( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] );
513
  if ( !empty( $cart_item ) ) {
514
+ $product = $cart_item["data"];
515
 
516
  $product_id = $product->get_id();
517
  $product_type = $product->get_type();
529
  $remarketing_id = $product_sku;
530
  }
531
 
532
+ $dataLayer["ecommerce"]["currencyCode"] = get_woocommerce_currency();
533
  $dataLayer["ecommerce"]["add"]["products"][] = array(
534
  "name" => $product->get_title(),
535
  "id" => $remarketing_id,
585
  }
586
  }
587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  $GLOBALS["gtm4wp_cart_item_proddata"] = '';
589
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $cart_id="" ) {
590
  global $gtm4wp_options, $gtm4wp_is_woocommerce3;
899
 
900
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
901
  $dataLayer["ecommerce"] = array(
902
+ "currencyCode" => get_woocommerce_currency(),
903
  "detail" => array(
904
  "products" => array($eec_product_array)
905
  )
953
  add_action( "woocommerce_shortcode_before_featured_products_loop", "gtm4wp_before_featured_products_loop" );
954
  add_action( "woocommerce_shortcode_before_related_products_loop", "gtm4wp_before_related_products_loop" );
955
  }
956
+ }
integration/youtube.php CHANGED
@@ -1,7 +1,10 @@
1
  <?php
2
  function gtm4wp_youtube( $return, $url, $data ) {
 
 
 
3
  if ( false !== strpos( $return, "youtube.com" ) ) {
4
- return str_replace( "feature=oembed", "feature=oembed&enablejsapi=1&origin=" . site_url(), $return );
5
  } else {
6
  return $return;
7
  }
1
  <?php
2
  function gtm4wp_youtube( $return, $url, $data ) {
3
+ $site_url = site_url();
4
+ $site_url_parts = parse_url( $site_url );
5
+
6
  if ( false !== strpos( $return, "youtube.com" ) ) {
7
+ return str_replace( "feature=oembed", "feature=oembed&enablejsapi=1&origin=" . $site_url_parts["scheme"] . "://" . $site_url_parts["host"], $return );
8
  } else {
9
  return $return;
10
  }
js/gtm4wp-woocommerce-enhanced.js CHANGED
@@ -1,4 +1,5 @@
1
  var gtm4wp_last_selected_product_variation;
 
2
 
3
  function gtm4wp_handle_cart_qty_change() {
4
  jQuery( '.product-quantity input.qty' ).each(function() {
@@ -297,7 +298,7 @@ jQuery(function() {
297
  return true;
298
  }
299
 
300
- var ctrl_key_pressed = event.ctrlKey;
301
 
302
  event.preventDefault();
303
  if ( ctrl_key_pressed ) {
@@ -339,6 +340,11 @@ jQuery(function() {
339
  return;
340
  }
341
 
 
 
 
 
 
342
  var _product_form = event.target;
343
  var _product_var_id = jQuery( '[name=variation_id]', _product_form );
344
  var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
@@ -381,8 +387,12 @@ jQuery(function() {
381
  },
382
  'ecomm_prodid': gtm4wp_id_prefix + current_product_detail_data.id,
383
  'ecomm_pagetype': 'product',
384
- 'ecomm_totalvalue': current_product_detail_data.price
385
  });
 
 
 
 
386
  });
387
  jQuery( '.variations select' ).trigger( 'change' );
388
 
@@ -440,7 +450,7 @@ jQuery(function() {
440
  gtm4wp_checkout_step_fired.push( 'shipping' );
441
  });
442
 
443
- jQuery( document ).on( 'click', 'input[name=shipping_method]', function() {
444
  // do not report checkout step if already reported
445
  if ( gtm4wp_checkout_step_fired.indexOf( 'shipping_method' ) > -1 ) {
446
  return;
@@ -466,7 +476,7 @@ jQuery(function() {
466
  gtm4wp_checkout_step_fired.push( 'shipping_method' );
467
  });
468
 
469
- jQuery( document ).on( 'click', 'input[name=payment_method]', function() {
470
  // do not report checkout step if already reported
471
  if ( gtm4wp_checkout_step_fired.indexOf( 'payment_method' ) > -1 ) {
472
  return;
1
  var gtm4wp_last_selected_product_variation;
2
+ var gtm4wp_changedetail_fired_during_pageload=false;
3
 
4
  function gtm4wp_handle_cart_qty_change() {
5
  jQuery( '.product-quantity input.qty' ).each(function() {
298
  return true;
299
  }
300
 
301
+ var ctrl_key_pressed = event.ctrlKey || event.metaKey;
302
 
303
  event.preventDefault();
304
  if ( ctrl_key_pressed ) {
340
  return;
341
  }
342
 
343
+ if ( (document.readyState === "interactive") && gtm4wp_changedetail_fired_during_pageload ) {
344
+ // some custom attribute rendering plugins fire this event multiple times during page load
345
+ return;
346
+ }
347
+
348
  var _product_form = event.target;
349
  var _product_var_id = jQuery( '[name=variation_id]', _product_form );
350
  var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
387
  },
388
  'ecomm_prodid': gtm4wp_id_prefix + current_product_detail_data.id,
389
  'ecomm_pagetype': 'product',
390
+ 'ecomm_totalvalue': current_product_detail_data.price,
391
  });
392
+
393
+ if ( document.readyState === "interactive" ) {
394
+ gtm4wp_changedetail_fired_during_pageload = true;
395
+ }
396
  });
397
  jQuery( '.variations select' ).trigger( 'change' );
398
 
450
  gtm4wp_checkout_step_fired.push( 'shipping' );
451
  });
452
 
453
+ jQuery( document ).on( 'change', 'input[name=shipping_method]', function() {
454
  // do not report checkout step if already reported
455
  if ( gtm4wp_checkout_step_fired.indexOf( 'shipping_method' ) > -1 ) {
456
  return;
476
  gtm4wp_checkout_step_fired.push( 'shipping_method' );
477
  });
478
 
479
+ jQuery( document ).on( 'change', 'input[name=payment_method]', function() {
480
  // do not report checkout step if already reported
481
  if ( gtm4wp_checkout_step_fired.indexOf( 'payment_method' ) > -1 ) {
482
  return;
js/gtm4wp-woocommerce-tracker.js DELETED
@@ -1,15 +0,0 @@
1
- jQuery( function() {
2
- jQuery( "body" )
3
- .on( "added_to_cart", function() {
4
- window[ gtm4wp_datalayer_name ].push({
5
- 'event': 'gtm4wp.addProductToCart'
6
- });
7
- });
8
-
9
- if ( window.location.search.indexOf( "added-to-cart" ) > -1 ) {
10
- window[ gtm4wp_datalayer_name ].push({
11
- 'event': 'gtm4wp.addProductToCart'
12
- });
13
- }
14
- });
15
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public/frontend.php CHANGED
@@ -49,6 +49,72 @@ function gtm4wp_is_assoc($arr) {
49
  return array_keys($arr) !== range(0, count($arr) - 1);
50
  }
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  if ( !function_exists( "getallheaders") ) {
53
  function getallheaders() {
54
  $headers = array();
@@ -121,17 +187,7 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
121
  }
122
 
123
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_VISITOR_IP ] ) {
124
- if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
125
- //check ip from shared internet
126
- $ip = $_SERVER['HTTP_CLIENT_IP'];
127
- } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
128
- //to check ip is passed from proxy
129
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
130
- } else {
131
- $ip = $_SERVER['REMOTE_ADDR'];
132
- }
133
-
134
- $dataLayer["visitorIP"] = $ip;
135
  }
136
 
137
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTITLE ] ) {
@@ -254,7 +310,15 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
254
 
255
  if ( is_search() ) {
256
  $dataLayer["siteSearchTerm"] = get_search_query();
257
- $dataLayer["siteSearchFrom"] = ( isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "" );
 
 
 
 
 
 
 
 
258
  $dataLayer["siteSearchResults"] = $wp_query->post_count;
259
  }
260
 
@@ -457,13 +521,11 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
457
  $dataLayer[ "geoLongitude" ] = __( "(no geo data available)", 'duracelltomi-google-tag-manager' );
458
  }
459
 
460
- $gtm4wp_sessionid = array_key_exists( "gtm4wp_sessionid", $_COOKIE ) ? $_COOKIE[ "gtm4wp_sessionid" ] : "";
461
- // this is needed so that nobody can do a hack by editing our cookie
462
- $gtm4wp_sessionid = str_replace( "'", "", trim( basename( $gtm4wp_sessionid ) ) );
463
 
464
- if ( "" !== $gtm4wp_sessionid ) {
465
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) {
466
- $weatherdata = get_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid );
467
 
468
  if ( false !== $weatherdata ) {
469
  $dataLayer[ "weatherCategory" ] = $weatherdata->weather[0]->main;
@@ -475,26 +537,28 @@ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
475
  $dataLayer[ "weatherFullWeatherData" ] = $weatherdata;
476
  $dataLayer[ "weatherDataStatus" ] = "Read from cache";
477
  } else {
478
- $dataLayer[ "weatherDataStatus" ] = "GTM4WP session active but no weather data in cache (" . $gtm4wp_sessionid . ")";
479
  }
480
  }
481
 
482
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
483
- $geodata = get_transient( 'gtm4wp-geodata-'.$gtm4wp_sessionid );
484
 
485
  if ( false !== $geodata ) {
486
- $dataLayer[ "geoCountryCode" ] = $geodata->country_code;
487
- $dataLayer[ "geoCountryName" ] = $geodata->country_name;
488
- $dataLayer[ "geoRegionCode" ] = $geodata->region_code;
489
- $dataLayer[ "geoRegionName" ] = $geodata->region_name;
490
- $dataLayer[ "geoCity" ] = $geodata->city;
491
- $dataLayer[ "geoZipcode" ] = $geodata->zip;
492
- $dataLayer[ "geoLatitude" ] = $geodata->latitude;
493
- $dataLayer[ "geoLongitude" ] = $geodata->longitude;
494
  $dataLayer[ "geoFullGeoData" ] = $geodata;
 
 
 
 
 
 
 
 
 
 
 
495
  }
496
  }
497
-
498
  }
499
  }
500
 
@@ -505,28 +569,25 @@ function gtm4wp_wp_loaded() {
505
  global $gtm4wp_options;
506
 
507
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
508
- $gtm4wp_sessionid = array_key_exists( "gtm4wp_sessionid", $_COOKIE ) ? $_COOKIE[ "gtm4wp_sessionid" ] : "";
509
- // this is needed so that nobody can do a hack by editing our cookie
510
- $gtm4wp_sessionid = str_replace( "'", "", trim( basename( $gtm4wp_sessionid ) ) );
511
-
512
- if ( "" === $gtm4wp_sessionid ) {
513
- $gtm4wp_sessionid = substr( md5( date( "Ymd_His" ).rand() ), 0, 20 );
514
- setcookie( "gtm4wp_sessionid", $gtm4wp_sessionid, time()+(60*60*24*365*2) );
515
- }
516
-
517
- $geodata = get_transient( 'gtm4wp-geodata-'.$gtm4wp_sessionid );
518
 
519
  if ( false === $geodata ) {
520
- $gtm4wp_geodata = @wp_remote_get( sprintf( 'http://api.ipstack.com/%s?access_key=%s&format=1', $_SERVER['REMOTE_ADDR'], $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEOAPI ] ) );
 
 
 
 
 
521
 
522
  if ( is_array( $gtm4wp_geodata ) && ( 200 == $gtm4wp_geodata[ "response" ][ "code" ] ) ) {
523
  $gtm4wp_geodata = @json_decode( $gtm4wp_geodata[ "body" ] );
524
 
525
  if ( is_object( $gtm4wp_geodata ) ) {
526
- set_transient( 'gtm4wp-geodata-'.$gtm4wp_sessionid, $gtm4wp_geodata, 60 * 60 );
527
 
528
- $weatherdata = get_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid );
529
- if ( false === $weatherdata) {
530
 
531
  $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') );
532
 
@@ -534,7 +595,7 @@ function gtm4wp_wp_loaded() {
534
  $weatherdata = @json_decode( $weatherdata[ "body" ] );
535
 
536
  if ( is_object( $weatherdata ) ) {
537
- set_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid, $weatherdata, 60 * 60 );
538
  setcookie( "gtm4wp_last_weatherstatus", "Weather data loaded." );
539
  } else {
540
  setcookie( "gtm4wp_last_weatherstatus", "Openweathermap.org did not return processable data: " . var_dump( $weatherdata, true ) );
@@ -548,13 +609,13 @@ function gtm4wp_wp_loaded() {
548
  }
549
  }
550
  } else {
551
- setcookie( "gtm4wp_last_weatherstatus", "freegeoip.net did not return lat-lng data: " . var_dump( $gtm4wp_geodata, true ) );
552
  }
553
  } else {
554
  if ( is_wp_error( $gtm4wp_geodata ) ) {
555
- setcookie( "gtm4wp_last_weatherstatus", "freegeoip.net request error: " . $gtm4wp_geodata->get_error_message() );
556
  } else {
557
- setcookie( "gtm4wp_last_weatherstatus", "freegeoip.net returned status code: " . $gtm4wp_geodata[ "response" ][ "code" ] );
558
  }
559
  }
560
  }
@@ -748,7 +809,7 @@ function gtm4wp_wp_header_begin( $echo = true ) {
748
  add_filter( GTM4WP_WPFILTER_COMPILE_REMARKTING, "gtm4wp_filter_visitor_keys" );
749
  $gtm4wp_remarketing_tags = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_REMARKTING, $gtm4wp_datalayer_data );
750
 
751
- $_gtm_header_content .= 'var google_tag_params = ';
752
  $_gtm_header_content .= json_encode( $gtm4wp_remarketing_tags );
753
  $_gtm_header_content .= ';';
754
  $gtm4wp_datalayer_data["google_tag_params"] = "-~-window.google_tag_params-~-";
49
  return array_keys($arr) !== range(0, count($arr) - 1);
50
  }
51
 
52
+ /**
53
+ * Original copyright:
54
+ * By Grant Burton @ BURTONTECH.COM (11-30-2008): IP-Proxy-Cluster Fix
55
+ *
56
+ * Code improved by Thomas Geiger
57
+ */
58
+ function gtm4wp_ip_is_private( $ip ) {
59
+ $int_ip = ip2long($ip);
60
+ if ( !empty($ip) && $int_ip!=-1 && $int_ip!==false ) {
61
+ $private_ips = array (
62
+ array('0.0.0.0', '2.255.255.255'),
63
+ array('10.0.0.0', '10.255.255.255'),
64
+ array('127.0.0.0', '127.255.255.255'),
65
+ array('169.254.0.0', '169.254.255.255'),
66
+ array('172.16.0.0', '172.31.255.255'),
67
+ array('192.0.2.0', '192.0.2.255'),
68
+ array('192.168.0.0', '192.168.255.255'),
69
+ array('255.255.255.0','255.255.255.255')
70
+ );
71
+
72
+ foreach ($private_ips as $private_ip) {
73
+ $min_int_ip = ip2long( $private_ip[0] );
74
+ $max_int_ip = ip2long( $private_ip[1] );
75
+ if ( ($int_ip >= $min) && ($int_ip <= $max) ) {
76
+ return true;
77
+ }
78
+ }
79
+
80
+ return false;
81
+ } else {
82
+ return true;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Original copyright:
88
+ * By Grant Burton @ BURTONTECH.COM
89
+ *
90
+ * Code improved by Thomas Geiger
91
+ */
92
+ function gtm4wp_get_user_ip() {
93
+ if ( !empty($_SERVER["HTTP_CLIENT_IP"]) && !gtm4wp_ip_is_private($_SERVER["HTTP_CLIENT_IP"]) ) {
94
+ return $_SERVER["HTTP_CLIENT_IP"];
95
+ }
96
+
97
+ if ( !empty($_SERVER["HTTP_X_FORWARDED_FOR"]) ) {
98
+ foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) {
99
+ if ( !gtm4wp_ip_is_private(trim($ip)) ) {
100
+ return $ip;
101
+ }
102
+ }
103
+ }
104
+
105
+ if ( !empty($_SERVER["HTTP_X_FORWARDED"]) && !gtm4wp_ip_is_private($_SERVER["HTTP_X_FORWARDED"]) ) {
106
+ return $_SERVER["HTTP_X_FORWARDED"];
107
+ } elseif ( !empty($_SERVER["HTTP_X_CLUSTER_CLIENT_IP"]) && !gtm4wp_ip_is_private($_SERVER["HTTP_X_CLUSTER_CLIENT_IP"]) ) {
108
+ return $_SERVER["HTTP_X_CLUSTER_CLIENT_IP"];
109
+ } elseif ( !empty($_SERVER["HTTP_FORWARDED_FOR"]) && !gtm4wp_ip_is_private($_SERVER["HTTP_FORWARDED_FOR"]) ) {
110
+ return $_SERVER["HTTP_FORWARDED_FOR"];
111
+ } elseif ( !empty($_SERVER["HTTP_FORWARDED"]) && !gtm4wp_ip_is_private($_SERVER["HTTP_FORWARDED"]) ) {
112
+ return $_SERVER["HTTP_FORWARDED"];
113
+ } else {
114
+ return $_SERVER["REMOTE_ADDR"];
115
+ }
116
+ }
117
+
118
  if ( !function_exists( "getallheaders") ) {
119
  function getallheaders() {
120
  $headers = array();
187
  }
188
 
189
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_VISITOR_IP ] ) {
190
+ $dataLayer["visitorIP"] = esc_js( gtm4wp_get_user_ip() );
 
 
 
 
 
 
 
 
 
 
191
  }
192
 
193
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTITLE ] ) {
310
 
311
  if ( is_search() ) {
312
  $dataLayer["siteSearchTerm"] = get_search_query();
313
+ $dataLayer["siteSearchFrom"] = "";
314
+ if ( !empty($_SERVER["HTTP_REFERER"]) ) {
315
+ $referer_url_parts = explode("?", $_SERVER["HTTP_REFERER"]);
316
+ if ( count( $referer_url_parts ) > 1 ) {
317
+ $dataLayer["siteSearchFrom"] = $referer_url_parts[0] . "?" . rawurlencode( $referer_url_parts[1] );
318
+ } else {
319
+ $dataLayer["siteSearchFrom"] = $referer_url_parts[0];
320
+ }
321
+ }
322
  $dataLayer["siteSearchResults"] = $wp_query->post_count;
323
  }
324
 
521
  $dataLayer[ "geoLongitude" ] = __( "(no geo data available)", 'duracelltomi-google-tag-manager' );
522
  }
523
 
524
+ $client_ip = gtm4wp_get_user_ip();
 
 
525
 
526
+ if ( "" !== $client_ip ) {
527
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) {
528
+ $weatherdata = get_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ) );
529
 
530
  if ( false !== $weatherdata ) {
531
  $dataLayer[ "weatherCategory" ] = $weatherdata->weather[0]->main;
537
  $dataLayer[ "weatherFullWeatherData" ] = $weatherdata;
538
  $dataLayer[ "weatherDataStatus" ] = "Read from cache";
539
  } else {
540
+ $dataLayer[ "weatherDataStatus" ] = "No weather data in cache (" . esc_attr( $client_ip ) . ")";
541
  }
542
  }
543
 
544
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
545
+ $geodata = get_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ) );
546
 
547
  if ( false !== $geodata ) {
 
 
 
 
 
 
 
 
548
  $dataLayer[ "geoFullGeoData" ] = $geodata;
549
+
550
+ if ( isset( $geodata->latitude ) ) {
551
+ $dataLayer[ "geoCountryCode" ] = $geodata->country_code;
552
+ $dataLayer[ "geoCountryName" ] = $geodata->country_name;
553
+ $dataLayer[ "geoRegionCode" ] = $geodata->region_code;
554
+ $dataLayer[ "geoRegionName" ] = $geodata->region_name;
555
+ $dataLayer[ "geoCity" ] = $geodata->city;
556
+ $dataLayer[ "geoZipcode" ] = $geodata->zip;
557
+ $dataLayer[ "geoLatitude" ] = $geodata->latitude;
558
+ $dataLayer[ "geoLongitude" ] = $geodata->longitude;
559
+ }
560
  }
561
  }
 
562
  }
563
  }
564
 
569
  global $gtm4wp_options;
570
 
571
  if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
572
+ $client_ip = gtm4wp_get_user_ip();
573
+ $geodata = get_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ) );
 
 
 
 
 
 
 
 
574
 
575
  if ( false === $geodata ) {
576
+ $log =
577
+ "User: ".gtm4wp_get_user_ip()." - ".date("F j, Y, g:i a")." - Session ID: " . esc_attr( $client_ip ) . " - ".
578
+ "URL: ".sprintf( 'http://api.ipstack.com/%s?access_key=%s&format=1', urlencode( gtm4wp_get_user_ip() ), $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEOAPI ] ).PHP_EOL;
579
+ file_put_contents(dirname(__FILE__).'/ipstack_log/'.date("Y-m-d").'.log', $log, FILE_APPEND);
580
+
581
+ $gtm4wp_geodata = @wp_remote_get( sprintf( 'http://api.ipstack.com/%s?access_key=%s&format=1', urlencode( $client_ip ), $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEOAPI ] ) );
582
 
583
  if ( is_array( $gtm4wp_geodata ) && ( 200 == $gtm4wp_geodata[ "response" ][ "code" ] ) ) {
584
  $gtm4wp_geodata = @json_decode( $gtm4wp_geodata[ "body" ] );
585
 
586
  if ( is_object( $gtm4wp_geodata ) ) {
587
+ set_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ), $gtm4wp_geodata, 60 * 60 );
588
 
589
+ $weatherdata = get_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ) );
590
+ if ( false === $weatherdata && isset( $gtm4wp_geodata->latitude ) ) {
591
 
592
  $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') );
593
 
595
  $weatherdata = @json_decode( $weatherdata[ "body" ] );
596
 
597
  if ( is_object( $weatherdata ) ) {
598
+ set_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ), $weatherdata, 60 * 60 );
599
  setcookie( "gtm4wp_last_weatherstatus", "Weather data loaded." );
600
  } else {
601
  setcookie( "gtm4wp_last_weatherstatus", "Openweathermap.org did not return processable data: " . var_dump( $weatherdata, true ) );
609
  }
610
  }
611
  } else {
612
+ setcookie( "gtm4wp_last_weatherstatus", "ipstack.com did not return lat-lng data: " . var_dump( $gtm4wp_geodata, true ) );
613
  }
614
  } else {
615
  if ( is_wp_error( $gtm4wp_geodata ) ) {
616
+ setcookie( "gtm4wp_last_weatherstatus", "ipstack.com request error: " . $gtm4wp_geodata->get_error_message() );
617
  } else {
618
+ setcookie( "gtm4wp_last_weatherstatus", "ipstack.com returned status code: " . $gtm4wp_geodata[ "response" ][ "code" ] );
619
  }
620
  }
621
  }
809
  add_filter( GTM4WP_WPFILTER_COMPILE_REMARKTING, "gtm4wp_filter_visitor_keys" );
810
  $gtm4wp_remarketing_tags = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_REMARKTING, $gtm4wp_datalayer_data );
811
 
812
+ $_gtm_header_content .= "\nvar google_tag_params = ";
813
  $_gtm_header_content .= json_encode( $gtm4wp_remarketing_tags );
814
  $_gtm_header_content .= ';';
815
  $gtm4wp_datalayer_data["google_tag_params"] = "-~-window.google_tag_params-~-";
readme.txt CHANGED
@@ -1,15 +1,15 @@
1
  === DuracellTomi's Google Tag Manager for WordPress ===
2
  Contributors: duracelltomi
3
  Donate link: https://gtm4wp.com/
4
- Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, google ads, adwords remarketing, google ads remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel, google optimize
5
  Requires at least: 3.4.0
6
  Requires PHP: 5.6
7
- Tested up to: 4.9.8
8
- Stable tag: 1.9
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
12
- The first Google Tag Manager plugin for WordPress with business goals in mind. Includes full support for Google Optimize as well.
13
 
14
  == Description ==
15
 
@@ -258,6 +258,19 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So
258
 
259
  == Changelog ==
260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  = 1.9 =
262
 
263
  * Added: initial support for AMP plugin from Automattic (thx koconder for the contribution!)
@@ -564,6 +577,10 @@ Please report all bugs found in my plugin using the [contact form on my website]
564
 
565
  == Upgrade Notice ==
566
 
 
 
 
 
567
  = 1.9 =
568
 
569
  New AMP GTM support, full Google Optimize support, lots of WooCommerce tracking improvements.
1
  === DuracellTomi's Google Tag Manager for WordPress ===
2
  Contributors: duracelltomi
3
  Donate link: https://gtm4wp.com/
4
+ Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, google ads, adwords remarketing, google ads remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel, google optimize, personalisation
5
  Requires at least: 3.4.0
6
  Requires PHP: 5.6
7
+ Tested up to: 5.0.3
8
+ Stable tag: 1.9.1
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
12
+ Advanced measurement/advertising tag management and site personalisation for WordPress with Google Tag Manager and Google Optimize
13
 
14
  == Description ==
15
 
258
 
259
  == Changelog ==
260
 
261
+ = 1.9.1 =
262
+
263
+ * Fixed: handle out of quota cases with ipstack queries properly
264
+ * Fixed: proper YouTube tracking for WordPress sites and WordPress multisites installed in a subdirectory
265
+ * Fixed: properly detect client IP address and also properly escape this data while using it
266
+ * Fixed: WooCommerce checkout steps after page load did not include products in the cart
267
+ * Fixed: checkout step events for payment mode and shipping type not always fired
268
+ * Fixed: the CMD on Mac will be treated just like the Ctrl key on Windows while processing the product click event in the WooCommerce integration (thy for luzinis)
269
+ * Fixed: add currencyCode to every ecommerce action in WooCommerce integration
270
+ * Fixed: better WooCommere Quick View integration
271
+ * Fixed: possible cross site scripting vulnerability if site search tracking was enabled due to not properly escaped referrer url tracking
272
+ * Changed: code cleanup in WooCommerce integration
273
+
274
  = 1.9 =
275
 
276
  * Added: initial support for AMP plugin from Automattic (thx koconder for the contribution!)
577
 
578
  == Upgrade Notice ==
579
 
580
+ = 1.9.1 =
581
+
582
+ Bugfix version
583
+
584
  = 1.9 =
585
 
586
  New AMP GTM support, full Google Optimize support, lots of WooCommerce tracking improvements.