Skip to content

ACR Dashboard Subtle Notification #9612

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

Merged
merged 45 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e457584
Create base of ACR new key metrics banner.
benbowler Nov 5, 2024
8f90e33
Sync with develop.
zutigrm Nov 5, 2024
b772a87
Update widget and notification components.
zutigrm Nov 7, 2024
71e9e7a
Extract callbacks to a parent component.
zutigrm Nov 7, 2024
0c012a8
Add useConversionReportingEventsForTailoredMetrics hook.
zutigrm Nov 7, 2024
f0faf4d
Add useConversionReportingEventsForTailoredMetrics tests.
zutigrm Nov 7, 2024
abbbd8a
Add ConversionReportingNotificationCTAWidget tests.
zutigrm Nov 7, 2024
2056d01
Update link for ConversionReportingDashboardSubtleNotification.
zutigrm Nov 7, 2024
951d8dd
Update user input saving to include includeConversionTailoredMetrics …
zutigrm Nov 7, 2024
4d4ce8d
Update ACR KMW tailored metrics inclusion logic.
zutigrm Nov 7, 2024
eacb2e2
Add getKeyMetricsConversionEventWidgets to group ACR KMW under their …
zutigrm Nov 7, 2024
61ffdd8
Include useConversionReportingEventsForTailoredMetrics in confirm modal.
zutigrm Nov 7, 2024
52cdb6c
Update component name in import.
zutigrm Nov 7, 2024
231e049
Add reducer callback.
zutigrm Nov 7, 2024
22f34ce
Update styles.
zutigrm Nov 7, 2024
d4c6104
Update stories.
zutigrm Nov 7, 2024
57ae99b
Add inline comment.
zutigrm Nov 7, 2024
cc5480e
Expand on tests.
zutigrm Nov 7, 2024
ba26855
Fix conflicts.
zutigrm Nov 7, 2024
7211f98
Revert returned code.
zutigrm Nov 7, 2024
49229b2
Fix tests.
zutigrm Nov 7, 2024
32cf10d
Add VRT.
zutigrm Nov 7, 2024
f621be4
Add additional test.
zutigrm Nov 8, 2024
0ec1298
Sync with develop and resolve merge conflicts.
zutigrm Nov 18, 2024
0443cf6
Fix merge conflicts.
zutigrm Nov 19, 2024
dd8219d
Adapt logic to the latest change in develop for splitting the tailore…
zutigrm Nov 19, 2024
92ab8f5
Adapt new logic to the confirm modal current vs new metrics preview.
zutigrm Nov 19, 2024
5622dcd
Update banner display ocnditional to account for manual switch.
zutigrm Nov 19, 2024
70f5808
Update logic for rendering and callback in CTAWidget.
zutigrm Nov 19, 2024
e230cff
Fix failing tests.
zutigrm Nov 19, 2024
e026f03
Fix line causing issues in stories and VRT.
zutigrm Nov 20, 2024
7d7a9e4
Merge branch 'enhancement/9371-acr-dashboard-banner' of github.com:go…
10upsimon Nov 20, 2024
e4902a9
Fix console error.
zutigrm Nov 20, 2024
d28b510
Merge branch 'enhancement/9371-acr-dashboard-banner' of github.com:go…
10upsimon Nov 20, 2024
49f5c26
Update VRT reference images following BackstopJS and Chromium updates.
10upsimon Nov 21, 2024
4ea5b68
Revert "Update VRT reference images following BackstopJS and Chromium…
10upsimon Nov 21, 2024
0f4c2a4
Update per CR feedback.
zutigrm Nov 21, 2024
dd3a7a1
Merge branch 'enhancement/9371-acr-dashboard-banner' of github.com:go…
zutigrm Nov 21, 2024
7bf6a58
Resolve merge conflict.
zutigrm Nov 21, 2024
8e5730f
Fix confirm disable modal story.
zutigrm Nov 21, 2024
ea1a5af
Update VRT.
zutigrm Nov 21, 2024
f3596a9
Update per CR feedback.
zutigrm Nov 21, 2024
0ec1c45
Merge remote-tracking branch 'origin/develop' into enhancement/9371-a…
zutigrm Nov 25, 2024
dc2ee5b
Update per CR feedback.
zutigrm Nov 25, 2024
ce19904
Fix tests.
zutigrm Nov 25, 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
20 changes: 19 additions & 1 deletion assets/js/components/KeyMetrics/ConfirmSitePurposeChangeModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,33 @@ import {
USER_INPUT_QUESTIONS_PURPOSE,
} from '../user-input/util/constants';
import { CORE_UI } from '../../googlesitekit/datastore/ui/constants';
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants';
import { CORE_MODULES } from '../../googlesitekit/modules/datastore/constants';

function ConfirmSitePurposeChangeModal( {
dialogActive = false,
handleDialog = null,
} ) {
const [ isSaving, setIsSaving ] = useState( false );

const includeConversionTailoredMetrics = useSelect( ( select ) => {
const isGA4Connected =
select( CORE_MODULES ).isModuleConnected( 'analytics-4' );

if ( ! isGA4Connected ) {
return false;
}

return select(
MODULES_ANALYTICS_4
).haveConversionEventsForTailoredMetrics();
} );

const newMetrics = useSelect( ( select ) => {
return select( CORE_USER ).getKeyMetrics();
return select( CORE_USER ).getAnswerBasedMetrics(
null,
includeConversionTailoredMetrics
);
} );

const savedPurpose = useSelect( ( select ) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@
*/
import ConfirmSitePurposeChangeModal from './ConfirmSitePurposeChangeModal';
import {
provideKeyMetrics,
provideKeyMetricsUserInputSettings,
provideModules,
provideUserAuthentication,
provideSiteInfo,
} from '../../../../tests/js/utils';
import WithRegistrySetup from '../../../../tests/js/WithRegistrySetup';
import {
KM_ANALYTICS_MOST_ENGAGING_PAGES,
KM_ANALYTICS_NEW_VISITORS,
KM_ANALYTICS_POPULAR_AUTHORS,
KM_ANALYTICS_POPULAR_CONTENT,
} from '../../googlesitekit/datastore/user/constants';
import { CORE_FORMS } from '../../googlesitekit/datastore/forms/constants';
import {
FORM_USER_INPUT_QUESTION_SNAPSHOT,
Expand Down Expand Up @@ -68,31 +60,14 @@ export default {
.setValues( FORM_USER_INPUT_QUESTION_SNAPSHOT, {
[ USER_INPUT_QUESTIONS_PURPOSE ]: [ 'publish_news' ],
} );
provideModules( registry, [
{
slug: 'analytics-4',
active: true,
connected: true,
},
] );
provideUserAuthentication( registry );
provideKeyMetrics( registry, {
widgetSlugs: [
KM_ANALYTICS_NEW_VISITORS,
KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_MOST_ENGAGING_PAGES,
KM_ANALYTICS_POPULAR_AUTHORS,
],
} );
provideKeyMetricsUserInputSettings( registry, {
purpose: {
values: [ 'publish_news' ],
values: [ 'publish_blog' ],
scope: 'site',
},
} );
provideSiteInfo( registry, {
postTypes: [ { slug: 'product', label: 'Product' } ],
} );
provideSiteInfo( registry );
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* ConversionReportingDashboardSubtleNotification component.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';

/**
* Internal dependencies
*/
import { useSelect } from 'googlesitekit-data';
import { Button, SpinnerButton } from 'googlesitekit-components';
import StarFill from '../../../svg/icons/star-fill.svg';
import SubtleNotification from '../../googlesitekit/notifications/components/layout/SubtleNotification';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import Link from '../Link';

export default function ConversionReportingDashboardSubtleNotification( {
ctaLabel,
handleCTAClick,
isSaving = false,
onDismiss,
dismissCTALabel = __( 'Maybe later', 'google-site-kit' ),
} ) {
const documentationURL = useSelect( ( select ) =>
select( CORE_SITE ).getDocumentationLinkURL( 'key-metrics' )
);

return (
<SubtleNotification
className="googlesitekit-acr-subtle-notification"
title={ __( 'New key metrics were added!', 'google-site-kit' ) }
description={ createInterpolateElement(
__(
'We’ve extended your metrics selection with metrics that aren’t available by default in Analytics. Add them to your dashboard to get a better understanding of how users interact with your site. <a>Learn more</a>',
'google-site-kit'
),
{
a: (
<Link
href={ documentationURL }
external
aria-label={ __(
'Learn more about advanced conversion reporting',
'google-site-kit'
) }
/>
),
}
) }
dismissCTA={
<Button tertiary onClick={ onDismiss }>
{ dismissCTALabel }
</Button>
}
additionalCTA={
<SpinnerButton onClick={ handleCTAClick } isSaving={ isSaving }>
{ ctaLabel }
</SpinnerButton>
}
icon={ <StarFill width={ 24 } height={ 24 } /> }
/>
);
}

ConversionReportingDashboardSubtleNotification.propTypes = {
ctaLabel: PropTypes.string.isRequired,
handleCTAClick: PropTypes.func.isRequired,
isSaving: PropTypes.bool,
onDismiss: PropTypes.func.isRequired,
dismissCTALabel: PropTypes.string,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* ConversionReportingNotificationCTAWidget component.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useCallback, useState } from '@wordpress/element';

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/
import { useSelect, useDispatch } from 'googlesitekit-data';
import { CORE_USER } from '../../googlesitekit/datastore/user/constants';
import whenActive from '../../util/when-active';
import ConversionReportingDashboardSubtleNotification from './ConversionReportingDashboardSubtleNotification';
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants';

function ConversionReportingNotificationCTAWidget( { Widget, WidgetNull } ) {
const [ isSaving, setIsSaving ] = useState( false );
const isUserInputCompleted = useSelect( ( select ) =>
select( CORE_USER ).isUserInputCompleted()
);

const keyMetricSettings = useSelect( ( select ) =>
select( CORE_USER ).getKeyMetricsSettings()
);
const hasUserPickedMetrics = useSelect( ( select ) =>
select( CORE_USER ).getUserPickedMetrics()
);

const haveConversionReportingEventsForTailoredMetrics = useSelect(
( select ) =>
select(
MODULES_ANALYTICS_4
).haveConversionEventsForTailoredMetrics()
);

// Initial callout is surfaced to the users with tailored metrics, if detectedEvents setting
// has a conversion event associated with the ACR key metrics matching the current site purpose answer.
// If new ACR key metrics that can be added are found using haveConversionReportingEventsForTailoredMetrics,
// and have not been already included, which is determined by includeConversionTailoredMetrics setting, callout banner should be displayed.
const shouldShowInitialCalloutForTailoredMetrics =
! hasUserPickedMetrics?.length &&
isUserInputCompleted &&
haveConversionReportingEventsForTailoredMetrics &&
! keyMetricSettings?.includeConversionTailoredMetrics;

const { setKeyMetricsSetting, saveKeyMetricsSettings } =
useDispatch( CORE_USER );
const { dismissNewConversionReportingEvents } =
useDispatch( MODULES_ANALYTICS_4 );

const handleAddMetricsClick = useCallback( () => {
if ( shouldShowInitialCalloutForTailoredMetrics ) {
setIsSaving( true );
setKeyMetricsSetting( 'includeConversionTailoredMetrics', true );
saveKeyMetricsSettings( {
widgetSlugs: undefined,
} );
setIsSaving( false );
}

dismissNewConversionReportingEvents();
}, [
setKeyMetricsSetting,
saveKeyMetricsSettings,
dismissNewConversionReportingEvents,
shouldShowInitialCalloutForTailoredMetrics,
] );

if ( ! shouldShowInitialCalloutForTailoredMetrics ) {
return <WidgetNull />;
}

return (
<Widget noPadding fullWidth>
<ConversionReportingDashboardSubtleNotification
ctaLabel={ __( 'Add metrics', 'google-site-kit' ) }
handleCTAClick={ handleAddMetricsClick }
isSaving={ isSaving }
onDismiss={ dismissNewConversionReportingEvents }
/>
</Widget>
);
}

ConversionReportingNotificationCTAWidget.propTypes = {
Widget: PropTypes.elementType.isRequired,
WidgetNull: PropTypes.elementType,
};

export default whenActive( { moduleName: 'analytics-4' } )(
ConversionReportingNotificationCTAWidget
);
Loading
Loading