我正在尝试将一些 Google Analytics 事件跟踪代码从 cURL 请求转换为 Guzzlehttp 6。Guzzle 请求返回 200,但未跟踪该事件。使用 cURL 跟踪相同的请求。有任何想法吗?
工作卷曲:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google-analytics.com/collect');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/x-www-form-urlencoded"]);
curl_setopt($ch, CURL_HTTP_VERSION_1_1, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'v=1&t=event&tid=UA-xxxxxxxx-x&cid=' . $cid . '&ec=' . $cat . '&ea=' . urlencode($action) . '&el=' . urlencode($label) . '&uip=' . $uip . '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
GuzzleHttp:
$postData['form_params'] = [
'v' => '1',
't' => 'event',
'tid' => 'UA-xxxxxxxx-x',
'cid' => $cid,
'ec' => $cat,
'ea' => $action,
'el' => $label,
'uip' => $uip
];
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://www.google-analytics.com/collect', $postData);