Skip to content

Commit

Permalink
Merge pull request #566 from matomo-org/PG-3989-improve-error-message
Browse files Browse the repository at this point in the history
Improves error message on UI, #PG-3989
  • Loading branch information
AltamashShaikh authored Jan 17, 2025
2 parents be09005 + dfe5f5b commit 3d21395
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 163 deletions.
2 changes: 1 addition & 1 deletion Exceptions/CloudApiQuotaExceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class CloudApiQuotaExceeded extends \RuntimeException
{
public function __construct($limit = 0)
{
parent::__construct(Piwik::translate('GoogleAnalyticsImporter_CloudRateLimitHelp', [$limit]));
parent::__construct(Piwik::translate('GoogleAnalyticsImporter_StatusCloudRateLimitedDescription', [$limit]));
}
}
2 changes: 1 addition & 1 deletion Google/GoogleGA4ResponseDataTableFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function mergeGaResponse(\Matomo\Dependencies\GoogleAnalyticsImporter\Goo
$gaRowDimensions[] = $dimensionValues[$i]->getValue();
}
foreach (array_values($this->dimensions) as $index => $dimension) {
$labelValue = $gaRowDimensions[$index] == '(not set)' ? null : $gaRowDimensions[$index];
$labelValue = (empty($gaRowDimensions[$index]) || $gaRowDimensions[$index] == '(not set)') ? null : $gaRowDimensions[$index];
$tableRow->setMetadata($dimension, $labelValue);
$label[$dimension] = $labelValue;
}
Expand Down
2 changes: 2 additions & 0 deletions GoogleAnalyticsImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = 'GoogleAnalyticsImporter_Start';
$translationKeys[] = 'GoogleAnalyticsImporter_RateLimitHelp';
$translationKeys[] = 'GoogleAnalyticsImporter_CloudRateLimitHelp';
$translationKeys[] = 'GoogleAnalyticsImporter_StatusCloudRateLimitedDescription';
$translationKeys[] = 'GoogleAnalyticsImporter_RateLimitHourlyHelp';
$translationKeys[] = 'GoogleAnalyticsImporter_KilledStatusHelp';
$translationKeys[] = 'GoogleAnalyticsImporter_ResumeDesc';
Expand Down Expand Up @@ -241,6 +242,7 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = "ConnectAccounts_OptionQuickConnectWithGa";
$translationKeys[] = "ConnectAccounts_OptionAdvancedConnectWithGa";
}
$translationKeys[] = "GoogleAnalyticsImporter_StatusErroredName";
}
public function getJsFiles(&$files)
{
Expand Down
41 changes: 40 additions & 1 deletion ImportStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private function enrichStatus($status, $checkKilledStatus)
}
if (!empty($status['ga'])) {
if (!empty($status['isGA4'])) {
$status['gaInfoPretty'] = 'Import Type: GA4' . "\n" . 'Property: ' . $status['ga']['property'] . "\nAccount: " . $status['ga']['account'];
$status['gaInfoPretty'] = 'Import Type: GA4' . "\n" . 'Property: ' . str_replace('properties/', '', $status['ga']['property']) . "\nAccount: " . str_replace('accounts/', '', $status['ga']['account']);
if (!empty($status['streamIds'])) {
$status['gaInfoPretty'] .= "\nStreamIds: " . implode(', ', $status['streamIds']);
}
Expand All @@ -287,6 +287,45 @@ private function enrichStatus($status, $checkKilledStatus)
) {
$status['status'] = self::STATUS_KILLED;
}
$status['statusName'] = isset($status['status']) ? ucwords($status['status']) : '';
$status['statusDescription'] = '';
$status['errorDescription'] = '';
$status['errorCode'] = '';
$statuesToPretty = [
self::STATUS_ERRORED => Piwik::translate('GoogleAnalyticsImporter_StatusErroredDescription'),
self::STATUS_RATE_LIMITED => Piwik::translate('GoogleAnalyticsImporter_StatusRateLimitedDescription'),
self::STATUS_FUTURE_DATE_IMPORT_PENDING => Piwik::translate('GoogleAnalyticsImporter_StatusFutureDateImportPendingDescription'),
self::STATUS_RATE_LIMITED_HOURLY => Piwik::translate('GoogleAnalyticsImporter_StatusRateLimitedHourlyDescription'),
self::STATUS_CLOUD_RATE_LIMITED => $status['error'] ?? '',
self::STATUS_KILLED => Piwik::translate('GoogleAnalyticsImporter_StatusKilledDescription'),
];
if (!empty($status['status']) && isset($statuesToPretty[$status['status']])) {
$status['statusName'] = str_replace(
array_keys($statuesToPretty),
[
Piwik::translate('GoogleAnalyticsImporter_StatusErroredName'),
Piwik::translate('GoogleAnalyticsImporter_StatusRateLimitedName'),
Piwik::translate('GoogleAnalyticsImporter_StatusFutureDateImportPendingName'),
Piwik::translate('GoogleAnalyticsImporter_StatusRateLimitedHourlyName'),
Piwik::translate('GoogleAnalyticsImporter_StatusCloudRateLimitedName'),
Piwik::translate('GoogleAnalyticsImporter_StatusKilledName'),
],
$status['status']
);
$status['statusDescription'] = $statuesToPretty[$status['status']];
if (in_array($status['status'], [self::STATUS_KILLED, self::STATUS_ERRORED]) && !empty($status['error'])) {
$msg = str_replace('Error on day (unknown), ', '', $status['error']);
$jsonDecoded = json_decode($msg, true);
if (is_array($jsonDecoded) && !empty($jsonDecoded['error']['message'])) {
$msg = $jsonDecoded['error']['message'];
}
if (!empty($jsonDecoded['error']['code'])) {
$status['errorCode'] = $jsonDecoded['error']['code'];
}
$status['errorDescription'] = $msg;
}
}

return $status;
}
public static function getEstimatedDaysLeftToFinish($status)
Expand Down
2 changes: 1 addition & 1 deletion Importers/VisitFrequency/RecordImporterGA4.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RecordImporterGA4 extends \Piwik\Plugins\GoogleAnalyticsImporter\RecordImp
public const PLUGIN_NAME = 'VisitFrequency';
public function importRecords(Date $day)
{
$filters = ['dimensionFilter' => ['dimension' => 'newVsReturning', 'filterType' => 'inList', 'filterValue' => ['(not set)', 'returning']]];
$filters = ['dimensionFilter' => ['dimension' => 'newVsReturning', 'filterType' => 'inList', 'filterValue' => ['(not set)', '', 'returning']]];
$visitsSummaryRecordImporter = new VisitsSummaryAPI($this->getGaClient(), $this->getIdSite(), $this->getLogger(), null, $filters);
$importer = StaticContainer::get(ImporterGA4::class);
$importer->importDay(new \Piwik\Site($this->getIdSite()), $day, ['VisitsSummary' => $visitsSummaryRecordImporter], API::RETURNING_VISITOR_SEGMENT, 'VisitsSummary');
Expand Down
15 changes: 14 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@
"RecommendationTitle": "Import Google Analytics data to Matomo (recommended for you)",
"RecommendationText": "We have detected Google Analytics on your site, so you can set up Matomo by importing your Google Analytics data.",
"RecommendationButton": "Import data",
"NoteImportNotCountedAsHit": "%1$sNote:%2$s Data imported through the Google Analytics Import does not count towards your hits quota."
"NoteImportNotCountedAsHit": "%1$sNote:%2$s Data imported through the Google Analytics Import does not count towards your hits quota.",
"StatusErroredName": "Error",
"StatusErroredDescription": "An unexpected error occurred. Unexpected errors usually persist during a calendar day, and are automatically resolved the next day. If the error persists, please ask on the Matomo forum or contact the Matomo support team. Providing access to your Google Analytics account to a member of Matomo's support team can help speed up the resolution process.",
"StatusRateLimitedName": "Rate limited (daily)",
"StatusRateLimitedDescription": "By default, Google limits API requests for each project to 50,000 per day. This import job has exceeded that limit and will resume tomorrow.",
"StatusFutureDateImportPendingName": "Up to date",
"StatusFutureDateImportPendingDescription": "All available data has been imported. The importer will automatically retry tomorrow to ensure that newly available data is imported.",
"StatusRateLimitedHourlyName": "Rate limited (hourly)",
"StatusRateLimitedHourlyDescription": "By default, Google limits API requests for each project to 5,000 per hour. This import job has exceeded that limit and will continue after the hourly limit resets.",
"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."

}
}
Loading

0 comments on commit 3d21395

Please sign in to comment.