Reputation: 1820
When I make a query to the core reporting api filtered by a specific keyword, it returns the data in chunks. I believe it does this because the query uses an extended time period of a year. This a complete pain since some the data like the total_value
needs to be summed and revenue_per_transaction
needs to be averaged.
Is there any way to prevent this "chunking"? If not, what it is the best way to overcome this?
Sample response:
{keyword="KEYWORD_A", visits="2", total_value="20192.75", revenue_per_transaction="20192.75", transactions="1", day="31", month="05"},
{keyword="KEYWORD_A", visits="1", total_value="5789.8", revenue_per_transaction="2894.9", transactions="2", day="12", month="07"}
Here is my current solution to summing the total_value
attribute. Since revenue_per_transaction
needs to be averaged, I figured I'd try to address the root of the problem, the chunked response.
sum_keys = [:total_value, :revenue_per_transaction]
data.group_by{ |h| h[:keyword] }
.map{ |keyword, related|
tmp = {keyword: keyword}
tmp.merge! Hash[sum_keys.zip Array.new(sum_keys.size, 0)]
related.reduce(tmp) { |summed, h|
sum_keys.each { |key| summed[key] += h[key].to_f }
summed
}
}
Upvotes: 0
Views: 179
Reputation: 7177
From your sample response, it looks like you're specifying some time dimensions on the query (ga.day
, ga.month
)?
If you leave out the time dimensions, the Core Reporting API should return a summed value over the start/end date.
Have you tried using the Google Analytics Query Explorer? It's a great to experiment with different dimensions/metrics to make sure you're getting the data you expect.
Upvotes: 1