TheIconic\Tracking\GoogleAnalytics\Network\HttpClient::post PHP Method

post() public method

Sends request to Google Analytics.
public post ( string $url, boolean $nonBlocking = false ) : AnalyticsResponse
$url string
$nonBlocking boolean
return TheIconic\Tracking\GoogleAnalytics\AnalyticsResponse
    public function post($url, $nonBlocking = false)
    {
        $request = new Request('GET', $url, ['User-Agent' => self::PHP_GA_MEASUREMENT_PROTOCOL_USER_AGENT]);
        $response = $this->getClient()->sendAsync($request, ['synchronous' => !$nonBlocking, 'timeout' => self::REQUEST_TIMEOUT_SECONDS, 'connect_timeout' => self::REQUEST_TIMEOUT_SECONDS]);
        if ($nonBlocking) {
            self::$promises[] = $response;
        } else {
            $response = $response->wait();
        }
        return $this->getAnalyticsResponse($request, $response);
    }

Usage Example

 public function testPost()
 {
     $response = $this->mockHttpClient->post('http://test-collector.com/collect?v=1');
     $this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
     $responseAsync = $this->mockHttpClient->post('http://test-collector.com/collect?v=1', true);
     $this->assertInstanceOf('GuzzleHttp\\Promise\\PromiseInterface', $responseAsync);
     $response = $this->httpClient->post('http://test-collector.com/collect?v=1');
     $this->assertInstanceOf('TheIconic\\Tracking\\GoogleAnalytics\\AnalyticsResponse', $response);
     // Promises should be unwrapped on the object destruction
     $this->httpClient = null;
     $this->mockHttpClient = null;
 }
All Usage Examples Of TheIconic\Tracking\GoogleAnalytics\Network\HttpClient::post