ahoy_captain 0.11.1 → 0.76

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -25
  3. data/Rakefile +2 -23
  4. data/app/assets/javascript/ahoy_captain/application.js +4 -4
  5. data/app/assets/javascript/ahoy_captain/controllers/application.js +5 -5
  6. data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +8 -27
  7. data/app/assets/javascript/ahoy_captain/controllers/details_modal_controller.js +5 -5
  8. data/app/assets/javascript/ahoy_captain/controllers/dropdown_label_controller.js +2 -2
  9. data/app/assets/javascript/ahoy_captain/controllers/filter_controller.js +145 -0
  10. data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +17 -0
  11. data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +127 -113
  12. data/app/assets/javascript/ahoy_captain/controllers/index.js +3 -4
  13. data/app/assets/javascript/ahoy_captain/controllers/link_controller.js +43 -0
  14. data/app/assets/javascript/ahoy_captain/controllers/navigation_controller.js +25 -0
  15. data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +9 -12
  16. data/app/components/ahoy_captain/dropdown_button_component.html.erb +5 -5
  17. data/app/components/ahoy_captain/dropdown_link_component.html.erb +7 -5
  18. data/app/components/ahoy_captain/dropdown_link_component.rb +0 -4
  19. data/app/components/ahoy_captain/filter/modal_component.html.erb +9 -12
  20. data/app/components/ahoy_captain/filter/select_component.html.erb +19 -23
  21. data/app/components/ahoy_captain/filter/select_component.rb +9 -41
  22. data/app/components/ahoy_captain/filter/tag_component.html.erb +4 -8
  23. data/app/components/ahoy_captain/filter/tag_component.rb +30 -6
  24. data/app/components/ahoy_captain/filter/tag_container_component.html.erb +3 -2
  25. data/app/components/ahoy_captain/filter/tag_container_component.rb +8 -1
  26. data/app/components/ahoy_captain/sticky_nav_component.html.erb +33 -28
  27. data/app/components/ahoy_captain/sticky_nav_component.rb +0 -19
  28. data/app/components/ahoy_captain/table_component.html.erb +37 -4
  29. data/app/components/ahoy_captain/table_component.rb +5 -25
  30. data/app/components/ahoy_captain/tile_component.html.erb +10 -21
  31. data/app/components/ahoy_captain/tile_component.rb +2 -10
  32. data/app/components/ahoy_captain/tooltip_component.html.erb +2 -2
  33. data/app/controllers/ahoy_captain/application_controller.rb +30 -23
  34. data/app/controllers/ahoy_captain/campaigns_controller.rb +10 -2
  35. data/app/controllers/ahoy_captain/cities_controller.rb +24 -0
  36. data/app/controllers/ahoy_captain/countries_controller.rb +24 -0
  37. data/app/controllers/ahoy_captain/devices_controller.rb +6 -3
  38. data/app/controllers/ahoy_captain/entry_pages_controller.rb +4 -2
  39. data/app/controllers/ahoy_captain/exit_pages_controller.rb +4 -3
  40. data/app/controllers/ahoy_captain/filters/base_controller.rb +3 -1
  41. data/app/controllers/ahoy_captain/filters/pages/actions_controller.rb +1 -1
  42. data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +3 -3
  43. data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +3 -2
  44. data/app/controllers/ahoy_captain/filters/sources_controller.rb +1 -1
  45. data/app/controllers/ahoy_captain/filters/utms_controller.rb +1 -1
  46. data/app/controllers/ahoy_captain/realtimes_controller.rb +1 -1
  47. data/app/controllers/ahoy_captain/regions_controller.rb +24 -0
  48. data/app/controllers/ahoy_captain/sources_controller.rb +5 -2
  49. data/app/controllers/ahoy_captain/stats/base_controller.rb +0 -142
  50. data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +2 -4
  51. data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +1 -2
  52. data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +1 -2
  53. data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +1 -3
  54. data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +8 -3
  55. data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -2
  56. data/app/controllers/ahoy_captain/top_pages_controller.rb +8 -2
  57. data/app/decorators/ahoy_captain/application_decorator.rb +3 -27
  58. data/app/decorators/ahoy_captain/campaign_decorator.rb +0 -8
  59. data/app/decorators/ahoy_captain/city_decorator.rb +0 -12
  60. data/app/decorators/ahoy_captain/country_decorator.rb +0 -10
  61. data/app/decorators/ahoy_captain/device_decorator.rb +2 -13
  62. data/app/decorators/ahoy_captain/page_decorator.rb +0 -11
  63. data/app/decorators/ahoy_captain/region_decorator.rb +0 -16
  64. data/app/decorators/ahoy_captain/source_decorator.rb +0 -7
  65. data/app/helpers/ahoy_captain/application_helper.rb +3 -60
  66. data/app/models/ahoy_captain/current.rb +9 -0
  67. data/app/models/ahoy_captain/rangeable.rb +3 -0
  68. data/app/models/ahoy_captain/url_helpers.rb +6 -0
  69. data/app/models/concerns/ahoy_captain/range_options.rb +14 -1
  70. data/app/presenters/ahoy_captain/dashboard_presenter.rb +46 -18
  71. data/app/presenters/ahoy_captain/funnel_presenter.rb +29 -32
  72. data/app/presenters/ahoy_captain/goals_presenter.rb +23 -33
  73. data/app/queries/ahoy_captain/application_query.rb +13 -81
  74. data/app/queries/ahoy_captain/entry_pages_query.rb +2 -3
  75. data/app/queries/ahoy_captain/event_query.rb +8 -30
  76. data/app/queries/ahoy_captain/exit_pages_query.rb +4 -6
  77. data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +4 -11
  78. data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +7 -15
  79. data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +7 -24
  80. data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +2 -2
  81. data/app/queries/ahoy_captain/stats/total_visitors_query.rb +2 -2
  82. data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +2 -2
  83. data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +3 -3
  84. data/app/queries/ahoy_captain/stats/visit_duration_query.rb +5 -5
  85. data/app/queries/ahoy_captain/visit_query.rb +13 -12
  86. data/app/views/ahoy_captain/devices/index.html+details.erb +1 -1
  87. data/app/views/ahoy_captain/devices/index.html.erb +2 -2
  88. data/app/views/ahoy_captain/funnels/show.html.erb +2 -5
  89. data/app/views/ahoy_captain/goals/index.html.erb +37 -2
  90. data/app/views/ahoy_captain/layouts/application.html.erb +4 -3
  91. data/app/views/ahoy_captain/realtimes/show.html.erb +1 -1
  92. data/app/views/ahoy_captain/roots/show.html.erb +118 -117
  93. data/app/views/ahoy_captain/stats/base/index.html.erb +1 -38
  94. data/app/views/ahoy_captain/stats/show.html.erb +56 -14
  95. data/config/routes.rb +3 -16
  96. data/lib/ahoy_captain/ahoy/event_methods.rb +75 -36
  97. data/lib/ahoy_captain/ahoy/visit_methods.rb +1 -1
  98. data/lib/ahoy_captain/configuration.rb +7 -18
  99. data/lib/ahoy_captain/engine.rb +0 -22
  100. data/lib/ahoy_captain/goals.rb +4 -16
  101. data/lib/ahoy_captain/period_collection.rb +1 -1
  102. data/lib/ahoy_captain/version.rb +1 -1
  103. data/lib/ahoy_captain.rb +1 -8
  104. data/lib/generators/ahoy_captain/templates/config.rb.tt +3 -50
  105. metadata +17 -185
  106. data/app/assets/javascript/ahoy_captain/controllers/combobox_controller.js +0 -371
  107. data/app/assets/javascript/ahoy_captain/controllers/filter/item_controller.js +0 -12
  108. data/app/assets/javascript/ahoy_captain/controllers/filter_form_controller.js +0 -13
  109. data/app/assets/javascript/ahoy_captain/controllers/filter_modal_controller.js +0 -45
  110. data/app/assets/javascript/ahoy_captain/controllers/frame_link_controller.js +0 -20
  111. data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +0 -15
  112. data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +0 -251
  113. data/app/assets/javascript/ahoy_captain/controllers/map_controller.js +0 -47
  114. data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +0 -10
  115. data/app/assets/javascript/ahoy_captain/controllers/properties_controller.js +0 -8
  116. data/app/assets/javascript/ahoy_captain/controllers/property_filter_controller.js +0 -45
  117. data/app/assets/javascript/ahoy_captain/controllers/tile_controller.js +0 -33
  118. data/app/assets/javascript/ahoy_captain/controllers/toggle_controller.js +0 -17
  119. data/app/assets/javascript/ahoy_captain/helpers/chart_utils.js +0 -156
  120. data/app/assets/javascript/ahoy_captain/helpers/countries.js +0 -2261
  121. data/app/assets/javascript/ahoy_captain/helpers/number_formatters.js +0 -55
  122. data/app/components/ahoy_captain/combobox_component.html.erb +0 -33
  123. data/app/components/ahoy_captain/combobox_component.rb +0 -13
  124. data/app/components/ahoy_captain/comparison_link_component.html.erb +0 -17
  125. data/app/components/ahoy_captain/comparison_link_component.rb +0 -44
  126. data/app/components/ahoy_captain/filter/dropdown_component.html.erb +0 -50
  127. data/app/components/ahoy_captain/filter/dropdown_component.rb +0 -51
  128. data/app/components/ahoy_captain/previous_next_component.html.erb +0 -8
  129. data/app/components/ahoy_captain/previous_next_component.rb +0 -11
  130. data/app/components/ahoy_captain/stats/comparable_container_component.html.erb +0 -25
  131. data/app/components/ahoy_captain/stats/comparable_container_component.rb +0 -86
  132. data/app/components/ahoy_captain/stats/container_component.html.erb +0 -15
  133. data/app/components/ahoy_captain/stats/container_component.rb +0 -26
  134. data/app/components/ahoy_captain/tables/devices_table_component.rb +0 -11
  135. data/app/components/ahoy_captain/tables/dynamic_table.rb +0 -13
  136. data/app/components/ahoy_captain/tables/dynamic_table_component.rb +0 -204
  137. data/app/components/ahoy_captain/tables/goals_table_component.rb +0 -17
  138. data/app/components/ahoy_captain/tables/header_component.html.erb +0 -5
  139. data/app/components/ahoy_captain/tables/header_component.rb +0 -18
  140. data/app/components/ahoy_captain/tables/headers/header_component.html.erb +0 -5
  141. data/app/components/ahoy_captain/tables/headers/header_component.rb +0 -16
  142. data/app/components/ahoy_captain/tables/properties_table_component.rb +0 -27
  143. data/app/components/ahoy_captain/tables/row_component.html.erb +0 -4
  144. data/app/components/ahoy_captain/tables/rows/row_component.html.erb +0 -6
  145. data/app/components/ahoy_captain/tables/rows/row_component.rb +0 -40
  146. data/app/controllers/ahoy_captain/exports_controller.rb +0 -14
  147. data/app/controllers/ahoy_captain/filters/goals_controller.rb +0 -9
  148. data/app/controllers/ahoy_captain/filters/properties/names_controller.rb +0 -11
  149. data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +0 -15
  150. data/app/controllers/ahoy_captain/locations/cities_controller.rb +0 -22
  151. data/app/controllers/ahoy_captain/locations/countries_controller.rb +0 -22
  152. data/app/controllers/ahoy_captain/locations/maps_controller.rb +0 -24
  153. data/app/controllers/ahoy_captain/locations/regions_controller.rb +0 -22
  154. data/app/controllers/ahoy_captain/properties_controller.rb +0 -41
  155. data/app/models/ahoy_captain/comparison_mode.rb +0 -72
  156. data/app/models/ahoy_captain/export.rb +0 -48
  157. data/app/models/ahoy_captain/filter_parser.rb +0 -82
  158. data/app/models/ahoy_captain/range_from_params.rb +0 -78
  159. data/app/models/concerns/ahoy_captain/compare_mode.rb +0 -19
  160. data/app/models/concerns/ahoy_captain/limitable.rb +0 -17
  161. data/app/queries/ahoy_captain/campaign_query.rb +0 -14
  162. data/app/queries/ahoy_captain/city_query.rb +0 -11
  163. data/app/queries/ahoy_captain/country_query.rb +0 -10
  164. data/app/queries/ahoy_captain/device_query.rb +0 -10
  165. data/app/queries/ahoy_captain/region_query.rb +0 -11
  166. data/app/queries/ahoy_captain/source_query.rb +0 -10
  167. data/app/queries/ahoy_captain/stats/base_query.rb +0 -18
  168. data/app/queries/ahoy_captain/top_page_query.rb +0 -13
  169. data/app/queries/concerns/ahoy_captain/comparable_queries.rb +0 -25
  170. data/app/queries/concerns/ahoy_captain/comparable_query.rb +0 -138
  171. data/app/queries/concerns/ahoy_captain/lazy_comparable_query.rb +0 -42
  172. data/app/views/ahoy_captain/devices/_table.html.erb +0 -2
  173. data/app/views/ahoy_captain/layouts/shared/_tile_loader.html.erb +0 -12
  174. data/app/views/ahoy_captain/locations/maps/show.html.erb +0 -3
  175. data/app/views/ahoy_captain/properties/_form.html.erb +0 -6
  176. data/app/views/ahoy_captain/properties/index.html.erb +0 -3
  177. data/app/views/ahoy_captain/properties/show.html.erb +0 -6
  178. data/app/views/ahoy_captain/roots/_filters.html.erb +0 -80
  179. data/lib/ahoy_captain/filter_configuration/filter.rb +0 -16
  180. data/lib/ahoy_captain/filter_configuration/filter_collection.rb +0 -48
  181. data/lib/ahoy_captain/filters_configuration.rb +0 -77
  182. data/lib/ahoy_captain/predicate_label.rb +0 -7
  183. data/lib/generators/ahoy_captain/migration_generator.rb +0 -21
  184. data/lib/generators/ahoy_captain/templates/migration.rb.tt +0 -7
  185. /data/app/views/ahoy_captain/{locations/cities → cities}/index.html+details.erb +0 -0
  186. /data/app/views/ahoy_captain/{locations/cities → cities}/index.html.erb +0 -0
  187. /data/app/views/ahoy_captain/{locations/countries → countries}/index.html+details.erb +0 -0
  188. /data/app/views/ahoy_captain/{locations/countries → countries}/index.html.erb +0 -0
  189. /data/app/views/ahoy_captain/{locations/regions → regions}/index.html+details.erb +0 -0
  190. /data/app/views/ahoy_captain/{locations/regions → regions}/index.html.erb +0 -0
@@ -1,17 +0,0 @@
1
- module AhoyCaptain
2
- module Tables
3
- class GoalsTableComponent < DynamicTable
4
- register fixed_height: false do
5
- progress_bar value: :cr, max: 100, title: "Name" do |row|
6
- search_params = view_context.search_params
7
- query = search_params.dup.merge(q: { goal_in: row.goal_id}).to_query
8
- url = AhoyCaptain::Engine.app.url_helpers.root_path + "?#{query}"
9
- link_to row.item.name, url, target: :_top
10
- end
11
- number :unique_visits, title: "Uniques"
12
- number :total_events, title: "Total"
13
- percent :cr, title: "CR"
14
- end
15
- end
16
- end
17
- end
@@ -1,5 +0,0 @@
1
- <div class="flex text-sm font-bold mb-4">
2
- <% @headers.each do |header| %>
3
- <span class="<%= header[:grow] ? 'grow' : 'w-8 ml-8 text-right' %>"><%= header[:label] %></span>
4
- <% end %>
5
- </div>
@@ -1,18 +0,0 @@
1
- module AhoyCaptain
2
- module Tables
3
- class HeaderComponent < ViewComponent::Base
4
- def initialize(headers, options = {})
5
- @headers = headers.flatten
6
- @options = options
7
- end
8
-
9
- def fixed_height?
10
- if @options.key?(:fixed_height)
11
- @options[:fixed_height]
12
- else
13
- true
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,5 +0,0 @@
1
- <div class=" flex text-sm font-bold mb-4">
2
- <span class="grow"><%= @category_name %></span>
3
- <span ><%= @unit_name %></span>
4
- <%= content %>
5
- </div>
@@ -1,16 +0,0 @@
1
- module AhoyCaptain
2
- module Tables
3
- module Headers
4
- class HeaderComponent < ViewComponent::Base
5
- def initialize(category_name:, unit_name:)
6
- @category_name = category_name
7
- @unit_name = unit_name
8
- end
9
-
10
- def fixed_height?
11
- true
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,27 +0,0 @@
1
- module AhoyCaptain
2
- module Tables
3
- class PropertiesTableComponent < DynamicTable
4
- register do
5
- progress_bar :label, value: :percentage, max: 100, title: "Name" do |item|
6
- link_to item.label, url(item), target: :_top
7
- end
8
- number :unique_visitors_count, title: "Visitors"
9
- number :events_count, title: "Events"
10
- percent :percentage, title: "%"
11
- end
12
-
13
- def self.url(item)
14
- name = Base64.decode64(item.request.params[:id])
15
- params = item.search_params.dup
16
- if params["q"] && params["q"].key?("properties_json_cont")
17
- json = JSON.parse(params["q"]["properties_json_cont"])
18
- json[name] = item.item.label
19
- params["q"]["properties_json_cont"] = json.to_json
20
- else
21
- params[:q] = { "properties_json_cont" => { name => item.item.label }.to_json }
22
- end
23
- params
24
- end
25
- end
26
- end
27
- end
@@ -1,4 +0,0 @@
1
- <% @rows.each do |row| %>
2
- <%= row.render(@item, view_context) %>
3
-
4
- <% end %>
@@ -1,6 +0,0 @@
1
- <%= progress_bar(@item.count, @item.total_count, @item.display_name) %>
2
- <%=
3
- item do
4
- tooltip(@item.count)
5
- end
6
- %>
@@ -1,40 +0,0 @@
1
- module AhoyCaptain
2
- module Tables
3
- module Rows
4
- class RowComponent < ViewComponent::Base
5
- def initialize(table:, item:)
6
- @table = table
7
- @item = item
8
- end
9
-
10
- def progress_bar(value, max, label)
11
- items = []
12
- items << view_context.content_tag(:progress, "", class: "progress-primary bg-base-100 h-8 grow", value: value, max: max)
13
- items << view_context.content_tag(:span, class: "grow text-elipsis overflow-hidden absolute left-4 bottom-3 h-8 text-primary-content") do
14
- label
15
- end
16
-
17
- items.join.html_safe
18
- end
19
-
20
- def item(value = nil, &block)
21
- view_context.content_tag(:span, class: "w-8 ml-8 text-right ") do
22
- if value
23
- value
24
- else
25
- capture(&block)
26
- end
27
- end
28
- end
29
-
30
- def percent_total(item)
31
- '%.1f' % ((item.unit_amount.to_i * 1.0 / total)*100.0)
32
- end
33
-
34
- def tooltip(value)
35
- AhoyCaptain::TooltipComponent.new(amount: value).render_in(self)
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,14 +0,0 @@
1
- module AhoyCaptain
2
- class ExportsController < ApplicationController
3
- skip_before_action :act_like_an_spa
4
-
5
- def show
6
- export = Export.new(params, self).build
7
- file = export.to_zip
8
- send_data file.read,
9
- type: 'application/zip',
10
- disposition: 'attachment',
11
- filename: "AhoyCaptain export #{request.host} #{range[0].to_date} to #{(range[1] || Time.current).to_date}.zip"
12
- end
13
- end
14
- end
@@ -1,9 +0,0 @@
1
- module AhoyCaptain
2
- module Filters
3
- class GoalsController < BaseController
4
- def index
5
- render json: AhoyCaptain.configuration.goals.map { |goal| { text: goal.title, value: goal.id } }
6
- end
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- module AhoyCaptain
2
- module Filters
3
- module Properties
4
- class NamesController < BaseController
5
- def index
6
- render json: ::Ahoy::Event.select("jsonb_object_keys(properties) as keys").distinct("jsonb_object_keys(properties)").map(&:keys).map { |key| serialize(key) }
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- module AhoyCaptain
2
- module Filters
3
- module Properties
4
- class ValuesController < BaseController
5
- def index
6
- param_key = params[:q].to_unsafe_h.detect { |k,v| k.ends_with?("_i_cont") && k.starts_with?("properties.") }[0]
7
- key = param_key.delete_prefix("properties.").delete_suffix("_i_cont")
8
- query = event_query.all.distinct.select("properties->>'#{key}'").pluck(Arel.sql "properties->>'#{key}'")
9
-
10
- render json: query.map { |element| serialize(element) }
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- module AhoyCaptain
2
- module Locations
3
- class CitiesController < ApplicationController
4
- include AhoyCaptain::Limitable
5
-
6
- before_action do
7
- if Widget.disabled?(:locations, :cities)
8
- raise Widget::WidgetDisabled.new("Widget disabled", :geography)
9
- end
10
- end
11
-
12
- def index
13
- results = cached(:cities) do
14
- CityQuery.call(params)
15
- .limit(limit)
16
- end
17
-
18
- @cities = paginate(results).map { |city| CityDecorator.new(city, self) }
19
- end
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- module AhoyCaptain
2
- module Locations
3
- class CountriesController < ApplicationController
4
- include Limitable
5
-
6
- before_action do
7
- if Widget.disabled?(:locations, :countries)
8
- raise Widget::WidgetDisabled.new("Widget disabled", :geography)
9
- end
10
- end
11
-
12
- def index
13
- results = cached(:countries) do
14
- CountryQuery.call(params)
15
- .limit(limit)
16
- end
17
-
18
- @countries = paginate(results).map { |country| CountryDecorator.new(country, self) }
19
- end
20
- end
21
- end
22
- end
@@ -1,24 +0,0 @@
1
- module AhoyCaptain
2
- module Locations
3
- class MapsController < ApplicationController
4
- include Limitable
5
-
6
- before_action do
7
- if Widget.disabled?(:locations, :map)
8
- raise Widget::WidgetDisabled.new("Widget disabled", :geography)
9
- end
10
- end
11
-
12
- def show
13
- if request.variant.include?(:details)
14
- results = CountryQuery.call(params)
15
- results = results.limit(limit)
16
- @countries = paginate(results).map { |country| CountryDecorator.new(country, self) }
17
- render template: 'ahoy_captain/locations/countries/index'
18
- else
19
- @countries = visit_query.group("country").count
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,22 +0,0 @@
1
- module AhoyCaptain
2
- module Locations
3
- class RegionsController < ApplicationController
4
- include Limitable
5
-
6
- before_action do
7
- if Widget.disabled?(:locations, :regions)
8
- raise Widget::WidgetDisabled.new("Widget disabled", :geography)
9
- end
10
- end
11
-
12
- def index
13
- results = cached(:regions) do
14
- RegionQuery.call(params)
15
- .limit(limit)
16
- end
17
-
18
- @regions = paginate(results).map { |region| RegionDecorator.new(region, self) }
19
- end
20
- end
21
- end
22
- end
@@ -1,41 +0,0 @@
1
- module AhoyCaptain
2
- class PropertiesController < ApplicationController
3
- before_action do
4
- @options = ::Ahoy::Event.select("jsonb_object_keys(properties) as keys").distinct("jsonb_object_keys(properties)").map(&:keys).map { |key| [Base64.urlsafe_encode64(key), key]}.to_h
5
- end
6
-
7
- def index
8
- end
9
-
10
- def show
11
- value = Base64.urlsafe_decode64(params[:id])
12
-
13
- @properties = event_query
14
- .select(
15
- "COALESCE(properties->>'#{value}', '(none)') AS label",
16
- "COUNT(*) AS events_count",
17
- "COUNT(DISTINCT visit_id) AS unique_visitors_count",
18
- "(COUNT(DISTINCT visit_id)/COUNT(*)::numeric) * 100 as percentage"
19
- )
20
- .group("COALESCE(properties->>'#{value}', '(none)')")
21
- .order(Arel.sql "COUNT(*) desc")
22
- end
23
-
24
- private
25
-
26
- helper_method :has_property?
27
- def has_property?(value)
28
- searching_properties[value]
29
- end
30
-
31
- helper_method :selected_property?
32
- def selected_property?(value)
33
- encoded = Base64.urlsafe_encode64(value, padding: false)
34
- encoded == params[:id]
35
- end
36
-
37
- def searching_properties
38
- JSON.parse(params.dig("q", "properties_json_cont") || '{}')
39
- end
40
- end
41
- end
@@ -1,72 +0,0 @@
1
- module AhoyCaptain
2
- class ComparisonMode
3
- VALID_COMPARISONS = %w{previous year true}
4
-
5
- include RangeOptions
6
- include Rangeable
7
-
8
- attr_reader :params
9
- def initialize(params)
10
- @params = params
11
- end
12
-
13
- # can't compare realtime
14
- def enabled?(strict = true)
15
- comparing = (params[:comparison].in?(VALID_COMPARISONS) || custom_compare?)
16
- if strict
17
- comparing && !range.realtime?
18
- else
19
- comparing
20
- end
21
- end
22
-
23
- def label
24
- if custom_compare?
25
- return "Custom period"
26
- end
27
-
28
- if type == :true || type == :previous
29
- "Previous period"
30
- elsif type == :year
31
- "Year-over-year"
32
- else
33
- raise ArgumentError
34
- end
35
- end
36
-
37
- def compared_to_range
38
- return custom_compare if custom_compare?
39
-
40
- if type == :true || type == :previous
41
- RangeFromParams.new(period: nil, start_date: (range[0] - (range[1] - range[0])).utc.to_s, end_date: range[0].utc.to_s).build
42
- elsif type == :year
43
- RangeFromParams.new(period: nil, start_date: range[0].change(year: range[0].year - 1).utc.to_s, end_date: range[1].change(year: range[1].year - 1).utc.to_s).build
44
- else
45
- raise ArgumentError
46
- end
47
- end
48
-
49
- def type
50
- return params[:comparison].to_sym if params[:comparison].in?(VALID_COMPARISONS)
51
- return :custom if custom_compare?
52
-
53
- nil
54
- end
55
-
56
- def match_to
57
- return params[:compare_to].to_sym if params[:compare_to].in?(%w{dow date})
58
-
59
- nil
60
- end
61
-
62
- def custom_compare
63
- return nil unless (params[:compare_to_start_date].present? && params[:compare_to_end_date].present?)
64
-
65
- RangeFromParams.new(period: nil, start_date: params[:compare_to_start_date], end_date: params[:compare_to_end_date]).build
66
- end
67
-
68
- def custom_compare?
69
- custom_compare
70
- end
71
- end
72
- end
@@ -1,48 +0,0 @@
1
- module AhoyCaptain
2
- class Export
3
- def initialize(params, context)
4
- @params = params
5
- @context = context
6
- @files = {}
7
- end
8
-
9
- def build
10
- @files["browsers.csv"] = to_csv(DeviceQuery.call(merged_params(devices_type: "browser")), DeviceDecorator)
11
- @files["cities.csv"] = to_csv(CityQuery.call(merged_params), CityDecorator)
12
- @files["countries.csv"] = to_csv(CountryQuery.call(merged_params), CountryDecorator)
13
- @files["devices.csv"] = to_csv(DeviceQuery.call(merged_params(devices_type: :device_type)), DeviceDecorator)
14
- @files["entry_pages.csv"] = to_csv(EntryPagesQuery.call(merged_params), EntryPageDecorator)
15
- @files["exit_pages.csv"] = to_csv(ExitPagesQuery.call(merged_params), ExitPageDecorator)
16
- @files["operating_systems.csv"] = to_csv(DeviceQuery.call(merged_params(devices_type: "os")), DeviceDecorator)
17
- @files["top_pages.csv"] = to_csv(TopPageQuery.call(merged_params), TopPageDecorator)
18
- @files["regions.csv"] = to_csv(RegionQuery.call(merged_params), RegionDecorator)
19
- @files["sources.csv"] = to_csv(SourceQuery.call(merged_params), SourceDecorator)
20
- ["campaign", "content", "medium", "source", "term"].each do |utm|
21
- @files["utm_#{utm.pluralize}.csv"] = to_csv(CampaignQuery.call(merged_params(campaigns_type: "utm_#{utm}")), CampaignDecorator)
22
- end
23
- self
24
- end
25
-
26
- def to_zip
27
- zip_stream = Zip::OutputStream.write_buffer do |zip|
28
- @files.each do |filename, csv|
29
- zip.put_next_entry(filename)
30
- zip.write(csv)
31
- end
32
- end
33
-
34
- zip_stream.rewind
35
- zip_stream
36
- end
37
-
38
- private
39
-
40
- def to_csv(query, decorator)
41
- decorator.to_csv(query, @context)
42
- end
43
-
44
- def merged_params(params_to_merge = {})
45
- @params.dup.merge(params_to_merge)
46
- end
47
- end
48
- end
@@ -1,82 +0,0 @@
1
- module AhoyCaptain
2
- class FilterParser
3
- FILTER_MENU_MAX_SIZE = 2
4
- class Item
5
- attr_accessor :name, :column, :description, :values, :predicate, :url, :modal, :label
6
-
7
- def title
8
- column.titleize
9
- end
10
- end
11
-
12
- def self.parse(request)
13
- new(request).tap do |instance|
14
- instance.parse
15
- end
16
- end
17
-
18
- delegate_missing_to :@items
19
-
20
- def initialize(request)
21
- @request = request
22
- @params = @request.params
23
- @filter_params = @request.params[:q] || {}
24
- @items = {}
25
- end
26
-
27
- def parse
28
- @filter_params.each do |key, values|
29
- next if ::AhoyCaptain.event.ransackable_scopes.include?(key.to_sym)
30
-
31
- item = build_item(key, values)
32
- @items[key] = item
33
- end
34
-
35
- @items
36
- end
37
-
38
- private
39
-
40
- def build_item(key, values)
41
- item = Item.new
42
- item.values = Array(values)
43
-
44
- item.predicate = Ransack::Predicate.detect_and_strip_from_string!(key.dup)
45
- item.column = key.delete_suffix("_#{item.predicate}")
46
- modal_name = AhoyCaptain.config.filters.detect { |_, filters| filters.include?(item.column) }
47
- if modal_name
48
- item.modal = modal_name[1].modal_name
49
- end
50
-
51
- label = if item.column == "goal"
52
- item.values.map { |value| AhoyCaptain.config.goals[value].title }
53
- else
54
- item.values
55
- end.to_sentence(last_word_connector: " or ")
56
-
57
- item.label = if key.start_with?("properties.")
58
- item.modal = "customPropertyFilterModal"
59
- item.column = item.column.dup.delete_prefix("properties.")
60
- label
61
- else
62
- label
63
- end
64
-
65
- item.description = "#{item.label} #{::AhoyCaptain::PredicateLabel[item.predicate]} #{label}"
66
- item.url = build_url(key, values)
67
- item
68
- end
69
-
70
- def build_url(name, values)
71
- search_params = @request.query_parameters.deep_dup
72
- if search_params["q"][name].is_a?(Array)
73
- search_params["q"][name] = search_params["q"][name] - Array(values)
74
- else
75
- search_params["q"].delete(name)
76
- end
77
-
78
- @request.path + "?" + search_params.to_query
79
- end
80
-
81
- end
82
- end
@@ -1,78 +0,0 @@
1
- module AhoyCaptain
2
- class RangeFromParams
3
- def self.from_params(params)
4
- compare = ComparisonMode.new(params)
5
- new(period: params[:period], start_date: params[:start_date], end_date: params[:end_date], date: params[:date], comparison: compare.enabled?(false), raw: params).tap { |instance| instance.build }
6
- end
7
-
8
- attr_reader :params, :range
9
- def initialize(period: AhoyCaptain.config.ranges.default, start_date: nil, end_date: nil, date: nil, comparison: false, raw: {})
10
- @period = period || AhoyCaptain.config.ranges.default
11
- @start_date = start_date
12
- @end_date = end_date
13
- @date = date
14
- @range = nil
15
- @comparison = comparison
16
- @raw = raw
17
- end
18
-
19
- def build
20
- if (@start_date.present? && @end_date.present?) || @date.present?
21
- if @date
22
- @start_date ||= @date.to_datetime.beginning_of_day
23
- @end_date ||= @date.to_datetime.end_of_day
24
- end
25
-
26
- custom = [@start_date.to_datetime, @end_date.to_datetime].sort
27
- duration = (custom[1].to_date - custom[0].to_date)
28
-
29
- # if AhoyCaptain.config.ranges.max && (duration.days <= AhoyCaptain.config.ranges.max)
30
- @range = Range.new(custom[0].utc, custom[1].utc)
31
- return self
32
- # end
33
- end
34
-
35
- @range = Range.new(selected_period[0], selected_period[1])
36
- self
37
- end
38
-
39
- def starts_at
40
- Time.at(@range.min)
41
- end
42
-
43
- def ends_at
44
- if realtime?
45
- Time.current
46
- else
47
- Time.at(@range.max)
48
- end
49
- end
50
-
51
- def realtime?
52
- @range.end.nil?
53
- end
54
-
55
- def custom?
56
- @raw[:start_date].present? && @raw[:end_date].present?
57
- end
58
-
59
- def [](value)
60
- if value == 0
61
- starts_at
62
- elsif value == 1
63
- ends_at
64
- else
65
- raise NoMethodError
66
- end
67
- end
68
-
69
- # return an integer-based range which works with step
70
- def numeric
71
- @numeric ||= Range.new(starts_at.to_i, ends_at.to_i)
72
- end
73
-
74
- def selected_period
75
- AhoyCaptain.config.ranges.for(@period) || AhoyCaptain.config.ranges.default
76
- end
77
- end
78
- end
@@ -1,19 +0,0 @@
1
- module AhoyCaptain
2
- module CompareMode
3
- def self.included(klass)
4
- if klass < ActionController::Base
5
- klass.helper_method :compare_mode?
6
- klass.helper_method :comparison_label
7
- end
8
- end
9
-
10
- # doesn't work for realtime and realtime doesn't need a secondary range
11
- def compare_mode?
12
- comparison_mode.enabled?
13
- end
14
-
15
- def comparison_mode
16
- @comparison_mode ||= ComparisonMode.new(params)
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- module AhoyCaptain
2
- module Limitable
3
- private
4
-
5
- def limit
6
- if request.variant.include?(:details)
7
- nil
8
- else
9
- if params[:limit]
10
- params[:limit].to_i
11
- else
12
- 10
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,14 +0,0 @@
1
- module AhoyCaptain
2
- class CampaignQuery < ApplicationQuery
3
- def build
4
- visit_query
5
- .select(
6
- "COALESCE(#{params[:campaigns_type]}, 'Direct/None') as label",
7
- "count(COALESCE(#{params[:campaigns_type]}, 'Direct/None')) as count",
8
- "sum(count(COALESCE(#{params[:campaigns_type]}, 'Direct/None'))) OVER() as total_count"
9
- )
10
- .group("COALESCE(#{params[:campaigns_type]}, 'Direct/None')")
11
- .order(Arel.sql("count(COALESCE(#{params[:campaigns_type]}, 'Direct/None')) desc"))
12
- end
13
- end
14
- end