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

Enhancement/9281 Refactor Audience Segmentation Setup Success Notification #9434

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
96eae24
Register the Audiences Setup Success Banner Notification.
jimmymadon Sep 23, 2024
d56f1d0
Initialize all analytics specific registered notifications.
jimmymadon Sep 23, 2024
c39fb4d
Add requirements checks for Audiences Setup Success notification.
jimmymadon Sep 23, 2024
0a1fb30
Remove all redundant logic from Audiences Setup Success Subtle Notifi…
jimmymadon Sep 23, 2024
adb29ff
Refactor the audiences setup success notification to use the new noti…
jimmymadon Sep 23, 2024
e545757
Use a constant for the audiences setup success notification ID.
jimmymadon Sep 23, 2024
02e07f7
Fix format of audiences setup success notification ID.
jimmymadon Sep 23, 2024
95b8d7d
Use the Notifications datastore to dismiss the audiences notification…
jimmymadon Sep 23, 2024
ca3e0e5
Update notification ID for dismissed items reset check.
jimmymadon Sep 23, 2024
58040a2
Remove direct call to the Audience Segmentation setup success notific…
jimmymadon Sep 23, 2024
0278e52
Remove deprecated passing of viewContext.
jimmymadon Sep 23, 2024
eb603e9
Fix Audiences Setup Success notification story.
jimmymadon Sep 24, 2024
734bfb0
Re-evaluate notification queue when audiences are configured.
jimmymadon Sep 29, 2024
e6b6ef3
Merge branch 'develop' into enhancement/9281-refactor-audience-segeme…
jimmymadon Sep 29, 2024
b79c884
Merge branch 'develop' into enhancement/9281-refactor-audience-segeme…
jimmymadon Oct 2, 2024
53aa127
Merge remote-tracking branch 'origin/develop' into enhancement/9281-r…
benbowler Oct 9, 2024
7fecdc9
Wrap audience segmentation notification registration with feature flag.
jimmymadon Oct 9, 2024
3fac4fa
Merge branch 'develop' into enhancement/9281-refactor-audience-segeme…
jimmymadon Oct 11, 2024
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
30 changes: 1 addition & 29 deletions assets/js/components/notifications/SubtleNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,12 @@
* limitations under the License.
*/

/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
*/
import { useFeature } from '../../hooks/useFeature';
import AudienceSegmentationSetupSuccessSubtleNotification from '../../modules/analytics-4/components/audience-segmentation/dashboard/AudienceSegmentationSetupSuccessSubtleNotification';
import useViewContext from '../../hooks/useViewContext';
import Notifications from './Notifications';
import { NOTIFICATION_AREAS } from '../../googlesitekit/notifications/datastore/constants';

export default function SubtleNotifications() {
const viewContext = useViewContext();
const audienceSegmentationEnabled = useFeature( 'audienceSegmentation' );

// Each notification component rendered here has its own logic to determine
// whether it should be displayed; in most cases none of these components
// will be displayed, but it's also (currently) possible for multiple
// notifications to be displayed if they each meet their criteria and haven't
// been dismissed by the user.
//
// Because these notifications are subtle and small, this is acceptable UX.
return (
<Fragment>
{ audienceSegmentationEnabled && (
<AudienceSegmentationSetupSuccessSubtleNotification />
) }
<Notifications
viewContext={ viewContext }
areaSlug={ NOTIFICATION_AREAS.BANNERS_BELOW_NAV }
/>
</Fragment>
);
return <Notifications areaSlug={ NOTIFICATION_AREAS.BANNERS_BELOW_NAV } />;
}
3 changes: 3 additions & 0 deletions assets/js/googlesitekit-modules-analytics-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
import Data from 'googlesitekit-data';
import Modules from 'googlesitekit-modules';
import Widgets from 'googlesitekit-widgets';
import Notifications from 'googlesitekit-notifications';
import {
registerStore,
registerModule,
registerWidgets,
registerNotifications,
} from './modules/analytics-4';

registerStore( Data );
registerModule( Modules );
registerWidgets( Widgets );
registerNotifications( Notifications );
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import whenActive from '../../../../../util/when-active';
import { CORE_FORMS } from '../../../../../googlesitekit/datastore/forms/constants';
import { CORE_USER } from '../../../../../googlesitekit/datastore/user/constants';
import { CORE_SITE } from '../../../../../googlesitekit/datastore/site/constants';
import { CORE_NOTIFICATIONS } from '../../../../../googlesitekit/notifications/datastore/constants';
import {
MODULES_ANALYTICS_4,
AUDIENCE_SEGMENTATION_SETUP_FORM,
Expand All @@ -51,6 +52,7 @@ import {
BREAKPOINT_TABLET,
useBreakpoint,
} from '../../../../../hooks/useBreakpoint';
import useViewContext from '../../../../../hooks/useViewContext';
import {
AdminMenuTooltip,
useShowTooltip,
Expand All @@ -65,11 +67,16 @@ export const AUDIENCE_SEGMENTATION_SETUP_CTA_NOTIFICATION =
'audience_segmentation_setup_cta-notification';

function AudienceSegmentationSetupCTAWidget( { Widget, WidgetNull } ) {
const viewContext = useViewContext();

const breakpoint = useBreakpoint();
const isMobileBreakpoint = breakpoint === BREAKPOINT_SMALL;
const isTabletBreakpoint = breakpoint === BREAKPOINT_TABLET;

const { invalidateResolution } = useDispatch( CORE_NOTIFICATIONS );

const { setValues } = useDispatch( CORE_FORMS );

const showTooltip = useShowTooltip(
AUDIENCE_SEGMENTATION_SETUP_CTA_NOTIFICATION
);
Expand Down Expand Up @@ -110,6 +117,9 @@ function AudienceSegmentationSetupCTAWidget( { Widget, WidgetNull } ) {
const { apiErrors, failedAudiences, isSaving, onEnableGroups } =
useEnableAudienceGroup( {
onSuccess: () => {
invalidateResolution( 'getQueuedNotifications', [
viewContext,
] );
dismissPrompt( AUDIENCE_SEGMENTATION_SETUP_CTA_NOTIFICATION, {
expiresInSeconds: 0,
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,28 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { useDispatch, useSelect } from 'googlesitekit-data';
import { CORE_USER } from '../../../../../googlesitekit/datastore/user/constants';
import { Button } from 'googlesitekit-components';
import SubtleNotification from '../../SubtleNotification';
import SubtleNotification from '../../../../../googlesitekit/notifications/components/layout/SubtleNotification';
import { getNavigationalScrollTop } from '../../../../../util/scroll';
import { useBreakpoint } from '../../../../../hooks/useBreakpoint';
import useDashboardType, {
DASHBOARD_TYPE_MAIN,
} from '../../../../../hooks/useDashboardType';
import useViewOnly from '../../../../../hooks/useViewOnly';
import Dismiss from '../../../../../googlesitekit/notifications/components/common/Dismiss';
import { useDispatch } from 'googlesitekit-data';
import { CORE_NOTIFICATIONS } from '../../../../../googlesitekit/notifications/datastore/constants';

export const AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION =
'audience_segmentation_setup_success_notification';
'setup-success-notification-audiences';

export default function AudienceSegmentationSetupSuccessSubtleNotification() {
export default function AudienceSegmentationSetupSuccessSubtleNotification( {
id,
Notification,
} ) {
const breakpoint = useBreakpoint();
const dashboardType = useDashboardType();
const viewOnly = useViewOnly();

const configuredAudiences = useSelect( ( select ) =>
select( CORE_USER ).getConfiguredAudiences()
);

const isDismissed = useSelect( ( select ) => {
if ( ! dashboardType || viewOnly ) {
return null;
}

return select( CORE_USER ).isItemDismissed(
AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION
);
} );

const { dismissItem } = useDispatch( CORE_USER );

function dismissNotificationForUser() {
dismissItem( AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION );
}
const { dismissNotification } = useDispatch( CORE_NOTIFICATIONS );

const scrollToWidgetArea = ( event ) => {
event.preventDefault();

dismissNotificationForUser();
dismissNotification( AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION );

setTimeout( () => {
const widgetClass =
Expand All @@ -79,37 +58,30 @@ export default function AudienceSegmentationSetupSuccessSubtleNotification() {
}, 50 );
};

const shouldShowNotification =
// Only show this notification on the main dashboard, where the Setup CTA Banner is shown.
dashboardType === DASHBOARD_TYPE_MAIN &&
// Don't show this notification on the view-only dashboard.
! viewOnly &&
// Don't show this notification if `isDismissed` call is still loading
// or the user has dismissed it.
! isDismissed &&
// Only show this notification if the user has a set of configured audiences.
Array.isArray( configuredAudiences );

if ( ! shouldShowNotification ) {
return null;
}

return (
<SubtleNotification
title={ __(
'Success! Visitor groups added to your dashboard',
'google-site-kit'
) }
description={ __(
'Get to know how different types of visitors interact with your site, e.g. which pages they visit and for how long',
'google-site-kit'
) }
onDismiss={ dismissNotificationForUser }
additionalCTA={
<Button onClick={ scrollToWidgetArea }>
{ __( 'Show me', 'google-site-kit' ) }
</Button>
}
/>
<Notification>
<SubtleNotification
title={ __(
'Success! Visitor groups added to your dashboard',
'google-site-kit'
) }
description={ __(
'Get to know how different types of visitors interact with your site, e.g. which pages they visit and for how long',
'google-site-kit'
) }
dismissCTA={
<Dismiss
id={ id }
primary={ false }
dismissLabel={ __( 'Got it', 'google-site-kit' ) }
/>
}
additionalCTA={
<Button onClick={ scrollToWidgetArea }>
{ __( 'Show me', 'google-site-kit' ) }
</Button>
}
/>
</Notification>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,22 @@
/**
* Internal dependencies
*/
import { Provider as ViewContextProvider } from '../../../../../components/Root/ViewContextContext';
import AudienceSegmentationSetupSuccessSubtleNotification from './AudienceSegmentationSetupSuccessSubtleNotification';
import WithRegistrySetup from '../../../../../../../tests/js/WithRegistrySetup';
import { VIEW_CONTEXT_MAIN_DASHBOARD } from '../../../../../googlesitekit/constants';
import { CORE_USER } from '../../../../../googlesitekit/datastore/user/constants';
import { withNotificationComponentProps } from '../../../../../googlesitekit/notifications/util/component-props';

const NotificationWithComponentProps = withNotificationComponentProps(
'setup-success-notification-audiences'
)( AudienceSegmentationSetupSuccessSubtleNotification );

function Template() {
return (
<ViewContextProvider value={ VIEW_CONTEXT_MAIN_DASHBOARD }>
<AudienceSegmentationSetupSuccessSubtleNotification />
</ViewContextProvider>
);
return <NotificationWithComponentProps />;
}

export const Default = Template.bind( {} );
Default.storyName = 'Default';
Default.storyName = 'AudienceSegmentationSetupSuccessSubtleNotification';
Default.scenario = {
label: 'Modules/Analytics4/Components/AudienceSegmentation/Dashboard/AudienceSegmentationSetupSuccessSubtleNotification',
};

export default {
title: 'Modules/Analytics4/Components/AudienceSegmentation/Dashboard/AudienceSegmentationSetupSuccessSubtleNotification',
decorators: [
( Story ) => {
const setupRegistry = ( registry ) => {
registry.dispatch( CORE_USER ).receiveGetDismissedItems( [] );

registry.dispatch( CORE_USER ).receiveGetAudienceSettings( {
configuredAudiences: [ 'audienceA', 'audienceB' ],
} );
};

return (
<WithRegistrySetup func={ setupRegistry }>
<Story />
</WithRegistrySetup>
);
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ProgressBar } from 'googlesitekit-components';
import { CORE_FORMS } from '../../../../../../googlesitekit/datastore/forms/constants';
import { CORE_SITE } from '../../../../../../googlesitekit/datastore/site/constants';
import { CORE_USER } from '../../../../../../googlesitekit/datastore/user/constants';
import { CORE_NOTIFICATIONS } from '../../../../../../googlesitekit/notifications/datastore/constants';
import { AUDIENCE_SEGMENTATION_SETUP_FORM } from '../../../../datastore/constants';
import { AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION } from '../../dashboard/AudienceSegmentationSetupSuccessSubtleNotification';
import Link from '../../../../../../components/Link';
Expand All @@ -39,14 +40,16 @@ import useEnableAudienceGroup from '../../../../hooks/useEnableAudienceGroup';
export default function SetupCTA() {
const [ showErrorModal, setShowErrorModal ] = useState( false );

const { dismissItem } = useDispatch( CORE_USER );
const { dismissNotification } = useDispatch( CORE_NOTIFICATIONS );

const { apiErrors, failedAudiences, isSaving, onEnableGroups } =
useEnableAudienceGroup( {
redirectURL: global.location.href,
onSuccess: () => {
// Dismiss success notification in dashboard.
dismissItem( AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION );
dismissNotification(
AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION
);
},
onError: () => {
setShowErrorModal( true );
Expand Down
29 changes: 29 additions & 0 deletions assets/js/modules/analytics-4/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ import {
} from './components/audience-segmentation/dashboard';
import DashboardMainEffectComponent from './components/DashboardMainEffectComponent';
import { CORE_MODULES } from '../../googlesitekit/modules/datastore/constants';
import AudienceSegmentationSetupSuccessSubtleNotification, {
AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION,
} from './components/audience-segmentation/dashboard/AudienceSegmentationSetupSuccessSubtleNotification';
import { NOTIFICATION_AREAS } from '../../googlesitekit/notifications/datastore/constants';
import { VIEW_CONTEXT_MAIN_DASHBOARD } from '../../googlesitekit/constants';
import { isFeatureEnabled } from '../../features';

export { registerStore } from './datastore';

Expand Down Expand Up @@ -660,3 +666,26 @@ export const registerWidgets = ( widgets ) => {
[ AREA_MAIN_DASHBOARD_KEY_METRICS_PRIMARY ]
);
};

export const registerNotifications = ( notifications ) => {
if ( isFeatureEnabled( 'audienceSegmentation' ) ) {
notifications.registerNotification(
AUDIENCE_SEGMENTATION_SETUP_SUCCESS_NOTIFICATION,
{
Component: AudienceSegmentationSetupSuccessSubtleNotification,
priority: 10,
areaSlug: NOTIFICATION_AREAS.BANNERS_BELOW_NAV,
viewContexts: [ VIEW_CONTEXT_MAIN_DASHBOARD ],
checkRequirements: async ( { select, resolveSelect } ) => {
await resolveSelect( MODULES_ANALYTICS_4 ).getSettings();
const configuredAudiences =
select( CORE_USER ).getConfiguredAudiences();

// Only show this notification if the user has a set of configured audiences.
return Array.isArray( configuredAudiences );
},
isDismissible: true,
}
);
}
};
2 changes: 1 addition & 1 deletion includes/Modules/Analytics_4/Reset_Audiences.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Reset_Audiences {

const AUDIENCE_SEGMENTATION_DISMISSED_ITEMS = array(
'audience-segmentation-add-group-notice',
'audience_segmentation_setup_success_notification',
'setup-success-notification-audiences',
'settings_visitor_groups_setup_success_notification',
'audience-segmentation-no-audiences-banner',
'audience-tile-*',
Expand Down
Loading