Skip to content

Commit

Permalink
Merge pull request #321 from woocommerce/add/ua-update-notice
Browse files Browse the repository at this point in the history
Add upgrade notice if property ID starts with "UA"
  • Loading branch information
martynmjones authored Oct 31, 2023
2 parents a3d1ae9 + 1f0b6fc commit 27ba6d9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions includes/class-wc-google-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -111,6 +113,28 @@ 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 ) ) {
echo sprintf(
'<div class="%1$s"><p>%2$s</p></div>',
'notice notice-error',
sprintf(
/* translators: 1) URL for Google documentation on upgrading from UA to GA4 2) URL to WooCommerce Google Analytics settings page */
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' ),
'<a href="https://support.google.com/analytics/answer/9744165" target="_blank">',
'</a>',
'<a href="/wp-admin/admin.php?page=wc-settings&tab=integration&section=google_analytics">',
'</a>'
)
);
}
}

/**
* Loads all of our options for this plugin (stored as properties as well)
*
Expand Down

0 comments on commit 27ba6d9

Please sign in to comment.