Class: Sentiero::Web::Views::AnalyticsIndexView
- Inherits:
-
BaseView
- Object
- BaseView
- Sentiero::Web::Views::AnalyticsIndexView
show all
- Defined in:
- lib/sentiero/web/views/analytics_index_view.rb
Constant Summary
collapse
- BUCKET_COLORS =
%w[#2563eb #7c3aed #db2777 #ea580c #16a34a].freeze
Constants inherited
from BaseView
BaseView::TEMPLATES_DIR, BaseView::TEMPLATE_CACHE
Constants included
from Escaping
Escaping::HTML_UNSAFE_IN_SCRIPT, Escaping::HTML_UNSAFE_IN_SCRIPT_PATTERN
Instance Attribute Summary collapse
Attributes inherited from BaseView
#base_path, #csrf_token
Instance Method Summary
collapse
Methods inherited from BaseView
#built_asset, compiled_template, #escape_js, #h, #range_pairs, #render, #render_layout, #render_partial, #render_session_row
Methods included from Formatting
#format_duration, #format_vital, #parse_browser, #parse_device
Methods included from Escaping
#escape_html, #escape_js_string, #escape_json
Constructor Details
#initialize(range_days:, allowed_ranges:, custom_range:, since:, until_str:, deltas:, stats:) ⇒ AnalyticsIndexView
Returns a new instance of AnalyticsIndexView.
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 13
def initialize(range_days:, allowed_ranges:, custom_range:, since:, until_str:, deltas:, stats:)
super()
@range_days = range_days
@allowed_ranges = allowed_ranges
@custom_range = custom_range
@since = since
@until_str = until_str
@deltas = deltas
@stats = stats
end
|
Instance Attribute Details
#allowed_ranges ⇒ Object
Returns the value of attribute allowed_ranges.
24
25
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 24
def allowed_ranges
@allowed_ranges
end
|
#custom_range ⇒ Object
Returns the value of attribute custom_range.
24
25
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 24
def custom_range
@custom_range
end
|
#deltas ⇒ Object
Returns the value of attribute deltas.
24
25
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 24
def deltas
@deltas
end
|
#range_days ⇒ Object
Returns the value of attribute range_days.
24
25
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 24
def range_days
@range_days
end
|
#since ⇒ Object
Returns the value of attribute since.
24
25
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 24
def since
@since
end
|
#stats ⇒ Object
Returns the value of attribute stats.
24
25
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 24
def stats
@stats
end
|
#until_str ⇒ Object
Returns the value of attribute until_str.
24
25
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 24
def until_str
@until_str
end
|
Instance Method Details
62
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 62
def browser_tags = stats[:browser_event_tags] || {}
|
#bucket_colors ⇒ Object
57
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 57
def bucket_colors = BUCKET_COLORS
|
#bucket_total ⇒ Object
56
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 56
def bucket_total = buckets.values.sum
|
#buckets ⇒ Object
55
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 55
def buckets = stats[:session_duration_buckets] || {}
|
61
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 61
def custom_tags = stats[:custom_event_tags] || {}
|
#distributions ⇒ Object
48
49
50
51
52
53
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 48
def distributions
[
["Browsers", stats[:browser_distribution], "No browser data."],
["Devices", stats[:device_distribution], "No device data."]
]
end
|
#donut_circumference ⇒ Object
59
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 59
def donut_circumference = 2 * Math::PI * donut_radius
|
#donut_radius ⇒ Object
58
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 58
def donut_radius = 42
|
#err_pct(row) ⇒ Object
78
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 78
def err_pct(row) = (row[:count].to_i > 0) ? (row[:error_count].to_f / row[:count] * 100).round : 0
|
#max_events ⇒ Object
45
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 45
def max_events = series.map { |d| d[:event_count] }.max || 0
|
#max_sessions ⇒ Object
46
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 46
def max_sessions = series.map { |d| d[:session_count] }.max || 0
|
#nav_sections(nav) ⇒ Object
80
81
82
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 80
def nav_sections(nav)
[["Internal destinations", nav[:internal] || []], ["External destinations", nav[:external] || []]]
end
|
#range_qs ⇒ Object
An active custom range is carried into the range-scoped cross-links
(the open-problems count is all-time, so its link stays unscoped).
38
39
40
41
42
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 38
def range_qs
return "" unless custom_range
"&" + Rack::Utils.build_query(range_pairs)
end
|
#render_delta(value, attr, unit) ⇒ Object
Sessions/events deltas are % change; the error-free rate is percentage points.
29
30
31
32
33
34
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 29
def render_delta(value, attr, unit)
return "" if value.nil?
arrow = (value >= 0) ? "▲" : "▼"
color = (value >= 0) ? "#16a34a" : "#dc2626"
%(<span class="normal-case tracking-normal tabular-nums" style="color:#{color}" data-#{attr}="#{value}" title="vs previous period">#{arrow} #{value.abs}#{unit}</span>)
end
|
#seg_href(row) ⇒ Object
74
75
76
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 74
def seg_href(row)
"#{base_path}/analytics/segments?" + Rack::Utils.build_query({"url_pattern" => row[:url], "has_errors" => "true"})
end
|
#series ⇒ Object
44
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 44
def series = stats[:events_per_day_series] || []
|
#tag_day_series(tag) ⇒ Object
71
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 71
def tag_day_series(tag) = tag_series[tag] || []
|
#tag_href(tag) ⇒ Object
65
66
67
68
69
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 65
def tag_href(tag)
q = "search=#{CGI.escape(tag)}"
q = "source=browser&#{q}" if browser_tags.key?(tag)
"#{base_path}/custom-events?#{q}"
end
|
#tag_series ⇒ Object
63
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 63
def tag_series = stats[:custom_event_tag_series] || {}
|
#tag_series_max(tag) ⇒ Object
72
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 72
def tag_series_max(tag) = tag_day_series(tag).map { |day| day[:count] }.max.to_i
|
#template ⇒ Object
26
|
# File 'lib/sentiero/web/views/analytics_index_view.rb', line 26
def template = "analytics_index.html.erb"
|