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 all 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
  •  
  •  
  •  
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
Loading