rugalytics 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.1.2. added profile.report_names method; handle '.' or '/' in graph column names without failing
2
+
1
3
  v0.1.1. fixed bug due to change in google's graph csv
2
4
 
3
5
  v0.1.0. fixed bug due to change in google's graph csv; removed deprecated load_report method
data/README CHANGED
@@ -84,15 +84,40 @@ In the report, there is a +pageviews_graph+ containing the points:
84
84
  => [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]
85
85
 
86
86
 
87
- == Load a Report
87
+ == What Reports are There?
88
88
 
89
- The report name, e.g. 'Pageviews' or 'TrafficSources', is the rpt parameter from
90
- the Google Analytics URL for a CSV report export, e.g.:
89
+ The report name comes from the Google Analytics URL for a CSV report export.
90
+ The report name is the rpt parameter from the URL, e.g. 'Pageviews' or
91
+ 'TrafficSources':
91
92
 
93
+ https://www.google.com/analytics/reporting/export?fmt=2&...&&rpt=PageviewsReport&...
92
94
  https://www.google.com/analytics/reporting/export?fmt=2&...&&rpt=TrafficSourcesReport&...
93
95
 
94
- From a page on the Analytics website, you can find the CSV URL by clicking on
95
- the Export tab, and then mousing over the CSV option.
96
+ If you are logged in to the Analytics website, you can find the CSV URL by
97
+ clicking on the Export tab, and then mousing over the CSV option.
98
+
99
+ To discover a list of report names, there's a method on profile:
100
+
101
+ profile.report_names
102
+ => ["ad_versions_report", "adwords_report", "all_sources_report",
103
+ "average_pageviews_report", "bounce_rate_report", "browsers_report",
104
+ "campaigns_report", "colors_report", "content_by_title_report",
105
+ "content_drilldown_report", "content_report", "dashboard_report",
106
+ "depth_of_visit_report", "direct_sources_report", "entrances_report",
107
+ "exits_report", "flash_report", "geo_map_report", "hostnames_report",
108
+ "java_report", "keyword_position_report", "keywords_report",
109
+ "languages_report", "length_of_visit_report", "loyalty_report",
110
+ "networks_report", "os_browsers_report", "pageviews_report",
111
+ "platforms_report", "recency_report", "referring_sources_report",
112
+ "resolutions_report", "search_engines_report", "speeds_report",
113
+ "time_on_site_report", "top_content_detail_keywords_report",
114
+ "top_content_detail_navigation_report", "top_content_detail_path_report",
115
+ "top_content_detail_sources_report", "top_content_report",
116
+ "traffic_sources_report", "unique_visitors_report",
117
+ "visitor_types_report", "visitors_overview_report", "visits_report"]
118
+
119
+
120
+ == Load a Report
96
121
 
97
122
  Let's load the TrafficSources report:
98
123
 
@@ -136,17 +161,14 @@ Let's now grab 100 lines of the Networks report:
136
161
 
137
162
  == Report by URL
138
163
 
139
- You can get a content drilldown report:
164
+ Entrance search keywords by URL:
140
165
 
141
- report = profile.content_drilldown_report(:url => "/projects/abc/")
166
+ report = profile.top_content_detail_keywords_report(:url=>'/projects/abc')
142
167
  report.name
143
- => "Content Drilldown,/projects/abc/"
168
+ => "Entrance Keywords:,/projects/abc"
144
169
 
145
- report.items.first
146
- => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="155",
147
- @percentage_exit="0.776536312849162", @time_on_page="165.75",
148
- @pageviews="179", @path="/reports/", @dollar_index="0.0",
149
- @url="http://your_site.com/projects/abc/reports/"
170
+ report.items.collect{|i| "#{i.keyword} (#{i.unique_pageviews})"}
171
+ => ["project abc (200)", "abc project (110)"]
150
172
 
151
173
  Pageviews by URL:
152
174
 
@@ -157,6 +179,18 @@ Pageviews by URL:
157
179
  report.pageviews_total
158
180
  => 179
159
181
 
182
+ You can get a content drilldown report, for pages under a certain URL path:
183
+
184
+ report = profile.content_drilldown_report(:url => "/projects/abc/")
185
+ report.name
186
+ => "Content Drilldown,/projects/abc/"
187
+
188
+ report.items.first
189
+ => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="155",
190
+ @percentage_exit="0.776536312849162", @time_on_page="165.75",
191
+ @pageviews="179", @path="/reports/", @dollar_index="0.0",
192
+ @url="http://your_site.com/projects/abc/reports/"
193
+
160
194
  Pageviews by page title:
161
195
 
162
196
  report = profile.content_by_title_detail_report(:page_title => "Project ABC | Company XYZ")
@@ -176,10 +210,10 @@ To use from Rails, make a config file rails_root/config/rugalytics.yml
176
210
  with the following contents:
177
211
 
178
212
  ---
179
- account: [account_name]
180
- profile: [profile_name]
181
- username: [user_name]
182
- password: [pass_w]
213
+ account: your_account_name
214
+ profile: your_profile_name
215
+ username: your_user_name
216
+ password: your_pass_w
183
217
 
184
218
  Remember to tell your source control system to ignore this file! If you're
185
219
  using git, this means adding config/rugalytics.yml to your .gitignore
data/README.rdoc CHANGED
@@ -84,15 +84,40 @@ In the report, there is a +pageviews_graph+ containing the points:
84
84
  => [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]
85
85
 
86
86
 
87
- == Load a Report
87
+ == What Reports are There?
88
88
 
89
- The report name, e.g. 'Pageviews' or 'TrafficSources', is the rpt parameter from
90
- the Google Analytics URL for a CSV report export, e.g.:
89
+ The report name comes from the Google Analytics URL for a CSV report export.
90
+ The report name is the rpt parameter from the URL, e.g. 'Pageviews' or
91
+ 'TrafficSources':
91
92
 
93
+ https://www.google.com/analytics/reporting/export?fmt=2&...&&rpt=PageviewsReport&...
92
94
  https://www.google.com/analytics/reporting/export?fmt=2&...&&rpt=TrafficSourcesReport&...
93
95
 
94
- From a page on the Analytics website, you can find the CSV URL by clicking on
95
- the Export tab, and then mousing over the CSV option.
96
+ If you are logged in to the Analytics website, you can find the CSV URL by
97
+ clicking on the Export tab, and then mousing over the CSV option.
98
+
99
+ To discover a list of report names, there's a method on profile:
100
+
101
+ profile.report_names
102
+ => ["ad_versions_report", "adwords_report", "all_sources_report",
103
+ "average_pageviews_report", "bounce_rate_report", "browsers_report",
104
+ "campaigns_report", "colors_report", "content_by_title_report",
105
+ "content_drilldown_report", "content_report", "dashboard_report",
106
+ "depth_of_visit_report", "direct_sources_report", "entrances_report",
107
+ "exits_report", "flash_report", "geo_map_report", "hostnames_report",
108
+ "java_report", "keyword_position_report", "keywords_report",
109
+ "languages_report", "length_of_visit_report", "loyalty_report",
110
+ "networks_report", "os_browsers_report", "pageviews_report",
111
+ "platforms_report", "recency_report", "referring_sources_report",
112
+ "resolutions_report", "search_engines_report", "speeds_report",
113
+ "time_on_site_report", "top_content_detail_keywords_report",
114
+ "top_content_detail_navigation_report", "top_content_detail_path_report",
115
+ "top_content_detail_sources_report", "top_content_report",
116
+ "traffic_sources_report", "unique_visitors_report",
117
+ "visitor_types_report", "visitors_overview_report", "visits_report"]
118
+
119
+
120
+ == Load a Report
96
121
 
97
122
  Let's load the TrafficSources report:
98
123
 
@@ -136,17 +161,14 @@ Let's now grab 100 lines of the Networks report:
136
161
 
137
162
  == Report by URL
138
163
 
139
- You can get a content drilldown report:
164
+ Entrance search keywords by URL:
140
165
 
141
- report = profile.content_drilldown_report(:url => "/projects/abc/")
166
+ report = profile.top_content_detail_keywords_report(:url=>'/projects/abc')
142
167
  report.name
143
- => "Content Drilldown,/projects/abc/"
168
+ => "Entrance Keywords:,/projects/abc"
144
169
 
145
- report.items.first
146
- => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="155",
147
- @percentage_exit="0.776536312849162", @time_on_page="165.75",
148
- @pageviews="179", @path="/reports/", @dollar_index="0.0",
149
- @url="http://your_site.com/projects/abc/reports/"
170
+ report.items.collect{|i| "#{i.keyword} (#{i.unique_pageviews})"}
171
+ => ["project abc (200)", "abc project (110)"]
150
172
 
151
173
  Pageviews by URL:
152
174
 
@@ -157,6 +179,18 @@ Pageviews by URL:
157
179
  report.pageviews_total
158
180
  => 179
159
181
 
182
+ You can get a content drilldown report, for pages under a certain URL path:
183
+
184
+ report = profile.content_drilldown_report(:url => "/projects/abc/")
185
+ report.name
186
+ => "Content Drilldown,/projects/abc/"
187
+
188
+ report.items.first
189
+ => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="155",
190
+ @percentage_exit="0.776536312849162", @time_on_page="165.75",
191
+ @pageviews="179", @path="/reports/", @dollar_index="0.0",
192
+ @url="http://your_site.com/projects/abc/reports/"
193
+
160
194
  Pageviews by page title:
161
195
 
162
196
  report = profile.content_by_title_detail_report(:page_title => "Project ABC | Company XYZ")
@@ -176,10 +210,10 @@ To use from Rails, make a config file rails_root/config/rugalytics.yml
176
210
  with the following contents:
177
211
 
178
212
  ---
179
- account: [account_name]
180
- profile: [profile_name]
181
- username: [user_name]
182
- password: [pass_w]
213
+ account: your_account_name
214
+ profile: your_profile_name
215
+ username: your_user_name
216
+ password: your_pass_w
183
217
 
184
218
  Remember to tell your source control system to ignore this file! If you're
185
219
  using git, this means adding config/rugalytics.yml to your .gitignore
@@ -3,7 +3,7 @@ module Rugalytics
3
3
 
4
4
  class << self
5
5
  def find_all(account_id)
6
- doc = Hpricot::XML get("https://www.google.com:443/analytics/settings/home?scid=#{account_id}")
6
+ doc = Hpricot get("https://www.google.com:443/analytics/settings/home?scid=#{account_id}")
7
7
  (doc/'select[@id=profile] option').inject([]) do |profiles, option|
8
8
  profile_id = option['value'].to_i
9
9
  profiles << Profile.new(:account_id => account_id, :profile_id => profile_id, :name => option.inner_html) if profile_id > 0
@@ -27,6 +27,39 @@ module Rugalytics
27
27
  @profile_id = attrs[:profile_id] if attrs.has_key?(:profile_id)
28
28
  end
29
29
 
30
+ def report_names
31
+ unless @report_names
32
+ html = Profile.get("https://www.google.com/analytics/reporting/?scid=#{profile_id}")
33
+ # reports = html.scan(/rpt=([A-Za-z]+)("|&)/)
34
+ reports = html.scan(/changeReport\(&(#39|quot);([a-z_]+)&(#39|quot);/)
35
+
36
+ non_report_names = ['goal_intro', 'add_segment', 'customs_overview',
37
+ 'manage_emails', 'manage_segments', 'user_defined', 'audio',
38
+ 'custom_reports_overview', 'site_search_intro', 'tv']
39
+ names = reports.collect { |name| name[1] } - non_report_names
40
+ more_names = []
41
+
42
+ names.each do |name|
43
+ html = Profile.get("https://www.google.com/analytics/reporting/#{name}?id=#{profile_id}")
44
+ reports = html.scan(/changeReport\(&(#39|quot);([a-z_]+)&(#39|quot);/)
45
+ more_names += reports.collect { |name| name[1] }
46
+ end
47
+
48
+ names += more_names
49
+ names -= non_report_names
50
+ names = names.collect do |name|
51
+ name = name.sub(/^maps$/,'geo_map').sub(/^sources$/,'traffic_sources')
52
+ name = name.sub(/^visitors$/,'visitors_overview')
53
+ name = name.sub(/^content_detail_(.*)$/,'top_content_detail_\1')
54
+ name = name.sub(/^content_titles$/,'content_by_title')
55
+ "#{name}_report"
56
+ end
57
+
58
+ @report_names = names.uniq.sort
59
+ end
60
+ @report_names
61
+ end
62
+
30
63
  def method_missing symbol, *args
31
64
  if name = symbol.to_s[/^(.+)_report$/, 1]
32
65
  options = args && args.size == 1 ? args[0] : {}
@@ -79,6 +112,11 @@ module Rugalytics
79
112
  :gdfmt => 'nth_day',
80
113
  :view => 0
81
114
  })
115
+ if options[:report] == 'GeoMap'
116
+ options.delete(:tab)
117
+ options.delete(:gdfmt)
118
+ options.delete(:rows)
119
+ end
82
120
  options[:from] = ensure_datetime_in_google_format(options[:from])
83
121
  options[:to] = ensure_datetime_in_google_format(options[:to])
84
122
  options
@@ -123,9 +161,17 @@ module Rugalytics
123
161
  private
124
162
 
125
163
  def create_report(name, options={})
126
- report = Rugalytics::Report.new get_report_csv(options.merge({:report=>name}))
127
- puts report.attribute_names
128
- report
164
+ options = options.merge({:report=>name})
165
+ csv = get_report_csv(options)
166
+ begin
167
+ report = Rugalytics::Report.new csv
168
+ puts report.attribute_names
169
+ report
170
+ rescue Exception => e
171
+ puts convert_options_to_uri_params(options).inspect
172
+ puts csv
173
+ raise e
174
+ end
129
175
  end
130
176
  end
131
177
  end
@@ -67,6 +67,7 @@ module Rugalytics
67
67
  index = index.next
68
68
  end
69
69
 
70
+ name = name.gsub('/','_per_').gsub('.','')
70
71
  graph = Graph.new name, points, start_date, end_date
71
72
  morph("#{name.sub(/page views/i,'pageviews')} graph", graph)
72
73
  end
data/lib/rugalytics.rb CHANGED
@@ -11,7 +11,7 @@ require 'yaml'
11
11
 
12
12
  # See README for usage documentation.
13
13
  module Rugalytics
14
- VERSION = "0.1.1"
14
+ VERSION = "0.1.2"
15
15
 
16
16
  FORMAT_PDF = '0' unless defined? FORMAT_PDF
17
17
  FORMAT_XML = '1' unless defined? FORMAT_XML
@@ -43,6 +43,13 @@ module Rugalytics
43
43
  end
44
44
  end
45
45
 
46
+ def reports
47
+ profile = Rugalytics.default_profile
48
+ names = profile.report_names
49
+ puts names
50
+ names.collect {|n| puts ''; puts n; profile.send(n.to_sym)}
51
+ end
52
+
46
53
  def default_profile
47
54
  config_setup '.' unless config
48
55
  if config && config.account
data/rugalytics.gemspec CHANGED
@@ -1,137 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
1
2
 
2
- # Gem::Specification for Rugalytics-0.1.1
3
- # Originally generated by Echoe
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rugalytics}
5
+ s.version = "0.1.2"
4
6
 
5
- --- !ruby/object:Gem::Specification
6
- name: rugalytics
7
- version: !ruby/object:Gem::Version
8
- version: 0.1.1
9
- platform: ruby
10
- authors:
11
- - Rob McKinnon
12
- autorequire:
13
- bindir: bin
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rob McKinnon"]
9
+ s.date = %q{2008-11-21}
10
+ s.description = %q{Rugalytics is a Ruby API for Google Analytics.}
11
+ s.email = ["rob ~@nospam@~ rubyforge.org"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
13
+ s.files = ["CHANGELOG", "lib/rugalytics/account.rb", "lib/rugalytics/connection.rb", "lib/rugalytics/graph.rb", "lib/rugalytics/item.rb", "lib/rugalytics/profile.rb", "lib/rugalytics/report.rb", "lib/rugalytics.rb", "LICENSE", "Manifest", "README", "README.rdoc", "rugalytics.yml.example", "spec/fixtures/analytics_account_find_all.html", "spec/fixtures/analytics_profile_find_all.html", "spec/fixtures/dashboard_report_webgroup.xml", "spec/lib/rugalytics/account_spec.rb", "spec/lib/rugalytics/graph_spec.rb", "spec/lib/rugalytics/item_spec.rb", "spec/lib/rugalytics/profile_spec.rb", "spec/lib/rugalytics/report_spec.rb", "spec/lib/rugalytics_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "rugalytics.gemspec", "Rakefile"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rugalytics", "--main", "README", "--inline-source"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{rugalytics}
19
+ s.rubygems_version = %q{1.3.0}
20
+ s.summary = %q{Rugalytics is a Ruby API for Google Analytics.}
14
21
 
15
- date: 2008-09-28 00:00:00 +01:00
16
- default_executable:
17
- dependencies:
18
- - !ruby/object:Gem::Dependency
19
- name: hpricot
20
- type: :runtime
21
- version_requirement:
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: "0.6"
27
- version:
28
- - !ruby/object:Gem::Dependency
29
- name: activesupport
30
- type: :runtime
31
- version_requirement:
32
- version_requirements: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.0.2
37
- version:
38
- - !ruby/object:Gem::Dependency
39
- name: googlebase
40
- type: :runtime
41
- version_requirement:
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.2.0
47
- version:
48
- - !ruby/object:Gem::Dependency
49
- name: morph
50
- type: :runtime
51
- version_requirement:
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.2.0
57
- version:
58
- - !ruby/object:Gem::Dependency
59
- name: echoe
60
- type: :development
61
- version_requirement:
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
67
- version:
68
- description: Rugalytics is a Ruby API for Google Analytics.
69
- email:
70
- - rob ~@nospam@~ rubyforge.org
71
- executables: []
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
72
25
 
73
- extensions: []
74
-
75
- extra_rdoc_files:
76
- - CHANGELOG
77
- - LICENSE
78
- - README
79
- files:
80
- - CHANGELOG
81
- - lib/rugalytics/account.rb
82
- - lib/rugalytics/connection.rb
83
- - lib/rugalytics/graph.rb
84
- - lib/rugalytics/item.rb
85
- - lib/rugalytics/profile.rb
86
- - lib/rugalytics/report.rb
87
- - lib/rugalytics.rb
88
- - LICENSE
89
- - Manifest
90
- - README
91
- - README.rdoc
92
- - rugalytics.yml.example
93
- - spec/fixtures/analytics_account_find_all.html
94
- - spec/fixtures/analytics_profile_find_all.html
95
- - spec/fixtures/dashboard_report_webgroup.xml
96
- - spec/lib/rugalytics/account_spec.rb
97
- - spec/lib/rugalytics/graph_spec.rb
98
- - spec/lib/rugalytics/item_spec.rb
99
- - spec/lib/rugalytics/profile_spec.rb
100
- - spec/lib/rugalytics/report_spec.rb
101
- - spec/lib/rugalytics_spec.rb
102
- - spec/spec.opts
103
- - spec/spec_helper.rb
104
- - rugalytics.gemspec
105
- - Rakefile
106
- has_rdoc: true
107
- homepage: ""
108
- post_install_message:
109
- rdoc_options:
110
- - --line-numbers
111
- - --inline-source
112
- - --title
113
- - Rugalytics
114
- - --main
115
- - README
116
- - --inline-source
117
- require_paths:
118
- - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: "0"
124
- version:
125
- required_rubygems_version: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "="
128
- - !ruby/object:Gem::Version
129
- version: "1.2"
130
- version:
131
- requirements: []
132
-
133
- rubyforge_project: rugalytics
134
- rubygems_version: 1.2.0
135
- specification_version: 2
136
- summary: Rugalytics is a Ruby API for Google Analytics.
137
- test_files: []
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.6"])
28
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
29
+ s.add_runtime_dependency(%q<googlebase>, [">= 0.2.0"])
30
+ s.add_runtime_dependency(%q<morph>, [">= 0.2.0"])
31
+ s.add_development_dependency(%q<echoe>, [">= 0"])
32
+ else
33
+ s.add_dependency(%q<hpricot>, [">= 0.6"])
34
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
35
+ s.add_dependency(%q<googlebase>, [">= 0.2.0"])
36
+ s.add_dependency(%q<morph>, [">= 0.2.0"])
37
+ s.add_dependency(%q<echoe>, [">= 0"])
38
+ end
39
+ else
40
+ s.add_dependency(%q<hpricot>, [">= 0.6"])
41
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
42
+ s.add_dependency(%q<googlebase>, [">= 0.2.0"])
43
+ s.add_dependency(%q<morph>, [">= 0.2.0"])
44
+ s.add_dependency(%q<echoe>, [">= 0"])
45
+ end
46
+ end
@@ -31,6 +31,98 @@ describe Profile do
31
31
  end
32
32
  end
33
33
 
34
+ describe 'finding report names' do
35
+ before do
36
+ @profile = Profile.new :profile_id=>123
37
+ end
38
+
39
+ it 'should return list of reports linked from main profile page' do
40
+ report = {}
41
+ report[0] = 'os_browsers'
42
+ report[1] = 'colors'
43
+ report[2] = 'dashboard'
44
+ report[3] = 'visits'
45
+ report[4] = 'unique_visitors'
46
+ report[5] = 'pageviews'
47
+ report[6] = 'average_pageviews'
48
+ report[7] = 'time_on_site'
49
+ report[8] = 'bounce_rate'
50
+ report[9] = 'visitor_types'
51
+ report[10] = 'languages'
52
+ report[11] = 'networks'
53
+ report[13] = 'browsers'
54
+ report[14] = 'platforms'
55
+ report[15] = 'maps'
56
+ report[16] = 'sources'
57
+ report[17] = 'visitors'
58
+ report[18] = 'resolutions'
59
+ report[19] = 'java'
60
+ report[20] = 'flash'
61
+ report[21] = 'loyalty'
62
+ report[22] = 'recency'
63
+ report[23] = 'content'
64
+ html = %Q|<html><head><title>Visitors Overview - Google Analytics</title></head>
65
+ <body dir="ltr" class="report_body">
66
+ <a href="#" onclick="return VisualizationModule.changeReport(&#39;add_segment&#39;);">Create a new advanced segment</a>
67
+ <a href="#" id="f_managesegment_format" onclick="return VisualizationModule.changeReport(&#39;manage_segments&#39;);">Manage your advanced segments</a>
68
+ <b> Your report has been added.<a href="dashboard?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;#{report[2]}&#39;)">View Dashboard</a>
69
+ <a href="visits?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&quot;#{report[3]}&quot;);"> Visits </a>
70
+ <a href="unique_visitors?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&quot;#{report[4]}&quot;);"> Absolute Unique Visitors </a>
71
+ <a href="pageviews?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&quot;#{report[5]}&quot;);"> Pageviews </a>
72
+ <a href="average_pageviews?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&quot;#{report[6]}&quot;);"> Average Pageviews </a>
73
+ <a href="time_on_site?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&quot;#{report[7]}&quot;);"> Time on Site </a>
74
+ <a href="bounce_rate?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&quot;#{report[8]}&quot;);"> Bounce Rate </a>
75
+ <a href="visitor_types?id=321&amp;pdr=20081020-20081119&amp;cmp=average&amp;view=1" onclick="return VisualizationModule.changeReport(&quot;#{report[9]}&quot;, &quot;view\x3d1&quot;);"> New Visits</a>
76
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[10]}&quot;)">languages</a>,
77
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[11]}&quot;)">network locations</a>,
78
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;user_defined&quot;)">user defined</a>
79
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[13]}&quot;, &quot;view=1&quot;)">browsers</a>,
80
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[14]}&quot;, &quot;view=1&quot;)">operating systems</a>,
81
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[0]}&quot;, &quot;view=1&quot;)">browser and operating systems</a>,
82
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[1]}&quot;, &quot;view=1&quot;)">screen colors</a>,
83
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[18]}&quot;, &quot;view=1&quot;)">screen resolutions</a>,
84
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[19]}&quot;, &quot;view=1&quot;, &quot;view=1&quot;)">java support</a>,
85
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[20]}&quot;, &quot;view=1&quot;, &quot;view=1&quot;)">Flash</a>
86
+ <a href="#" onclick="VisualizationModule.changeReport(&quot;#{report[15]}&quot;)">Map Overlay</a>
87
+ <a href="browsers?id=321&amp;pdr=20081020-20081119&amp;cmp=average&amp;view=1" onclick="return VisualizationModule.changeReport(&quot;browsers&quot;, &quot;view\x3d1&quot;);"> view full report</a>
88
+ <a href="speeds?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return Vis <a href="dashboard?dashboard=1&amp;id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;dashboard&#39;)" class="" id="dashboard_nav_item">
89
+ <a href="visitors?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;#{report[17]}&#39;)" class="current" id="visitors_nav_item">
90
+ <a href="visitors?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;visitors&#39;)" class="current">
91
+ <a href="benchmark?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReportAndComparison(&#39;benchmark&#39;, &#39;benchmark&#39;)" class="">
92
+ <a href="maps?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;#{report[15]}&#39;)" class="">
93
+ <a href="visitor_types?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;visitor_types&#39;, &#39;view=1&#39;)" class="">
94
+ <a href="languages?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;languages&#39;)" class="">
95
+ <a href="visits?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;visits&#39;)" class="">
96
+ <a href="unique_visitors?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;unique_visitors&#39;)" class="">
97
+ <a href="pageviews?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;pageviews&#39;)" class="">
98
+ <a href="average_pageviews?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;average_pageviews&#39;)" class="">
99
+ <a href="time_on_site?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;time_on_site&#39;)" class="">
100
+ <a href="bounce_rate?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;bounce_rate&#39;)" class="">
101
+ <a href="loyalty?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;#{report[21]}&#39;)" class="">
102
+ <a href="recency?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;#{report[22]}&#39;)" class="">
103
+ <a href="user_defined?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;user_defined&#39;)" class="">
104
+ <a href="sources?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;#{report[16]}&#39;)" class="" id="traffic_sources_nav_item">
105
+ <a href="content?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;#{report[23]}&#39;)" class="" id="content_nav_item">
106
+ <a href="goal_intro?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;goal_intro&#39;)" class="" id="goals_nav_item">
107
+ <a href="custom_reports_overview?id=321&amp;pdr=20081020-20081119&amp;cmp=average" onclick="return VisualizationModule.changeReport(&#39;custom_reports_overview&#39;)" class="custom_reporting_section" id="custom_report_nav_item">
108
+ <a href="#" onclick="return VisualizationModule.changeReport(&quot;manage_segments&quot;);">Advanced Segments</a>&nbsp;<b class="beta_label small">Beta</b>
109
+ <a href="#" onclick="return VisualizationModule.changeReport(&quot;manage_emails&quot;);">Email</a>
110
+ </body></html>|
111
+ Profile.should_receive(:get).with("https://www.google.com/analytics/reporting/?scid=#{@profile.profile_id}").and_return html
112
+
113
+ report.values.each do |name|
114
+ Profile.stub!(:get).with("https://www.google.com/analytics/reporting/#{name}?id=#{@profile.profile_id}").and_return ''
115
+ end
116
+
117
+ reports = @profile.report_names
118
+ report.each do |k,name|
119
+ report_name = "#{name.sub(/^maps$/,'geo_map').sub(/^sources$/,'traffic_sources').sub(/^visitors$/,'visitors_overview')}_report"
120
+ reports.should include(report_name)
121
+ end
122
+ end
123
+
124
+ end
125
+
34
126
  describe 'finding pageviews' do
35
127
  before do
36
128
  @profile = Profile.new :profile_id=>123
@@ -102,9 +194,10 @@ describe Profile do
102
194
  before do
103
195
  @profile = Profile.new :profile_id=>123
104
196
  end
105
- def self.it_should_default option, value
197
+ def self.it_should_default option, value, report=nil
198
+ options = report ? %Q|{:report=>"#{report}"}| : '{}'
106
199
  eval %Q|it 'should set :#{option} to #{value}' do
107
- @profile.set_default_options({})[:#{option}].should == #{value}
200
+ @profile.set_default_options(#{options})[:#{option}].should == #{value}
108
201
  end|
109
202
  end
110
203
  it_should_default :report, '"Dashboard"'
@@ -114,6 +207,11 @@ describe Profile do
114
207
  it_should_default :compute, '"average"'
115
208
  it_should_default :gdfmt, '"nth_day"'
116
209
  it_should_default :view, '0'
210
+
211
+ it_should_default :tab, 'nil', 'GeoMap'
212
+ it_should_default :rows, 'nil', 'GeoMap'
213
+ it_should_default :gdfmt, 'nil', 'GeoMap'
214
+
117
215
  it 'should default :from to a month ago, and :to to today' do
118
216
  @month_ago = mock('month_ago')
119
217
  @today = mock('today')
@@ -165,9 +165,9 @@ describe Report do
165
165
  end
166
166
 
167
167
  describe "when creating graph points from 'Graph'" do
168
- def graph_correct expected_start, expected_end
168
+ def graph_correct expected_start, expected_end, column_name='Page Views', graph_name=:pageviews_graph
169
169
  @start_end_dates = "#{@start},#{@end}"
170
- @name = %Q|Page Views|
170
+ @name = column_name
171
171
  @column_names = "Day,#{@name}"
172
172
  @csv = ['# ----------------------------------------',
173
173
  'your_site.com',
@@ -184,11 +184,11 @@ describe Report do
184
184
  '# ----------------------------------------']
185
185
  graph = mock('graph')
186
186
 
187
- Graph.should_receive(:new).with(@name, [5360, 575], expected_start, expected_end).and_return graph
187
+ Graph.should_receive(:new).with(@name.sub('/','_per_').sub('.',''), [5360, 575], expected_start, expected_end).and_return graph
188
188
 
189
189
  report = Report.new(@csv.join("\n"))
190
- report.pageviews_graph.should == graph
191
- report.attribute_names.should == ['pageviews_graph']
190
+ report.send(graph_name).should == graph
191
+ report.attribute_names.should == [graph_name.to_s]
192
192
  end
193
193
 
194
194
  describe 'with source date format "Month Day, Year"' do
@@ -206,6 +206,22 @@ describe Report do
206
206
  graph_correct Date.parse(@start), Date.parse(@end)
207
207
  end
208
208
  end
209
+
210
+ describe "with forward slash in column name" do
211
+ it 'should create graph with forward slash replaced by _per_ in column name' do
212
+ @start = %Q|28 August 2008|
213
+ @end = %Q|29 August 2008|
214
+ graph_correct Date.parse(@start), Date.parse(@end), 'Pages/Visit', :pages_per_visit_graph
215
+ end
216
+ end
217
+
218
+ describe "with dot in column name" do
219
+ it 'should create graph with dot removed in column name' do
220
+ @start = %Q|28 August 2008|
221
+ @end = %Q|29 August 2008|
222
+ graph_correct Date.parse(@start), Date.parse(@end), 'Avg. Time on Site', :avg_time_on_site_graph
223
+ end
224
+ end
209
225
  end
210
226
  end
211
227
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugalytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob McKinnon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-28 00:00:00 +01:00
12
+ date: 2008-11-21 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -121,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
121
  version:
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - "="
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: "1.2"
127
127
  version:
128
128
  requirements: []
129
129
 
130
130
  rubyforge_project: rugalytics
131
- rubygems_version: 1.2.0
131
+ rubygems_version: 1.3.0
132
132
  signing_key:
133
133
  specification_version: 2
134
134
  summary: Rugalytics is a Ruby API for Google Analytics.