Skip to content

Commit da86c7b

Browse files
authored
Merge pull request #625 from google/fix/346-no-error-message-tag-manager-no-account
fix: Don't show an error when user cannot access Tag Manager
2 parents 6b65054 + 83fe16c commit da86c7b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

assets/js/modules/tagmanager/setup.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ class TagmanagerSetup extends Component {
133133
let errorMsg = '';
134134
const responseData = await data.get( TYPE_MODULES, 'tagmanager', 'accounts-containers', queryArgs );
135135

136+
if ( ! selectedAccount && 0 === responseData.accounts.length ) {
137+
errorCode = 'accountEmpty';
138+
errorMsg = __(
139+
'We didn’t find an associated Google Tag Manager account, would you like to set it up now? If you’ve just set up an account please re-fetch your account to sync it with Site Kit.',
140+
'google-site-kit'
141+
);
142+
}
143+
136144
// Verify if user has access to the selected account.
137145
if ( selectedAccount && ! responseData.accounts.find( ( account ) => account.accountId === selectedAccount ) ) {
138146
data.invalidateCacheGroup( TYPE_MODULES, 'tagmanager', 'accounts-containers' );
@@ -147,12 +155,15 @@ class TagmanagerSetup extends Component {
147155
responseData.containers.push( chooseContainer );
148156

149157
if ( this._isMounted ) {
158+
const accountId = responseData.accounts[ 0 ] ? responseData.accounts[ 0 ].accountId : null;
159+
const publicId = responseData.containers[ 0 ] ? responseData.containers[ 0 ].publicId : null;
160+
150161
this.setState( {
151162
isLoading: false,
152163
accounts: responseData.accounts,
153-
selectedAccount: ( selectedAccount ) ? selectedAccount : responseData.accounts[ 0 ].accountId,
164+
selectedAccount: ( selectedAccount ) ? selectedAccount : accountId,
154165
containers: responseData.containers,
155-
selectedContainer: ( selectedContainer ) ? selectedContainer : responseData.containers[ 0 ].publicId,
166+
selectedContainer: ( selectedContainer ) ? selectedContainer : publicId,
156167
refetch: false,
157168
errorCode,
158169
errorMsg,

includes/Modules/TagManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ protected function parse_data_response( $method, $datapoint, $response ) {
494494
'containers' => array(),
495495
);
496496
if ( 0 === count( $response['accounts'] ) ) {
497-
return new WP_Error( 'google_tagmanager_account_empty', __( 'We didn’t find an associated Google Tag Manager account, would you like to set it up now? If you’ve just set up an account please re-fetch your account to sync it with Site Kit.', 'google-site-kit' ), array( 'status' => 500 ) );
497+
return $response;
498498
}
499499
if ( is_array( $this->_list_accounts_data ) && isset( $this->_list_accounts_data['accountId'] ) ) {
500500
$account_id = $this->_list_accounts_data['accountId'];

0 commit comments

Comments
 (0)