Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upgrade notice if property ID starts with "UA" #321

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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