简体   繁体   中英

Google Analytics Measurement protocol event tracking : events not logging

I am trying to use Google Analytics Measurement protocol (available with Universal Analytics) to track an offline event.

I am using the documentation here : https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event

Here is the CURL I am calling :

https://www.google-analytics.com/collect?v=1&tid=UA-5520857-25&cid=1260961011.1389432370&t=event&ec=Test-event-cat&ea=Test-event-action&el=&ev=

I get the cid (client ID) via :

ga(function(tracker) {
  var clientId = tracker.get('clientId');
});

Here is the full CURL call :

$getString = 'https://www.google-analytics.com/collect?';
$getString .= http_build_query($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $getString);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);

$info = curl_getinfo($ch);

curl_close($ch);

// TEST
echo 'CURL call : '.$getString.'<br />';
echo 'Response : <pre>';
print_r($info);
echo '</pre>';

It returns a 200 HTTP code (but I've read that its always the case, even if something is wrong). No event is shown in my Google Analytics account, even on the real time section.

Do you have any idea about what I am doing wrong ?

Thank you

The problem was that I wasn't setting the el and ev parameters.

The correct call is :

https://www.google-analytics.com/collect?v=1&tid=UA-5520857-25&cid=1260961011.1389432370&t=event&ec=Test-event-cat&ea=Test-event-action&el=test-label&ev=1

如果没有 User-Agent,Measurement 协议中的请求不起作用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM