Skip to content

Notify users when an Ads account is suspended #2654

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

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
74 changes: 74 additions & 0 deletions js/src/dashboard/ads-account-suspended/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Notice } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { Icon, external as externalIcon, warning as warningIcon } from '@wordpress/icons';

Check failure on line 7 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Replace `·Icon,·external·as·externalIcon,·warning·as·warningIcon·` with `⏎↹Icon,⏎↹external·as·externalIcon,⏎↹warning·as·warningIcon,⏎`

/**
* Internal dependencies
*/

Check failure on line 11 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Insert `·`

Check failure on line 11 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[jsdoc/check-alignment] Expected JSDoc block to be aligned.
import './index.scss';

Check failure on line 12 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[@woocommerce/dependency-group] Expected preceding "Internal dependencies" comment block

/**
* Renders a Notice component with extra props.
*
* ## Usage
*
* ```jsx
* <AdsAccountSuspended >
* My Notice
* </AdsAccountSuspended>
* ```
*/
const AdsAccountSuspended = () => {
const [ isShown, setIsShown ] = useState( true );
const isSuspended = true;
if ( ! isSuspended ) {
return null;
}

const getActionLabel = () => (
<>
{ __(
'Resolve issues.',
'google-listings-and-ads'
) }

Check failure on line 37 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Replace `⏎↹↹↹↹'Resolve·issues.',⏎↹↹↹↹'google-listings-and-ads'⏎↹↹↹` with `·'Resolve·issues.',·'google-listings-and-ads'·`
<Icon
className="gla-get-started-notice__icon"
icon={ externalIcon }
size={ 18 }
/>
</>
);

return ( isShown &&

Check failure on line 46 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Replace `·isShown·&&` with `⏎↹↹isShown·&&·(`
<Notice

Check failure on line 47 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Insert `↹`
className="gla-ads-suspended-notice"

Check failure on line 48 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Insert `↹`
status="error"

Check failure on line 49 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Insert `↹`
onDismiss={ () => setIsShown( false ) }

Check failure on line 50 in js/src/dashboard/ads-account-suspended/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Insert `↹`
actions={[
{
label: getActionLabel(),
onClick: 'https://ads.google.com/aw/overview?euid=0',
className: 'gla-ads-suspended-notice__action',
},
]}
>
<p className="gla-ads-suspended-notice__message">
<Icon
icon={ warningIcon }
size={ 24 }
className="gla-ads-suspended-notice__icon"
/>
{ __(
'Your Google Ads account has been suspended. Your campaigns are not running.',
'google-listings-and-ads'
) }
</p>
</Notice>
);
};

export default AdsAccountSuspended;
19 changes: 19 additions & 0 deletions js/src/dashboard/ads-account-suspended/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.components-notice.gla-ads-suspended-notice {
background-color: white;

Check failure on line 2 in js/src/dashboard/ads-account-suspended/index.scss

View workflow job for this annotation

GitHub Actions / Lint CSS

Unexpected named color "white" (color-named)
margin-bottom: $grid-unit-20;

.gla-ads-suspended-notice__message {
align-items: center;
display: flex;
margin-top: 0;
gap: $grid-unit-05;
}

.gla-ads-suspended-notice__icon {
fill: $alert-red;
}

.components-notice__actions {
margin-left: $grid-unit-20;
}
}
2 changes: 2 additions & 0 deletions js/src/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AppButton from '.~/components/app-button';
import DifferentCurrencyNotice from '.~/components/different-currency-notice';
import MainTabNav from '.~/components/main-tab-nav';
import CustomerEffortScorePrompt from '.~/components/customer-effort-score-prompt';
import AdsAccountSuspended from './ads-account-suspended';
import AppDateRangeFilterPicker from './app-date-range-filter-picker';
import SummarySection from './summary-section';
import CampaignCreationSuccessGuide from './campaign-creation-success-guide';
Expand Down Expand Up @@ -87,6 +88,7 @@ const Dashboard = () => {
return (
<>
<div className="gla-dashboard">
<AdsAccountSuspended />
<DifferentCurrencyNotice context="dashboard" />
<MainTabNav />
<RebrandingTour />
Expand Down
30 changes: 30 additions & 0 deletions src/API/Google/Ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,36 @@ private function get_account_details( string $account ): ?array {
return null;
}

/**
* Get the account status.
*
* @return string|null Account status.
*/
public function get_account_status() {
try {
$ads_id = $this->options->get_ads_id();
$account = ResourceNames::forCustomer( $ads_id );
$customer = ( new AdsAccountQuery() )
->set_client( $this->client, $ads_id )
->columns( [ 'customer.status' ] )
->where( 'customer.resource_name', $account, '=' )
->get_result()
->getCustomer();

if ( ! $customer ) {
return null;
}

$status = $customer->getStatus();

} catch ( ApiException $e ) {
do_action( 'woocommerce_gla_ads_client_exception', $e, __METHOD__ );
$status = null;
}

return $status;
}

/**
* Get the link from a merchant account.
*
Expand Down
2 changes: 1 addition & 1 deletion src/API/Google/Query/AdsAccountQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class AdsAccountQuery extends AdsQuery {
*/
public function __construct() {
parent::__construct( 'customer' );
$this->columns( [ 'customer.id', 'customer.descriptive_name', 'customer.manager', 'customer.test_account' ] );
$this->columns( [ 'customer.id', 'customer.descriptive_name', 'customer.manager', 'customer.test_account', 'customer.status' ] );
}
}
9 changes: 9 additions & 0 deletions src/Ads/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public function get_connected_account(): array {
$status['step'] = $incomplete;
}

if ( $id > 0 ) {
$customer_status = $this->container->get( Ads::class )->get_account_status();

// @todo: use ENUM for these values.
// 4 maps to 'SUSPENDED' in the API.
// See: https://github.com/googleads/google-ads-php/blob/legacy-v22.1.0/src/Google/Ads/GoogleAds/V16/Enums/CustomerStatusEnum/CustomerStatus.php
$status['account_status'] = ( 4 === $customer_status ) ? 'suspended' : 'active';
}

$status += $this->state->get_step_data( 'set_id' );

return $status;
Expand Down
Loading