From acbe1a4e27d7b311a53d19fe7027ff91fda4fe63 Mon Sep 17 00:00:00 2001 From: Martyn Jones Date: Fri, 27 Oct 2023 17:02:11 +0100 Subject: [PATCH 1/3] Add notice if property ID starts with "UA" --- includes/class-wc-google-analytics.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/includes/class-wc-google-analytics.php b/includes/class-wc-google-analytics.php index f3775753..53001265 100644 --- a/includes/class-wc-google-analytics.php +++ b/includes/class-wc-google-analytics.php @@ -90,6 +90,8 @@ public function __construct() { $this->init_settings(); $constructor = $this->init_options(); + add_action( 'admin_notices', array( $this, 'universal_analytics_upgrade_notice' ) ); + // Contains snippets/JS tracking code include_once 'class-wc-abstract-google-analytics-js.php'; include_once 'class-wc-google-gtag-js.php'; @@ -111,6 +113,26 @@ public function __construct() { add_filter( 'woocommerce_get_return_url', array( $this, 'utm_nooverride' ) ); } + /** + * Conditionally display an error notice to the merchant if the stored property ID starts with "UA" + * + * @return void + */ + public function universal_analytics_upgrade_notice () { + if ( 'ua' === substr( strtolower( $this->get_option( 'ga_id' ) ), 0, 2 ) ) { + printf( + '

%2$s

', + 'notice notice-error', + sprintf( + /* translators: 1) URL for Google documentation on upgrading from UA to GA4 2) URL to WooCommerce Google Analytics settings page */ + __( 'Your website is configured to use Universal Analytics which Google retired in July of 2023. Update your account using the setup assistant and then update your WooCommerce settings.', 'woocommerce-google-analytics-integration' ), + 'https://support.google.com/analytics/answer/9744165?sjid=9632005471070882766-EU#zippy=%2Cin-this-article', + '/wp-admin/admin.php?page=wc-settings&tab=integration§ion=google_analytics' + ) + ); + } + } + /** * Loads all of our options for this plugin (stored as properties as well) * From 6c818bc2fa7a8f6befbf40dd49e0ea93d04444fd Mon Sep 17 00:00:00 2001 From: Martyn Jones Date: Mon, 30 Oct 2023 03:57:28 +0000 Subject: [PATCH 2/3] CS Fixes --- includes/class-wc-google-analytics.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-google-analytics.php b/includes/class-wc-google-analytics.php index 53001265..bd3053f5 100644 --- a/includes/class-wc-google-analytics.php +++ b/includes/class-wc-google-analytics.php @@ -118,14 +118,14 @@ public function __construct() { * * @return void */ - public function universal_analytics_upgrade_notice () { + public function universal_analytics_upgrade_notice() { if ( 'ua' === substr( strtolower( $this->get_option( 'ga_id' ) ), 0, 2 ) ) { - printf( + echo sprintf( '

%2$s

', 'notice notice-error', sprintf( /* translators: 1) URL for Google documentation on upgrading from UA to GA4 2) URL to WooCommerce Google Analytics settings page */ - __( 'Your website is configured to use Universal Analytics which Google retired in July of 2023. Update your account using the setup assistant and then update your WooCommerce settings.', 'woocommerce-google-analytics-integration' ), + __( 'Your website is configured to use Universal Analytics which Google retired in July of 2023. Update your account using the setup assistant and then update your WooCommerce settings.', 'woocommerce-google-analytics-integration' ), // phpcs:ignore WordPress.Security.EscapeOutput 'https://support.google.com/analytics/answer/9744165?sjid=9632005471070882766-EU#zippy=%2Cin-this-article', '/wp-admin/admin.php?page=wc-settings&tab=integration§ion=google_analytics' ) From 1f0b6fc4a75f5a98127e482614363253c689a0a2 Mon Sep 17 00:00:00 2001 From: martynmjones Date: Tue, 31 Oct 2023 08:59:33 +0000 Subject: [PATCH 3/3] Escape notice text and update external URL --- includes/class-wc-google-analytics.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-google-analytics.php b/includes/class-wc-google-analytics.php index bd3053f5..53ebd2ed 100644 --- a/includes/class-wc-google-analytics.php +++ b/includes/class-wc-google-analytics.php @@ -125,9 +125,11 @@ public function universal_analytics_upgrade_notice() { 'notice notice-error', sprintf( /* translators: 1) URL for Google documentation on upgrading from UA to GA4 2) URL to WooCommerce Google Analytics settings page */ - __( 'Your website is configured to use Universal Analytics which Google retired in July of 2023. Update your account using the setup assistant and then update your WooCommerce settings.', 'woocommerce-google-analytics-integration' ), // phpcs:ignore WordPress.Security.EscapeOutput - 'https://support.google.com/analytics/answer/9744165?sjid=9632005471070882766-EU#zippy=%2Cin-this-article', - '/wp-admin/admin.php?page=wc-settings&tab=integration§ion=google_analytics' + esc_html__( 'Your website is configured to use Universal Analytics which Google retired in July of 2023. Update your account using the %1$ssetup assistant%2$s and then update your %3$sWooCommerce settings%4$s.', 'woocommerce-google-analytics-integration' ), + '', + '', + '', + '' ) ); }