Measurement protocol docs give me these directions to send a batch request:
POST /batch HTTP/1.1
Host: www.google-analytics.com
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fabout
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fcontact
Im a little confused on how i would build my url for this?
What i have tried:
$guzzle = new \GuzzleHttp\Client();
$guzzle->request('POST','www.google-analytics.com/batch',[
'query' => "v=1&tid=UA-XXXXX-Y&cid=555&t=event
v=1&tid=UA-XXXXX-Y&cid=555&t=event
v=1&tid=UA-XXXXX-Y&cid=555&t=event
v=1&tid=UA-XXXXX-Y&cid=555&t=event
v=1&tid=UA-XXXXX-Y&cid=555&t=event"
]);
This does not work, there should 5 new events in ga, but i only receive 1 (the first one).
How can i send a batch request to the measurement protocol?
If you use GuzzleHttp
, you should use body
instead of query
:
$guzzle = new \GuzzleHttp\Client();
$guzzle->request('POST','www.google-analytics.com/batch', [
'body' => implode("\n", array(
'v=1&tid=UA-XXXXX-Y&cid=555&t=event',
'v=1&tid=UA-XXXXX-Y&cid=555&t=event',
'v=1&tid=UA-XXXXX-Y&cid=555&t=event',
'v=1&tid=UA-XXXXX-Y&cid=555&t=event',
'v=1&tid=UA-XXXXX-Y&cid=555&t=event',
)]);