I'm trying to post to Google Measurement Protocol using Ruby:
uri = URI.parse("http://www.google-analytics.com/collect")
params = {"v"=>"1", "tid"=>"UA-XXXXXXXX-X", "cid"=>"XXXXXXXXX.XXXXXXXXX", "t"=>"event", "ec"=>"200", "ea"=>"John"}
result = Net::HTTP.post_form(uri, params) #<Net::HTTPOK 200 OK readbody=true>
result.body # "GIF89a\x01\x00\x01\x00\x80\xFF\x00\xFF\xFF\xFF\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;"
Also tried to send a GET request instead of POST:
RestClient.get("http://www.google-analytics.com/collect", params: params, timeout: 4, open_timeout: 4) # "GIF89a\x01\x00\x01\x00\x80\xFF\x00\xFF\xFF\xFF\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;"
And the event is not being tracked:
They I tried to send the same parameters by simply typing them into Chrome:
It worked:
I guess I'm missing a header or something like this when I'm sending the request to Management Protocol using Ruby. But I can't figure out what I'm missing.