Skip to content
Merged
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
11 changes: 9 additions & 2 deletions Google/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,17 @@ public function configureClient(\Matomo\Dependencies\GoogleAnalyticsImporter\Goo
$client->setAccessToken($accessToken);
}
//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
if (!empty($clientConfig['web']['redirect_uris']) && !Common::isRunningConsoleCommand() && !PluginsArchiver::isArchivingProcessActive() && !$this->isMiscCron()) {
$expectedUri = Url::getCurrentUrlWithoutQueryString() . '?module=GoogleAnalyticsImporter&action=processAuthCode';
if (
!empty($clientConfig['web']['redirect_uris']) &&
!Common::isRunningConsoleCommand() &&
!PluginsArchiver::isArchivingProcessActive() &&
!$this->isMiscCron() &&
stripos($expectedUri, 'unknown/_/console?') === false // To handle case where we are unable to determine the correct URI
) {
$uri = $this->getValidUri($clientConfig['web']['redirect_uris']);
if (empty($uri)) {
throw new \Exception(Piwik::translate('GoogleAnalyticsImporter_InvalidRedirectUriInClientConfiguration', array(Url::getCurrentUrlWithoutQueryString() . '?module=GoogleAnalyticsImporter&action=processAuthCode')));
throw new \Exception(Piwik::translate('GoogleAnalyticsImporter_InvalidRedirectUriInClientConfiguration', array($expectedUri)));
}
$client->setRedirectUri($uri);
}
Expand Down
13 changes: 13 additions & 0 deletions ImportStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Piwik\Plugins\GoogleAnalyticsImporter\Commands\ImportReports;
use Piwik\SettingsPiwik;
use Piwik\Site;
use Piwik\Url;

// TODO: maybe make an import status entity class
class ImportStatus
Expand All @@ -34,6 +35,8 @@ class ImportStatus
public const STATUS_RATE_LIMITED_HOURLY = 'rate_limited_hourly';
public const STATUS_CLOUD_RATE_LIMITED = 'cloud_rate_limited';
public const STATUS_KILLED = 'killed';
public const STATUS_PERMISSION_DENIED = 'PERMISSION_DENIED';
public const STATUS_UNAUTHENTICATED = 'UNAUTHENTICATED';
public static function isImportRunning($status)
{
$idSite = $status['idSite'];
Expand Down Expand Up @@ -323,7 +326,17 @@ private function enrichStatus($status, $checkKilledStatus)
$status['errorCode'] = $jsonDecoded['error']['code'];
}
$status['errorDescription'] = $msg;
if (stripos($msg, 'User does not have sufficient permissions for this profile') !== false) {
$status['errorDescription'] = Piwik::translate('GoogleAnalyticsImporter_StatusInsufficientProfilePermissionDescription');
}
}
} elseif (!empty($status['status']) && $status['status'] === self::STATUS_PERMISSION_DENIED) {
$forumUrl = Url::addCampaignParametersToMatomoLink('https://forum.matomo.org/');
$status['statusName'] = Piwik::translate('GoogleAnalyticsImporter_StatusPermissionDenied');
$status['errorDescription'] = Piwik::translate('GoogleAnalyticsImporter_StatusPermissionDeniedDescription', ['<a href="' . $forumUrl . '" target="_blank" rel="noreferrer noopener">', '</a>']);
} elseif (!empty($status['status']) && $status['status'] === self::STATUS_UNAUTHENTICATED) {
$status['statusName'] = Piwik::translate('GoogleAnalyticsImporter_StatusUnAuthenticated');
$status['errorDescription'] = Piwik::translate('GoogleAnalyticsImporter_StatusUnAuthenticatedDescription', ['<a href=https://console.cloud.google.com/" target="_blank" rel="noreferrer noopener">', '</a>']);
}

return $status;
Expand Down
7 changes: 6 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@
"StatusCloudRateLimitedName": "Rate limited (account)",
"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.",
"StatusKilledName": "Terminated",
"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."
"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.",
"StatusPermissionDenied": "Permission Denied",
"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.",
"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.",
"StatusUnAuthenticated": "Unauthenticated",
"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."

}
}
Loading