mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: page view stats for mobile view
This commit is contained in:
parent
db75774440
commit
86cd1a19cc
5 changed files with 25 additions and 5 deletions
|
@ -7,7 +7,9 @@ class ApplicationRequest < ActiveRecord::Base
|
|||
http_5xx
|
||||
page_view_crawler
|
||||
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
|
||||
# auto flush if backlog is larger than this
|
||||
|
|
|
@ -57,7 +57,7 @@ class Report
|
|||
data =
|
||||
if filter == :page_view_total
|
||||
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
|
||||
ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])
|
||||
|
|
|
@ -652,6 +652,14 @@ en:
|
|||
title: "Total"
|
||||
xaxis: "Day"
|
||||
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:
|
||||
title: "Background"
|
||||
xaxis: "Day"
|
||||
|
|
|
@ -21,8 +21,10 @@ class Middleware::RequestTracker
|
|||
ApplicationRequest.increment!(:page_view_crawler)
|
||||
elsif data[:has_auth_cookie]
|
||||
ApplicationRequest.increment!(:page_view_logged_in)
|
||||
ApplicationRequest.increment!(:page_view_logged_in_mobile) if data[:is_mobile]
|
||||
else
|
||||
ApplicationRequest.increment!(:page_view_anon)
|
||||
ApplicationRequest.increment!(:page_view_anon_mobile) if data[:is_mobile]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,6 +64,7 @@ class Middleware::RequestTracker
|
|||
is_crawler: helper.is_crawler?,
|
||||
has_auth_cookie: helper.has_auth_cookie?,
|
||||
is_background: request.path =~ /^\/message-bus\// || request.path == /\/topics\/timings/,
|
||||
is_mobile: helper.is_mobile?,
|
||||
track_view: track_view
|
||||
}
|
||||
end
|
||||
|
|
|
@ -50,13 +50,20 @@ describe Middleware::RequestTracker do
|
|||
|
||||
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!
|
||||
|
||||
expect(ApplicationRequest.http_total.first.count).to eq(2)
|
||||
expect(ApplicationRequest.http_2xx.first.count).to eq(2)
|
||||
expect(ApplicationRequest.http_total.first.count).to eq(3)
|
||||
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_anon_mobile.first.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue