Module: RedisAnalytics::Metrics
- Included in:
- Visit
- Defined in:
- lib/redis_analytics/metrics.rb
Instance Attribute Summary collapse
-
#first_visits_count_per_visit ⇒ Object
readonly
Returns the value of attribute first_visits_count_per_visit.
-
#page_views_count_per_hit ⇒ Object
readonly
Returns the value of attribute page_views_count_per_hit.
-
#repeat_visits_count_per_visit ⇒ Object
readonly
Returns the value of attribute repeat_visits_count_per_visit.
-
#second_page_views_count_per_hit ⇒ Object
readonly
Returns the value of attribute second_page_views_count_per_hit.
-
#unique_visits_ratio_per_visit ⇒ Object
readonly
Returns the value of attribute unique_visits_ratio_per_visit.
-
#visit_time_count_per_visit ⇒ Object
readonly
Returns the value of attribute visit_time_count_per_visit.
-
#visits_count_per_visit ⇒ Object
readonly
Returns the value of attribute visits_count_per_visit.
Instance Method Summary collapse
-
#browser_ratio_per_visit ⇒ Object
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.
- #country_ratio_per_visit ⇒ Object
- #device_ratio_per_visit ⇒ Object
-
#http_response_ratio_per_hit ⇒ Object
track the landing pages ratio.
-
#landing_page_ratio_per_hit ⇒ Object
track the landing pages ratio.
- #platform_ratio_per_visit ⇒ Object
- #recency_ratio_per_visit ⇒ Object
- #referrer_ratio_per_visit ⇒ Object
-
#url_ratio_per_hit ⇒ Object
track the ratio of URL’s visits.
Instance Attribute Details
#first_visits_count_per_visit ⇒ Object (readonly)
Returns the value of attribute first_visits_count_per_visit.
5 6 7 |
# File 'lib/redis_analytics/metrics.rb', line 5 def first_visits_count_per_visit @first_visits_count_per_visit end |
#page_views_count_per_hit ⇒ Object (readonly)
Returns the value of attribute page_views_count_per_hit.
7 8 9 |
# File 'lib/redis_analytics/metrics.rb', line 7 def page_views_count_per_hit @page_views_count_per_hit end |
#repeat_visits_count_per_visit ⇒ Object (readonly)
Returns the value of attribute repeat_visits_count_per_visit.
5 6 7 |
# File 'lib/redis_analytics/metrics.rb', line 5 def repeat_visits_count_per_visit @repeat_visits_count_per_visit end |
#second_page_views_count_per_hit ⇒ Object (readonly)
Returns the value of attribute second_page_views_count_per_hit.
7 8 9 |
# File 'lib/redis_analytics/metrics.rb', line 7 def second_page_views_count_per_hit @second_page_views_count_per_hit end |
#unique_visits_ratio_per_visit ⇒ Object (readonly)
Returns the value of attribute unique_visits_ratio_per_visit.
6 7 8 |
# File 'lib/redis_analytics/metrics.rb', line 6 def unique_visits_ratio_per_visit @unique_visits_ratio_per_visit end |
#visit_time_count_per_visit ⇒ Object (readonly)
Returns the value of attribute visit_time_count_per_visit.
4 5 6 |
# File 'lib/redis_analytics/metrics.rb', line 4 def visit_time_count_per_visit @visit_time_count_per_visit end |
#visits_count_per_visit ⇒ Object (readonly)
Returns the value of attribute visits_count_per_visit.
5 6 7 |
# File 'lib/redis_analytics/metrics.rb', line 5 def visits_count_per_visit @visits_count_per_visit end |
Instance Method Details
#browser_ratio_per_visit ⇒ Object
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
14 15 16 |
# File 'lib/redis_analytics/metrics.rb', line 14 def browser_ratio_per_visit user_agent.name.to_s end |
#country_ratio_per_visit ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
52 53 54 |
# 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 ⇒ Object
track the landing pages ratio
84 85 86 |
# 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 ⇒ Object
track the landing pages ratio
79 80 81 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/redis_analytics/metrics.rb', line 18 def platform_ratio_per_visit user_agent.platform.to_s end |
#recency_ratio_per_visit ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 ⇒ Object
track the ratio of URL’s visits
74 75 76 |
# File 'lib/redis_analytics/metrics.rb', line 74 def url_ratio_per_hit return @rack_request.path end |