module RedisAnalytics::Metrics
Attributes
first_visits_count_per_visit[R]
page_views_count_per_hit[R]
repeat_visits_count_per_visit[R]
second_page_views_count_per_hit[R]
unique_visits_ratio_per_visit[R]
visit_time_count_per_visit[R]
visits_count_per_visit[R]
Public Instance Methods
browser_ratio_per_visit()
click to toggle source
Developers can override or define new public methods here Methods should start with track and end with count or types Return types should be Integer or String resp. If you return nil or an error nothing will be tracked
# File lib/redis_analytics/metrics.rb, line 14 def browser_ratio_per_visit user_agent.name.to_s end
country_ratio_per_visit()
click to toggle source
# File lib/redis_analytics/metrics.rb, line 22 def country_ratio_per_visit if defined?(GeoIP) begin g = GeoIP.new(RedisAnalytics.geo_ip_data_path) geo_country_code = g.country(@rack_request.ip).to_hash[:country_code2] if geo_country_code and geo_country_code =~ /^[A-Z]{2}$/ return geo_country_code end rescue Exception => e warn "Unable to fetch country info #{e}" end end end
device_ratio_per_visit()
click to toggle source
# File lib/redis_analytics/metrics.rb, line 52 def device_ratio_per_visit return ((user_agent.mobile? or user_agent.tablet?) ? 'mobile' : 'desktop') end
http_response_ratio_per_hit()
click to toggle source
track the landing pages ratio
# File lib/redis_analytics/metrics.rb, line 84 def http_response_ratio_per_hit return @rack_response.status.to_s end
landing_page_ratio_per_hit()
click to toggle source
track the landing pages ratio
# File lib/redis_analytics/metrics.rb, line 79 def landing_page_ratio_per_hit return @rack_request.path if @page_view_seq_no.to_i == 0 end
platform_ratio_per_visit()
click to toggle source
# File lib/redis_analytics/metrics.rb, line 18 def platform_ratio_per_visit user_agent.platform.to_s end
recency_ratio_per_visit()
click to toggle source
# File lib/redis_analytics/metrics.rb, line 36 def recency_ratio_per_visit # tracking for visitor recency if @last_visit_time # from first_visit_cookie days_since_last_visit = ((@t.to_i - @last_visit_time.to_i)/(24*3600)).round if days_since_last_visit <= 1 return 'd' elsif days_since_last_visit <= 7 return 'w' elsif days_since_last_visit <= 30 return 'm' else return 'o' end end end
referrer_ratio_per_visit()
click to toggle source
# File lib/redis_analytics/metrics.rb, line 56 def referrer_ratio_per_visit if @rack_request.referrer ['google', 'bing', 'yahoo', 'cleartrip', 'github'].each do |referrer| # this will track x.google.mysite.com as google so its buggy, fix the regex if m = @rack_request.referrer.match(/^(https?:\/\/)?([a-zA-Z0-9\.\-]+\.)?(#{referrer})\.([a-zA-Z\.]+)(:[0-9]+)?(\/.*)?$/) "REFERRER => #{m.to_a[3]}" referrer = m.to_a[3] else referrer = 'other' end end else referrer = 'organic' end return referrer end
url_ratio_per_hit()
click to toggle source
track the ratio of URL's visits
# File lib/redis_analytics/metrics.rb, line 74 def url_ratio_per_hit return @rack_request.path end
Private Instance Methods
user_agent()
click to toggle source
# File lib/redis_analytics/metrics.rb, line 89 def user_agent Browser.new(:ua => @rack_request.user_agent, :accept_language => 'en-us') end