WooCommerce Google Analytics Integration - Version 1.4.23

Version Description

  • 2020-08-19 =
  • Fix - Prevent transaction from being tracked a second time when page is reloaded locally or from cache.
  • Tweak - WordPress 5.5 compatibility.
Download this release

Release Info

Developer brezo.cordero
Plugin Icon 128x128 WooCommerce Google Analytics Integration
Version 1.4.23
Comparing to
See all releases

Code changes from version 1.4.22 to 1.4.23

changelog.txt CHANGED
@@ -1,5 +1,9 @@
1
  *** Changelog ***
2
 
 
 
 
 
3
  = 1.4.22 - 2020-06-05 =
4
  * Tweak - WC 4.2 compatibility.
5
 
1
  *** Changelog ***
2
 
3
+ = 1.4.23 - 2020-08-19 =
4
+ * Fix - Prevent transaction from being tracked a second time when page is reloaded locally or from cache.
5
+ * Tweak - WordPress 5.5 compatibility.
6
+
7
  = 1.4.22 - 2020-06-05 =
8
  * Tweak - WC 4.2 compatibility.
9
 
includes/class-wc-google-analytics-js.php CHANGED
@@ -246,7 +246,7 @@ class WC_Google_Analytics_JS {
246
  // See https://developers.google.com/analytics/devguides/collection/analyticsjs/events for reference
247
  $track_404_enabled = "" . self::tracker_var() . "( 'send', 'event', 'Error', '404 Not Found', 'page: ' + document.location.pathname + document.location.search + ' referrer: ' + document.referrer );";
248
  }
249
-
250
  $src = apply_filters('woocommerce_google_analytics_script_src', '//www.google-analytics.com/analytics.js');
251
 
252
  $ga_snippet_head = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@@ -281,20 +281,38 @@ class WC_Google_Analytics_JS {
281
  }
282
 
283
  /**
284
- * Used to pass transaction data to Google Analytics
285
- * @param object $order WC_Order Object
286
- * @return string Add Transaction code
 
287
  */
288
- function add_transaction( $order ) {
289
- if ( 'yes' == self::get( 'ga_use_universal_analytics' ) ) {
290
  if ( 'yes' === self::get( 'ga_enhanced_ecommerce_tracking_enabled' ) ) {
291
- return self::add_transaction_enhanced( $order );
292
  } else {
293
- return self::add_transaction_universal( $order );
294
  }
295
  } else {
296
- return self::add_transaction_classic( $order );
297
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  }
299
 
300
  /**
246
  // See https://developers.google.com/analytics/devguides/collection/analyticsjs/events for reference
247
  $track_404_enabled = "" . self::tracker_var() . "( 'send', 'event', 'Error', '404 Not Found', 'page: ' + document.location.pathname + document.location.search + ' referrer: ' + document.referrer );";
248
  }
249
+
250
  $src = apply_filters('woocommerce_google_analytics_script_src', '//www.google-analytics.com/analytics.js');
251
 
252
  $ga_snippet_head = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
281
  }
282
 
283
  /**
284
+ * Used to pass transaction data to Google Analytics.
285
+ *
286
+ * @param object $order WC_Order Object.
287
+ * @return string Add Transaction code.
288
  */
289
+ public function add_transaction( $order ) {
290
+ if ( 'yes' === self::get( 'ga_use_universal_analytics' ) ) {
291
  if ( 'yes' === self::get( 'ga_enhanced_ecommerce_tracking_enabled' ) ) {
292
+ $transaction_code = self::add_transaction_enhanced( $order );
293
  } else {
294
+ $transaction_code = self::add_transaction_universal( $order );
295
  }
296
  } else {
297
+ $transaction_code = self::add_transaction_classic( $order );
298
  }
299
+
300
+ // Check localStorage to avoid duplicate transactions if page is reloaded without hitting server.
301
+ $code = "
302
+ var ga_orders = [];
303
+ try {
304
+ ga_orders = localStorage.getItem( 'ga_orders' );
305
+ ga_orders = ga_orders ? JSON.parse( ga_orders ) : [];
306
+ } catch {}
307
+ if ( -1 === ga_orders.indexOf( '" . esc_js( $order->get_order_number() ) . "' ) ) {
308
+ " . $transaction_code . "
309
+ try {
310
+ ga_orders.push( '" . esc_js( $order->get_order_number() ) . "' );
311
+ localStorage.setItem( 'ga_orders', JSON.stringify( ga_orders ) );
312
+ } catch {}
313
+ }";
314
+
315
+ return $code;
316
  }
317
 
318
  /**
languages/woocommerce-google-analytics-integration.pot CHANGED
@@ -2,11 +2,11 @@
2
  # This file is distributed under the GPLv2 or later.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WooCommerce Google Analytics Integration 1.4.22\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/woocommerce-google-analytics-"
8
  "integration\n"
9
- "POT-Creation-Date: 2020-06-06 00:00:03+00:00\n"
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=utf-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
2
  # This file is distributed under the GPLv2 or later.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WooCommerce Google Analytics Integration 1.4.23\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/woocommerce-google-analytics-"
8
  "integration\n"
9
+ "POT-Creation-Date: 2020-08-19 20:17:02+00:00\n"
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=utf-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: woocommerce, claudiosanches, bor0, royho, laurendavissmith001, c-shultz
3
  Tags: woocommerce, google analytics
4
  Requires at least: 3.9
5
- Tested up to: 5.4
6
- Stable tag: 1.4.22
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -68,6 +68,10 @@ Exact wording depends on the national data privacy laws and should be adjusted.
68
 
69
  == Changelog ==
70
 
 
 
 
 
71
  = 1.4.22 - 2020-06-05 =
72
  * Tweak - WC 4.2 compatibility.
73
 
2
  Contributors: woocommerce, claudiosanches, bor0, royho, laurendavissmith001, c-shultz
3
  Tags: woocommerce, google analytics
4
  Requires at least: 3.9
5
+ Tested up to: 5.5
6
+ Stable tag: 1.4.23
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
68
 
69
  == Changelog ==
70
 
71
+ = 1.4.23 - 2020-08-19 =
72
+ * Fix - Prevent transaction from being tracked a second time when page is reloaded locally or from cache.
73
+ * Tweak - WordPress 5.5 compatibility.
74
+
75
  = 1.4.22 - 2020-06-05 =
76
  * Tweak - WC 4.2 compatibility.
77
 
woocommerce-google-analytics-integration.php CHANGED
@@ -5,10 +5,10 @@
5
  * Description: Allows Google Analytics tracking code to be inserted into WooCommerce store pages.
6
  * Author: WooCommerce
7
  * Author URI: https://woocommerce.com
8
- * Version: 1.4.22
9
  * WC requires at least: 2.1
10
  * WC tested up to: 4.2
11
- * Tested up to: 5.4
12
  * License: GPLv2 or later
13
  * Text Domain: woocommerce-google-analytics-integration
14
  * Domain Path: languages/
@@ -20,7 +20,7 @@ if ( ! defined( 'ABSPATH' ) ) {
20
 
21
  if ( ! class_exists( 'WC_Google_Analytics_Integration' ) ) {
22
 
23
- define( 'WC_GOOGLE_ANALYTICS_INTEGRATION_VERSION', '1.4.22' ); // WRCS: DEFINED_VERSION.
24
 
25
  /**
26
  * WooCommerce Google Analytics Integration main class.
5
  * Description: Allows Google Analytics tracking code to be inserted into WooCommerce store pages.
6
  * Author: WooCommerce
7
  * Author URI: https://woocommerce.com
8
+ * Version: 1.4.23
9
  * WC requires at least: 2.1
10
  * WC tested up to: 4.2
11
+ * Tested up to: 5.5
12
  * License: GPLv2 or later
13
  * Text Domain: woocommerce-google-analytics-integration
14
  * Domain Path: languages/
20
 
21
  if ( ! class_exists( 'WC_Google_Analytics_Integration' ) ) {
22
 
23
+ define( 'WC_GOOGLE_ANALYTICS_INTEGRATION_VERSION', '1.4.23' ); // WRCS: DEFINED_VERSION.
24
 
25
  /**
26
  * WooCommerce Google Analytics Integration main class.