schone
schone

Reputation: 572

Universal Analytics Measurement Protocol 200 - Nothing shows up

Like the title says, nothing shows up in real time events nor in any other event The request being sent is done with ruby's faraday gem

require 'faraday'
require 'json'

GOOGLE_ANALYTICS_SETTINGS = {}

class GoogleAnalyticsApi

  def event(client_id = '555', category, action, label, value, user_agent)
    return unless !GOOGLE_ANALYTICS_SETTINGS["tracking_code"].empty?

    params = {
      v: GOOGLE_ANALYTICS_SETTINGS["version"],
      tid: GOOGLE_ANALYTICS_SETTINGS["tracking_code"],
      cid: client_id,
      t: "event",
      ec: category,
      ea: action,
      el: label,
      ev: value
    }

    begin      
      puts params
      c = Faraday.new() do |f|
        f.request :url_encoded          
        f.response :logger
        f.adapter  Faraday.default_adapter
      end
      response = c.post GOOGLE_ANALYTICS_SETTINGS["endpoint"], params, { "User-Agent" => user_agent || "Subscribing Worker theSkimm" }

      puts response.headers
      puts response.body
      return true
    rescue  Exception => rex
      return false
    end
  end

end

From the console:

{:v=>1, :tid=>"UA-XXXXXXXX-1", :cid=>"1999999999.1389999972", :t=>"event", :ec=>"test-event", :ea=>"test-action", :el=>nil, :ev=>nil}
I, [2014-01-15T18:04:04.555555 #7666]  INFO -- : post http://www.google-analytics.com/collect
D, [2014-01-15T18:04:04.555667 #7666] DEBUG -- request: User-Agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36"
Content-Type: "application/x-www-form-urlencoded"
I, [2014-01-15T18:04:04.670273 #7666]  INFO -- Status: 200
D, [2014-01-15T18:04:04.670512 #7666] DEBUG -- response: pragma: "no-cache"
expires: "Mon, 07 Aug 1995 23:30:00 GMT"
cache-control: "private, no-cache, no-cache=Set-Cookie, proxy-revalidate"
access-control-allow-origin: "*"
last-modified: "Sun, 17 May 1998 03:00:00 GMT"
x-content-type-options: "nosniff"
content-type: "image/gif"
date: "Wed, 15 Jan 2014 23:04:04 GMT"
server: "Golfe2"
content-length: "35"
alternate-protocol: "80:quic"
connection: "close"
{"pragma"=>"no-cache", "expires"=>"Mon, 07 Aug 1995 23:30:00 GMT", "cache-control"=>"private, no-cache, no-cache=Set-Cookie, proxy-revalidate", "access-control-allow-origin"=>"*", "last-modified"=>"Sun, 17 May 1998 03:00:00 GMT", "x-content-type-options"=>"nosniff", "content-type"=>"image/gif", "date"=>"Wed, 15 Jan 2014 23:04:04 GMT", "server"=>"Golfe2", "content-length"=>"35", "alternate-protocol"=>"80:quic", "connection"=>"close"}
GIF89a�����,D;

Upvotes: 2

Views: 393

Answers (1)

schone
schone

Reputation: 572

For whomever encounters this the problem was setting nil value for el and ev. When the params hash is moved through Faraday the nil valued items get converted to the key name without any value and google didn't like that.

IE a query string with nil values going through Faraday would be: ...&el&ev Not good for google's Measurement Protocol.

Upvotes: 2

Related Questions