Skip to content

Commit

Permalink
Merge pull request #522 from matomo-org/PG-3437-fix-proxy-for-ga4
Browse files Browse the repository at this point in the history
Making GA4 imports work with a proxy
  • Loading branch information
snake14 authored Jan 6, 2025
2 parents c9992f2 + e2fe38e commit 519cf63
Show file tree
Hide file tree
Showing 1,216 changed files with 80,019 additions and 19,578 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
tools: cs2pr
- name: Install dependencies
run:
Expand Down
25 changes: 23 additions & 2 deletions Google/AuthorizationGA4.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class AuthorizationGA4
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 @@ -40,4 +40,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

0 comments on commit 519cf63

Please sign in to comment.