4
votes

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

1

1 Answers

2
votes

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