Skip to content

Commit 519cf63

Browse files
authored
Merge pull request #522 from matomo-org/PG-3437-fix-proxy-for-ga4
Making GA4 imports work with a proxy
2 parents c9992f2 + e2fe38e commit 519cf63

File tree

1,216 files changed

+80019
-19578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,216 files changed

+80019
-19578
lines changed

.github/workflows/phpcs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Setup PHP
2727
uses: shivammathur/setup-php@v2
2828
with:
29-
php-version: '7.4'
29+
php-version: '8.1'
3030
tools: cs2pr
3131
- name: Install dependencies
3232
run:

Google/AuthorizationGA4.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class AuthorizationGA4
2020
public function getClient()
2121
{
2222
$klass = StaticContainer::get('GoogleAnalyticsImporter.googleAnalyticsDataClientClass');
23-
$client = new $klass(['credentials' => \Matomo\Dependencies\GoogleAnalyticsImporter\Google\ApiCore\CredentialsWrapper::build(['keyFile' => $this->getClientConfiguration()])]);
23+
$client = new $klass($this->getClientClassArguments());
2424
return $client;
2525
}
2626
public function getAdminClient()
2727
{
2828
$klass = StaticContainer::get('GoogleAnalyticsImporter.googleAnalyticsAdminServiceClientClass');
29-
$adminClient = new $klass(['credentials' => \Matomo\Dependencies\GoogleAnalyticsImporter\Google\ApiCore\CredentialsWrapper::build(['keyFile' => $this->getClientConfiguration()])]);
29+
$adminClient = new $klass($this->getClientClassArguments());
3030
return $adminClient;
3131
}
3232
public function getClientConfiguration()
@@ -40,4 +40,25 @@ public function getClientConfiguration()
4040
}
4141
return $clientConfig;
4242
}
43+
44+
protected function getClientClassArguments(): array
45+
{
46+
$arguments = [
47+
'keyFile' => $this->getClientConfiguration()
48+
];
49+
50+
$proxyHttpClient = StaticContainer::get('GoogleAnalyticsImporter.proxyHttpClient');
51+
if ($proxyHttpClient) {
52+
$proxyHttpHandler = \Matomo\Dependencies\GoogleAnalyticsImporter\Google\Auth\HttpHandler\HttpHandlerFactory::build($proxyHttpClient);
53+
$arguments['credentialsConfig'] = ['authHttpHandler' => $proxyHttpHandler, 'keyFile' => $arguments['keyFile']];
54+
$arguments['transport'] = 'rest';
55+
$arguments['transportConfig'] = ['rest' => ['httpHandler' => [$proxyHttpHandler, 'async']]];
56+
57+
return $arguments;
58+
}
59+
60+
$credentialWrapper = \Matomo\Dependencies\GoogleAnalyticsImporter\Google\ApiCore\CredentialsWrapper::build($arguments);
61+
62+
return ['credentials' => $credentialWrapper];
63+
}
4364
}

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"google/apiclient": "^2.15.3",
55
"google/apiclient-services": "^0.224.1",
66
"guzzlehttp/guzzle": "^7.0",
7-
"guzzlehttp/psr7": "2.5.1",
8-
"guzzlehttp/promises": "1.5.3",
9-
"google/analytics-data": "^0.9.4",
10-
"google/analytics-admin": "^0.10.0",
7+
"guzzlehttp/psr7": "^2.5.1",
8+
"guzzlehttp/promises": "^2.0.0",
119
"phpseclib/phpseclib": "3.0.36",
12-
"phpseclib/bcmath_compat": "^2.0"
10+
"phpseclib/bcmath_compat": "^2.0",
11+
"google/analytics-admin": "^0.22.2",
12+
"google/analytics-data": "^0.17.1"
1313
},
1414
"config": {
1515
"platform-check": "false"

0 commit comments

Comments
 (0)