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: inform users of the feature removal #38701

Merged
merged 5 commits into from
Aug 5, 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 @@ -6,7 +6,7 @@ import type { NoticeOptions } from '../../context/notices/types';
type RedBubbleAlerts = Window[ 'myJetpackInitialState' ][ 'redBubbleAlerts' ];

const useDeprecateFeatureNotice = ( redBubbleAlerts: RedBubbleAlerts ) => {
const { setNotice } = useContext( NoticeContext );
const { setNotice, resetNotice } = useContext( NoticeContext );

useEffect( () => {
const deprecateAlerts = Object.keys( redBubbleAlerts ).filter( key =>
Expand All @@ -18,12 +18,18 @@ const useDeprecateFeatureNotice = ( redBubbleAlerts: RedBubbleAlerts ) => {
}

const alert = redBubbleAlerts[ deprecateAlerts[ 0 ] ];
const { text, link } = alert.data;
const { text, link, id } = alert.data;

const onCtaClick = () => {
window.open( link.url );
};

const onCloseClick = () => {
document.cookie = `jetpack_deprecate_dismissed[${ id }]=1; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=None;`;
delete redBubbleAlerts[ deprecateAlerts[ 0 ] ];
resetNotice();
};

const noticeOptions: NoticeOptions = {
id: 'deprecate-feature-notice',
level: 'error',
Expand All @@ -34,14 +40,16 @@ const useDeprecateFeatureNotice = ( redBubbleAlerts: RedBubbleAlerts ) => {
noDefaultClasses: true,
},
],
hideCloseButton: false,
onClose: onCloseClick,
priority: NOTICE_PRIORITY_MEDIUM,
};

setNotice( {
message: text,
options: noticeOptions,
} );
}, [ redBubbleAlerts, setNotice ] );
}, [ redBubbleAlerts, setNotice, resetNotice ] );
};

export default useDeprecateFeatureNotice;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Modify the Google Analytics notice to notify of the feature removal.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ConnectionBanner from 'components/connection-banner';
import NoticesList from 'components/global-notices';
import SimpleNotice from 'components/notice';
import NoticeAction from 'components/notice/notice-action.jsx';
import cookie from 'cookie';
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
Expand All @@ -33,9 +34,9 @@ import {
isWoASite,
} from 'state/initial-state';
import { getLicensingError, clearLicensingError } from 'state/licensing';
import { getModule, isModuleActivated } from 'state/modules';
import { getModule } from 'state/modules';
import { getSiteDataErrors } from 'state/site';
import { isFetchingPluginsData, isPluginActive } from 'state/site/plugins';
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 @@ -181,12 +182,43 @@ UserUnlinked.propTypes = {
class JetpackNotices extends React.Component {
static displayName = 'JetpackNotices';

constructor( props ) {
super( props );

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]' ],
};

this.dismissGoogleAnalyticsNotice = this.dismissGoogleAnalyticsNotice.bind( this );
}

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

render() {
const siteDataErrors = this.props.siteDataErrors.filter( error =>
error.hasOwnProperty( 'action' )
);

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

return (
<div aria-live="polite">
Expand Down Expand Up @@ -245,17 +277,16 @@ class JetpackNotices extends React.Component {
<StartFreshDeprecationWarning siteAdminUrl={ this.props.siteAdminUrl } />
</SimpleNotice>
) }
{ this.props.showGoogleAnalyticsNotice && (
<SimpleNotice status="is-warning" showDismiss={ false }>
<div>
{ __(
"Jetpack's Google Analytics feature will be removed on August 6, 2024.",
'jetpack'
) }
</div>
{ 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' ) }>
{ __(
'Read this document for details and how to keep tracking visits with Google Analytics',
'To keep tracking visits and more information on this change, please refer to this document',
'jetpack'
) }
</ExternalLink>
Expand Down Expand Up @@ -288,9 +319,13 @@ export default connect(
siteAdminUrl: getSiteAdminUrl( state ),
startFreshEnabled: !! getModule( state, 'custom-css' )?.options?.replace,
showGoogleAnalyticsNotice:
isModuleActivated( state, 'google-analytics' ) &&
window.Initial_State?.isGoogleAnalyticsActive &&
! isWoASite( state ) &&
! isFetchingPluginsData( 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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Automattic\Jetpack\IP\Utils as IP_Utils;
use Automattic\Jetpack\Licensing;
use Automattic\Jetpack\Licensing\Endpoints as Licensing_Endpoints;
use Automattic\Jetpack\Modules;
use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
use Automattic\Jetpack\My_Jetpack\Jetpack_Manage;
use Automattic\Jetpack\Partner;
Expand Down Expand Up @@ -247,6 +248,7 @@ 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 ),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Modify the Google Analytics notice to notify of the feature removal.
12 changes: 7 additions & 5 deletions projects/plugins/jetpack/src/class-deprecate.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public function render_admin_notices() {
$support_url = Redirect::get_url( 'jetpack-support-google-analytics' );

$this->render_notice(
'jetpack-ga-admin-notice',
esc_html__( "Jetpack's Google Analytics feature will be removed on August 6, 2024.", 'jetpack' )
. ' <a href="' . $support_url . '" target="_blank">' . esc_html__( 'Read this document for details and how to keep tracking visits with Google Analytics', 'jetpack' ) . '</a>.'
'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>.'
);
}
}
Expand All @@ -97,11 +97,12 @@ 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 feature will be removed on August 6, 2024. Read the documentation for details and how to keep tracking visits with Google Analytics.", 'jetpack' ),
'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',
),
);
}
Expand Down Expand Up @@ -161,6 +162,7 @@ private function has_notices() {
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();
&& ! ( new Host() )->is_woa_site()
&& empty( $_COOKIE['jetpack_deprecate_dismissed']['jetpack-ga-admin-removal-notice'] );
}
}
Loading