rugalytics 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.0.9. allowed setting of :url and :page_title options for drilldown and content reports; merged masolino's changes
2
+
1
3
  v0.0.8. moved i18n date parse method to Rugalytics module
2
4
 
3
5
  v0.0.7. consolidated on US English spelling of pageviews for method names
data/README CHANGED
@@ -96,7 +96,7 @@ Let's load the TrafficSources report:
96
96
 
97
97
  report = profile.traffic_sources_report
98
98
 
99
- report.report_name
99
+ report.name
100
100
  => "Traffic Sources Overview"
101
101
 
102
102
  report.start_date
@@ -132,6 +132,42 @@ Let's now grab 100 lines of the Networks report:
132
132
  => "telecom xtra"
133
133
 
134
134
 
135
+ == Report by URL
136
+
137
+ You can get a content drilldown report:
138
+
139
+ report = profile.content_drilldown_report(:url => "/projects/abc/")
140
+ report.name
141
+ => "Content Drilldown,/projects/abc/"
142
+
143
+ report.items.first
144
+ => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="155",
145
+ @percentage_exit="0.776536312849162", @time_on_page="165.75",
146
+ @pageviews="179", @path="/reports/", @dollar_index="0.0",
147
+ @url="http://your_site.com/projects/abc/reports/"
148
+
149
+ Pageviews by URL:
150
+
151
+ report = profile.top_content_detail_report(:url => "/projects/abc")
152
+ report.name
153
+ => "Content Detail:,/projects/abc"
154
+
155
+ report.pageviews_total
156
+ => 179
157
+
158
+ Pageviews by page title:
159
+
160
+ report = profile.content_by_title_detail_report(:page_title => "Project ABC | Company XYZ")
161
+ report.name
162
+ => "Content by Title Detail:,Project ABC | Company XYZ"
163
+
164
+ report.items.first
165
+ => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="1550",
166
+ @percentage_exit="0.776536312849162", @time_on_page="165.75",
167
+ @pageviews="179", @path="/projects/abc", @dollar_index="0.0",
168
+ @url="http://your_site.com/projects/abc"
169
+
170
+
135
171
  ==Use in Rails
136
172
 
137
173
  To use from Rails, make a config file rails_root/config/rugalytics.yml
data/README.rdoc CHANGED
@@ -96,7 +96,7 @@ Let's load the TrafficSources report:
96
96
 
97
97
  report = profile.traffic_sources_report
98
98
 
99
- report.report_name
99
+ report.name
100
100
  => "Traffic Sources Overview"
101
101
 
102
102
  report.start_date
@@ -132,6 +132,42 @@ Let's now grab 100 lines of the Networks report:
132
132
  => "telecom xtra"
133
133
 
134
134
 
135
+ == Report by URL
136
+
137
+ You can get a content drilldown report:
138
+
139
+ report = profile.content_drilldown_report(:url => "/projects/abc/")
140
+ report.name
141
+ => "Content Drilldown,/projects/abc/"
142
+
143
+ report.items.first
144
+ => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="155",
145
+ @percentage_exit="0.776536312849162", @time_on_page="165.75",
146
+ @pageviews="179", @path="/reports/", @dollar_index="0.0",
147
+ @url="http://your_site.com/projects/abc/reports/"
148
+
149
+ Pageviews by URL:
150
+
151
+ report = profile.top_content_detail_report(:url => "/projects/abc")
152
+ report.name
153
+ => "Content Detail:,/projects/abc"
154
+
155
+ report.pageviews_total
156
+ => 179
157
+
158
+ Pageviews by page title:
159
+
160
+ report = profile.content_by_title_detail_report(:page_title => "Project ABC | Company XYZ")
161
+ report.name
162
+ => "Content by Title Detail:,Project ABC | Company XYZ"
163
+
164
+ report.items.first
165
+ => # Rugalytics::Item @bounce_rate="0.85", @unique_pageviews="1550",
166
+ @percentage_exit="0.776536312849162", @time_on_page="165.75",
167
+ @pageviews="179", @path="/projects/abc", @dollar_index="0.0",
168
+ @url="http://your_site.com/projects/abc"
169
+
170
+
135
171
  ==Use in Rails
136
172
 
137
173
  To use from Rails, make a config file rails_root/config/rugalytics.yml
@@ -15,6 +15,7 @@ module Rugalytics
15
15
 
16
16
  if respond_to?(:url)
17
17
  self.path = url
18
+ # todo: For drilldown report, URLs need to be cumulatively created e.g. /health/ -> http://theyworkforyou.co.nz/portfolios/health/
18
19
  self.url = "http://#{base_url}#{url}"
19
20
  end
20
21
  end
@@ -46,20 +46,12 @@ module Rugalytics
46
46
  end
47
47
 
48
48
  def get_report_csv(options={})
49
- options.reverse_merge!({
50
- :report => 'Dashboard',
51
- :from => Time.now.utc - 7.days,
52
- :to => Time.now.utc,
53
- :tab => 0,
54
- :format => FORMAT_CSV,
55
- :rows => 50,
56
- :compute => 'average',
57
- :gdfmt => 'nth_day',
58
- :view => 0
59
- })
60
- options[:from] = ensure_datetime_in_google_format(options[:from])
61
- options[:to] = ensure_datetime_in_google_format(options[:to])
49
+ options = set_default_options(options)
50
+ params = convert_options_to_uri_params(options)
51
+ self.class.get("https://google.com/analytics/reporting/export", :query_hash => params)
52
+ end
62
53
 
54
+ def convert_options_to_uri_params(options)
63
55
  params = {
64
56
  :pdr => "#{options[:from]}-#{options[:to]}",
65
57
  :rpt => "#{options[:report]}Report",
@@ -69,13 +61,48 @@ module Rugalytics
69
61
  :tab => options[:tab],
70
62
  :trows=> options[:rows],
71
63
  :gdfmt=> options[:gdfmt],
72
- :id => profile_id,
64
+ :id => profile_id
73
65
  }
74
- puts params.inspect
75
- # https://www.google.com/analytics/reporting/export?fmt=2&id=1712313&pdr=20080701-20080731&cmp=average&&rpt=PageviewsReport
76
- self.class.get("https://google.com/analytics/reporting/export", :query_hash => params)
66
+ params[:d1] = options[:url] if options[:url]
67
+ params[:d1] = options[:page_title] if options[:page_title]
68
+ params
69
+ end
70
+
71
+ def a_month_ago
72
+ Time.now.utc.last_month
77
73
  end
78
74
 
75
+ def today
76
+ Time.now.utc
77
+ end
78
+
79
+ def set_default_options(options)
80
+ options.reverse_merge!({
81
+ :report => 'Dashboard',
82
+ :from => a_month_ago,
83
+ :to => today,
84
+ :tab => 0,
85
+ :format => FORMAT_CSV,
86
+ :rows => 50,
87
+ :compute => 'average',
88
+ :gdfmt => 'nth_day',
89
+ :view => 0
90
+ })
91
+ options[:from] = ensure_datetime_in_google_format(options[:from])
92
+ options[:to] = ensure_datetime_in_google_format(options[:to])
93
+ options
94
+ end
95
+
96
+ # Extract Page Views from Content Drilldown Report URLs.
97
+ # Use with :url => "/projects/68263/" to options hash
98
+ #
99
+ # def drilldown(options={})
100
+ # content_drilldown_report(options).pageviews_total
101
+ # end
102
+ #
103
+ # instead do
104
+ # profile.content_drilldown_report(:url => '/projects/68263/').pageviews_total
105
+
79
106
  def pageviews(options={})
80
107
  pageviews_report(options).pageviews_total
81
108
  end
@@ -4,7 +4,7 @@ module Rugalytics
4
4
 
5
5
  include MorphLessMethodMissing
6
6
 
7
- attr_reader :base_url, :report_name, :start_date, :end_date
7
+ attr_reader :base_url, :start_date, :end_date, :name
8
8
 
9
9
  def initialize csv=''
10
10
  return if csv.empty?
@@ -36,11 +36,18 @@ module Rugalytics
36
36
  end
37
37
  end
38
38
 
39
+ def report_name
40
+ ActiveSupport::Deprecation.warn "Report#report_name has been deprecated, use Report#name instead"
41
+ name
42
+ end
43
+
39
44
  private
40
45
 
41
46
  def set_attributes lines
42
47
  @base_url = lines[1]
43
- @report_name = lines[2].chomp(',')
48
+ names = lines[2].split(',')
49
+ @base_url = "#{@base_url}#{names[1].chomp('/')}" if names.size > 1 && names[1][/^\/.+$/]
50
+ @name = lines[2].chomp(',')
44
51
  dates = lines[3].include?('","') ? lines[3].split('","') : lines[3].split(',')
45
52
  @start_date = Rugalytics.i18n_date_parse(dates[0])
46
53
  @end_date = Rugalytics.i18n_date_parse(dates[1])
@@ -73,7 +80,7 @@ module Rugalytics
73
80
  def handle_tables lines
74
81
  index = 5
75
82
  while index < lines.size
76
- while (lines[index][/^# .*Table/].nil? || lines[index].strip.size == 0)
83
+ while (lines[index][/^# .*Table/].nil? || lines[index].blank?)
77
84
  index = index.next
78
85
  return if index == lines.size
79
86
  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.0.8"
14
+ VERSION = "0.0.9"
15
15
 
16
16
  FORMAT_PDF = '0' unless defined? FORMAT_PDF
17
17
  FORMAT_XML = '1' unless defined? FORMAT_XML
data/rugalytics.gemspec CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Rugalytics-0.0.8
2
+ # Gem::Specification for Rugalytics-0.0.9
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: rugalytics
7
7
  version: !ruby/object:Gem::Version
8
- version: 0.0.8
8
+ version: 0.0.9
9
9
  platform: ruby
10
10
  authors:
11
11
  - Rob McKinnon
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-08-06 00:00:00 +01:00
15
+ date: 2008-08-08 00:00:00 +01:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -1,5 +1,5 @@
1
- ---
2
- account: <account_name>
3
- profile: <profile_name>
4
- username: <user_name>
5
- password: <pass_w>
1
+ ---
2
+ account: account_name
3
+ profile: profile_name
4
+ username: user_name
5
+ password: pass_w
@@ -98,6 +98,65 @@ describe Profile do
98
98
  end
99
99
  end
100
100
 
101
+ describe 'when asked to set default options when no options specified' do
102
+ before do
103
+ @profile = Profile.new :profile_id=>123
104
+ end
105
+ def self.it_should_default option, value
106
+ eval %Q|it 'should set :#{option} to #{value}' do
107
+ @profile.set_default_options({})[:#{option}].should == #{value}
108
+ end|
109
+ end
110
+ it_should_default :report, '"Dashboard"'
111
+ it_should_default :tab, '0'
112
+ it_should_default :format, 'Rugalytics::FORMAT_CSV'
113
+ it_should_default :rows, '50'
114
+ it_should_default :compute, '"average"'
115
+ it_should_default :gdfmt, '"nth_day"'
116
+ it_should_default :view, '0'
117
+ it 'should default :from to a month ago, and :to to today' do
118
+ @month_ago = mock('month_ago')
119
+ @today = mock('today')
120
+ @profile.should_receive(:a_month_ago).and_return @month_ago
121
+ @profile.should_receive(:today).and_return @today
122
+ @profile.should_receive(:ensure_datetime_in_google_format).with(@month_ago).and_return @month_ago
123
+ @profile.should_receive(:ensure_datetime_in_google_format).with(@today).and_return @today
124
+ options = @profile.set_default_options({})
125
+ options[:from].should == @month_ago
126
+ options[:to].should == @today
127
+ end
128
+ end
129
+
130
+ describe 'when asked to convert option keys to uri parameter keys' do
131
+ before do
132
+ @profile = Profile.new :profile_id=>123
133
+ end
134
+ def self.it_should_convert option_key, param_key, value_addition=''
135
+ eval %Q|it 'should convert :#{option_key} to :#{param_key}' do
136
+ params = @profile.convert_options_to_uri_params({:#{option_key} => 'value'})
137
+ params[:#{param_key}].should == 'value#{value_addition}'
138
+ end|
139
+ end
140
+ it_should_convert :report, :rpt, 'Report'
141
+ it_should_convert :compute, :cmp
142
+ it_should_convert :format, :fmt
143
+ it_should_convert :view, :view
144
+ it_should_convert :rows, :trows
145
+ it_should_convert :gdfmt, :gdfmt
146
+ it_should_convert :url, :d1
147
+ it_should_convert :page_title,:d1
148
+
149
+ it 'should convert from and to dates into the period param' do
150
+ from = '20080801'
151
+ to = '20080808'
152
+ params = @profile.convert_options_to_uri_params :from=>from, :to=>to
153
+ params[:pdr].should == "#{from}-#{to}"
154
+ end
155
+ it 'should set param id to be the profile id' do
156
+ @profile.convert_options_to_uri_params({})[:id].should == 123
157
+ end
158
+ end
159
+
101
160
  it "should be able to find all profiles for an account" do
102
161
  html = fixture('analytics_profile_find_all.html')
103
162
  Profile.should_receive(:get).and_return(html)
@@ -21,6 +21,7 @@ describe Report do
21
21
 
22
22
  it "should set report name from third line of text" do
23
23
  @report.report_name.should == 'Top Content'
24
+ @report.name.should == 'Top Content'
24
25
  end
25
26
 
26
27
  it "should set start date from fourth line of text" do
@@ -30,6 +31,41 @@ describe Report do
30
31
  it "should set end date from fourth line of text" do
31
32
  @report.end_date.should == Date.parse('31 May 2008')
32
33
  end
34
+
35
+ describe "for a Content Drilldown report and a path is in report name" do
36
+ before :all do
37
+ csv = ['# ----------------------------------------',
38
+ 'your_site.com',
39
+ 'Content Drilldown,/portfolios/health/',
40
+ '26 May 2008,31 May 2008',
41
+ '# ----------------------------------------']
42
+ @report = Report.new(csv.join("\n"))
43
+ end
44
+ it 'should append path at end of base_url' do
45
+ @report.base_url.should == 'your_site.com/portfolios/health'
46
+ end
47
+ it 'should set report name including path' do
48
+ @report.report_name.should == 'Content Drilldown,/portfolios/health/'
49
+ @report.name.should == 'Content Drilldown,/portfolios/health/'
50
+ end
51
+ end
52
+
53
+ describe "for a Top Content by title report and page title is in report name" do
54
+ before :all do
55
+ csv = ['# ----------------------------------------',
56
+ 'your_site.com',
57
+ 'Content by Title Detail:,Project ABC | Company XZY',
58
+ '26 May 2008,31 May 2008',
59
+ '# ----------------------------------------']
60
+ @report = Report.new(csv.join("\n"))
61
+ end
62
+ it 'should not append title to end of base_url' do
63
+ @report.base_url.should == 'your_site.com'
64
+ end
65
+ it 'should set report name including page title' do
66
+ @report.name.should == 'Content by Title Detail:,Project ABC | Company XZY'
67
+ end
68
+ end
33
69
  end
34
70
 
35
71
  describe "when setting report dates" do
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.0.8
4
+ version: 0.0.9
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-08-06 00:00:00 +01:00
12
+ date: 2008-08-08 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency