mitamirri 0.13.8 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/Capfile +4 -0
  2. data/Gemfile +29 -0
  3. data/README.rdoc +6 -55
  4. data/Rakefile +34 -21
  5. data/VERSION +1 -1
  6. data/app/controllers/admin/tracking/reports_controller.rb +78 -0
  7. data/app/controllers/admin/tracking/trackable_sessions_controller.rb +7 -0
  8. data/app/controllers/application_controller.rb +1 -8
  9. data/app/controllers/trackable_actions_controller.rb +0 -2
  10. data/app/helpers/application_helper.rb +21 -0
  11. data/app/helpers/layout_helper.rb +18 -0
  12. data/app/models/content_report.rb +35 -0
  13. data/app/models/content_stat.rb +4 -0
  14. data/app/models/destination.rb +4 -0
  15. data/app/models/intersite_traffic_report.rb +47 -0
  16. data/app/models/keyword_stat.rb +4 -0
  17. data/app/models/lead.rb +3 -0
  18. data/app/models/lead_stat.rb +5 -0
  19. data/app/models/leads_report.rb +32 -0
  20. data/app/models/location_stat.rb +37 -0
  21. data/app/models/referrer_stat.rb +4 -0
  22. data/app/models/report.rb +83 -0
  23. data/app/models/stat_base.rb +11 -0
  24. data/app/models/trackable_action.rb +114 -91
  25. data/app/models/trackable_base.rb +12 -0
  26. data/app/models/trackable_location.rb +7 -13
  27. data/app/models/trackable_session.rb +255 -171
  28. data/app/models/trackable_stat.rb +45 -27
  29. data/app/models/traffic_explorer_report.rb +92 -0
  30. data/app/models/traffic_summary_report.rb +142 -0
  31. data/app/models/user_agent_stat.rb +4 -0
  32. data/app/models/visit.rb +6 -0
  33. data/app/models/visit_stat.rb +5 -0
  34. data/app/models/visitor.rb +4 -0
  35. data/app/models/visitor_profile_report.rb +23 -0
  36. data/app/views/admin/tracking/reports/_content.html.erb +28 -0
  37. data/app/views/admin/tracking/reports/_conversion_rate.html.erb +30 -0
  38. data/app/views/admin/tracking/reports/_criteria.html.erb +33 -0
  39. data/app/views/admin/tracking/reports/_entrance_pages.html.erb +29 -0
  40. data/app/views/admin/tracking/reports/_exit_pages.html.erb +28 -0
  41. data/app/views/admin/tracking/reports/_explorer_criteria.html.erb +22 -0
  42. data/app/views/admin/tracking/reports/_explorer_summary.html.erb +22 -0
  43. data/app/views/admin/tracking/reports/_intersite_destinations.html.erb +28 -0
  44. data/app/views/admin/tracking/reports/_intersite_referrals.html.erb +30 -0
  45. data/app/views/admin/tracking/reports/_leads.html.erb +30 -0
  46. data/app/views/admin/tracking/reports/_locations.html.erb +47 -0
  47. data/app/views/admin/tracking/reports/_recent_visits.html.erb +33 -0
  48. data/app/views/admin/tracking/reports/_referring_keywords.html.erb +28 -0
  49. data/app/views/admin/tracking/reports/_referring_sites.html.erb +28 -0
  50. data/app/views/admin/tracking/reports/_traffic_summary.html.erb +26 -0
  51. data/app/views/admin/tracking/reports/_user_agents.html.erb +28 -0
  52. data/app/views/{trackable_sessions/_visits_graph.html.erb → admin/tracking/reports/_visits_by_kind.html.erb} +3 -3
  53. data/app/views/admin/tracking/reports/content.html.erb +12 -0
  54. data/app/views/admin/tracking/reports/explorer.html.erb +13 -0
  55. data/app/views/admin/tracking/reports/index.html.erb +16 -0
  56. data/app/views/admin/tracking/reports/intersite.html.erb +11 -0
  57. data/app/views/admin/tracking/reports/leads.html.erb +11 -0
  58. data/app/views/admin/tracking/reports/summary.html.erb +16 -0
  59. data/app/views/admin/tracking/reports/visitor_profile.html.erb +11 -0
  60. data/app/views/{trackable_sessions → admin/tracking/trackable_sessions}/show.html.erb +5 -4
  61. data/app/views/layouts/application.html.erb +51 -18
  62. data/config.ru +4 -0
  63. data/config/application.rb +13 -0
  64. data/config/boot.rb +13 -110
  65. data/config/cucumber.yml +10 -0
  66. data/config/deploy.rb +40 -0
  67. data/config/environment.rb +4 -23
  68. data/config/environments/development.rb +24 -13
  69. data/config/environments/production.rb +41 -20
  70. data/config/environments/test.rb +28 -24
  71. data/config/initializers/formats.rb +19 -0
  72. data/config/initializers/metric_fu.rb +9 -0
  73. data/config/initializers/secret_token.rb +7 -0
  74. data/config/initializers/session_store.rb +3 -10
  75. data/config/locales/en.yml +1 -1
  76. data/config/mongoid.yml +19 -0
  77. data/config/routes.rb +16 -10
  78. data/features/access_reports.feature +26 -0
  79. data/features/step_definitions/reports_steps.rb +9 -0
  80. data/features/step_definitions/web_steps.rb +219 -0
  81. data/features/support/env.rb +32 -0
  82. data/features/support/hooks.rb +1 -0
  83. data/features/support/paths.rb +33 -0
  84. data/features/traffic_summary_report.feature +43 -0
  85. data/init.rb +0 -7
  86. data/lib/mitamirri.rb +9 -12
  87. data/lib/mitamirri/engine.rb +7 -0
  88. data/lib/mitamirri/helper.rb +13 -29
  89. data/lib/mitamirri/railtie.rb +10 -0
  90. data/lib/tasks/cucumber.rake +60 -0
  91. data/lib/tasks/rcov.rake +44 -0
  92. data/mitamirri.gemspec +228 -100
  93. data/public/404.html +26 -0
  94. data/public/422.html +26 -0
  95. data/public/500.html +26 -0
  96. data/{config/database.yml → public/favicon.ico} +0 -0
  97. data/public/images/icons/add.png +0 -0
  98. data/public/images/icons/collapsed.gif +0 -0
  99. data/public/images/icons/delete.png +0 -0
  100. data/public/images/icons/drag.png +0 -0
  101. data/public/images/icons/edit.png +0 -0
  102. data/public/images/icons/expanded.gif +0 -0
  103. data/public/images/icons/help_icon.png +0 -0
  104. data/public/images/icons/link_icon.png +0 -0
  105. data/public/images/icons/move.png +0 -0
  106. data/public/images/icons/move_white.png +0 -0
  107. data/public/images/icons/note.png +0 -0
  108. data/public/images/icons/note_white.png +0 -0
  109. data/public/images/icons/notification_icon_sprite.png +0 -0
  110. data/public/images/icons/spinner.gif +0 -0
  111. data/public/images/icons/view.png +0 -0
  112. data/public/images/icons/warning.png +0 -0
  113. data/public/images/icons/warning_2.png +0 -0
  114. data/public/images/icons/warning_box.png +0 -0
  115. data/public/images/icons/warning_icon.png +0 -0
  116. data/public/images/icons/warning_white.png +0 -0
  117. data/public/images/layout/arrow_asc.png +0 -0
  118. data/public/images/layout/arrow_desc.png +0 -0
  119. data/public/images/layout/back.png +0 -0
  120. data/public/images/layout/black_bar.png +0 -0
  121. data/public/images/layout/branding.png +0 -0
  122. data/public/images/layout/breadcrumb_bg.png +0 -0
  123. data/public/images/layout/button_bg.png +0 -0
  124. data/public/images/layout/content_left_bg.png +0 -0
  125. data/public/images/layout/content_right_bg.png +0 -0
  126. data/public/images/layout/footer_bg.png +0 -0
  127. data/public/images/layout/h1_bg.png +0 -0
  128. data/public/images/layout/h2_bg.png +0 -0
  129. data/public/images/layout/h2_bg_for_table.png +0 -0
  130. data/public/images/layout/header_bg_grey.png +0 -0
  131. data/public/images/layout/header_bg_purple.png +0 -0
  132. data/public/images/layout/legend_bg.png +0 -0
  133. data/public/images/layout/menu_box_bg.png +0 -0
  134. data/public/images/layout/shadow_border.png +0 -0
  135. data/public/images/layout/shadow_border_2.png +0 -0
  136. data/public/images/layout/shadow_border_3.png +0 -0
  137. data/public/images/layout/shadow_border_4.png +0 -0
  138. data/public/images/layout/tab.png +0 -0
  139. data/public/images/layout/tab_active.png +0 -0
  140. data/public/images/layout/table_header.png +0 -0
  141. data/public/images/layout/text_field_bg.jpg +0 -0
  142. data/public/images/layout/text_field_error_bg.png +0 -0
  143. data/public/images/layout/th_bg.png +0 -0
  144. data/public/images/layout/th_bg_selected.png +0 -0
  145. data/public/images/menu_icons/content_report.png +0 -0
  146. data/public/images/menu_icons/content_report_on.png +0 -0
  147. data/public/images/menu_icons/funnel.png +0 -0
  148. data/public/images/menu_icons/funnel_on.png +0 -0
  149. data/public/images/menu_icons/intersite_traffic.png +0 -0
  150. data/public/images/menu_icons/intersite_traffic_on.png +0 -0
  151. data/public/images/menu_icons/leads.png +0 -0
  152. data/public/images/menu_icons/leads_on.png +0 -0
  153. data/public/images/menu_icons/traffic_explorer.png +0 -0
  154. data/public/images/menu_icons/traffic_explorer_on.png +0 -0
  155. data/public/images/menu_icons/traffic_summary.png +0 -0
  156. data/public/images/menu_icons/traffic_summary_on.png +0 -0
  157. data/public/images/menu_icons/visitor_profile.png +0 -0
  158. data/public/images/menu_icons/visitor_profile_on.png +0 -0
  159. data/public/index.html +8 -0
  160. data/public/javascripts/application.js +2 -0
  161. data/public/javascripts/controls.js +965 -0
  162. data/public/javascripts/dragdrop.js +974 -0
  163. data/public/javascripts/effects.js +1123 -0
  164. data/public/javascripts/prototype.js +6001 -0
  165. data/public/javascripts/rails.js +175 -0
  166. data/public/robots.txt +5 -0
  167. data/public/stylesheets/.gitkeep +0 -0
  168. data/public/stylesheets/application.css +876 -0
  169. data/public/stylesheets/core.css +1146 -0
  170. data/public/stylesheets/core_ie.css +52 -0
  171. data/public/stylesheets/csshover3.htc +14 -0
  172. data/public/stylesheets/mitamirri.css +37 -724
  173. data/public/stylesheets/mitamirri_print.css +3 -0
  174. data/script/cucumber +10 -0
  175. data/script/rails +6 -0
  176. data/spec/blueprints.rb +13 -0
  177. data/spec/helpers/application_helper_spec.rb +23 -35
  178. data/spec/{lib → models}/content_report_spec.rb +12 -8
  179. data/spec/{lib → models}/intersite_traffic_report_spec.rb +6 -9
  180. data/spec/{lib → models}/leads_report_spec.rb +11 -12
  181. data/spec/models/location_stat_spec.rb +18 -0
  182. data/spec/models/trackable_action_spec.rb +46 -14
  183. data/spec/models/trackable_base_spec.rb +27 -0
  184. data/spec/models/trackable_session_spec.rb +181 -57
  185. data/spec/{lib/session_report_spec.rb → models/traffic_explorer_report_spec.rb} +8 -25
  186. data/spec/spec_helper.rb +8 -28
  187. data/{lib/mitamirri/tasks.rb → tasks/mitamirri.rake} +6 -7
  188. data/vendor/plugins/.gitkeep +0 -0
  189. metadata +316 -77
  190. data/.gitignore +0 -26
  191. data/app/controllers/trackable_sessions_controller.rb +0 -100
  192. data/app/views/trackable_sessions/_keywords_graph.html.erb +0 -24
  193. data/app/views/trackable_sessions/_print_buttons.html.erb +0 -3
  194. data/app/views/trackable_sessions/_sessions.html.erb +0 -26
  195. data/app/views/trackable_sessions/_top_referrers.html.erb +0 -24
  196. data/app/views/trackable_sessions/_traffic_summary_all.html.erb +0 -64
  197. data/app/views/trackable_sessions/_traffic_summary_by_kind.html.erb +0 -48
  198. data/app/views/trackable_sessions/content.html.erb +0 -119
  199. data/app/views/trackable_sessions/explorer.html.erb +0 -67
  200. data/app/views/trackable_sessions/export.xls.erb +0 -5
  201. data/app/views/trackable_sessions/index.html.erb +0 -47
  202. data/app/views/trackable_sessions/intersite.html.erb +0 -97
  203. data/app/views/trackable_sessions/leads.html.erb +0 -98
  204. data/app/views/trackable_sessions/visitor_profile.html.erb +0 -114
  205. data/config/initializers/backtrace_silencers.rb +0 -7
  206. data/config/initializers/database.rb +0 -1
  207. data/config/initializers/inflections.rb +0 -10
  208. data/config/initializers/mime_types.rb +0 -5
  209. data/config/initializers/new_rails_defaults.rb +0 -21
  210. data/db/development.sqlite3 +0 -0
  211. data/db/migrate/20100810173533_create_trackable_sessions.rb +0 -23
  212. data/db/migrate/20100810173605_create_trackable_actions.rb +0 -20
  213. data/db/test.sqlite3 +0 -1
  214. data/lib/mitamirri/content_report.rb +0 -75
  215. data/lib/mitamirri/intersite_traffic_report.rb +0 -122
  216. data/lib/mitamirri/leads_report.rb +0 -90
  217. data/lib/mitamirri/session_report.rb +0 -219
  218. data/lib/mitamirri/stat_report.rb +0 -216
  219. data/lib/mitamirri/visitor_profile_report.rb +0 -127
  220. data/script/about +0 -4
  221. data/script/console +0 -3
  222. data/script/dbconsole +0 -3
  223. data/script/destroy +0 -3
  224. data/script/generate +0 -3
  225. data/script/performance/benchmarker +0 -3
  226. data/script/performance/profiler +0 -3
  227. data/script/plugin +0 -3
  228. data/script/runner +0 -3
  229. data/script/server +0 -3
  230. data/spec/controllers/trackable_actions_controller_spec.rb +0 -5
  231. data/spec/controllers/trackable_sessions_controller_spec.rb +0 -5
  232. data/spec/custom_matchers.rb +0 -23
  233. data/spec/lib/stat_report_spec.rb +0 -106
  234. data/spec/rcov.opts +0 -4
  235. data/spec/schema.rb +0 -34
  236. data/spec/spec.opts +0 -4
@@ -1 +0,0 @@
1
- S
@@ -1,75 +0,0 @@
1
- module Mitamirri
2
-
3
- class ContentReport
4
-
5
- # Search params
6
- attr_accessor :site
7
- attr_accessor :time_period
8
- attr_accessor :visit_kind
9
-
10
- # Initialization
11
-
12
- def initialize(args = {})
13
- args.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}
14
- self.time_period = args[:time_period] || 'past 3 months'
15
- self.sessions
16
- end
17
-
18
- def sessions
19
- @sessions ||= TrackableSession.search(
20
- :site => self.site,
21
- :time_period => self.time_period,
22
- :visit_kind => self.visit_kind
23
- )
24
- end
25
-
26
- # Generate an array of dates spanning the appropriate time period.
27
- def dates
28
- return @dates if @dates
29
- @dates = []
30
- case self.time_period
31
- when 'past month'
32
- _increment = 1
33
- when 'past 3 months'
34
- _increment = 2
35
- when 'past 6 months'
36
- _increment = 5
37
- when 'past 12 months'
38
- _increment = 11
39
- else 'all time'
40
- _increment = 24
41
- end
42
-
43
- (1.._increment).each{ |i| @dates << (Time.zone.now - i.months).beginning_of_month }
44
- @dates.reverse!
45
- @dates << Time.zone.now.end_of_month
46
- @dates
47
- end
48
-
49
- # Graphing data
50
-
51
- def pages_series(args)
52
- TrackableAction.pages_histogram(args).map{|datum| ContentStat.new(:url => datum[0], :views => datum[1].to_i)}
53
- end
54
-
55
- def entrance_pages_series(args)
56
- TrackableSession.entrance_pages_histogram(args).map{|datum| ContentStat.new(:url => datum[0], :views => datum[1].to_i)}
57
- end
58
-
59
- def exit_pages_series(args)
60
- TrackableSession.exit_pages_histogram(args).map{|datum| ContentStat.new(:url => datum[0], :views => datum[1].to_i)}
61
- end
62
-
63
- # Inner stat classes
64
-
65
- class ContentStat
66
- attr_accessor :url
67
- attr_accessor :views
68
- def initialize(args)
69
- args.each{ |k,v| self.send("#{k}=", v) }
70
- end
71
- end
72
-
73
- end
74
-
75
- end
@@ -1,122 +0,0 @@
1
- module Mitamirri
2
-
3
- class IntersiteTrafficReport
4
-
5
- # Search params
6
- attr_accessor :site
7
- attr_accessor :time_period
8
- attr_accessor :visit_kind
9
-
10
- # Initialization
11
-
12
- def initialize(args = {})
13
- args.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}
14
- self.time_period = args[:time_period] || 'past 6 months'
15
- self.sessions
16
- end
17
-
18
- def destination_histogram
19
- @destination_histogram ||= TrackableSession.clickthroughs_histogram(self.sessions.to_hash)
20
- end
21
-
22
- def destination_sites
23
- self.destination_histogram.keys
24
- end
25
-
26
- def sessions
27
- @sessions ||= TrackableSession.search(
28
- :site => self.site,
29
- :time_period => self.time_period,
30
- :visit_kind => self.visit_kind,
31
- :action_kind => 'clickthrough'
32
- )
33
- end
34
-
35
- # Generate an array of dates spanning the appropriate time period.
36
- def dates
37
- return @dates if @dates
38
- @dates = []
39
- case self.time_period.downcase
40
- when 'past month'
41
- _increment = 4
42
- when 'past 3 months'
43
- _increment = 12
44
- when 'past 6 months'
45
- _increment = 24
46
- when 'past 12 months'
47
- _increment = 52
48
- else
49
- _increment = 52
50
- end
51
-
52
- (1.._increment).each{ |i| @dates << (Time.zone.now - i.weeks).end_of_week }
53
- @dates.reverse!
54
- @dates << Time.zone.now.end_of_week
55
- @dates
56
- end
57
-
58
- # Graphing data
59
-
60
- def total_visits(args)
61
- [Visit.new(:stats => visit_stats(args))]
62
- end
63
-
64
- def total_visit_stats(args)
65
- _visit_stats = []
66
- dates.each do |date|
67
- _visit_stats << VisitStat.new(:date => date, :clickthroughs => TrackableSession.search_without_date(args).for_week(date).with_clickthroughs.count)
68
- end
69
- _visit_stats
70
- end
71
-
72
- def destinations(args)
73
- _destinations = []
74
- self.destination_sites.each do |site|
75
- _destinations << Destination.new(:site => site, :clickthroughs => TrackableSession.search(args).with_clickthroughs.count)
76
- end
77
- _destinations
78
- end
79
-
80
- def visit_stats(args)
81
- _visit_stats = []
82
- dates.each do |date|
83
- _visit_stats << VisitStat.new(:date => date, :clickthroughs => TrackableSession.search_without_date(args).for_week(date).with_clickthroughs.count)
84
- end
85
- _visit_stats
86
- end
87
-
88
- # Inner stat classes
89
-
90
- class Destination
91
- attr_accessor :site
92
- attr_accessor :clickthroughs
93
- def initialize(args)
94
- args.each{ |k,v| self.send("#{k}=", v) }
95
- end
96
- end
97
-
98
- class Visit
99
- attr_accessor :site
100
- attr_accessor :stats
101
- def initialize(args)
102
- args.each{ |k,v| self.send("#{k}=", v) }
103
- end
104
- end
105
-
106
- class VisitStat
107
- attr_accessor :date
108
- attr_accessor :clickthroughs
109
-
110
- def initialize(args)
111
- args.each{ |k,v| self.send("#{k}=", v) }
112
- end
113
-
114
- def short_date
115
- self.date.to_s(:concise)
116
- end
117
-
118
- end
119
-
120
- end
121
-
122
- end
@@ -1,90 +0,0 @@
1
- module Mitamirri
2
-
3
- class LeadsReport
4
-
5
- # Search params
6
- attr_accessor :site
7
- attr_accessor :time_period
8
- attr_accessor :start_date
9
- attr_accessor :end_date
10
-
11
- # Stat attributes
12
-
13
- # Initialization
14
-
15
- def initialize(args = {})
16
- args.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}
17
- self.time_period = args[:time_period] || 'past 6 months'
18
- self.start_date = self.dates.first
19
- self.end_date = self.dates.last
20
- end
21
-
22
- # Generate an array of dates spanning the appropriate time period.
23
- def dates
24
- return @dates if @dates
25
- @dates = []
26
- case self.time_period.downcase
27
- when 'past month'
28
- _increment = 4
29
- when 'past 3 months'
30
- _increment = 12
31
- when 'past 6 months'
32
- _increment = 24
33
- when 'past 12 months'
34
- _increment = 52
35
- else 'all time'
36
- _increment = 104
37
- end
38
-
39
- (1.._increment).each{ |i| @dates << (Time.zone.now - i.weeks).beginning_of_week }
40
- @dates.reverse!
41
- @dates << Time.zone.now
42
- @dates
43
- end
44
-
45
- # Graphing objects
46
-
47
- def leads(args)
48
- _leads = []
49
- _leads << Lead.new(:stats => lead_stats(args))
50
- _leads
51
- end
52
-
53
- def lead_stats(args)
54
- _lead_stats = []
55
- dates.each do |date|
56
- _total_sessions = TrackableSession.search_without_date(args).for_week(date).count
57
- _total_conversions = TrackableSession.search_without_date(args).for_week(date).with_conversions.count
58
- _conversion_rate = (_total_conversions.to_f / _total_sessions) * 100
59
- _lead_stats << LeadStat.new(:date => date, :leads => _total_conversions, :conversion_rate => sprintf("%0.1f",_conversion_rate).to_f)
60
- end
61
- _lead_stats
62
- end
63
-
64
- # Inner stat classes
65
-
66
- class Lead
67
- attr_accessor :stats
68
- def initialize(args)
69
- args.each{ |k,v| self.send("#{k}=", v) }
70
- end
71
- end
72
-
73
- class LeadStat
74
- attr_accessor :date
75
- attr_accessor :leads
76
- attr_accessor :conversion_rate
77
-
78
- def initialize(args)
79
- args.each{ |k,v| self.send("#{k}=", v) }
80
- end
81
-
82
- def short_date
83
- self.date.to_s(:concise)
84
- end
85
-
86
- end
87
-
88
- end
89
-
90
- end
@@ -1,219 +0,0 @@
1
- module Mitamirri
2
-
3
- class SessionReport
4
-
5
- # Search params
6
- attr_accessor :action_kind
7
- attr_accessor :site
8
- attr_accessor :time_period
9
- attr_accessor :visit_kind
10
-
11
- # Initialization
12
-
13
- def initialize(args = {})
14
- args.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}
15
- self.time_period = args[:time_period] || 'past 6 months'
16
- self.sessions
17
- end
18
-
19
- def criteria
20
- _criteria = self.sessions.to_hash
21
- _criteria.delete(:sort)
22
- _criteria
23
- end
24
-
25
- def sessions
26
- @sessions ||= TrackableSession.search(
27
- :action_kind => self.action_kind,
28
- :site => self.site,
29
- :time_period => self.time_period,
30
- :visit_kind => self.visit_kind
31
- )
32
- end
33
-
34
- # Generate an array of dates spanning the appropriate time period.
35
- def dates
36
- return @dates if @dates
37
- @dates = []
38
- case self.time_period
39
- when 'past month'
40
- _increment = 1
41
- when 'past 3 months'
42
- _increment = 2
43
- when 'past 6 months'
44
- _increment = 5
45
- when 'past 12 months'
46
- _increment = 11
47
- else 'all time'
48
- _increment = 24
49
- end
50
-
51
- (1.._increment).each{ |i| @dates << (Time.zone.now - i.months).beginning_of_month }
52
- @dates.reverse!
53
- @dates << Time.zone.now.end_of_month
54
- @dates
55
- end
56
-
57
- # Graphing data
58
- def self.keywords_by_frequency(args)
59
- TrackableSession.keywords_histogram(args).inject([]){|a,v| a << KeywordStat.new(:keyword => v[0], :count => v[1]); a}.sort{|a,b| a.count <=> b.count}.reverse[0..24]
60
- end
61
-
62
- def self.top_referrers(args)
63
- TrackableSession.referrers_histogram(args).inject([]){|a,v| a << ReferrerStat.new(:referrer => v[0], :count => v[1]); a}.sort{|a,b| a.count <=> b.count}.reverse[0..24]
64
- end
65
-
66
- def visits(args)
67
- _visits = []
68
- _visits << Visit.new(:kind => "#{args[:visit_kind].titleize} Visits", :stats => visit_stats(args))
69
- _visits
70
- end
71
-
72
- def visit_stats(args)
73
- _visit_stats = []
74
- dates.each do |date|
75
- _visit_stats << VisitStat.new(:date => date, :visits => TrackableSession.search_without_date(args).for_month(date).count)
76
- end
77
- _visit_stats
78
- end
79
-
80
- # Statistics
81
-
82
- def average_pages_per_visit
83
- sprintf("%.1f", total_pageviews / total_visits.to_f)
84
- end
85
-
86
- def average_time_on_site
87
- average = total_duration / total_visits.to_f
88
- average > 60 ? sprintf("%.1f minutes", average / 60.0) : sprintf("%.1f seconds", average)
89
- end
90
-
91
- def bounce_rate
92
- bounce_rate = total_bounces / total_visits.to_f
93
- sprintf("%.1f%", bounce_rate * 100)
94
- end
95
-
96
- def conversion_rate
97
- conversion_rate = total_conversions / total_visits.to_f
98
- sprintf("%.1f%", conversion_rate * 100)
99
- end
100
-
101
- def total_bounces
102
- @total_bounces ||= self.sessions.bounces.count
103
- end
104
-
105
- def total_clickthroughs
106
- @total_clickthroughs ||= self.sessions.with_clickthroughs.count
107
- end
108
-
109
- def total_clickthroughs_percentage
110
- sprintf("%.1f%", (total_clickthroughs / total_visits.to_f) * 100)
111
- end
112
-
113
- def total_conversions
114
- @total_conversions ||= self.sessions.with_conversions.count
115
- end
116
-
117
- def total_direct_visits
118
- @total_direct_visits ||= self.sessions.direct_visits.count
119
- end
120
-
121
- def total_duration
122
- @total_duration ||= TrackableSession.collection.group(["site"], self.criteria, {:duration => 0}, "function(doc,prev) { prev.duration += doc.duration}", true).map{|x| x['duration']}.sum.to_i
123
- end
124
-
125
- def total_new_visits
126
- @total_new_visits ||= self.sessions.new_visits.count
127
- end
128
-
129
- def total_return_visits
130
- @total_return_visits ||= total_visits - total_new_visits
131
- end
132
-
133
- def total_organic_visits
134
- @total_organic_visits ||= self.sessions.organic_visits.count
135
- end
136
-
137
- def total_pageviews
138
- @total_pageviews ||= TrackableSession.collection.group(["site"], self.criteria, {:views_count => 0}, "function(doc,prev) { prev.views_count += doc.views_count}", true).map{|x| x['views_count']}.sum.to_i
139
- end
140
-
141
- def total_ppc_visits
142
- @total_ppc_visits ||= self.sessions.ppc_visits.count
143
- end
144
-
145
- def total_search_visits
146
- @total_search_visits ||= self.sessions.search_visits.count
147
- end
148
-
149
- def total_direct_visits_percentage
150
- sprintf("%.1f%", (total_direct_visits / total_visits.to_f) * 100)
151
- end
152
-
153
- def total_organic_visits_percentage
154
- sprintf("%.1f%", (total_organic_visits / total_visits.to_f) * 100)
155
- end
156
-
157
- def total_new_visits_percentage
158
- sprintf("%.1f%", (total_new_visits / total_visits.to_f) * 100)
159
- end
160
-
161
- def total_ppc_visits_percentage
162
- sprintf("%.1f%", (total_ppc_visits / total_visits.to_f) * 100)
163
- end
164
-
165
- def total_return_visits_percentage
166
- sprintf("%.1f%", (total_return_visits / total_visits.to_f) * 100)
167
- end
168
-
169
- def total_search_visits_percentage
170
- sprintf("%.1f%", (total_search_visits / total_visits.to_f) * 100)
171
- end
172
-
173
- def total_visits
174
- @total_visits ||= self.sessions.count
175
- end
176
-
177
- # Inner stat classes
178
- class KeywordStat
179
- attr_accessor :keyword
180
- attr_accessor :count
181
- def initialize(args)
182
- args.each{ |k,v| self.send("#{k}=", v) }
183
- end
184
- end
185
-
186
- class ReferrerStat
187
- attr_accessor :referrer
188
- attr_accessor :count
189
- def initialize(args)
190
- args.each{ |k,v| self.send("#{k}=", v) }
191
- end
192
- end
193
-
194
- class Visit
195
- attr_accessor :kind
196
- attr_accessor :date
197
- attr_accessor :stats
198
- def initialize(args)
199
- args.each{ |k,v| self.send("#{k}=", v) }
200
- end
201
- end
202
-
203
- class VisitStat
204
- attr_accessor :date
205
- attr_accessor :visits
206
-
207
- def initialize(args)
208
- args.each{ |k,v| self.send("#{k}=", v) }
209
- end
210
-
211
- def short_date
212
- self.date.to_s(:month_year)
213
- end
214
-
215
- end
216
-
217
- end
218
-
219
- end