theiconic / php-ga-measurement-protocol

Send data to Google Analytics from the server using PHP. Implements GA measurement protocol.
MIT License
655 stars 136 forks source link

How to pass options to HttpClient/Guzzle? #80

Closed picks44 closed 4 years ago

picks44 commented 4 years ago

Hi there, I can see there is an $options array in the Analytics constructor, but when I looked a bit further, it seems that it's only dedicated to options "timeout" and "async". What if we want to pass other options (like "verify" => false) to Guzzle? Thanks!

eexit commented 4 years ago

Hey,

I saw a bunch of methods flagged as @internal so I'm not sure it's safe to use but from what I reverse engineered, it seems safe.

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\HandlerStack;
use TheIconic\Tracking\GoogleAnalytics\Analytics;
use TheIconic\Tracking\GoogleAnalytics\Network\HttpClient;

$handler = HandlerStack::create();
$handler->push(new MyCustomMiddleware());

$client = new HttpClient();
$client->setClient(new GuzzleClient([
    'handler' => $handler,
    'verify' => false,
    'timeout' => 10
]));

$isEnabled = true;

$analytics = new Analytics(false, !$isEnabled);
$analytics->setHttpClient($client);
picks44 commented 4 years ago

I'll try this, thanks @eexit