cannikin-gattica 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/README.rdoc +47 -29
- data/VERSION.yml +1 -1
- data/lib/gattica/data_point.rb +8 -9
- data/lib/gattica/data_set.rb +7 -10
- data/lib/gattica.rb +2 -1
- metadata +2 -2
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -39,7 +39,7 @@ The third parameter is the profile_id that we want to access data for.
|
|
39
39
|
|
40
40
|
Then we call +get+ with the parameters we want to shape our data with. In this case we want
|
41
41
|
total page views, broken down by browser, from Jan 1 2008 to Feb 1 2008, sorted by descending
|
42
|
-
page views.
|
42
|
+
page views. If you wanted to sort pageviews ascending, just leave off the minus.
|
43
43
|
|
44
44
|
If you don't know the profile_id you want to get data for, call +accounts+
|
45
45
|
|
@@ -79,38 +79,31 @@ which are not immediately apparent, about what you can filter and how.
|
|
79
79
|
By default filters passed to a +get+ are ANDed together. This means that all filters need to match for
|
80
80
|
the result to be returned.
|
81
81
|
|
82
|
-
:
|
82
|
+
results = gs.get({:start_date => '2008-01-01',
|
83
|
+
:end_date => '2008-02-01',
|
84
|
+
:dimensions => ['browser','browserVersion'],
|
85
|
+
:metrics => ['pageviews','visits'],
|
86
|
+
:sort => ['-pageviews'],
|
87
|
+
:filter => ['browser == Firefox','pageviews >= 10000']})
|
83
88
|
|
84
89
|
This says "return only results where the 'browser' dimension contains the word 'Firefox' and the
|
85
90
|
'pageviews' metric is greater than or equal to 10,000.
|
86
91
|
|
87
|
-
|
88
|
-
|
89
|
-
Google recommends not re-authenticating each time you do a request against the API. To accomplish
|
90
|
-
this you should save the authorization token you receive from Google and use that for future
|
91
|
-
requests:
|
92
|
+
Filters can contain spaces around the operators, or not. These two lines are equivalent (I think
|
93
|
+
the spaces make the filter more readable):
|
92
94
|
|
93
|
-
|
95
|
+
:filter => ['browser == Firefox','pageviews >= 10000']
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
-
ga = Gattica.new({:token => 'DSasdf94...'})
|
97
|
+
:filter => ['browser==Firefox','pageviews>=10000']
|
98
98
|
|
99
|
-
|
100
|
-
|
99
|
+
Once again, do _not_ include the +ga:+ prefix before the dimension/metric you're filtering against.
|
100
|
+
Gattica will add this automatically.
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
You will probably find that as you try different filters, GA will report that some of them aren't
|
103
|
+
valid. I haven't found any documentation that says which filter combinations are valid in what
|
104
|
+
circumstances, so I suppose it's just trial and error at this point.
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
This header is generated automatically. If you have your own headers you'd like to add, you can
|
109
|
-
pass them in when you initialize:
|
110
|
-
|
111
|
-
ga = Gattica.new({:token => 'DSasdf94...', :headers => {'My-Special-Header':'my_custom_value'}})
|
112
|
-
|
113
|
-
And they'll be sent with every request you make.
|
106
|
+
For more on filtering syntax, see the Analytics API docs: http://code.google.com/apis/analytics/docs/gdata/gdataReference.html#filtering
|
114
107
|
|
115
108
|
= Output
|
116
109
|
When Gattica was originally created it was intended to take the data returned and put it into
|
@@ -152,16 +145,42 @@ Gives you:
|
|
152
145
|
"id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12345&ga:browser=Internet%20Explorer&start-date=2009-01-01&end-date=2009-01-31",
|
153
146
|
"metrics"=>[{:pageviews=>53303}],
|
154
147
|
"updated"=>#<DateTime: 212100120000001/86400000,-1/3,2299161>}]}
|
148
|
+
|
149
|
+
== Notes on Authentication
|
150
|
+
=== Authentication Token
|
151
|
+
Google recommends not re-authenticating each time you do a request against the API. To accomplish
|
152
|
+
this you should save the authorization token you receive from Google and use that for future
|
153
|
+
requests:
|
154
|
+
|
155
|
+
ga.token => 'DSasdf94...' (some huge long string)
|
156
|
+
|
157
|
+
You can now initialize Gattica with this token for future requests:
|
158
|
+
|
159
|
+
ga = Gattica.new({:token => 'DSasdf94...'})
|
160
|
+
|
161
|
+
(You enter the full token, of course). I'm not sure how long a token from the Google's ClientLogin
|
162
|
+
system remains active, but if/when I do I'll add that to the docs here.
|
163
|
+
|
164
|
+
=== Headers
|
165
|
+
Google expects a special header in all HTTP requests called 'Authorization'. This contains your
|
166
|
+
token:
|
167
|
+
|
168
|
+
Authorization = GoogleLogin auth=DSasdf94...
|
169
|
+
|
170
|
+
This header is generated automatically. If you have your own headers you'd like to add, you can
|
171
|
+
pass them in when you initialize:
|
172
|
+
|
173
|
+
ga = Gattica.new({:token => 'DSasdf94...', :headers => {'My-Special-Header':'my_custom_value'}})
|
174
|
+
|
175
|
+
And they'll be sent with every request you make.
|
155
176
|
|
156
177
|
= Limitations
|
157
178
|
The GA API limits each call to 1000 results per "page." If you want more, you need to tell
|
158
179
|
the API what number to begin at and it will return the next 1000. Gattica does not currently
|
159
180
|
support this, but it's in the plan for the very next version.
|
160
181
|
|
161
|
-
|
162
|
-
|
163
|
-
to one report, the DataSet object that returns doesn't parse the results correctly. So for now,
|
164
|
-
avoid using filters.
|
182
|
+
Currently all filters you supply are ANDed together before being sent to GA. Support for ORing
|
183
|
+
is coming soon.
|
165
184
|
|
166
185
|
= The Future
|
167
186
|
A couple of things I have planned:
|
@@ -171,4 +190,3 @@ A couple of things I have planned:
|
|
171
190
|
3. Automatically handle paging (the API only returns 1000 results at a time). Gattica will request
|
172
191
|
one result set, see how many pages there are, then do several calls until all pages are retrieved
|
173
192
|
or it hits the limit of the number of results you want and return all that data as one big block.
|
174
|
-
4. Create a nice syntax for filters
|
data/VERSION.yml
CHANGED
data/lib/gattica/data_point.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
1
3
|
module Gattica
|
2
4
|
|
3
5
|
# Represents a single "row" of data containing any number of dimensions, metrics
|
@@ -26,24 +28,21 @@ module Gattica
|
|
26
28
|
# Outputs in Comma Seperated Values format
|
27
29
|
def to_csv(format = :long)
|
28
30
|
output = ''
|
31
|
+
columns = []
|
29
32
|
|
30
33
|
# only output
|
31
34
|
case format
|
32
35
|
when :long
|
33
|
-
|
36
|
+
[@id, @updated, @title].each { |c| columns << c }
|
34
37
|
end
|
35
38
|
|
36
39
|
# output all dimensions
|
37
|
-
|
38
|
-
"\"#{dimension.value}\""
|
39
|
-
end.join(',')
|
40
|
-
output += ','
|
40
|
+
@dimensions.map {|d| d.value}.each { |c| columns << c }
|
41
41
|
|
42
42
|
# output all metrics
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
@metrics.map {|m| m.value}.each { |c| columns << c }
|
44
|
+
|
45
|
+
output = CSV.generate_line(columns)
|
47
46
|
return output
|
48
47
|
end
|
49
48
|
|
data/lib/gattica/data_set.rb
CHANGED
@@ -25,24 +25,21 @@ module Gattica
|
|
25
25
|
def to_csv(format = :long)
|
26
26
|
# build the headers
|
27
27
|
output = ''
|
28
|
-
|
28
|
+
columns = []
|
29
|
+
|
29
30
|
# only show the nitty gritty details of id, updated_at and title if requested
|
30
31
|
case format
|
31
32
|
when :long
|
32
|
-
|
33
|
+
["id", "updated", "title"].each { |c| columns << c }
|
33
34
|
end
|
34
35
|
|
35
36
|
unless @points.empty? # if there was at least one result
|
36
|
-
|
37
|
-
|
38
|
-
end.join(',')
|
39
|
-
output += ','
|
40
|
-
output += @points.first.metrics.collect do |metric|
|
41
|
-
"\"#{metric.key.to_s}\""
|
42
|
-
end.join(',')
|
43
|
-
output += "\n"
|
37
|
+
@points.first.dimensions.map {|d| d.key}.each { |c| columns << c }
|
38
|
+
@points.first.metrics.map {|m| m.key}.each { |c| columns << c }
|
44
39
|
end
|
45
40
|
|
41
|
+
output = CSV.generate_line(columns) + "\n"
|
42
|
+
|
46
43
|
# get the data from each point
|
47
44
|
@points.each do |point|
|
48
45
|
output += point.to_csv(format) + "\n"
|
data/lib/gattica.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cannikin-gattica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Cameron
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|