From b33df0449e6f128043e0c5bf98716a41591776f0 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Tue, 27 May 2025 12:31:50 +0530 Subject: [PATCH 1/3] Improved redirect URI check for MWP --- CHANGELOG.md | 3 +++ Google/Authorization.php | 4 +++- plugin.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94c09407..74d7d0ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +# 5.1.3 - 2025-05-28 +- Added fallback URI for valid redirect URI check to solve issues with some Matomo for WordPress install + # 5.1.2 - 2025-03-17 - Started importing region data as the region dimension is now available in the API request diff --git a/Google/Authorization.php b/Google/Authorization.php index 01c6f4b5..961f019c 100644 --- a/Google/Authorization.php +++ b/Google/Authorization.php @@ -15,6 +15,7 @@ use Piwik\Container\StaticContainer; use Piwik\Option; use Piwik\Piwik; +use Piwik\SettingsPiwik; use Piwik\Url; class Authorization @@ -136,8 +137,9 @@ protected function getUserInfoByAccessToken(\Matomo\Dependencies\GoogleAnalytics private function getValidUri($uris) { $validUri = Url::getCurrentUrlWithoutQueryString() . '?module=GoogleAnalyticsImporter&action=processAuthCode'; + $validUriFallback = SettingsPiwik::getPiwikUrl() . '?module=GoogleAnalyticsImporter&action=processAuthCode'; // Some MWP installs was not working as expected when using Url::getCurrentUrlWithoutQueryString() foreach ($uris as $uri) { - if (stripos($uri, $validUri) !== \FALSE) { + if (stripos($uri, $validUri) !== \false || stripos($uri, $validUriFallback) !== \false) { return $uri; } } diff --git a/plugin.json b/plugin.json index 9e0190a2..4fc5e109 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "name": "GoogleAnalyticsImporter", "description": "Import reports from a Google Analytics account into Matomo.", - "version": "5.1.2", + "version": "5.1.3", "theme": false, "require": { "matomo": ">=5.0.0-rc5,<6.0.0-b1" From bfb4da07e45d17eda54ab37e107c1cd6d78a8291 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 28 May 2025 07:20:39 +0530 Subject: [PATCH 2/3] Applied PR feedback --- Google/Authorization.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Google/Authorization.php b/Google/Authorization.php index 961f019c..41e63d03 100644 --- a/Google/Authorization.php +++ b/Google/Authorization.php @@ -137,7 +137,7 @@ protected function getUserInfoByAccessToken(\Matomo\Dependencies\GoogleAnalytics private function getValidUri($uris) { $validUri = Url::getCurrentUrlWithoutQueryString() . '?module=GoogleAnalyticsImporter&action=processAuthCode'; - $validUriFallback = SettingsPiwik::getPiwikUrl() . '?module=GoogleAnalyticsImporter&action=processAuthCode'; // Some MWP installs was not working as expected when using Url::getCurrentUrlWithoutQueryString() + $validUriFallback = SettingsPiwik::getPiwikUrl() . 'index.php?module=GoogleAnalyticsImporter&action=processAuthCode'; // Some MWP installs was not working as expected when using Url::getCurrentUrlWithoutQueryString() foreach ($uris as $uri) { if (stripos($uri, $validUri) !== \false || stripos($uri, $validUriFallback) !== \false) { return $uri; From ad2e43bc6105bfc28a8ec5fd12821cdbc3ef457b Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 28 May 2025 07:50:01 +0530 Subject: [PATCH 3/3] append index.php to fallback url only when not present --- Google/Authorization.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Google/Authorization.php b/Google/Authorization.php index 41e63d03..74ec8c61 100644 --- a/Google/Authorization.php +++ b/Google/Authorization.php @@ -137,7 +137,11 @@ protected function getUserInfoByAccessToken(\Matomo\Dependencies\GoogleAnalytics private function getValidUri($uris) { $validUri = Url::getCurrentUrlWithoutQueryString() . '?module=GoogleAnalyticsImporter&action=processAuthCode'; - $validUriFallback = SettingsPiwik::getPiwikUrl() . 'index.php?module=GoogleAnalyticsImporter&action=processAuthCode'; // Some MWP installs was not working as expected when using Url::getCurrentUrlWithoutQueryString() + $settingURL = SettingsPiwik::getPiwikUrl(); + if (stripos($settingURL, 'index.php') === false) { + $settingURL .= 'index.php'; + } + $validUriFallback = $settingURL . '?module=GoogleAnalyticsImporter&action=processAuthCode'; // Some MWP installs was not working as expected when using Url::getCurrentUrlWithoutQueryString() foreach ($uris as $uri) { if (stripos($uri, $validUri) !== \false || stripos($uri, $validUriFallback) !== \false) { return $uri;