FEATURE: page view stats for mobile view

This commit is contained in:
Neil Lalonde 2015-07-03 17:02:57 -04:00
parent db75774440
commit 86cd1a19cc
5 changed files with 25 additions and 5 deletions

View file

@ -7,7 +7,9 @@ class ApplicationRequest < ActiveRecord::Base
http_5xx http_5xx
page_view_crawler page_view_crawler
page_view_logged_in page_view_logged_in
page_view_anon) page_view_anon
page_view_logged_in_mobile
page_view_anon_mobile)
cattr_accessor :autoflush, :autoflush_seconds, :last_flush cattr_accessor :autoflush, :autoflush_seconds, :last_flush
# auto flush if backlog is larger than this # auto flush if backlog is larger than this

View file

@ -57,7 +57,7 @@ class Report
data = data =
if filter == :page_view_total if filter == :page_view_total
ApplicationRequest.where(req_type: [ ApplicationRequest.where(req_type: [
ApplicationRequest.req_types.map{|k,v| v if k =~ /page_view/}.compact ApplicationRequest.req_types.reject{|k,v| k =~ /mobile/}.map{|k,v| v if k =~ /page_view/}.compact
]) ])
else else
ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter]) ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])

View file

@ -652,6 +652,14 @@ en:
title: "Total" title: "Total"
xaxis: "Day" xaxis: "Day"
yaxis: "Total API Requests" yaxis: "Total API Requests"
page_view_logged_in_mobile_reqs:
title: "Mobile Logged In"
xaxis: "Day"
yaxis: "Mobile Logged In API Requests"
page_view_anon_mobile_reqs:
title: "Mobile Anon"
xaxis: "Day"
yaxis: "Mobile Anon API Requests"
http_background_reqs: http_background_reqs:
title: "Background" title: "Background"
xaxis: "Day" xaxis: "Day"

View file

@ -21,8 +21,10 @@ class Middleware::RequestTracker
ApplicationRequest.increment!(:page_view_crawler) ApplicationRequest.increment!(:page_view_crawler)
elsif data[:has_auth_cookie] elsif data[:has_auth_cookie]
ApplicationRequest.increment!(:page_view_logged_in) ApplicationRequest.increment!(:page_view_logged_in)
ApplicationRequest.increment!(:page_view_logged_in_mobile) if data[:is_mobile]
else else
ApplicationRequest.increment!(:page_view_anon) ApplicationRequest.increment!(:page_view_anon)
ApplicationRequest.increment!(:page_view_anon_mobile) if data[:is_mobile]
end end
end end
@ -62,6 +64,7 @@ class Middleware::RequestTracker
is_crawler: helper.is_crawler?, is_crawler: helper.is_crawler?,
has_auth_cookie: helper.has_auth_cookie?, has_auth_cookie: helper.has_auth_cookie?,
is_background: request.path =~ /^\/message-bus\// || request.path == /\/topics\/timings/, is_background: request.path =~ /^\/message-bus\// || request.path == /\/topics\/timings/,
is_mobile: helper.is_mobile?,
track_view: track_view track_view: track_view
} }
end end

View file

@ -50,13 +50,20 @@ describe Middleware::RequestTracker do
Middleware::RequestTracker.log_request(data) Middleware::RequestTracker.log_request(data)
data = Middleware::RequestTracker.get_data(env(
"HTTP_USER_AGENT" => "Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B410 Safari/600.1.4"
), ["200",{"Content-Type" => 'text/html'}])
Middleware::RequestTracker.log_request(data)
ApplicationRequest.write_cache! ApplicationRequest.write_cache!
expect(ApplicationRequest.http_total.first.count).to eq(2) expect(ApplicationRequest.http_total.first.count).to eq(3)
expect(ApplicationRequest.http_2xx.first.count).to eq(2) expect(ApplicationRequest.http_2xx.first.count).to eq(3)
expect(ApplicationRequest.page_view_anon.first.count).to eq(1) expect(ApplicationRequest.page_view_anon.first.count).to eq(2)
expect(ApplicationRequest.page_view_crawler.first.count).to eq(1) expect(ApplicationRequest.page_view_crawler.first.count).to eq(1)
expect(ApplicationRequest.page_view_anon_mobile.first.count).to eq(1)
end end
end end
end end