1
從我的服務器發送POST請求到谷歌分析時,我有問題。php - 谷歌分析測量協議POST請求
我想送考(事件,訂單等),但我沒有收到任何東西,當我看事件跟蹤器在瀏覽器中是絕對沒有發生......
PHP代碼
$x = [
'v'=>'1',
't'=>'event',
'tid'=>'.....', // here goes my tracking ID
'cid'=>'555',
'ec'=>'video'
];
echo(google_a($x));
function google_a($x) {
$x = http_build_query($x);
$ch = curl_init();
$user_agent = $_SERVER['HTTP_USER_AGENT'];
curl_setopt($ch,CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL,"https://www.google-analytics.com/collect");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch,CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$x);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
return($server_output);
}
我認爲我的CURL配置不好。你能幫助我嗎?
'pre'是沒有幫助。響應是空白頁面,即使發送到www.google-analytics.com/debug/collect –
似乎我解決了這個問題!我會發布答案 –