Skip to content

Commit 726ce87

Browse files
committed
PoC for repeatable feature tours.
1 parent 7736600 commit 726ce87

4 files changed

Lines changed: 91 additions & 8 deletions

File tree

assets/js/components/TourTooltips.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,26 @@ export default function TourTooltips( {
124124
setValue( runKey, true );
125125
}
126126

127+
const tour = useSelect( ( select ) =>
128+
select( CORE_USER ).getCurrentTour()
129+
);
130+
131+
const { receiveCurrentTour } = useDispatch( CORE_USER );
132+
127133
function endTour() {
128134
global.document.body.classList.remove(
129135
'googlesitekit-showing-feature-tour',
130136
`googlesitekit-showing-feature-tour--${ tourID }`
131137
);
132-
// Dismiss tour to avoid unwanted repeat viewing.
133-
dismissTour( tourID );
138+
139+
if ( tour?.isRepeatable ) {
140+
setValue( runKey, false ); // Not strictly necessary to allow the tour to be restarted, but it seems sensible to keep the state aligned to avoid unexpected behavior.
141+
setValue( stepKey, null ); // This is needed, otherwise the tour will be considered to be finished when it is restarted.
142+
receiveCurrentTour( null );
143+
} else {
144+
// Dismiss tour to avoid unwanted repeat viewing.
145+
dismissTour( tourID );
146+
}
134147
}
135148

136149
function trackAllTourEvents( {

assets/js/components/help/HelpMenu.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { __ } from '@wordpress/i18n';
3232
/**
3333
* Internal dependencies
3434
*/
35-
import { useSelect } from 'googlesitekit-data';
35+
import { useDispatch, useSelect } from 'googlesitekit-data';
3636
import { Button, Menu } from 'googlesitekit-components';
3737
import HelpIcon from '@/svg/icons/help.svg';
3838
import { useKeyCodesInside } from '@/js/hooks/useKeyCodesInside';
@@ -42,6 +42,8 @@ import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants';
4242
import useViewContext from '@/js/hooks/useViewContext';
4343
import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants';
4444
import { MODULE_SLUG_ADSENSE } from '@/js/modules/adsense/constants';
45+
import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants';
46+
import dashboardTour from '@/js/feature-tours/dashboard';
4547

4648
export default function HelpMenu( { children } ) {
4749
const [ menuOpen, setMenuOpen ] = useState( false );
@@ -75,6 +77,8 @@ export default function HelpMenu( { children } ) {
7577
);
7678
} );
7779

80+
const { triggerOnDemandTour } = useDispatch( CORE_USER );
81+
7882
return (
7983
<div
8084
ref={ menuWrapperRef }
@@ -98,6 +102,12 @@ export default function HelpMenu( { children } ) {
98102
onSelected={ handleMenuSelected }
99103
>
100104
{ children }
105+
<HelpMenuLink
106+
onClick={ () => triggerOnDemandTour( dashboardTour ) }
107+
gaEventLabel="start_tour"
108+
>
109+
{ __( 'Start tour', 'google-site-kit' ) }
110+
</HelpMenuLink>
101111
<HelpMenuLink
102112
gaEventLabel="fix_common_issues"
103113
href={ fixCommonIssuesURL }

assets/js/components/help/HelpMenuLink.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,28 @@ import Link from '@/js/components/Link';
3333
import { trackEvent } from '@/js/util';
3434
import useViewContext from '@/js/hooks/useViewContext';
3535

36-
function HelpMenuLink( { children, href, gaEventLabel } ) {
36+
function HelpMenuLink( { children, href, gaEventLabel, onClick } ) {
3737
const viewContext = useViewContext();
3838

39-
const onClick = useCallback( async () => {
39+
const handleClick = useCallback( async () => {
4040
if ( gaEventLabel ) {
4141
await trackEvent(
4242
`${ viewContext }_headerbar_helpmenu`,
4343
'click_outgoing_link',
4444
gaEventLabel
4545
);
4646
}
47-
}, [ gaEventLabel, viewContext ] );
47+
48+
onClick?.();
49+
}, [ gaEventLabel, viewContext, onClick ] );
4850

4951
return (
5052
<li className="googlesitekit-help-menu-link mdc-list-item" role="none">
5153
<Link
5254
className="mdc-list-item__text"
5355
href={ href }
5456
role="menuitem"
55-
onClick={ onClick }
57+
onClick={ handleClick }
5658
external
5759
hideExternalIndicator
5860
>
@@ -64,8 +66,9 @@ function HelpMenuLink( { children, href, gaEventLabel } ) {
6466

6567
HelpMenuLink.propTypes = {
6668
children: PropTypes.node.isRequired,
67-
href: PropTypes.string.isRequired,
69+
href: PropTypes.string,
6870
gaEventLabel: PropTypes.string,
71+
onClick: PropTypes.func,
6972
};
7073

7174
export default HelpMenuLink;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Site Kit by Google, Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* WordPress dependencies
19+
*/
20+
import { __ } from '@wordpress/i18n';
21+
22+
/*
23+
* Internal dependencies
24+
*/
25+
import { VIEW_CONTEXT_MAIN_DASHBOARD } from '@/js/googlesitekit/constants';
26+
27+
const dashboardTour = {
28+
slug: 'dashboard',
29+
isRepeatable: true,
30+
contexts: [ VIEW_CONTEXT_MAIN_DASHBOARD ],
31+
gaEventCategory: ( viewContext ) => `${ viewContext }_dashboard`,
32+
steps: [
33+
{
34+
target: '.googlesitekit-widget--searchFunnelGA4',
35+
title: __(
36+
'Track Search traffic trends, identify baselines',
37+
'google-site-kit'
38+
),
39+
content: __(
40+
"Know what's normal for your site. This is how you spot trends and measure real growth.",
41+
'google-site-kit'
42+
),
43+
placement: 'top',
44+
},
45+
{
46+
target: '.googlesitekit-sharing-settings__button',
47+
title: __( 'Collaboration made easy', 'google-site-kit' ),
48+
content: __(
49+
'Share the dashboard with other stakeholders and manage their permissions with dashboard sharing feature.',
50+
'google-site-kit'
51+
),
52+
placement: 'bottom',
53+
},
54+
],
55+
};
56+
57+
export default dashboardTour;

0 commit comments

Comments
 (0)