More Related Content Similar to Rugalytics | Ruby Manor Nov 2008 (20) Rugalytics | Ruby Manor Nov 200813. <MiniTable id=quot;BrowserMiniTablequot;>
<Row>
<Cell>
<Content>
<Value>8,995</Value>
</Content>
</Cell>
<Cell>
<Content>
<Value>70.79%</Value>
</Content>
</Cell>
<PrimaryKey>IE</PrimaryKey>
</Row>
<Row>
21. to
emerge
class
definitions
from data
at runtime
Photo: brilarian http://flickr.com/photos/bybri/4443691/
32. Morph
Photo: Salt Fired
http://www.flickr.com/photos/saltfired/201998836/
37. under
the
rug
Photo: LizMarie http://flickr.com/photos/perspicacious/104917207/
38. def morph_method_missing symbol,*args
attribute = symbol.to_s.chomp '='
base.class_eval quot;def #{attribute};
@#{attribute}; end;
def #{attribute}=(value);
@#{attribute} = value; endquot;
send(symbol, *args)
40. > klass = Rugalytics::Item
> y Ruby2Ruby.translate(klass)
41. class Rugalytics::Item < Object
def bounce_rate
@bounce_rate
end
def bounce_rate=(value)
@bounce_rate = value
end
def dollar_index
@dollar_index
end
def dollar_index=(value)
@dollar_index = value
end
def initialize(labels, values, base_url)
labels.each_with_index do |label,
index|
...
44. def top_content days
profile = Rugalytics.default_profile
from_date = Date.today - days
report = profile.top_content_report
:from => from_date
45. items = report.items
items = items.sort_by { |i|
i.unique_pageviews.to_i}
items = items.reverse
items = items[0..9] if items.size >10
items
end
47. %ul
- @top_pages.each do |item|
%li
= link_to(item.page_title,
item.url)
%span.page_views
=quot;(#{item.unique_pageviews})quot;
49. def get_report_csv(options={})
options = set_default_options(options)
params =
convert_options_to_uri_params(options)
self.class.get(
quot;https://google.com/analytics/
reporting/exportquot;,
:query_hash => params)
end
50. def set_default_options(options)
options.reverse_merge!({
:report => 'Dashboard',
:from => a_month_ago,
:to => today,
:tab => 0,
:format => FORMAT_CSV,
:rows => 50,
:compute => 'average',
:gdfmt => 'nth_day',
:view => 0
})
51. def convert_options_to_uri_params(options)
params = {
:pdr => quot;#{options[:from]}-
#{options[:to]}quot;,
:rpt =>
quot;#{options[:report]}Reportquot;,
:cmp => options[:compute],
:fmt => options[:format],
:view => options[:view],
:tab => options[:tab],
:trows=> options[:rows],
:gdfmt=> options[:gdfmt],
:id => profile_id
}
52. > profile.report_names
=> [quot;ad_versions_reportquot;, quot;adwords_reportquot;,
quot;all_sources_reportquot;, quot;average_pageviews_reportquot;,
quot;bounce_rate_reportquot;,quot;browsers_reportquot;,quot;campaigns_reportquot;,
quot;colors_reportquot;, quot;content_by_title_reportquot;,
quot;content_drilldown_reportquot;, quot;content_reportquot;,
quot;dashboard_reportquot;, quot;depth_of_visit_reportquot;,
quot;direct_sources_reportquot;, quot;entrances_reportquot;,
quot;exits_reportquot;,quot;flash_reportquot;,quot;geo_map_reportquot;,quot;hostnames_
reportquot;,quot;java_reportquot;,quot;keyword_position_reportquot;,
quot;keywords_reportquot;,quot;languages_reportquot;,quot;length_of_visit_repo
rtquot;,quot;loyalty_reportquot;,quot;networks_reportquot;,quot;os_browsers_report
quot;,quot;pageviews_reportquot;,quot;platforms_reportquot;,quot;recency_reportquot;,quot;
referring_sources_reportquot;, quot;resolutions_reportquot;,
quot;search_engines_reportquot;,quot;speeds_reportquot;,quot;time_on_site_repo
rtquot;,quot;top_content_detail_keywords_reportquot;,quot;top_content_deta
il_navigation_reportquot;, quot;top_content_detail_path_reportquot;,
quot;top_content_detail_sources_reportquot;, quot;top_content_reportquot;,
quot;traffic_sources_reportquot;, quot;unique_visitors_reportquot;,
quot;visitor_types_reportquot;, quot;visitors_overview_reportquot;,
quot;visits_reportquot;]
76. Rug rat
Photo: Ozyman http://flickr.com/photos/ozyman/465113688/
80. def call(env)
path = env['PATH_INFO'].tr('/','')
request = Rack::Request.new(env)
report_name = (path + '_report').to_sym
params = request.GET.symbolize_keys
report = @profile.send(report_name, params)
data = { :report_name => report.name,
:items => report.items}
[200, {'Content-Type' =>
quot;application/jsonquot;}, data.to_json ]
end
81. {
quot;report_namequot;:
quot;Entrance Keywords:,/mpsquot;,
quot;itemsquot;: [
{quot;bounce_ratequot;: quot;0.0quot;,
quot;pageviewsquot;: quot;17quot;,
quot;percentage_exitquot;: quot;0.058823529quot;,
quot;time_on_pagequot;: quot;21.9375quot;,
quot;dollar_indexquot;: quot;0.0quot;,
quot;keywordquot;: quot;gordon copelandquot;,
quot;unique_pageviewsquot;: quot;10quot;},