Skip to content

Commit ad7687e

Browse files
author
Alex Westergaard
committed
Move allowed response headers into constant array
1 parent 8e1ee56 commit ad7687e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Analytics.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace AlexWestergaard\PhpGa4;
44

55
use GuzzleHttp\Client as Guzzle;
6-
use AlexWestergaard\PhpGa4\Facade;
76
use AlexWestergaard\PhpGa4\Model;
7+
use AlexWestergaard\PhpGa4\Facade;
88

99
/**
1010
* Foundation class to collect all information and events to send to Google Analytics \
@@ -16,6 +16,8 @@ class Analytics extends Model\ToArray implements Facade\Analytics, Facade\Export
1616
const URL_LIVE = 'https://www.google-analytics.com/mp/collect';
1717
const URL_DEBUG = 'https://www.google-analytics.com/debug/mp/collect';
1818

19+
const ALLOW_RESPONSE_HEADERS = [200, 204];
20+
1921
private $debug;
2022
private $measurement_id;
2123
private $api_secret;
@@ -164,11 +166,11 @@ public function post()
164166
$res = $guzzle->request('POST', $url, ['json' => $reqBody]);
165167

166168
$resCode = $res->getStatusCode() ?? 0;
167-
if ($resCode !== 200 && $resCode !== 204) {
169+
if (!in_array($resCode, static::ALLOW_RESPONSE_HEADERS)) {
168170
GA4Exception::push("Request received code {$resCode}");
169171
}
170172

171-
if($resCode !== 204) {
173+
if ($resCode !== 204) {
172174
$resBody = $res->getBody()->getContents();
173175
$data = @json_decode($resBody, true);
174176

0 commit comments

Comments
 (0)