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

Google Analytics: delete feature removal notices #38882

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import { getLicensingError, clearLicensingError } from 'state/licensing';
import { getModule } from 'state/modules';
import { getSiteDataErrors } from 'state/site';
import { isPluginActive } from 'state/site/plugins';
import { StartFreshDeprecationWarning } from '../../writing/custom-css';
import DismissableNotices from './dismissable';
import JetpackConnectionErrors from './jetpack-connection-errors';
Expand Down Expand Up @@ -187,12 +186,6 @@ class JetpackNotices extends React.Component {

const cookieParsed = cookie.parse( document.cookie );
this.state = {
isGoogleAnalyticsNoticeDismissed:
cookieParsed &&
cookieParsed.hasOwnProperty(
'jetpack_deprecate_dismissed[jetpack-ga-admin-removal-notice]'
) &&
'1' === cookieParsed[ 'jetpack_deprecate_dismissed[jetpack-ga-admin-removal-notice]' ],
isMasterbarNoticeDismissed:
cookieParsed &&
cookieParsed.hasOwnProperty(
Expand All @@ -203,20 +196,6 @@ class JetpackNotices extends React.Component {
};
}

dismissGoogleAnalyticsNotice = () => {
this.setState( { isGoogleAnalyticsNoticeDismissed: true } );

document.cookie = cookie.serialize(
'jetpack_deprecate_dismissed[jetpack-ga-admin-removal-notice]',
'1',
{
path: '/',
maxAge: 365 * 24 * 60 * 60,
SameSite: 'None',
}
);
};

dismissMasterbarNotice = () => {
this.setState( { isMasterbarNoticeDismissed: true } );

Expand All @@ -237,8 +216,6 @@ class JetpackNotices extends React.Component {
);

const isUserConnectScreen = this.props.location.pathname.startsWith( '/connect-user' );
const showGoogleAnalyticsNotice =
this.props.showGoogleAnalyticsNotice && ! this.state.isGoogleAnalyticsNoticeDismissed;

const showMasterbarNotice =
this.props.showMasterbarNotice && ! this.state.isMasterbarNoticeDismissed;
Expand Down Expand Up @@ -300,21 +277,6 @@ class JetpackNotices extends React.Component {
<StartFreshDeprecationWarning siteAdminUrl={ this.props.siteAdminUrl } />
</SimpleNotice>
) }
{ showGoogleAnalyticsNotice && (
<SimpleNotice
status="is-warning"
dismissText={ __( 'Dismiss', 'jetpack' ) }
onDismissClick={ this.dismissGoogleAnalyticsNotice }
>
<div>{ __( "Jetpack's Google Analytics has been removed.", 'jetpack' ) }</div>
<ExternalLink href={ getRedirectUrl( 'jetpack-support-google-analytics' ) }>
{ __(
'To keep tracking visits and more information on this change, please refer to this document',
'jetpack'
) }
</ExternalLink>
</SimpleNotice>
) }
{ showMasterbarNotice && (
<SimpleNotice
status="is-warning"
Expand Down Expand Up @@ -358,18 +320,6 @@ export default connect(
hasConnectedOwner: hasConnectedOwner( state ),
siteAdminUrl: getSiteAdminUrl( state ),
startFreshEnabled: !! getModule( state, 'custom-css' )?.options?.replace,
showGoogleAnalyticsNotice:
window.Initial_State?.isGoogleAnalyticsActive &&
! isWoASite( state ) &&
isPluginActive(
// Making sure the plugins are loaded with no flickering caused by "isFetchingPluginsData".
state,
'jetpack/jetpack.php'
) &&
! isPluginActive(
state,
'jetpack-legacy-google-analytics/jetpack-legacy-google-analytics.php'
),
showMasterbarNotice: window.Initial_State?.isMasterbarActive && ! isWoASite( state ),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public static function get_initial_state() {
'isSubscriptionSiteEnabled' => apply_filters( 'jetpack_subscription_site_enabled', false ),
'newsletterDateExample' => gmdate( get_option( 'date_format' ), time() ),
'subscriptionSiteEditSupported' => $current_theme->is_block_theme(),
'isGoogleAnalyticsActive' => ( new Modules() )->is_active( 'google-analytics', false ),
'isMasterbarActive' => ( new Modules() )->is_active( 'masterbar', false ),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Delete the Google Analytics removal notices.
49 changes: 9 additions & 40 deletions projects/plugins/jetpack/src/class-deprecate.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class Deprecate {
* Initialize the class.
*/
private function __construct() {
add_action( 'admin_notices', array( $this, 'render_admin_notices' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_filter( 'my_jetpack_red_bubble_notification_slugs', array( $this, 'add_my_jetpack_red_bubbles' ) );
add_filter( 'jetpack_modules_list_table_items', array( $this, 'remove_masterbar_module_list' ) );
if ( $this->has_notices() ) {
add_action( 'admin_notices', array( $this, 'render_admin_notices' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_filter( 'my_jetpack_red_bubble_notification_slugs', array( $this, 'add_my_jetpack_red_bubbles' ) );
add_filter( 'jetpack_modules_list_table_items', array( $this, 'remove_masterbar_module_list' ) );
}
}

/**
Expand Down Expand Up @@ -76,15 +78,6 @@ public function enqueue_admin_scripts() {
* @return void
*/
public function render_admin_notices() {
if ( $this->show_ga_notice() ) {
$support_url = Redirect::get_url( 'jetpack-support-google-analytics' );

$this->render_notice(
'jetpack-ga-admin-removal-notice',
esc_html__( "Jetpack's Google Analytics has been removed.", 'jetpack' )
. ' <a href="' . $support_url . '" target="_blank">' . esc_html__( 'To keep tracking visits and more information on this change, please refer to this document', 'jetpack' ) . '</a>.'
);
}
if ( $this->show_masterbar_notice() ) {
$support_url = Redirect::get_url( 'jetpack-support-masterbar' );

Expand All @@ -101,21 +94,9 @@ public function render_admin_notices() {
*
* @param array $slugs Already added bubbles.
*
* @return mixed
* @return array
*/
public function add_my_jetpack_red_bubbles( $slugs ) {
if ( $this->show_ga_notice() ) {
$slugs['jetpack-google-analytics-deprecate-feature'] = array(
'data' => array(
'text' => __( "Jetpack's Google Analytics has been removed.", 'jetpack' ),
'link' => array(
'label' => esc_html__( 'See documentation', 'jetpack' ),
'url' => Redirect::get_url( 'jetpack-support-google-analytics' ),
),
'id' => 'jetpack-ga-admin-removal-notice',
),
);
}
if ( $this->show_masterbar_notice() ) {
$slugs['jetpack-masterbar-deprecate-feature'] = array(
'data' => array(
Expand Down Expand Up @@ -168,24 +149,12 @@ private function render_notice( $id, $text, $params = array() ) {
}

/**
* Check if there are any notices to be displayed, so we wouldn't load unnecessary JS.
* Check if there are any notices to be displayed, so we wouldn't load unnecessary JS and run excessive hooks.
*
* @return bool
*/
private function has_notices() {
return ( $this->show_ga_notice() || $this->show_masterbar_notice() );
}

/**
* Check if Google Analytics notice should show up.
*
* @return bool
*/
private function show_ga_notice() {
return ( new Modules() )->is_active( 'google-analytics', false )
&& ! is_plugin_active( 'jetpack-legacy-google-analytics/jetpack-legacy-google-analytics.php' )
&& ! ( new Host() )->is_woa_site()
&& empty( $_COOKIE['jetpack_deprecate_dismissed']['jetpack-ga-admin-removal-notice'] );
return $this->show_masterbar_notice();
}

/**
Expand Down
Loading