Skip to content

Commit

Permalink
Changes for error message display
Browse files Browse the repository at this point in the history
  • Loading branch information
AltamashShaikh committed Jan 16, 2025
1 parent 8852716 commit 411b907
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 56 deletions.
1 change: 1 addition & 0 deletions GoogleAnalyticsImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = "ConnectAccounts_OptionQuickConnectWithGa";
$translationKeys[] = "ConnectAccounts_OptionAdvancedConnectWithGa";
}
$translationKeys[] = "GoogleAnalyticsImporter_StatusErroredName";
}
public function getJsFiles(&$files)
{
Expand Down
13 changes: 11 additions & 2 deletions ImportStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ private function enrichStatus($status, $checkKilledStatus)
$status['statusName'] = isset($status['status']) ? ucwords($status['status']) : '';
$status['statusDescription'] = '';
$status['errorDescription'] = '';
$status['errorCode'] = '';
$statuesToPretty = [
self::STATUS_ERRORED => Piwik::translate('GoogleAnalyticsImporter_StatusErroredDescription', ['<a href="https://forum.matomo.org/" target="_blank" rel="noreferrer noopener">', '</a>']),
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'),
Expand All @@ -313,7 +314,15 @@ private function enrichStatus($status, $checkKilledStatus)
);
$status['statusDescription'] = $statuesToPretty[$status['status']];
if (in_array($status['status'], [self::STATUS_KILLED, self::STATUS_ERRORED]) && !empty($status['error'])) {
$status['errorDescription'] = $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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"RecommendationButton": "Import data",
"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 %1$sask on the forums%2$s 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.",
"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",
Expand Down
24 changes: 12 additions & 12 deletions tests/Integration/ImportStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,21 +357,21 @@ public function test_getAllImportStatuses_returnsAllStatuses()
$this->assertEquals([['status' => 'started', 'idSite' => 10, 'ga' => ['property' => 'property3', 'account' => 'account3', 'view' => 'view3', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(10), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property3
Account: account3
View: view3', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'started', 'idSite' => 9, 'ga' => ['property' => 'properties/879821', 'account' => 'account2', 'view' => '', 'import_type' => 'GA4'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(9), 'gaInfoPretty' => 'Import Type: GA4
View: view3', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'started', 'idSite' => 9, 'ga' => ['property' => 'properties/879821', 'account' => 'account2', 'view' => '', 'import_type' => 'GA4'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(9), 'gaInfoPretty' => 'Import Type: GA4
Property: 879821
Account: account2
StreamIds: streamId1, streamId2', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \true, 'streamIds' => ['streamId1', 'streamId2'], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'started', 'idSite' => 5, 'ga' => ['property' => 'properties/1234', 'account' => 'account', 'view' => '', 'import_type' => 'GA4'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(5), 'gaInfoPretty' => 'Import Type: GA4
StreamIds: streamId1, streamId2', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \true, 'streamIds' => ['streamId1', 'streamId2'], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'started', 'idSite' => 5, 'ga' => ['property' => 'properties/1234', 'account' => 'account', 'view' => '', 'import_type' => 'GA4'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(5), 'gaInfoPretty' => 'Import Type: GA4
Property: 1234
Account: account', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \true, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'started', 'idSite' => 3, 'ga' => ['property' => 'property3', 'account' => 'account3', 'view' => 'view3', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(3), 'gaInfoPretty' => 'Import Type: Universal Analytics
Account: account', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \true, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'started', 'idSite' => 3, 'ga' => ['property' => 'property3', 'account' => 'account3', 'view' => 'view3', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(3), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property3
Account: account3
View: view3', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'started', 'idSite' => 2, 'ga' => ['property' => 'property2', 'account' => 'account2', 'view' => 'view2', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(2), 'gaInfoPretty' => 'Import Type: Universal Analytics
View: view3', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'started', 'idSite' => 2, 'ga' => ['property' => 'property2', 'account' => 'account2', 'view' => 'view2', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(2), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property2
Account: account2
View: view2', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'started', 'idSite' => 1, 'ga' => ['property' => 'property', 'account' => 'account', 'view' => 'view', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(1), 'gaInfoPretty' => 'Import Type: Universal Analytics
View: view2', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'started', 'idSite' => 1, 'ga' => ['property' => 'property', 'account' => 'account', 'view' => 'view', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(1), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property
Account: account
View: view', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '']], $statuses);
View: view', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => '']], $statuses);
}
public function test_getAllImportStatuses_checksKilledStatusIfRequired()
{
Expand Down Expand Up @@ -414,22 +414,22 @@ public function test_getAllImportStatuses_checksKilledStatusIfRequired()
$this->cleanStatuses($statuses);
$this->assertEquals([['status' => 'started', 'idSite' => 6, 'ga' => ['property' => 'properties/6', 'account' => 'account', 'view' => '', 'import_type' => 'GA4'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(6), 'gaInfoPretty' => 'Import Type: GA4
Property: 6
Account: account', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \true, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'started', 'idSite' => 5, 'ga' => ['property' => 'property5', 'account' => 'account5', 'view' => 'view5', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(5), 'gaInfoPretty' => 'Import Type: Universal Analytics
Account: account', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \true, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'started', 'idSite' => 5, 'ga' => ['property' => 'property5', 'account' => 'account5', 'view' => 'view5', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(5), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property5
Account: account5
View: view5', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'killed', 'idSite' => 4, 'ga' => ['property' => 'property4', 'account' => 'account4', 'view' => 'view4', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(4), 'gaInfoPretty' => 'Import Type: Universal Analytics
View: view5', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'killed', 'idSite' => 4, 'ga' => ['property' => 'property4', 'account' => 'account4', 'view' => 'view4', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(4), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property4
Account: account4
View: view4', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'GoogleAnalyticsImporter_StatusKilledName', 'statusDescription' => 'GoogleAnalyticsImporter_StatusKilledDescription', 'errorDescription' => ''], ['status' => 'started', 'idSite' => 3, 'ga' => ['property' => 'property3', 'account' => 'account3', 'view' => 'view3', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(3), 'gaInfoPretty' => 'Import Type: Universal Analytics
View: view4', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'GoogleAnalyticsImporter_StatusKilledName', 'statusDescription' => 'GoogleAnalyticsImporter_StatusKilledDescription', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'started', 'idSite' => 3, 'ga' => ['property' => 'property3', 'account' => 'account3', 'view' => 'view3', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(3), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property3
Account: account3
View: view3', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => ''], ['status' => 'killed', 'idSite' => 2, 'ga' => ['property' => 'property2', 'account' => 'account2', 'view' => 'view2', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(2), 'gaInfoPretty' => 'Import Type: Universal Analytics
View: view3', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'Started', 'statusDescription' => '', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'killed', 'idSite' => 2, 'ga' => ['property' => 'property2', 'account' => 'account2', 'view' => 'view2', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(2), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property2
Account: account2
View: view2', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'GoogleAnalyticsImporter_StatusKilledName', 'statusDescription' => 'GoogleAnalyticsImporter_StatusKilledDescription', 'errorDescription' => ''], ['status' => 'killed', 'idSite' => 1, 'ga' => ['property' => 'property', 'account' => 'account', 'view' => 'view', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(1), 'gaInfoPretty' => 'Import Type: Universal Analytics
View: view2', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'GoogleAnalyticsImporter_StatusKilledName', 'statusDescription' => 'GoogleAnalyticsImporter_StatusKilledDescription', 'errorDescription' => '', 'errorCode' => ''], ['status' => 'killed', 'idSite' => 1, 'ga' => ['property' => 'property', 'account' => 'account', 'view' => 'view', 'import_type' => 'Universal Analytics'], 'last_date_imported' => null, 'import_end_time' => null, 'last_day_archived' => null, 'import_range_start' => null, 'import_range_end' => null, 'extra_custom_dimensions' => [], 'days_finished_since_rate_limit' => 0, 'site' => new Site(1), 'gaInfoPretty' => 'Import Type: Universal Analytics
Property: property
Account: account
View: view', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'GoogleAnalyticsImporter_StatusKilledName', 'statusDescription' => 'GoogleAnalyticsImporter_StatusKilledDescription', 'errorDescription' => '']], $statuses);
View: view', 'reimport_ranges' => [], 'main_import_progress' => null, 'isGA4' => \false, 'streamIds' => [], 'statusName' => 'GoogleAnalyticsImporter_StatusKilledName', 'statusDescription' => 'GoogleAnalyticsImporter_StatusKilledDescription', 'errorDescription' => '', 'errorCode' => '']], $statuses);
}
public function test_reImportDateRange_throwsIfRangeIsInvalid()
{
Expand Down
Loading

0 comments on commit 411b907

Please sign in to comment.