ahoy_captain 0.9 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/app/assets/javascript/ahoy_captain/controllers/active_links_controller.js +19 -3
- data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +8 -0
- data/app/assets/javascript/ahoy_captain/controllers/combobox_controller.js +341 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter_modal_controller.js +45 -0
- data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +58 -16
- data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +5 -0
- data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +170 -19
- data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +0 -1
- data/app/assets/javascript/ahoy_captain/controllers/properties_controller.js +8 -0
- data/app/assets/javascript/ahoy_captain/controllers/property_filter_controller.js +46 -0
- data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +4 -2
- data/app/assets/javascript/ahoy_captain/controllers/tile_controller.js +9 -0
- data/app/assets/javascript/ahoy_captain/helpers/chart_utils.js +156 -0
- data/app/assets/javascript/ahoy_captain/helpers/number_formatters.js +55 -0
- data/app/components/ahoy_captain/combobox_component.html.erb +33 -0
- data/app/components/ahoy_captain/combobox_component.rb +13 -0
- data/app/components/ahoy_captain/comparison_link_component.rb +40 -0
- data/app/components/ahoy_captain/filter/dropdown_component.html.erb +8 -6
- data/app/components/ahoy_captain/filter/modal_component.html.erb +7 -5
- data/app/components/ahoy_captain/filter/select_component.html.erb +23 -21
- data/app/components/ahoy_captain/filter/select_component.rb +2 -1
- data/app/components/ahoy_captain/filter/tag_component.html.erb +1 -1
- data/app/components/ahoy_captain/stats/comparable_container_component.html.erb +25 -0
- data/app/components/ahoy_captain/stats/comparable_container_component.rb +86 -0
- data/app/components/ahoy_captain/stats/container_component.html.erb +13 -6
- data/app/components/ahoy_captain/stats/container_component.rb +16 -1
- data/app/components/ahoy_captain/sticky_nav_component.html.erb +7 -4
- data/app/components/ahoy_captain/sticky_nav_component.rb +3 -0
- data/app/components/ahoy_captain/table_component.rb +13 -4
- data/app/components/ahoy_captain/tables/devices_table_component.rb +11 -0
- data/app/components/ahoy_captain/tables/dynamic_table.rb +13 -0
- data/app/components/ahoy_captain/tables/dynamic_table_component.rb +204 -0
- data/app/components/ahoy_captain/tables/goals_table_component.rb +17 -0
- data/app/components/ahoy_captain/tables/header_component.html.erb +5 -0
- data/app/components/ahoy_captain/tables/header_component.rb +18 -0
- data/app/components/ahoy_captain/tables/headers/header_component.rb +4 -0
- data/app/components/ahoy_captain/tables/properties_table_component.rb +27 -0
- data/app/components/ahoy_captain/tables/row_component.html.erb +4 -0
- data/app/components/ahoy_captain/tables/rows/row_component.rb +0 -1
- data/app/components/ahoy_captain/tile_component.html.erb +19 -9
- data/app/components/ahoy_captain/tile_component.rb +2 -1
- data/app/controllers/ahoy_captain/application_controller.rb +7 -16
- data/app/controllers/ahoy_captain/exports_controller.rb +1 -2
- data/app/controllers/ahoy_captain/filters/base_controller.rb +1 -3
- data/app/controllers/ahoy_captain/filters/goals_controller.rb +9 -0
- data/app/controllers/ahoy_captain/filters/pages/actions_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +4 -4
- data/app/controllers/ahoy_captain/filters/utms_controller.rb +1 -1
- data/app/controllers/ahoy_captain/properties_controller.rb +41 -0
- data/app/controllers/ahoy_captain/stats/base_controller.rb +86 -5
- data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +1 -1
- data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +1 -1
- data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +1 -1
- data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +2 -1
- data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +1 -10
- data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -1
- data/app/helpers/ahoy_captain/application_helper.rb +35 -9
- data/app/models/ahoy_captain/comparison_mode.rb +72 -0
- data/app/models/ahoy_captain/filter_parser.rb +33 -18
- data/app/models/ahoy_captain/range_from_params.rb +75 -0
- data/app/models/ahoy_captain/rangeable.rb +0 -3
- data/app/models/concerns/ahoy_captain/compare_mode.rb +19 -0
- data/app/models/concerns/ahoy_captain/limitable.rb +17 -0
- data/app/models/concerns/ahoy_captain/range_options.rb +1 -14
- data/app/presenters/ahoy_captain/dashboard_presenter.rb +18 -54
- data/app/queries/ahoy_captain/application_query.rb +74 -10
- data/app/queries/ahoy_captain/event_query.rb +7 -2
- data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +11 -4
- data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +14 -2
- data/app/queries/ahoy_captain/stats/base_query.rb +18 -0
- data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +15 -1
- data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +2 -2
- data/app/queries/ahoy_captain/stats/total_visitors_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/visit_duration_query.rb +3 -3
- data/app/queries/ahoy_captain/visit_query.rb +1 -2
- data/app/queries/concerns/ahoy_captain/comparable_queries.rb +25 -0
- data/app/queries/concerns/ahoy_captain/comparable_query.rb +138 -0
- data/app/queries/concerns/ahoy_captain/lazy_comparable_query.rb +42 -0
- data/app/views/ahoy_captain/devices/_table.html.erb +1 -4
- data/app/views/ahoy_captain/goals/index.html.erb +1 -4
- data/app/views/ahoy_captain/layouts/application.html.erb +0 -1
- data/app/views/ahoy_captain/properties/_form.html.erb +6 -0
- data/app/views/ahoy_captain/properties/index.html.erb +3 -0
- data/app/views/ahoy_captain/properties/show.html.erb +6 -0
- data/app/views/ahoy_captain/roots/_filters.html.erb +47 -1
- data/app/views/ahoy_captain/roots/show.html.erb +60 -31
- data/app/views/ahoy_captain/stats/base/index.html.erb +36 -8
- data/app/views/ahoy_captain/stats/show.html.erb +8 -10
- data/config/routes.rb +2 -0
- data/lib/ahoy_captain/ahoy/event_methods.rb +13 -15
- data/lib/ahoy_captain/configuration.rb +7 -6
- data/lib/ahoy_captain/engine.rb +4 -0
- data/lib/ahoy_captain/filters_configuration.rb +5 -1
- data/lib/ahoy_captain/version.rb +1 -1
- data/lib/ahoy_captain.rb +6 -1
- data/lib/generators/ahoy_captain/templates/config.rb.tt +7 -0
- metadata +35 -12
- data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +0 -20
- data/app/assets/javascript/ahoy_captain/controllers/search_select_controller.js +0 -65
- data/app/components/ahoy_captain/tables/headers/devices_header_component.html.erb +0 -3
- data/app/components/ahoy_captain/tables/headers/devices_header_component.rb +0 -9
- data/app/components/ahoy_captain/tables/headers/goals_header_component.html.erb +0 -6
- data/app/components/ahoy_captain/tables/headers/goals_header_component.rb +0 -9
- data/app/components/ahoy_captain/tables/rows/devices_row_component.html.erb +0 -5
- data/app/components/ahoy_captain/tables/rows/devices_row_component.rb +0 -12
- data/app/components/ahoy_captain/tables/rows/goals_row_component.html.erb +0 -11
- data/app/components/ahoy_captain/tables/rows/goals_row_component.rb +0 -20
@@ -0,0 +1,138 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module ComparableQuery
|
3
|
+
class Comparison
|
4
|
+
class ComparisonResult
|
5
|
+
attr_reader :current, :compared_to
|
6
|
+
def initialize(current, compared_to)
|
7
|
+
@current = current
|
8
|
+
@compared_to = compared_to
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(query)
|
13
|
+
@query = query
|
14
|
+
@params = @query.params.deep_dup
|
15
|
+
@compare = @query.class.call(comparison_params)
|
16
|
+
@model = @query.all.klass
|
17
|
+
@query_class = @query.class
|
18
|
+
end
|
19
|
+
|
20
|
+
def count(column_name = :id)
|
21
|
+
@operation = :count
|
22
|
+
@column = column_name
|
23
|
+
perform_calculations(:count, column_name)
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def average(column_name)
|
29
|
+
@operation = :average
|
30
|
+
@column = column_name
|
31
|
+
|
32
|
+
perform_calculations(:average, column_name)
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def perform_calculations(operation, column_name)
|
38
|
+
@query = perform_calculation(@query, operation, column_name)
|
39
|
+
@compare = perform_calculation(@compare, operation, column_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform_calculation(q, operation, column_name)
|
43
|
+
operation = operation.to_s.downcase
|
44
|
+
# If #count is used with #distinct (i.e. `relation.distinct.count`) it is
|
45
|
+
# considered distinct.
|
46
|
+
distinct = q.send(:distinct_value)
|
47
|
+
|
48
|
+
if operation == "count"
|
49
|
+
column_name ||= q.send(:select_for_count)
|
50
|
+
if column_name == :all
|
51
|
+
if !distinct
|
52
|
+
distinct = q.send(:distinct_select?, :select_for_count) if q.group_values.empty?
|
53
|
+
elsif q.send(:group_values).any? || q.send(:select_values).empty? && q.order_values.empty?
|
54
|
+
column_name = q.primary_key
|
55
|
+
end
|
56
|
+
elsif q.all.send(:distinct_select?, column_name)
|
57
|
+
distinct = nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if q.group_values.any?
|
62
|
+
raise "use a subquery"
|
63
|
+
else
|
64
|
+
execute_simple_calculation(q, operation, column_name, distinct)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def result
|
69
|
+
result = @model.with(
|
70
|
+
current: @query.to_sql,
|
71
|
+
compare: @compare.to_sql
|
72
|
+
).select("current, compare").from("current, compare")[0]
|
73
|
+
type = @query_class.cast_type(@column)
|
74
|
+
|
75
|
+
if result
|
76
|
+
current = @query_class.cast_value(type, result.current[1...-1])
|
77
|
+
compare = @query_class.cast_value(type, result.compare[1...-1])
|
78
|
+
else
|
79
|
+
current = @query_class.cast_value(type, '0')
|
80
|
+
compare = @query_class.cast_value(type, '0')
|
81
|
+
end
|
82
|
+
|
83
|
+
@result = ComparisonResult.new((current), (compare))
|
84
|
+
end
|
85
|
+
|
86
|
+
def compare_range
|
87
|
+
@compare_range ||= begin
|
88
|
+
og_range = range
|
89
|
+
[og_range[0] - (og_range[1] - og_range[0]), og_range[0]]
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def range
|
95
|
+
@range ||= @query.send(:range)
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def execute_simple_calculation(q, operation, column_name, distinct) # :nodoc:
|
101
|
+
if operation == "count" && (column_name == :all && distinct || q.has_limit_or_offset?)
|
102
|
+
# Shortcut when limit is zero.
|
103
|
+
return 0 if q.limit_value == 0
|
104
|
+
|
105
|
+
q.send(:build_count_subquery, q.spawn, column_name, distinct)
|
106
|
+
else
|
107
|
+
# PostgreSQL doesn't like ORDER BY when there are no GROUP BY
|
108
|
+
relation = q.all.unscope(:order).distinct!(false)
|
109
|
+
|
110
|
+
column = q.all.send(:aggregate_column, column_name)
|
111
|
+
select_value = q.all.send(:operation_over_aggregate_column, column, operation, distinct)
|
112
|
+
select_value.distinct = true if operation == "sum" && distinct
|
113
|
+
|
114
|
+
relation.select_values = [select_value]
|
115
|
+
|
116
|
+
relation.arel
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def comparison_params
|
121
|
+
params = @params.deep_dup
|
122
|
+
params.delete("period")
|
123
|
+
|
124
|
+
params[:start_date] = compare_range[0]
|
125
|
+
params[:end_date] = compare_range[1]
|
126
|
+
params
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def with_comparison(enabled = false)
|
131
|
+
if enabled
|
132
|
+
Comparison.new(self)
|
133
|
+
else
|
134
|
+
self
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module LazyComparableQuery
|
3
|
+
class LazyComparison
|
4
|
+
class LazyComparisonResult
|
5
|
+
attr_accessor :current, :compared_to
|
6
|
+
end
|
7
|
+
|
8
|
+
include ::AhoyCaptain::ComparableQueries
|
9
|
+
|
10
|
+
def initialize(query)
|
11
|
+
@query = query
|
12
|
+
@params = @query.params.deep_dup
|
13
|
+
@compare = @query.class.call(comparison_params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(name, *args)
|
17
|
+
perform_operations(name, *args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def perform_operations(name, *args)
|
21
|
+
@query = @query.public_send(name, *args)
|
22
|
+
@compare = @compare.public_send(name, *args)
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def result
|
28
|
+
return @result if @result
|
29
|
+
|
30
|
+
@result = LazyComparisonResult.new.tap { |comparison| comparison.current = @query; comparison.compared_to = @compare }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def with_lazy_comparison(enabled = false)
|
35
|
+
if enabled
|
36
|
+
LazyComparison.new(self)
|
37
|
+
else
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,5 +1,2 @@
|
|
1
1
|
<%= render AhoyCaptain::TableComponent.new(items: @devices,
|
2
|
-
|
3
|
-
unit_name: 'Visitors',
|
4
|
-
header: ::AhoyCaptain::Tables::Headers::DevicesHeaderComponent,
|
5
|
-
row: ::AhoyCaptain::Tables::Rows::DevicesRowComponent) %>
|
2
|
+
table: ::AhoyCaptain::Tables::DevicesTableComponent) %>
|
@@ -1,7 +1,4 @@
|
|
1
1
|
<%= turbo_frame_tag :goals do %>
|
2
2
|
<%= render AhoyCaptain::TableComponent.new(items: @presenter.goals,
|
3
|
-
|
4
|
-
row: ::AhoyCaptain::Tables::Rows::GoalsRowComponent) %>
|
5
|
-
|
6
|
-
|
3
|
+
table: ::AhoyCaptain::Tables::GoalsTableComponent) %>
|
7
4
|
<% end %>
|
@@ -21,7 +21,6 @@
|
|
21
21
|
<meta name="theme-color" content="#ffffff">
|
22
22
|
<link href="https://cdn.jsdelivr.net/npm/daisyui@3.5.0/dist/full.css" rel="stylesheet" type="text/css"/>
|
23
23
|
<script src="https://cdn.tailwindcss.com"></script>
|
24
|
-
<link href="https://unpkg.com/slim-select@latest/dist/slimselect.css" rel="stylesheet" />
|
25
24
|
<%= ahoy_captain_importmap_tags %>
|
26
25
|
<style>
|
27
26
|
/* Application styles */
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<select class="select text-accent-content bg-accent" data-controller="properties" data-action="change->properties#handleChange">
|
2
|
+
<option></option>
|
3
|
+
<% @options.each do |key, value| %>
|
4
|
+
<option value="<%= property_path(id: key) %>" <%= 'selected' if local_assigns[:selected] == value %>><%= value %></option>
|
5
|
+
<% end %>
|
6
|
+
</select>
|
@@ -6,12 +6,39 @@
|
|
6
6
|
<%= render AhoyCaptain::Filter::ModalComponent.new(title: "Filter by #{name}", id: "#{filters.modal_name}") do |modal| %>
|
7
7
|
<% modal.with_modal_display do %>
|
8
8
|
<% filters.each do |filter| %>
|
9
|
-
|
9
|
+
<%= render AhoyCaptain::Filter::SelectComponent.new(label: filter.label, column: filter.column, url: public_send(filter.url), predicates: filter.predicates, multiple: filter.multiple, form: form) %>
|
10
10
|
<% end %>
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
13
13
|
<% end %>
|
14
14
|
|
15
|
+
<%= render AhoyCaptain::Filter::ModalComponent.new(title: "Filter by Custom Property", id: "customPropertyFilterModal") do |modal| %>
|
16
|
+
<% modal.with_modal_display do %>
|
17
|
+
<div data-controller="property-filter">
|
18
|
+
<fieldset class="flex space-x-4 items-end">
|
19
|
+
<% if current_property_filter %>
|
20
|
+
<%= render ::AhoyCaptain::ComboboxComponent.new(name: "", multiple: false, column: "", url: filters_properties_names_path, value: [current_property_filter[:key].delete_prefix("properties.")], select_html: { "data-property-filter-target" => 'name', id: "property-name" }) %>
|
21
|
+
<% else %>
|
22
|
+
<%= render ::AhoyCaptain::ComboboxComponent.new(name: "", multiple: false, column: "", url: filters_properties_names_path, select_html: { "data-property-filter-target" => 'name', id: "property-name" } ) %>
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
<div class="flex flex-col w-[20%]">
|
26
|
+
<select class='select select-primary bg-gray-900 ring-0 focus-within:ring-0 focus-within:ring-0 focus:ring-0 focus:outline-none inline-flex justify-between items-center w-full rounded-md border px-4 py-2 text-sm'>
|
27
|
+
<option value="in">in</option>
|
28
|
+
</select>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<% if current_property_filter %>
|
32
|
+
<%= render ::AhoyCaptain::ComboboxComponent.new(name: "q[#{current_property_filter[:key]}_in]", multiple: false, column: "", url: filters_properties_values_path, value: [current_property_filter[:value]], select_html: { "data-property-filter-target" => 'value', id: "property-value" } ) %>
|
33
|
+
<% else %>
|
34
|
+
<%= render ::AhoyCaptain::ComboboxComponent.new(name: "", multiple: false, column: "", url: filters_properties_values_path, select_html: { "data-property-filter-target" => 'value', id: "property-value" }, disabled: true) %>
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
</fieldset>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
<% end %>
|
41
|
+
<% end %>
|
15
42
|
|
16
43
|
<%= render AhoyCaptain::Filter::ModalComponent.new(title: "Custom Range", id: "customRangeModal") do |modal| %>
|
17
44
|
<% modal.with_modal_display do %>
|
@@ -31,4 +58,23 @@
|
|
31
58
|
</div>
|
32
59
|
<% end %>
|
33
60
|
<% end %>
|
61
|
+
|
62
|
+
<%= render AhoyCaptain::Filter::ModalComponent.new(title: "Custom Comparison", id: "customComparisonModal") do |modal| %>
|
63
|
+
<% modal.with_modal_display do %>
|
64
|
+
<div class="flex gap-2 w-full">
|
65
|
+
<div class="form-control w-full max-w-xs">
|
66
|
+
<label class="label" for="start_date">
|
67
|
+
<span class="label-text">Start Date</span>
|
68
|
+
</label>
|
69
|
+
<input type="datetime-local" id="start_date" name="compare_to_start_date" class="input input-bordered w-full" value="<%= params[:compare_to_start_date] %>" />
|
70
|
+
</div>
|
71
|
+
<div class="form-control w-full max-w-xs">
|
72
|
+
<label class="label" for="end_date">
|
73
|
+
<span class="label-text">End Date</span>
|
74
|
+
</label>
|
75
|
+
<input type="datetime-local" id="end_date" name="compare_to_end_date" class="input input-bordered w-full" value="<%= params[:compare_to_end_date] %>" />
|
76
|
+
</div>
|
77
|
+
</div>
|
78
|
+
<% end %>
|
79
|
+
<% end %>
|
34
80
|
<% end %>
|
@@ -1,15 +1,19 @@
|
|
1
|
-
<main class='min-h-screen pb-4 max-w-6xl mx-auto' data-controller="application">
|
1
|
+
<main class='min-h-screen pb-4 max-w-6xl mx-auto' data-controller="application" data-action="combobox:init@window->application#comboboxInit">
|
2
2
|
<%= render AhoyCaptain::StickyNavComponent.new do |nav| %>
|
3
3
|
<% nav.with_realtime_update do %>
|
4
|
-
<%= turbo_frame_tag :realtime, src: realtime_path, data: { controller: "realtime" }, loading: :lazy %>
|
4
|
+
<%= turbo_frame_tag :realtime, src: realtime_path, data: { controller: "realtime", "realtime-interval-value" => AhoyCaptain.config.realtime_interval.to_i }, loading: :lazy %>
|
5
5
|
<% end %>
|
6
6
|
<% end %>
|
7
7
|
|
8
8
|
<div class="grid grid-cols-1 lg:grid-cols-2 grid-flow-row gap-4">
|
9
|
-
<%= render AhoyCaptain::TileComponent.new(wide: true) do |component| %>
|
9
|
+
<%= render AhoyCaptain::TileComponent.new(wide: true, classes: "p-4 m-2") do |component| %>
|
10
10
|
<% component.with_statistic_display do %>
|
11
11
|
<%= turbo_frame_tag :stats, src: stats_path(search_params), loading: :lazy %>
|
12
|
+
|
13
|
+
<%= turbo_frame_tag :chart, src: stats_unique_visitors_path(search_params) do %>
|
14
|
+
<% end %>
|
12
15
|
<% end %>
|
16
|
+
|
13
17
|
<% end %>
|
14
18
|
|
15
19
|
<%= render AhoyCaptain::TileComponent.new(title: 'Top Sources') do |component| %>
|
@@ -19,7 +23,9 @@
|
|
19
23
|
<%= render AhoyCaptain::DropdownLinkComponent.new(title: "Campaign") do |dropdown| %>
|
20
24
|
<% %w{utm_source utm_medium utm_term utm_content utm_campaign}.each do |source| %>
|
21
25
|
<% dropdown.with_option do %>
|
22
|
-
<a href="<%= public_send("campaign_#{source}_path".to_sym, **search_params) %>" class=""
|
26
|
+
<a href="<%= public_send("campaign_#{source}_path".to_sym, **search_params) %>" class=""
|
27
|
+
data-turbo-frame="sources"
|
28
|
+
data-active-links-target="link">
|
23
29
|
<%= source.titleize.gsub("Utm", "UTM") %>
|
24
30
|
</a>
|
25
31
|
<% end %>
|
@@ -37,11 +43,19 @@
|
|
37
43
|
|
38
44
|
<%= render AhoyCaptain::TileComponent.new(title: 'Top Pages') do |component| %>
|
39
45
|
<% component.with_display_links do %>
|
40
|
-
<div
|
41
|
-
<
|
42
|
-
|
43
|
-
|
46
|
+
<div class="flex text-xs font-medium text-gray-400 space-x-2">
|
47
|
+
<div class="relative inline-block text-left" data-controller="active-links"><div>
|
48
|
+
<a href="<%= top_pages_path(search_params) %>"
|
49
|
+
data-turbo-frame="pages"
|
50
|
+
class="inline-block h-5 font-semibold"
|
51
|
+
data-active-links-target="link"
|
52
|
+
data-action="click->tile#setTitle">Top Pages</a>
|
53
|
+
<a href="<%= entry_pages_path(search_params) %>" data-turbo-frame="pages" class="inline-block h-5 font-semibold" data-active-links-target="link" data-action="click->tile#setTitle">Entry Pages</a>
|
54
|
+
<a href="<%= exit_pages_path(search_params) %>" data-turbo-frame="pages" class="inline-block h-5 font-semibold" data-active-links-target="link" data-action="click->tile#setTitle">Exit Pages</a>
|
55
|
+
</div>
|
56
|
+
</div>
|
44
57
|
</div>
|
58
|
+
|
45
59
|
<% end %>
|
46
60
|
<% component.with_statistic_display do %>
|
47
61
|
<%= turbo_frame_tag :pages, src: top_pages_path(search_params), loading: :lazy %>
|
@@ -53,10 +67,13 @@
|
|
53
67
|
|
54
68
|
<%= render AhoyCaptain::TileComponent.new(title: 'Countries') do |component| %>
|
55
69
|
<% component.with_display_links do %>
|
56
|
-
<div
|
57
|
-
<
|
58
|
-
|
59
|
-
|
70
|
+
<div class="flex text-xs font-medium text-gray-400 space-x-2">
|
71
|
+
<div class="relative inline-block text-left" data-controller="active-links">
|
72
|
+
|
73
|
+
<a href="<%= countries_path(search_params) %>" data-turbo-frame="geography" class="inline-block h-5 font-semibold" data-active-links-target="link" data-action="click->tile#setTitle">Countries</a>
|
74
|
+
<a href="<%= regions_path(search_params) %>" data-turbo-frame="geography" class="inline-block h-5 font-semibold" data-active-links-target="link" data-action="click->tile#setTitle">Regions</a>
|
75
|
+
<a href="<%= cities_path(search_params) %>" data-turbo-frame="geography" class="inline-block h-5 font-semibold" data-active-links-target="link" data-action="click->tile#setTitle">Cities</a>
|
76
|
+
</div>
|
60
77
|
</div>
|
61
78
|
<% end %>
|
62
79
|
<% component.with_statistic_display do %>
|
@@ -69,10 +86,13 @@
|
|
69
86
|
|
70
87
|
<%= render AhoyCaptain::TileComponent.new(title: 'Devices') do |component| %>
|
71
88
|
<% component.with_display_links do %>
|
72
|
-
<div
|
73
|
-
<
|
74
|
-
|
75
|
-
|
89
|
+
<div class="flex text-xs font-medium text-gray-400 space-x-2">
|
90
|
+
<div class="relative inline-block text-left" data-controller="active-links">
|
91
|
+
|
92
|
+
<a href="<%= devices_browsers_path(search_params) %>" data-turbo-frame="devices" class=" inline-block h-5 font-semibold" data-active-links-target="link">Browser</a>
|
93
|
+
<a href="<%= devices_operating_systems_path(search_params) %>" data-turbo-frame="devices" class="inline-block h-5 font-semibold" data-active-links-target="link">OS</a>
|
94
|
+
<a href="<%= devices_device_types_path(search_params) %>" data-turbo-frame="devices" class="inline-block h-5 font-semibold" data-active-links-target="link">Size</a>
|
95
|
+
</div>
|
76
96
|
</div>
|
77
97
|
<% end %>
|
78
98
|
<% component.with_statistic_display do %>
|
@@ -82,30 +102,39 @@
|
|
82
102
|
<button data-action="click->details-modal#openModal" data-controller="details-modal" data-details-modal-target-value="#devices" class="link no-underline ">Details</button>
|
83
103
|
<% end %>
|
84
104
|
<% end %>
|
85
|
-
<%= render AhoyCaptain::TileComponent.new(wide: true) do |component| %>
|
105
|
+
<%= render AhoyCaptain::TileComponent.new(title: "Goals and Funnels", wide: true, classes: "p-4 m-2") do |component| %>
|
86
106
|
<% component.with_display_links do %>
|
87
|
-
<
|
88
|
-
|
89
|
-
</a>
|
90
|
-
<%= render AhoyCaptain::DropdownLinkComponent.new(title: "Funnels") do |dropdown| %>
|
91
|
-
<% AhoyCaptain.config.funnels.each do |id, funnel| %>
|
92
|
-
<% dropdown.with_option do %>
|
93
|
-
<a href="<%= funnel_path(id, search_params) %>" data-turbo-frame="goals" class="link ">
|
94
|
-
<%= funnel.title %>
|
95
|
-
</a>
|
96
|
-
<% end %>
|
97
|
-
<% end %>
|
98
|
-
<% end %>
|
107
|
+
<div>
|
108
|
+
<div data-controller="active-links">
|
99
109
|
|
110
|
+
<a href="<%= goals_path(search_params) %>" data-turbo-frame="goals" class="link ">
|
111
|
+
Goals
|
112
|
+
</a>
|
113
|
+
<a href="<%= properties_path(search_params) %>" data-turbo-frame="goals" class="link ">
|
114
|
+
Properties
|
115
|
+
</a>
|
116
|
+
<%= render AhoyCaptain::DropdownLinkComponent.new(title: "Funnels") do |dropdown| %>
|
117
|
+
<% AhoyCaptain.config.funnels.each do |id, funnel| %>
|
118
|
+
<% dropdown.with_option do %>
|
119
|
+
<a href="<%= funnel_path(id, search_params) %>" data-turbo-frame="goals" class="link ">
|
120
|
+
<%= funnel.title %>
|
121
|
+
</a>
|
122
|
+
<% end %>
|
123
|
+
<% end %>
|
124
|
+
<% end %>
|
125
|
+
</div>
|
126
|
+
</div>
|
100
127
|
<% end %>
|
101
128
|
<% component.with_statistic_display do %>
|
102
|
-
|
129
|
+
<div class="p-4">
|
130
|
+
<%= turbo_frame_tag :goals, src: goals_path(search_params), loading: :lazy %>
|
131
|
+
</div>
|
103
132
|
<% end %>
|
104
133
|
<% end %>
|
105
134
|
</div>
|
106
135
|
</main>
|
107
136
|
|
108
|
-
<%= render 'filters' %>
|
137
|
+
<%= render 'ahoy_captain/roots/filters' %>
|
109
138
|
|
110
139
|
<dialog id="detailsModal" class="modal">
|
111
140
|
<div class="modal-box w-11/12 max-w-5xl">
|
@@ -1,11 +1,39 @@
|
|
1
1
|
<%= turbo_frame_tag :chart do %>
|
2
|
-
<div class="
|
3
|
-
<
|
4
|
-
|
5
|
-
<%=
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
<
|
2
|
+
<div class="p-4">
|
3
|
+
<div class="flex justify-end gap-3 items-center ">
|
4
|
+
<a href="<%= export_path(request.query_parameters) %>" class="link text-sm" target="_blank" data-turbo-frame="false">Download</a>
|
5
|
+
<%= form_with url: url_for(params.permit!), method: :get, data: { controller: "interval" } do %>
|
6
|
+
<%= select_tag :interval, options_for_select(available_intervals.collect { |interval| [interval.titleize, interval] }, selected: selected_interval), class: "select text-accent select-sm w-full max-w-sm", 'data-action': "change->interval#handleChange" %>
|
7
|
+
<% end %>
|
8
|
+
</div>
|
9
|
+
<div>
|
10
|
+
|
11
|
+
<% if compare_mode? %>
|
12
|
+
<canvas class="h-[300px] w-full"
|
13
|
+
data-controller="line-chart"
|
14
|
+
data-line-chart-label-value="<%= @label %>"
|
15
|
+
data-line-chart-interval-value="<%= selected_interval %>"
|
16
|
+
data-line-chart-current-value="<%= @stats.current.to_json %>"
|
17
|
+
data-line-chart-comparison-value="<%= params[:comparison] %>"
|
18
|
+
data-line-chart-compared-to-value="<%= @stats.compared_to.to_json %>"
|
19
|
+
data-line-chart-metric-value="<%= metric_type(@stats) %>"
|
20
|
+
data-action="resize@window->line-chart#resize"
|
21
|
+
data-action="mouseenter->line-chart#hover"
|
22
|
+
data-action="mouseleave->line-chart#hover"
|
23
|
+
></canvas>
|
24
|
+
<% else %>
|
25
|
+
<canvas class="h-[300px] w-full"
|
26
|
+
data-controller="line-chart"
|
27
|
+
data-line-chart-label-value="<%= @label %>"
|
28
|
+
data-line-chart-interval-value="<%= selected_interval %>"
|
29
|
+
data-line-chart-current-value="<%= @stats.to_json %>"
|
30
|
+
data-line-chart-metric-value="<%= metric_type(@stats) %>"
|
31
|
+
data-action="resize@window->line-chart#resize"
|
32
|
+
data-action="mouseenter->line-chart#hover"
|
33
|
+
data-action="mouseleave->line-chart#hover"
|
34
|
+
></canvas>
|
35
|
+
<% end %>
|
36
|
+
</div>
|
10
37
|
</div>
|
38
|
+
|
11
39
|
<% end %>
|
@@ -1,12 +1,10 @@
|
|
1
|
-
<%= turbo_frame_tag :stats do %>
|
2
|
-
<dl class="grid grid-cols-1 divide-y divide-base-200 overflow-hidden rounded-lg grid-cols-2 md:grid-cols-6 md:divide-y-0 -
|
3
|
-
<%= render
|
4
|
-
<%= render
|
5
|
-
<%= render
|
6
|
-
<%= render
|
7
|
-
<%= render
|
8
|
-
<%= render
|
1
|
+
<%= turbo_frame_tag :stats, data: { controller: "active-frame-link" } do %>
|
2
|
+
<dl class="grid grid-cols-1 divide-y divide-base-200 overflow-hidden rounded-lg grid-cols-2 md:grid-cols-6 md:divide-y-0" data-controller="active-links" data-active-links-classes-value='["text-primary"]'>
|
3
|
+
<%= render stats_container(@presenter.unique_visitors, stats_unique_visitors_url(search_params), "Unique Visits", :number_with_delimiter, true) %>
|
4
|
+
<%= render stats_container(@presenter.total_visits, stats_total_visits_path(search_params), "Total Visits", :number_with_delimiter) %>
|
5
|
+
<%= render stats_container(@presenter.total_pageviews, stats_total_pageviews_path(search_params), "Total Pageviews", :number_with_delimiter) %>
|
6
|
+
<%= render stats_container(@presenter.views_per_visit, stats_views_per_visits_path(search_params), "Views per Visit", :number_with_delimiter) %>
|
7
|
+
<%= render stats_container(@presenter.bounce_rate, stats_bounce_rates_path(search_params), "Bounce Rate", :number_with_delimiter) %>
|
8
|
+
<%= render stats_container(@presenter.visit_duration, stats_visit_durations_url(search_params), "Visit Duration", :number_to_duration) %>
|
9
9
|
</dl>
|
10
|
-
<%= turbo_frame_tag :chart, src: stats_unique_visitors_path(search_params) do %>
|
11
|
-
<% end %>
|
12
10
|
<% end %>
|
data/config/routes.rb
CHANGED
@@ -12,6 +12,7 @@ AhoyCaptain::Engine.routes.draw do
|
|
12
12
|
get "/devices/#{k}" => 'devices#index', defaults: { devices_type: v }, as: "devices_#{k}"
|
13
13
|
end
|
14
14
|
|
15
|
+
resources :properties, only: [:index, :show]
|
15
16
|
resource :export, only: [:show]
|
16
17
|
resource :realtime, only: [:show]
|
17
18
|
resources :funnels, only: [:show]
|
@@ -48,6 +49,7 @@ AhoyCaptain::Engine.routes.draw do
|
|
48
49
|
resources :values, only: [:index]
|
49
50
|
end
|
50
51
|
|
52
|
+
resources :goals, only: [:index]
|
51
53
|
resources :sources, only: [:index]
|
52
54
|
resources :screens, only: [:index]
|
53
55
|
scope :operating_systems, module: :operating_systems do
|
@@ -4,6 +4,8 @@ module AhoyCaptain
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
+
scope :page_view, -> { where("name = '#{AhoyCaptain.config.event[:view_name]}'") }
|
8
|
+
|
7
9
|
ransacker :route do |_parent|
|
8
10
|
Arel.sql(AhoyCaptain.config.event[:url_column])
|
9
11
|
end
|
@@ -17,10 +19,13 @@ module AhoyCaptain
|
|
17
19
|
end
|
18
20
|
|
19
21
|
scope :with_entry_pages, -> {
|
20
|
-
with(entry_pages: self.select("MIN(
|
22
|
+
with(entry_pages: self.select("MIN(#{table_name}.id) as min_id, #{Arel.sql("#{AhoyCaptain.config.event.url_column} AS url")}").where(name: AhoyCaptain.config.event[:view_name]).group("#{table_name}.properties")).joins("INNER JOIN entry_pages ON entry_pages.min_id = #{table_name}.id")
|
21
23
|
}
|
24
|
+
|
22
25
|
scope :with_exit_pages, -> {
|
23
|
-
with(exit_pages: self.select("MAX(
|
26
|
+
with(exit_pages: self.select("MAX(#{table_name}.id) as max_id, #{Arel.sql("#{AhoyCaptain.config.event.url_column} AS url")}")
|
27
|
+
.where(name: AhoyCaptain.config.event[:view_name]).group("#{table_name}.properties"))
|
28
|
+
.joins("INNER JOIN exit_pages ON exit_pages.max_id = #{table_name}.id")
|
24
29
|
}
|
25
30
|
|
26
31
|
scope :with_routes, -> { where(AhoyCaptain.config.event[:url_exists]) }
|
@@ -33,16 +38,12 @@ module AhoyCaptain
|
|
33
38
|
distinct(Arel.sql("#{AhoyCaptain.config.event.url_column}"))
|
34
39
|
}
|
35
40
|
|
36
|
-
scope :
|
37
|
-
where("properties
|
38
|
-
}
|
39
|
-
|
40
|
-
scope :properties_eq, ->(value) {
|
41
|
-
where("properties @> ?", value)
|
41
|
+
scope :with_property_values, ->(value) {
|
42
|
+
where("JSONB_EXISTS(properties, '#{value}')")
|
42
43
|
}
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
ransacker :properties, args: [:parent, :ransacker_args] do |parent, args|
|
46
|
+
Arel::Nodes::InfixOperation.new('->>', parent.table[:properties], Arel::Nodes.build_quoted(args))
|
46
47
|
end
|
47
48
|
|
48
49
|
ransacker :goal,
|
@@ -57,14 +58,11 @@ module AhoyCaptain
|
|
57
58
|
|
58
59
|
class_methods do
|
59
60
|
def ransackable_attributes(auth_object = nil)
|
60
|
-
super + ["action", "controller", "id",
|
61
|
+
super + [ "action", "controller", "id", "name", "page", "properties", "time", "url", "user_id", "visit_id", "goal"] + self._ransackers.keys
|
61
62
|
end
|
62
63
|
|
63
64
|
def ransackable_scopes(auth_object = nil)
|
64
|
-
super + [
|
65
|
-
:properties_eq,
|
66
|
-
:properties_not_eq
|
67
|
-
]
|
65
|
+
super + [:with_property_values, :property_value_i_cont]
|
68
66
|
end
|
69
67
|
|
70
68
|
def ransackable_associations(auth_object = nil)
|
@@ -3,7 +3,7 @@ require 'ahoy_captain/filters_configuration'
|
|
3
3
|
|
4
4
|
module AhoyCaptain
|
5
5
|
class Configuration
|
6
|
-
attr_accessor :view_name, :theme
|
6
|
+
attr_accessor :view_name, :theme, :realtime_interval
|
7
7
|
attr_reader :goals, :funnels, :cache, :ranges, :disabled_widgets, :event, :models, :filters, :predicate_labels
|
8
8
|
def initialize
|
9
9
|
@goals = GoalCollection.new
|
@@ -15,15 +15,15 @@ module AhoyCaptain
|
|
15
15
|
option.store = Rails.cache
|
16
16
|
option.ttl = 1.minute
|
17
17
|
end
|
18
|
-
@event = ActiveSupport::OrderedOptions.new.tap do |option|
|
19
|
-
option.view_name = "$view"
|
20
|
-
option.url_column = "COALESCE(ahoy_events.properties->>'url', CONCAT(ahoy_events.properties->>'controller', '#', ahoy_events.properties->>'action'))"
|
21
|
-
option.url_exists = "(JSONB_EXISTS(ahoy_events.properties, 'controller') AND JSONB_EXISTS(ahoy_events.properties, 'action')) OR (JSONB_EXISTS(ahoy_events.properties, 'url'))"
|
22
|
-
end
|
23
18
|
@models = ActiveSupport::OrderedOptions.new.tap do |option|
|
24
19
|
option.event = "::Ahoy::Event"
|
25
20
|
option.visit = "::Ahoy::Visit"
|
26
21
|
end
|
22
|
+
@event = ActiveSupport::OrderedOptions.new.tap do |option|
|
23
|
+
option.view_name = "$view"
|
24
|
+
option.url_column = "CONCAT(#{@models.event.parameterize.tableize}.properties->>'controller', '#', #{@models.event.parameterize.tableize}.properties->>'action')"
|
25
|
+
option.url_exists = "JSONB_EXISTS(#{@models.event.parameterize.tableize}.properties, 'controller') AND JSONB_EXISTS(#{@models.event.parameterize.tableize}.properties, 'action')"
|
26
|
+
end
|
27
27
|
@filters = FiltersConfiguration.load_default
|
28
28
|
@predicate_labels = {
|
29
29
|
eq: 'equals',
|
@@ -33,6 +33,7 @@ module AhoyCaptain
|
|
33
33
|
not_in: 'not in',
|
34
34
|
}
|
35
35
|
|
36
|
+
@realtime_interval = 30.seconds
|
36
37
|
@disabled_widgets = []
|
37
38
|
end
|
38
39
|
|