Skip to content

Commit

Permalink
Merge branch 'develop' into enhance/#8138-audience-widget-area.
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-t committed May 13, 2024
2 parents e1c7d8d + eee61f5 commit 63c1180
Show file tree
Hide file tree
Showing 46 changed files with 1,238 additions and 134 deletions.
2 changes: 1 addition & 1 deletion assets/js/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Header( { children, subHeader, showNavigation } ) {

{ showNavigation && <DashboardNavigation /> }

<SubtleNotifications />
{ isDashboard && <SubtleNotifications /> }

<EntityHeader />
</Fragment>
Expand Down
9 changes: 9 additions & 0 deletions assets/js/components/notifications/UnsatisfiedScopesAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ const MESSAGE_MULTIPLE = 'multiple';
const MESSAGE_SINGULAR = 'single';
const MESSAGE_GENERIC = 'generic';

/**
* Maps unsatisfied scopes to module names.
*
* @since 1.39.0
*
* @param {Array} scopes Array of unsatisfied scopes.
* @param {Object} modules Object of all modules.
* @return {Array} Array of module names. If a scope does not map to a module, it is set to `false`.
*/
function mapScopesToModuleNames( scopes, modules ) {
if ( modules === undefined ) {
return null;
Expand Down
22 changes: 12 additions & 10 deletions assets/js/modules/ads/components/settings/SettingsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ export default function SettingsView() {
{ __( 'Conversion Tracking ID', 'google-site-kit' ) }
</h5>
<p className="googlesitekit-settings-module__meta-item-data">
{ conversionIDValue ? (
<DisplaySetting value={ conversionIDValue } />
) : (
__( 'None', 'google-site-kit' )
) }
{ conversionIDValue === '' &&
__( 'None', 'google-site-kit' ) }
{ conversionIDValue ||
( typeof conversionIDValue === 'undefined' && (
<DisplaySetting value={ conversionIDValue } />
) ) }
</p>
</div>
) }
Expand All @@ -81,11 +82,12 @@ export default function SettingsView() {
{ __( 'Customer ID', 'google-site-kit' ) }
</h5>
<p className="googlesitekit-settings-module__meta-item-data">
{ extCustomerID ? (
<DisplaySetting value={ extCustomerID } />
) : (
__( 'None', 'google-site-kit' )
) }
{ extCustomerID === '' &&
__( 'None', 'google-site-kit' ) }
{ extCustomerID ||
( typeof extCustomerID === 'undefined' && (
<DisplaySetting value={ extCustomerID } />
) ) }
</p>
</div>
) }
Expand Down
21 changes: 17 additions & 4 deletions assets/js/modules/ads/components/setup/SetupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ import { __ } from '@wordpress/i18n';
import Data from 'googlesitekit-data';
import { SpinnerButton } from 'googlesitekit-components';
import { MODULES_ADS } from '../../datastore/constants';
import { CORE_LOCATION } from '../../../../googlesitekit/datastore/location/constants';
import StoreErrorNotices from '../../../../components/StoreErrorNotices';
import { ConversionIDTextField } from '../common';
const { useSelect, useDispatch } = Data;

export default function SetupForm( { finishSetup } ) {
export default function SetupForm( {
finishSetup,
createAccountCTA,
isNavigatingToOAuthURL,
} ) {
const canSubmitChanges = useSelect( ( select ) =>
select( MODULES_ADS ).canSubmitChanges()
);
const isSaving = useSelect(
( select ) =>
select( MODULES_ADS ).isDoingSubmitChanges() ||
select( CORE_LOCATION ).isNavigating()
select( MODULES_ADS ).isDoingSubmitChanges() &&
! isNavigatingToOAuthURL
);

const { submitChanges } = useDispatch( MODULES_ADS );
Expand All @@ -71,6 +74,12 @@ export default function SetupForm( { finishSetup } ) {
<ConversionIDTextField />
</div>

{ createAccountCTA && (
<div className="googlesitekit-setup-module__create-account">
{ createAccountCTA }
</div>
) }

<div className="googlesitekit-setup-module__action">
<SpinnerButton
disabled={ ! canSubmitChanges || isSaving }
Expand All @@ -85,8 +94,12 @@ export default function SetupForm( { finishSetup } ) {

SetupForm.propTypes = {
finishSetup: PropTypes.func,
createAccountCTA: PropTypes.node,
isNavigatingToOAuthURL: PropTypes.bool,
};

SetupForm.defaultProps = {
finishSetup: () => {},
createAccountCTA: null,
isNavigatingToOAuthURL: false,
};
220 changes: 220 additions & 0 deletions assets/js/modules/ads/components/setup/SetupMainPAX.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/**
* Ads Main PAX setup 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 {
createInterpolateElement,
Fragment,
useCallback,
useState,
} from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import Data from 'googlesitekit-data';
import { SpinnerButton } from 'googlesitekit-components';
import AdsIcon from '../../../../../svg/graphics/ads.svg';
import SetupForm from './SetupForm';
import SupportLink from '../../../../components/SupportLink';
import AdBlockerWarning from '../common/AdBlockerWarning';
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import { CORE_LOCATION } from '../../../../googlesitekit/datastore/location/constants';
import { ADWORDS_SCOPE, MODULES_ADS } from '../../datastore/constants';
import useQueryArg from '../../../../hooks/useQueryArg';
import PAXEmbeddedApp from '../PAXEmbeddedApp';
const { useSelect, useDispatch } = Data;

const PARAM_SHOW_PAX = 'pax';

export default function SetupMainPAX( { finishSetup } ) {
const [ showPaxApp, setShowPaxApp ] = useQueryArg( PARAM_SHOW_PAX );
const [ paxApp, setPaxApp ] = useState( null );

const isAdBlockerActive = useSelect( ( select ) =>
select( CORE_USER ).isAdBlockerActive()
);
const hasAdwordsScope = useSelect( ( select ) =>
select( CORE_USER ).hasScope( ADWORDS_SCOPE )
);

const redirectURL = addQueryArgs( global.location.href, {
[ PARAM_SHOW_PAX ]: 1,
} );

const oAuthURL = useSelect( ( select ) =>
select( CORE_USER ).getConnectURL( {
additionalScopes: [ ADWORDS_SCOPE ],
redirectURL,
} )
);
const isNavigatingToOAuthURL = useSelect( ( select ) => {
if ( ! oAuthURL ) {
return false;
}

return select( CORE_LOCATION ).isNavigatingTo( oAuthURL );
} );

const { navigateTo } = useDispatch( CORE_LOCATION );
const { setPaxConversionID, setExtCustomerID, submitChanges } =
useDispatch( MODULES_ADS );

const onCompleteSetup = useCallback( async () => {
if ( ! paxApp ) {
return;
}

/* eslint-disable sitekit/acronym-case */
// Disabling rule because function and property names
// are expected in current format by PAX API.
const { accountService, conversionTrackingIdService } =
paxApp.getServices();
const customerData = await accountService.getAccountId( {} );
const conversionTrackingData =
await conversionTrackingIdService.getConversionTrackingId( {} );

if (
! customerData.externalCustomerId &&
! conversionTrackingData.conversionTrackingId
) {
return;
}

setExtCustomerID( customerData.externalCustomerId );
setPaxConversionID( conversionTrackingData.conversionTrackingId );
/* eslint-enable sitekit/acronym-case */

const { error } = await submitChanges();

if ( error ) {
return;
}
finishSetup();
}, [
paxApp,
setExtCustomerID,
setPaxConversionID,
submitChanges,
finishSetup,
] );

const createAccount = useCallback( () => {
if ( ! hasAdwordsScope ) {
navigateTo( oAuthURL );
return;
}

setShowPaxApp( true );
}, [ navigateTo, setShowPaxApp, hasAdwordsScope, oAuthURL ] );

return (
<div className="googlesitekit-setup-module googlesitekit-setup-module--ads">
<div className="googlesitekit-setup-module__step">
<div className="googlesitekit-setup-module__logo">
<AdsIcon width="33" height="33" />
</div>

<h2 className="googlesitekit-heading-3 googlesitekit-setup-module__title">
{ _x( 'Ads', 'Service name', 'google-site-kit' ) }
</h2>
</div>
<AdBlockerWarning />

{ ! isAdBlockerActive && !! showPaxApp && hasAdwordsScope && (
<Fragment>
<PAXEmbeddedApp
displayMode="setup"
onLaunch={ setPaxApp }
/>
<div className="googlesitekit-setup-module__action">
<SpinnerButton
isSaving={ isNavigatingToOAuthURL }
disabled={ isNavigatingToOAuthURL || ! paxApp }
onClick={ onCompleteSetup }
>
{ __( 'Complete setup', 'google-site-kit' ) }
</SpinnerButton>
</div>
</Fragment>
) }

{ ! isAdBlockerActive && ( ! showPaxApp || ! hasAdwordsScope ) && (
<Fragment>
<div className="googlesitekit-setup-module__description">
{ createInterpolateElement(
__(
'Add your conversion ID below. Site Kit will place it on your site so you can track the performance of your Google Ads campaigns. <a>Learn more</a>',
'google-site-kit'
),
{
a: (
<SupportLink
path="/google-ads/thread/108976144/where-i-can-find-google-conversion-id-begins-with-aw"
external
/>
),
}
) }
<br />
{ __(
'You can always change this later in Site Kit Settings.',
'google-site-kit'
) }
</div>

<SetupForm
finishSetup={ finishSetup }
isNavigatingToOAuthURL={ isNavigatingToOAuthURL }
createAccountCTA={
<Fragment>
<SpinnerButton
onClick={ createAccount }
disabled={ isNavigatingToOAuthURL }
isSaving={ isNavigatingToOAuthURL }
inverse
>
{ __(
'Create an account',
'google-site-kit'
) }
</SpinnerButton>
{ ! hasAdwordsScope && (
<p className="googlesitekit-setup-module__permission-notice">
{ __(
'You’ll be asked to grant Site Kit additional permissions during the account creation process to create a new Ads account.',
'google-site-kit'
) }
</p>
) }
</Fragment>
}
/>
</Fragment>
) }
</div>
);
}

SetupMainPAX.defaultProps = {
finishSetup: () => {},
};
Loading

0 comments on commit 63c1180

Please sign in to comment.