Skip to content

Commit 9b6a811

Browse files
committed
Display Ads campaign creation CES prompt
This is rather simple. This prompt should appear immediately after user successfully completes Ads creation flow and clicks "Got it" in the success modal.
1 parent bd41bcf commit 9b6a811

File tree

1 file changed

+60
-11
lines changed
  • js/src/dashboard/campaign-creation-success-guide

1 file changed

+60
-11
lines changed

js/src/dashboard/campaign-creation-success-guide/index.js

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22
* External dependencies
33
*/
44
import { getHistory, getNewPath, getQuery } from '@woocommerce/navigation';
5-
import { createInterpolateElement, useEffect } from '@wordpress/element';
5+
import {
6+
createInterpolateElement,
7+
useEffect,
8+
useCallback,
9+
useState,
10+
} from '@wordpress/element';
611
import { __ } from '@wordpress/i18n';
712
import { Button } from '@wordpress/components';
813
import { recordEvent } from '@woocommerce/tracks';
14+
import PropTypes from 'prop-types';
915

1016
/**
1117
* Internal dependencies
1218
*/
1319
import { getCreateCampaignUrl } from '.~/utils/urls';
20+
import isWCTracksEnabled from '.~/utils/isWCTracksEnabled';
1421
import AppModal from '.~/components/app-modal';
1522
import GuidePageContent, {
1623
ContentLink,
1724
} from '.~/components/guide-page-content';
25+
import CustomerEffortScorePrompt from '.~/components/customer-effort-score-prompt';
1826
import { GUIDE_NAMES } from '.~/constants';
1927
import headerImageURL from './header.svg';
2028
import './index.scss';
@@ -41,12 +49,26 @@ const handleCloseWithAction = ( e, specifiedAction ) => {
4149

4250
const handleRequestClose = ( e ) => handleCloseWithAction( e, 'dismiss' );
4351

44-
const GuideImplementation = () => {
52+
const GuideImplementation = ( { isOpen, setCESPromptOpen } ) => {
53+
const handleGotItClick = useCallback(
54+
( e ) => {
55+
handleCloseWithAction( e );
56+
setCESPromptOpen( true );
57+
},
58+
[ setCESPromptOpen ]
59+
);
60+
4561
useEffect( () => {
46-
recordEvent( 'gla_modal_open', {
47-
context: GUIDE_NAMES.CAMPAIGN_CREATION_SUCCESS,
48-
} );
49-
}, [] );
62+
if ( isOpen ) {
63+
recordEvent( 'gla_modal_open', {
64+
context: GUIDE_NAMES.CAMPAIGN_CREATION_SUCCESS,
65+
} );
66+
}
67+
}, [ isOpen ] );
68+
69+
if ( ! isOpen ) {
70+
return null;
71+
}
5072

5173
return (
5274
<AppModal
@@ -68,7 +90,7 @@ const GuideImplementation = () => {
6890
key="1"
6991
isPrimary
7092
data-action="confirm"
71-
onClick={ handleCloseWithAction }
93+
onClick={ handleGotItClick }
7294
>
7395
{ __( 'Got it', 'google-listings-and-ads' ) }
7496
</Button>,
@@ -110,17 +132,44 @@ const GuideImplementation = () => {
110132
);
111133
};
112134

135+
GuideImplementation.propTypes = {
136+
/**
137+
* Whether the campaign creation success guide must be shown
138+
*/
139+
isOpen: PropTypes.bool.isRequired,
140+
/**
141+
* Function to enable or disable the CES prompt
142+
*/
143+
setCESPromptOpen: PropTypes.func.isRequired,
144+
};
145+
113146
/**
114147
* Modal window to prompt the user at Dashboard, after successful completing the campaign creation.
115148
*
116149
* Show this guide modal by visiting the path with a specific query `guide=campaign-creation-success`.
117150
* For example: `/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&guide=campaign-creation-success`.
118151
*/
119152
export default function CampaignCreationSuccessGuide() {
153+
const [ isCESPromptOpen, setCESPromptOpen ] = useState( false );
154+
120155
const isOpen = getQuery().guide === GUIDE_NAMES.CAMPAIGN_CREATION_SUCCESS;
156+
const wcTracksEnabled = isWCTracksEnabled();
121157

122-
if ( ! isOpen ) {
123-
return null;
124-
}
125-
return <GuideImplementation />;
158+
return (
159+
<>
160+
<GuideImplementation
161+
isOpen={ isOpen }
162+
setCESPromptOpen={ setCESPromptOpen }
163+
/>
164+
{ isCESPromptOpen && wcTracksEnabled && (
165+
<CustomerEffortScorePrompt
166+
label={ __(
167+
'How easy was it to create a Google Ad campaign?',
168+
'google-listings-and-ads'
169+
) }
170+
eventContext="create-ad-campaign"
171+
/>
172+
) }
173+
</>
174+
);
126175
}

0 commit comments

Comments
 (0)