Skip to content

Commit 643cf45

Browse files
Merge pull request #577 from matomo-org/PG-4063-improve-error-msg
Improved display of error messages, #PG-4063
2 parents 7c4d848 + 3b67a17 commit 643cf45

File tree

6 files changed

+79
-48
lines changed

6 files changed

+79
-48
lines changed

Google/Authorization.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,17 @@ public function configureClient(\Matomo\Dependencies\GoogleAnalyticsImporter\Goo
9696
$client->setAccessToken($accessToken);
9797
}
9898
//since there ie no host defined when running via console it results in error, but we don't need to set any URI when running console commands so can be ignored
99-
if (!empty($clientConfig['web']['redirect_uris']) && !Common::isRunningConsoleCommand() && !PluginsArchiver::isArchivingProcessActive() && !$this->isMiscCron()) {
99+
$expectedUri = Url::getCurrentUrlWithoutQueryString() . '?module=GoogleAnalyticsImporter&action=processAuthCode';
100+
if (
101+
!empty($clientConfig['web']['redirect_uris']) &&
102+
!Common::isRunningConsoleCommand() &&
103+
!PluginsArchiver::isArchivingProcessActive() &&
104+
!$this->isMiscCron() &&
105+
stripos($expectedUri, 'unknown/_/console?') === false // To handle case where we are unable to determine the correct URI
106+
) {
100107
$uri = $this->getValidUri($clientConfig['web']['redirect_uris']);
101108
if (empty($uri)) {
102-
throw new \Exception(Piwik::translate('GoogleAnalyticsImporter_InvalidRedirectUriInClientConfiguration', array(Url::getCurrentUrlWithoutQueryString() . '?module=GoogleAnalyticsImporter&action=processAuthCode')));
109+
throw new \Exception(Piwik::translate('GoogleAnalyticsImporter_InvalidRedirectUriInClientConfiguration', array($expectedUri)));
103110
}
104111
$client->setRedirectUri($uri);
105112
}

ImportStatus.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Piwik\Plugins\GoogleAnalyticsImporter\Commands\ImportReports;
2020
use Piwik\SettingsPiwik;
2121
use Piwik\Site;
22+
use Piwik\Url;
2223

2324
// TODO: maybe make an import status entity class
2425
class ImportStatus
@@ -34,6 +35,8 @@ class ImportStatus
3435
public const STATUS_RATE_LIMITED_HOURLY = 'rate_limited_hourly';
3536
public const STATUS_CLOUD_RATE_LIMITED = 'cloud_rate_limited';
3637
public const STATUS_KILLED = 'killed';
38+
public const STATUS_PERMISSION_DENIED = 'PERMISSION_DENIED';
39+
public const STATUS_UNAUTHENTICATED = 'UNAUTHENTICATED';
3740
public static function isImportRunning($status)
3841
{
3942
$idSite = $status['idSite'];
@@ -323,7 +326,17 @@ private function enrichStatus($status, $checkKilledStatus)
323326
$status['errorCode'] = $jsonDecoded['error']['code'];
324327
}
325328
$status['errorDescription'] = $msg;
329+
if (stripos($msg, 'User does not have sufficient permissions for this profile') !== false) {
330+
$status['errorDescription'] = Piwik::translate('GoogleAnalyticsImporter_StatusInsufficientProfilePermissionDescription');
331+
}
326332
}
333+
} elseif (!empty($status['status']) && $status['status'] === self::STATUS_PERMISSION_DENIED) {
334+
$forumUrl = Url::addCampaignParametersToMatomoLink('https://forum.matomo.org/');
335+
$status['statusName'] = Piwik::translate('GoogleAnalyticsImporter_StatusPermissionDenied');
336+
$status['errorDescription'] = Piwik::translate('GoogleAnalyticsImporter_StatusPermissionDeniedDescription', ['<a href="' . $forumUrl . '" target="_blank" rel="noreferrer noopener">', '</a>']);
337+
} elseif (!empty($status['status']) && $status['status'] === self::STATUS_UNAUTHENTICATED) {
338+
$status['statusName'] = Piwik::translate('GoogleAnalyticsImporter_StatusUnAuthenticated');
339+
$status['errorDescription'] = Piwik::translate('GoogleAnalyticsImporter_StatusUnAuthenticatedDescription', ['<a href=https://console.cloud.google.com/" target="_blank" rel="noreferrer noopener">', '</a>']);
327340
}
328341

329342
return $status;

lang/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@
169169
"StatusCloudRateLimitedName": "Rate limited (account)",
170170
"StatusCloudRateLimitedDescription": "Google limits API requests for data imports. This limit is prorated across Matomo cloud customers. For your account, this has been prorated to %1$s requests. You have reached this limit for today, and the importer will automatically retry tomorrow. You can bypass this limit by configuring your Google Analytics import via your Google Analytics account.",
171171
"StatusKilledName": "Terminated",
172-
"StatusKilledDescription": "The import job was terminated. If you did not initiate this, your host may have restricted long-running PHP processes. The import job will automatically restart within the next hour. If the problem persists, refer to the user guide for more information and workarounds, or contact Matomo support."
172+
"StatusKilledDescription": "The import job was terminated. If you did not initiate this, your host may have restricted long-running PHP processes. The import job will automatically restart within the next hour. If the problem persists, refer to the user guide for more information and workarounds, or contact Matomo support.",
173+
"StatusPermissionDenied": "Permission Denied",
174+
"StatusPermissionDeniedDescription": "The import encountered a permission issue, which may persist with further import attempts. Verify that your Google Analytics account has the necessary permissions for data access. For further assistance, please ask for help on the %1$sforums%2$s. To expedite resolution, Matomo support can assist with access to your GA account.",
175+
"StatusInsufficientProfilePermissionDescription": "There was an issue because your user account does not have sufficient permissions for the selected profile. Check that your user account has the correct permissions for accessing this profile.",
176+
"StatusUnAuthenticated": "Unauthenticated",
177+
"StatusUnAuthenticatedDescription": "The request could not be completed due to invalid authentication credentials. An OAuth 2.0 access token, login cookie, or other valid authentication credentials are required. Check you are logged in with the correct credentials and your OAuth 2.0 access token hasn't expired. For more details, refer to the %1$sGoogle Sign-In Web Developer Console%2$s."
173178

174179
}
175180
}

0 commit comments

Comments
 (0)