Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making GA4 imports work with a proxy #522

Open
wants to merge 15 commits into
base: 5.x-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 23 additions & 5 deletions Google/AuthorizationGA4.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@
*/
namespace Piwik\Plugins\GoogleAnalyticsImporter\Google;

use Matomo\Dependencies\GoogleAnalyticsImporter\Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;
use Matomo\Dependencies\GoogleAnalyticsImporter\Google\Analytics\Admin\V1alpha\AnalyticsAdminServiceClient;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Option;
class AuthorizationGA4
{
const CLIENT_CONFIG_OPTION_NAME = 'GoogleAnalyticsImporter.clientConfiguration';
const ACCESS_TOKEN_OPTION_NAME = 'GoogleAnalyticsImporter.oauthAccessToken';
public function getClient()
{
$klass = StaticContainer::get('GoogleAnalyticsImporter.googleAnalyticsDataClientClass');
$client = new $klass(['credentials' => \Matomo\Dependencies\GoogleAnalyticsImporter\Google\ApiCore\CredentialsWrapper::build(['keyFile' => $this->getClientConfiguration()])]);
$client = new $klass($this->getClientClassArguments());
return $client;
}
public function getAdminClient()
{
$klass = StaticContainer::get('GoogleAnalyticsImporter.googleAnalyticsAdminServiceClientClass');
$adminClient = new $klass(['credentials' => \Matomo\Dependencies\GoogleAnalyticsImporter\Google\ApiCore\CredentialsWrapper::build(['keyFile' => $this->getClientConfiguration()])]);
$adminClient = new $klass($this->getClientClassArguments());
return $adminClient;
}
public function getClientConfiguration()
Expand All @@ -41,4 +38,25 @@ public function getClientConfiguration()
}
return $clientConfig;
}

protected function getClientClassArguments(): array
{
$arguments = [
'keyFile' => $this->getClientConfiguration()
];

$proxyHttpClient = StaticContainer::get('GoogleAnalyticsImporter.proxyHttpClient');
if ($proxyHttpClient) {
$proxyHttpHandler = \Matomo\Dependencies\GoogleAnalyticsImporter\Google\Auth\HttpHandler\HttpHandlerFactory::build($proxyHttpClient);
$arguments['credentialsConfig'] = ['authHttpHandler' => $proxyHttpHandler, 'keyFile' => $arguments['keyFile']];
$arguments['transport'] = 'rest';
$arguments['transportConfig'] = ['rest' => ['httpHandler' => [$proxyHttpHandler, 'async']]];

return $arguments;
}

$credentialWrapper = \Matomo\Dependencies\GoogleAnalyticsImporter\Google\ApiCore\CredentialsWrapper::build($arguments);

return ['credentials' => $credentialWrapper];
}
}
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"google/apiclient": "^2.15.3",
"google/apiclient-services": "^0.224.1",
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/psr7": "2.5.1",
"guzzlehttp/promises": "1.5.3",
"google/analytics-data": "^0.9.4",
"google/analytics-admin": "^0.10.0",
"guzzlehttp/psr7": "^2.5.1",
"guzzlehttp/promises": "^2.0.0",
"phpseclib/phpseclib": "3.0.36",
"phpseclib/bcmath_compat": "^2.0"
"phpseclib/bcmath_compat": "^2.0",
"google/analytics-admin": "^0.22.2",
"google/analytics-data": "^0.17.1"
},
"config": {
"platform-check": "false"
Expand Down
Loading
Loading