Google Analytics API: filter with AND is impossible #37

Closed
sqrrrl opened this Issue Apr 8, 2013 · 1 comment

Projects

None yet

1 participant

@sqrrrl
Member
sqrrrl commented Apr 8, 2013

(From https://code.google.com/p/google-api-ruby-client/issues/detail?id=57)

What steps will reproduce the problem?

  1. @client = Google::APIClient.new (then -> authorize)
  2. parameters={"ids"=>"ga:XXXXX", "start-date"=>"2011-07-30", "end-date"=>"2012-08-30", "metrics"=>"ga:visits", "filters"=>"ga:medium=~cpa|cpc|cpm|cpp|cpv|ppc;ga:source==google"}
  3. reference = Google::APIClient::Reference.new(:api_method => analytics.data.ga.get(), :parameters => parameters)
  4. request = @client.generate_request(reference)
  5. you will see that in request object, the 'filters' parameter is split in 2:
    "filters"=>"ga:medium=~cpa|cpc|cpm|cpp|cpv|ppc", "ga:source"=>"=google"

What is the expected output?

"filters"=>"ga:medium=~cpa|cpc|cpm|cpp|cpv|ppc;ga:source==google"

What do you see instead?

"filters"=>"ga:medium=~cpa|cpc|cpm|cpp|cpv|ppc", "ga:source"=>"=google"

What version of the product are you using? On what operating system?

  • Google Analytics Core reporting API V3
  • ruby 1.9.3
  • google-api-ruby-client : hedge (git)

The problem comes from Faraday (or Google Analytics Core reporting API V3 syntax for filters) 👍

  1. in Faraday::Utils, DEFAULT_SEP = /[&;] */n
  2. so the method ''parse_nested_query" splits the part
    "&filters=ga:medium=~cpa|cpc|cpm|cpp|cpv|ppc;ga:source==google" in {"filters" => "ga:medium=~cpa|cpc|cpm|cpp|cpv|ppc", "ga:source" => "=google"}

One solution would be to open Faraday and edit DEFAULT_SEP (remove the ';'): DEFAULT_SEP = /[&] */n
How can we deal with this ?

Aug 31, 2012
I really need to have a chat with the rest of the Ruby community on how to process URIs.

Mar 18, 2013
I'd like to do what I can to make the appropriate change happen in Faraday. A few questions:

  1. Is there an issue open in Faraday to reflect that this problem is happening?
  2. Is it a typo in the URL that the URL includes "ga:source==google"? Should that just be a single equals? That is, is "=google" the value of the "ga:source" parameter, or is it "google"?
@sqrrrl
Member
sqrrrl commented Jun 7, 2013

Fixed for 0.7 (soon)

@sqrrrl sqrrrl closed this Jun 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment