4

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

user3429942
  • 61
  • 1
  • 3

2 Answers2

2

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
user3429942
  • 61
  • 1
  • 3
  • 3
    Hmmmm - I thought that ev and el were NOT required. – M Schenkel Oct 08 '14 at 01:45
  • 1
    doing a post this answer helped http://stackoverflow.com/a/9183272/1815624 `curl_setopt($ch, CURLOPT_HEADER, 1);` – CrandellWS Feb 16 '15 at 18:09
  • The normal API endpoint will return a 200 for all queries. There is a special /debug endpoint that can be used to isolate problems. I have found this invaluable. - https://developers.google.com/analytics/devguides/collection/protocol/v1/validating-hits – astletron Jun 25 '15 at 16:20
  • BTW, exists an URL for debugging purpose: https://www.google-analytics.com/debug/collect More info: https://developers.google.com/analytics/devguides/collection/protocol/v1/validating-hits#request – nikoskip Nov 09 '15 at 17:51
0

The request in Measurement protocol, does not work, if there is no User-Agent

aksik
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 12 '22 at 16:38
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30800674) – Simas Joneliunas Jan 15 '22 at 07:48