2017-07-06 38 views
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配置不好。你能幫助我嗎?

回答

1

我已經解決了這個問題。他們,據我所知,禁用SSL連接驗證:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 

所以,我能夠控制從服務器的谷歌分析:))

0

谷歌的迴應是什麼? $ server_output

這樣做:

echo "<pre>" 
print_r($server_output) 

而且加入這行把這裏闕反饋

+0

'pre'是沒有幫助。響應是空白頁面,即使發送到www.google-analytics.com/debug/collect –

+0

似乎我解決了這個問題!我會發布答案 –