ahoy_captain 0.91 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -4
  3. data/Rakefile +23 -2
  4. data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +20 -0
  5. data/app/assets/javascript/ahoy_captain/controllers/combobox_controller.js +371 -0
  6. data/app/assets/javascript/ahoy_captain/controllers/filter_modal_controller.js +45 -0
  7. data/app/assets/javascript/ahoy_captain/controllers/frame_link_controller.js +20 -0
  8. data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +58 -16
  9. data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +5 -0
  10. data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +235 -21
  11. data/app/assets/javascript/ahoy_captain/controllers/map_controller.js +47 -0
  12. data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +1 -1
  13. data/app/assets/javascript/ahoy_captain/controllers/properties_controller.js +8 -0
  14. data/app/assets/javascript/ahoy_captain/controllers/property_filter_controller.js +45 -0
  15. data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +4 -2
  16. data/app/assets/javascript/ahoy_captain/controllers/tile_controller.js +33 -0
  17. data/app/assets/javascript/ahoy_captain/helpers/chart_utils.js +156 -0
  18. data/app/assets/javascript/ahoy_captain/helpers/countries.js +2261 -0
  19. data/app/assets/javascript/ahoy_captain/helpers/number_formatters.js +55 -0
  20. data/app/components/ahoy_captain/combobox_component.html.erb +33 -0
  21. data/app/components/ahoy_captain/combobox_component.rb +13 -0
  22. data/app/components/ahoy_captain/comparison_link_component.html.erb +17 -0
  23. data/app/components/ahoy_captain/comparison_link_component.rb +44 -0
  24. data/app/components/ahoy_captain/dropdown_link_component.html.erb +2 -4
  25. data/app/components/ahoy_captain/dropdown_link_component.rb +4 -0
  26. data/app/components/ahoy_captain/filter/dropdown_component.html.erb +8 -6
  27. data/app/components/ahoy_captain/filter/modal_component.html.erb +7 -5
  28. data/app/components/ahoy_captain/filter/select_component.html.erb +23 -21
  29. data/app/components/ahoy_captain/filter/select_component.rb +2 -1
  30. data/app/components/ahoy_captain/filter/tag_component.html.erb +1 -1
  31. data/app/components/ahoy_captain/previous_next_component.html.erb +8 -0
  32. data/app/components/ahoy_captain/previous_next_component.rb +11 -0
  33. data/app/components/ahoy_captain/stats/comparable_container_component.html.erb +25 -0
  34. data/app/components/ahoy_captain/stats/comparable_container_component.rb +86 -0
  35. data/app/components/ahoy_captain/stats/container_component.html.erb +13 -6
  36. data/app/components/ahoy_captain/stats/container_component.rb +15 -1
  37. data/app/components/ahoy_captain/sticky_nav_component.html.erb +27 -20
  38. data/app/components/ahoy_captain/sticky_nav_component.rb +11 -0
  39. data/app/components/ahoy_captain/table_component.rb +13 -4
  40. data/app/components/ahoy_captain/tables/devices_table_component.rb +11 -0
  41. data/app/components/ahoy_captain/tables/dynamic_table.rb +13 -0
  42. data/app/components/ahoy_captain/tables/dynamic_table_component.rb +204 -0
  43. data/app/components/ahoy_captain/tables/goals_table_component.rb +17 -0
  44. data/app/components/ahoy_captain/tables/header_component.html.erb +5 -0
  45. data/app/components/ahoy_captain/tables/header_component.rb +18 -0
  46. data/app/components/ahoy_captain/tables/headers/header_component.rb +4 -0
  47. data/app/components/ahoy_captain/tables/properties_table_component.rb +27 -0
  48. data/app/components/ahoy_captain/tables/row_component.html.erb +4 -0
  49. data/app/components/ahoy_captain/tables/rows/row_component.rb +0 -1
  50. data/app/components/ahoy_captain/tile_component.html.erb +19 -9
  51. data/app/components/ahoy_captain/tile_component.rb +9 -1
  52. data/app/controllers/ahoy_captain/application_controller.rb +7 -16
  53. data/app/controllers/ahoy_captain/exports_controller.rb +1 -2
  54. data/app/controllers/ahoy_captain/filters/base_controller.rb +1 -3
  55. data/app/controllers/ahoy_captain/filters/goals_controller.rb +9 -0
  56. data/app/controllers/ahoy_captain/filters/pages/actions_controller.rb +1 -1
  57. data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +1 -1
  58. data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +1 -1
  59. data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +4 -4
  60. data/app/controllers/ahoy_captain/filters/utms_controller.rb +1 -1
  61. data/app/controllers/ahoy_captain/locations/cities_controller.rb +22 -0
  62. data/app/controllers/ahoy_captain/locations/countries_controller.rb +22 -0
  63. data/app/controllers/ahoy_captain/locations/maps_controller.rb +24 -0
  64. data/app/controllers/ahoy_captain/locations/regions_controller.rb +22 -0
  65. data/app/controllers/ahoy_captain/properties_controller.rb +41 -0
  66. data/app/controllers/ahoy_captain/stats/base_controller.rb +86 -5
  67. data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +1 -1
  68. data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +1 -1
  69. data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +1 -1
  70. data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +2 -1
  71. data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +1 -10
  72. data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -1
  73. data/app/helpers/ahoy_captain/application_helper.rb +33 -9
  74. data/app/models/ahoy_captain/comparison_mode.rb +72 -0
  75. data/app/models/ahoy_captain/filter_parser.rb +33 -18
  76. data/app/models/ahoy_captain/range_from_params.rb +78 -0
  77. data/app/models/ahoy_captain/rangeable.rb +0 -3
  78. data/app/models/concerns/ahoy_captain/compare_mode.rb +19 -0
  79. data/app/models/concerns/ahoy_captain/limitable.rb +17 -0
  80. data/app/models/concerns/ahoy_captain/range_options.rb +1 -14
  81. data/app/presenters/ahoy_captain/dashboard_presenter.rb +18 -54
  82. data/app/queries/ahoy_captain/application_query.rb +74 -10
  83. data/app/queries/ahoy_captain/event_query.rb +7 -2
  84. data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +11 -4
  85. data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +14 -2
  86. data/app/queries/ahoy_captain/stats/base_query.rb +18 -0
  87. data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +15 -1
  88. data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +2 -2
  89. data/app/queries/ahoy_captain/stats/total_visitors_query.rb +1 -1
  90. data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +1 -1
  91. data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +1 -1
  92. data/app/queries/ahoy_captain/stats/visit_duration_query.rb +2 -2
  93. data/app/queries/ahoy_captain/visit_query.rb +1 -2
  94. data/app/queries/concerns/ahoy_captain/comparable_queries.rb +25 -0
  95. data/app/queries/concerns/ahoy_captain/comparable_query.rb +138 -0
  96. data/app/queries/concerns/ahoy_captain/lazy_comparable_query.rb +42 -0
  97. data/app/views/ahoy_captain/devices/_table.html.erb +1 -4
  98. data/app/views/ahoy_captain/goals/index.html.erb +1 -4
  99. data/app/views/ahoy_captain/layouts/application.html.erb +0 -1
  100. data/app/views/ahoy_captain/layouts/shared/_tile_loader.html.erb +12 -0
  101. data/app/views/ahoy_captain/locations/maps/show.html.erb +3 -0
  102. data/app/views/ahoy_captain/properties/_form.html.erb +6 -0
  103. data/app/views/ahoy_captain/properties/index.html.erb +3 -0
  104. data/app/views/ahoy_captain/properties/show.html.erb +6 -0
  105. data/app/views/ahoy_captain/roots/_filters.html.erb +47 -1
  106. data/app/views/ahoy_captain/roots/show.html.erb +109 -48
  107. data/app/views/ahoy_captain/stats/base/index.html.erb +37 -8
  108. data/app/views/ahoy_captain/stats/show.html.erb +14 -11
  109. data/config/routes.rb +9 -3
  110. data/lib/ahoy_captain/ahoy/event_methods.rb +12 -14
  111. data/lib/ahoy_captain/configuration.rb +2 -1
  112. data/lib/ahoy_captain/engine.rb +4 -0
  113. data/lib/ahoy_captain/filters_configuration.rb +10 -6
  114. data/lib/ahoy_captain/version.rb +1 -1
  115. data/lib/ahoy_captain.rb +7 -1
  116. data/lib/generators/ahoy_captain/templates/config.rb.tt +7 -0
  117. metadata +137 -22
  118. data/app/assets/javascript/ahoy_captain/controllers/active_links_controller.js +0 -18
  119. data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +0 -20
  120. data/app/assets/javascript/ahoy_captain/controllers/search_select_controller.js +0 -65
  121. data/app/components/ahoy_captain/tables/headers/devices_header_component.html.erb +0 -3
  122. data/app/components/ahoy_captain/tables/headers/devices_header_component.rb +0 -9
  123. data/app/components/ahoy_captain/tables/headers/goals_header_component.html.erb +0 -6
  124. data/app/components/ahoy_captain/tables/headers/goals_header_component.rb +0 -9
  125. data/app/components/ahoy_captain/tables/rows/devices_row_component.html.erb +0 -5
  126. data/app/components/ahoy_captain/tables/rows/devices_row_component.rb +0 -12
  127. data/app/components/ahoy_captain/tables/rows/goals_row_component.html.erb +0 -11
  128. data/app/components/ahoy_captain/tables/rows/goals_row_component.rb +0 -20
  129. data/app/controllers/ahoy_captain/cities_controller.rb +0 -20
  130. data/app/controllers/ahoy_captain/countries_controller.rb +0 -20
  131. data/app/controllers/ahoy_captain/regions_controller.rb +0 -20
  132. /data/app/views/ahoy_captain/{cities → locations/cities}/index.html+details.erb +0 -0
  133. /data/app/views/ahoy_captain/{cities → locations/cities}/index.html.erb +0 -0
  134. /data/app/views/ahoy_captain/{countries → locations/countries}/index.html+details.erb +0 -0
  135. /data/app/views/ahoy_captain/{countries → locations/countries}/index.html.erb +0 -0
  136. /data/app/views/ahoy_captain/{regions → locations/regions}/index.html+details.erb +0 -0
  137. /data/app/views/ahoy_captain/{regions → locations/regions}/index.html.erb +0 -0
@@ -1,34 +1,66 @@
1
- <main class='min-h-screen pb-4 max-w-6xl mx-auto' data-controller="application">
1
+ <main class='w-screen overflow-hidden' data-action="combobox:init@window->application#comboboxInit">
2
+ <script id="tile-loader-template" type="template/html">
3
+ <%= render '/ahoy_captain/layouts/shared/tile_loader' %>
4
+ </script>
2
5
  <%= render AhoyCaptain::StickyNavComponent.new do |nav| %>
3
6
  <% nav.with_realtime_update do %>
4
- <%= turbo_frame_tag :realtime, src: realtime_path, data: { controller: "realtime" }, loading: :lazy %>
7
+ <%= turbo_frame_tag :realtime, src: realtime_path, data: { controller: "realtime", "realtime-interval-value" => AhoyCaptain.config.realtime_interval.to_i }, loading: :lazy %>
5
8
  <% end %>
6
9
  <% end %>
7
10
 
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| %>
11
+ <div class="grid grid-cols-1 lg:grid-cols-2 grid-flow-row gap-4 min-h-screen pb-4 max-w-6xl mx-auto">
12
+ <%= render AhoyCaptain::TileComponent.new(wide: true, classes: "p-4 m-2") do |component| %>
10
13
  <% component.with_statistic_display do %>
11
- <%= turbo_frame_tag :stats, src: stats_path(search_params), loading: :lazy %>
14
+ <%= turbo_frame_tag :stats, src: stats_path(search_params), loading: :lazy, skeleton: false do %>
15
+ <div 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">
16
+ <% 6.times do %>
17
+ <div class="relative px-4 md:px-6 w-1/2 my-4 w-auto group cursor-pointer" >
18
+ <div role="status" class="max-w-sm animate-pulse">
19
+ <div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[120px] mb-2.5"></div>
20
+ <div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5 max-w-[60px]"></div>
21
+ <span class="sr-only">Loading...</span>
22
+ </div>
23
+ </div>
24
+ <% end %>
25
+ </div>
26
+ <% end %>
27
+ <%= turbo_frame_tag :chart, src: stats_unique_visitors_path(search_params) do %>
28
+ <div role="status" class="p-4 animate-pulse md:p-6">
29
+ <div class="flex items-baseline mt-4 space-x-6">
30
+ <div class="w-full bg-gray-200 rounded-t-lg h-72 dark:bg-gray-700"></div>
31
+ <div class="w-full h-56 bg-gray-200 rounded-t-lg dark:bg-gray-700"></div>
32
+ <div class="w-full bg-gray-200 rounded-t-lg h-72 dark:bg-gray-700"></div>
33
+ <div class="w-full h-64 bg-gray-200 rounded-t-lg dark:bg-gray-700"></div>
34
+ <div class="w-full bg-gray-200 rounded-t-lg h-80 dark:bg-gray-700"></div>
35
+ <div class="w-full bg-gray-200 rounded-t-lg h-72 dark:bg-gray-700"></div>
36
+ <div class="w-full bg-gray-200 rounded-t-lg h-80 dark:bg-gray-700"></div>
37
+ </div>
38
+ <span class="sr-only">Loading...</span>
39
+ </div>
40
+ <% end %>
12
41
  <% end %>
42
+
13
43
  <% end %>
14
44
 
15
45
  <%= render AhoyCaptain::TileComponent.new(title: 'Top Sources') do |component| %>
16
- <% component.with_display_links do %>
17
- <div data-controller="active-links">
18
- <a href="<%= sources_path(search_params) %>" data-turbo-frame="sources" class="" data-active-links-target="link">All</a>
19
- <%= render AhoyCaptain::DropdownLinkComponent.new(title: "Campaign") do |dropdown| %>
20
- <% %w{utm_source utm_medium utm_term utm_content utm_campaign}.each do |source| %>
21
- <% dropdown.with_option do %>
22
- <a href="<%= public_send("campaign_#{source}_path".to_sym, **search_params) %>" class="" data-turbo-frame="sources" data-active-links-target="link">
23
- <%= source.titleize.gsub("Utm", "UTM") %>
24
- </a>
46
+ <% component.with_display_links do %>
47
+ <div class="flex text-xs font-medium text-gray-400 space-x-2">
48
+ <div class="relative inline-block text-left">
49
+ <%= component.link_to "All", sources_path(search_params), data: { turbo_frame: "sources" } %>
50
+ <%= render AhoyCaptain::DropdownLinkComponent.new(title: "Campaign") do |dropdown| %>
51
+ <% %w{utm_source utm_medium utm_term utm_content utm_campaign}.each do |source| %>
52
+ <%= dropdown.link_to source.titleize.gsub("Utm", "UTM"), public_send("campaign_#{source}_path".to_sym, **search_params), data: { turbo_frame: "sources" } %>
25
53
  <% end %>
26
54
  <% end %>
27
- <% end %>
55
+ </div>
28
56
  </div>
57
+
58
+
29
59
  <% end %>
30
60
  <% component.with_statistic_display do %>
31
- <%= turbo_frame_tag :sources, src: sources_path(search_params), loading: :lazy %>
61
+ <%= turbo_frame_tag :sources, src: sources_path(search_params), loading: :lazy do %>
62
+ <%= render '/ahoy_captain/layouts/shared/tile_loader' %>
63
+ <% end %>
32
64
  <% end %>
33
65
  <% component.with_details_cta do %>
34
66
  <button data-action="click->details-modal#openModal" data-controller="details-modal" data-details-modal-target-value="#sources" class="link no-underline ">Details</button>
@@ -37,75 +69,104 @@
37
69
 
38
70
  <%= render AhoyCaptain::TileComponent.new(title: 'Top Pages') do |component| %>
39
71
  <% component.with_display_links do %>
40
- <div data-controller='active-links'>
41
- <a href="<%= top_pages_path(search_params) %>" data-turbo-frame="pages" class=" text-sm" data-active-links-target="link">Top Pages</a>
42
- <a href="<%= entry_pages_path(search_params) %>" data-turbo-frame="pages" class=" text-sm" data-active-links-target="link">Entry Pages</a>
43
- <a href="<%= exit_pages_path(search_params) %>" data-turbo-frame="pages" class=" text-sm" data-active-links-target="link">Exit Pages</a>
72
+ <div class="flex text-xs font-medium text-gray-400 space-x-2">
73
+ <div class="relative inline-block text-left"><div>
74
+ <%= component.link_to "Top Pages", top_pages_path(search_params), data: { action: "click->tile#setTitle", turbo_frame: "pages" } %>
75
+ <%= component.link_to "Entry Pages", entry_pages_path(search_params), data: { action: "click->tile#setTitle", turbo_frame: "pages" } %>
76
+ <%= component.link_to "Exit Pages", exit_pages_path(search_params), data: { action: "click->tile#setTitle", turbo_frame: "pages" } %>
77
+ </div>
78
+ </div>
44
79
  </div>
80
+
45
81
  <% end %>
46
82
  <% component.with_statistic_display do %>
47
- <%= turbo_frame_tag :pages, src: top_pages_path(search_params), loading: :lazy %>
83
+ <%= turbo_frame_tag :pages, src: top_pages_path(search_params), loading: :lazy do %>
84
+ <%= render '/ahoy_captain/layouts/shared/tile_loader' %>
85
+ <% end %>
48
86
  <% end %>
49
87
  <% component.with_details_cta do %>
50
88
  <button data-action="click->details-modal#openModal" data-controller="details-modal" data-details-modal-target-value="#pages" class="link no-underline ">Details</button>
51
89
  <% end %>
52
90
  <% end %>
53
91
 
54
- <%= render AhoyCaptain::TileComponent.new(title: 'Countries') do |component| %>
92
+ <%= render AhoyCaptain::TileComponent.new(title: 'Map') do |component| %>
55
93
  <% component.with_display_links do %>
56
- <div data-controller="active-links">
57
- <a href="<%= countries_path(search_params) %>" data-turbo-frame="geography" class=" text-sm" data-active-links-target="link">Countries</a>
58
- <a href="<%= regions_path(search_params) %>" data-turbo-frame="geography" class=" text-sm" data-active-links-target="link">Regions</a>
59
- <a href="<%= cities_path(search_params) %>" data-turbo-frame="geography" class=" text-sm" data-active-links-target="link">Cities</a>
94
+ <div class="flex text-xs font-medium text-gray-400 space-x-2">
95
+ <div class="relative inline-block text-left">
96
+ <%= component.link_to "Map", locations_map_path(search_params), data: { action: "click->tile#setTitle", turbo_frame: "geography" } %>
97
+ <%= component.link_to "Countries", locations_countries_path(search_params), data: { action: "click->tile#setTitle", turbo_frame: "geography" } %>
98
+ <%= component.link_to "Regions", locations_regions_path(search_params), data: { action: "click->tile#setTitle", turbo_frame: "geography" } %>
99
+ <%= component.link_to "Cities", locations_cities_path(search_params), data: { action: "click->tile#setTitle", turbo_frame: "geography" } %>
100
+ </div>
60
101
  </div>
61
102
  <% end %>
62
103
  <% component.with_statistic_display do %>
63
- <%= turbo_frame_tag :geography, src: countries_path(search_params), loading: :lazy %>
104
+ <%= turbo_frame_tag :geography, src: locations_map_path(search_params), loading: :lazy do %>
105
+ <%= render '/ahoy_captain/layouts/shared/tile_loader' %>
106
+
107
+ <% end %>
64
108
  <% end %>
65
109
  <% component.with_details_cta do %>
66
- <button data-action="click->details-modal#openModal" data-controller="details-modal" data-details-modal-target-value="#geography" class="link no-underline ">Details</button>
110
+ <button data-action="click->details-modal#openModal" data-controller="details-modal" data-details-modal-target-value="#geography" class="link no-underline ">Details</button>
67
111
  <% end %>
68
112
  <% end %>
69
113
 
70
114
  <%= render AhoyCaptain::TileComponent.new(title: 'Devices') do |component| %>
71
115
  <% component.with_display_links do %>
72
- <div data-controller="active-links">
73
- <a href="<%= devices_browsers_path(search_params) %>" data-turbo-frame="devices" class=" text-sm" data-active-links-target="link">Browser</a>
74
- <a href="<%= devices_operating_systems_path(search_params) %>" data-turbo-frame="devices" class=" text-sm" data-active-links-target="link">OS</a>
75
- <a href="<%= devices_device_types_path(search_params) %>" data-turbo-frame="devices" class=" text-sm" data-active-links-target="link">Size</a>
116
+ <div class="flex text-xs font-medium text-gray-400 space-x-2">
117
+ <div class="relative inline-block text-left">
118
+ <%= component.link_to "Browser", devices_browsers_path(search_params), data: { turbo_frame: "devices" } %>
119
+ <%= component.link_to "OS", devices_operating_systems_path(search_params), data: { turbo_frame: "devices" } %>
120
+ <%= component.link_to "Size", devices_device_types_path(search_params), data: { turbo_frame: "devices" } %>
121
+ </div>
76
122
  </div>
77
123
  <% end %>
78
124
  <% component.with_statistic_display do %>
79
- <%= turbo_frame_tag :devices, src: devices_browsers_path(search_params), loading: :lazy %>
125
+ <%= turbo_frame_tag :devices, src: devices_browsers_path(search_params), loading: :lazy do %>
126
+ <%= render '/ahoy_captain/layouts/shared/tile_loader' %>
127
+
128
+ <% end %>
80
129
  <% end %>
81
130
  <% component.with_details_cta do %>
82
131
  <button data-action="click->details-modal#openModal" data-controller="details-modal" data-details-modal-target-value="#devices" class="link no-underline ">Details</button>
83
132
  <% end %>
84
133
  <% end %>
85
- <%= render AhoyCaptain::TileComponent.new(wide: true) do |component| %>
134
+ <%= render AhoyCaptain::TileComponent.new(title: "Goals and Funnels", wide: true, classes: "p-4 m-2") do |component| %>
86
135
  <% component.with_display_links do %>
87
- <a href="<%= goals_path(search_params) %>" data-turbo-frame="goals" class="link ">
88
- Goals
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 %>
136
+ <div>
137
+ <div >
138
+ <div class="flex text-xs font-medium text-gray-400 space-x-2">
139
+ <div class="relative inline-block text-left">
140
+ <a href="<%= goals_path(search_params) %>" data-turbo-frame="goals" class="inline-block h-5 font-semibold" data-controller="frame-link" data-action="click->tile#setTitle">Goals</a>
141
+ <a href="<%= properties_path(search_params) %>" data-turbo-frame="goals" class="inline-block h-5 font-semibold" data-controller="frame-link" data-action="click->tile#setTitle">Properties</a>
142
+ <%= render AhoyCaptain::DropdownLinkComponent.new(title: "Funnels") do |dropdown| %>
143
+ <% AhoyCaptain.config.funnels.each do |id, funnel| %>
144
+ <% dropdown.with_option do %>
145
+ <a href="<%= funnel_path(id, search_params) %>" data-turbo-frame="goals" class="link " data-action="click->tile#setTitle" title="<%= funnel.title %> Funnel">
146
+ <%= funnel.title %>
147
+ </a>
148
+ <% end %>
149
+ <% end %>
150
+ <% end %>
151
+ </div>
152
+ </div>
99
153
 
154
+ </div>
155
+ </div>
100
156
  <% end %>
101
157
  <% component.with_statistic_display do %>
102
- <%= turbo_frame_tag :goals, src: goals_path(search_params), loading: :lazy %>
158
+ <div class="p-4">
159
+ <%= turbo_frame_tag :goals, src: goals_path(search_params), loading: :lazy do %>
160
+ <%= render '/ahoy_captain/layouts/shared/tile_loader' %>
161
+ <% end %>
162
+
163
+ </div>
103
164
  <% end %>
104
165
  <% end %>
105
166
  </div>
106
167
  </main>
107
168
 
108
- <%= render 'filters' %>
169
+ <%= render 'ahoy_captain/roots/filters' %>
109
170
 
110
171
  <dialog id="detailsModal" class="modal">
111
172
  <div class="modal-box w-11/12 max-w-5xl">
@@ -1,11 +1,40 @@
1
1
  <%= turbo_frame_tag :chart do %>
2
- <div class="flex justify-end gap-3 items-center">
3
- <a href="<%= export_path(request.query_parameters) %>" class="link text-sm" target="_blank" data-turbo-frame="false">Download</a>
4
- <%= form_with url: url_for(params.permit!), method: :get, data: { controller: "interval" } do %>
5
- <%= select_tag :interval, options_for_select(available_intervals.collect { |interval| [interval.titleize, interval] }, selected: selected_interval), class: "select text-primary select-sm w-full max-w-sm", 'data-action': "change->interval#handleChange" %>
6
- <% end %>
7
- </div>
8
- <div>
9
- <canvas style="height:300px;width:100%;" data-controller="line-chart" data-line-chart-label-value="<%= @label %>" data-line-chart-data-value="<%= @stats.to_json %>"></canvas>
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
+ <canvas id="overlay" width="600" height="400" style="position:absolute;pointer-events:none;"></canvas>
11
+
12
+ <% if compare_mode? %>
13
+ <canvas class="h-[300px] w-full"
14
+ data-controller="line-chart"
15
+ data-line-chart-label-value="<%= @label %>"
16
+ data-line-chart-interval-value="<%= selected_interval %>"
17
+ data-line-chart-current-value="<%= @stats.current.to_json %>"
18
+ data-line-chart-comparison-value="<%= params[:comparison] %>"
19
+ data-line-chart-compared-to-value="<%= @stats.compared_to.to_json %>"
20
+ data-line-chart-metric-value="<%= metric_type(@stats) %>"
21
+ data-action="resize@window->line-chart#resize"
22
+ data-action="mouseenter->line-chart#hover"
23
+ data-action="mouseleave->line-chart#hover"
24
+ ></canvas>
25
+ <% else %>
26
+ <canvas class="h-[300px] w-full"
27
+ data-controller="line-chart"
28
+ data-line-chart-label-value="<%= @label %>"
29
+ data-line-chart-interval-value="<%= selected_interval %>"
30
+ data-line-chart-current-value="<%= @stats.to_json %>"
31
+ data-line-chart-metric-value="<%= metric_type(@stats) %>"
32
+ data-action="resize@window->line-chart#resize"
33
+ data-action="mouseenter->line-chart#hover"
34
+ data-action="mouseleave->line-chart#hover"
35
+ ></canvas>
36
+ <% end %>
37
+ </div>
10
38
  </div>
39
+
11
40
  <% end %>
@@ -1,12 +1,15 @@
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 -mt-4 mb-4" data-controller="active-links" data-active-links-classes-value='["text-primary"]'>
3
- <%= render ::AhoyCaptain::Stats::ContainerComponent.new(stats_unique_visitors_url(search_params), "Unique Visits", number_with_delimiter(@presenter.unique_visitors), true) %>
4
- <%= render ::AhoyCaptain::Stats::ContainerComponent.new(stats_total_visits_path(search_params), "Total Visits", number_with_delimiter(@presenter.total_visits)) %>
5
- <%= render ::AhoyCaptain::Stats::ContainerComponent.new(stats_total_pageviews_path(search_params), "Total Pageviews", number_with_delimiter(@presenter.total_pageviews)) %>
6
- <%= render ::AhoyCaptain::Stats::ContainerComponent.new(stats_views_per_visits_path(search_params), "Views per Visit", number_with_delimiter(@presenter.views_per_visit)) %>
7
- <%= render ::AhoyCaptain::Stats::ContainerComponent.new(stats_bounce_rates_path(search_params), "Bounce Rate", "#{number_with_delimiter(@presenter.bounce_rate)}%") %>
8
- <%= render ::AhoyCaptain::Stats::ContainerComponent.new(stats_visit_durations_url(search_params), "Visit Duration", @presenter.visit_duration) %>
9
- </dl>
10
- <%= turbo_frame_tag :chart, src: stats_unique_visitors_path(search_params) do %>
11
- <% end %>
1
+ <%= turbo_frame_tag :stats, data: { controller: "active-frame-link" } do %>
2
+ <div 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
+ <% if @presenter.send(:range).realtime? %>
4
+ <%= render stats_container(@presenter.unique_visitors, stats_unique_visitors_url(search_params), "Unique Visits (30 min)", :number_with_delimiter, true) %>
5
+ <%= render stats_container(@presenter.total_pageviews, stats_total_pageviews_path(search_params), "Total Pageviews (30 min)", :number_with_delimiter) %>
6
+ <% else %>
7
+ <%= render stats_container(@presenter.unique_visitors, stats_unique_visitors_url(search_params), "Unique Visits", :number_with_delimiter, true) %>
8
+ <%= render stats_container(@presenter.total_visits, stats_total_visits_path(search_params), "Total Visits", :number_with_delimiter) %>
9
+ <%= render stats_container(@presenter.total_pageviews, stats_total_pageviews_path(search_params), "Total Pageviews", :number_with_delimiter) %>
10
+ <%= render stats_container(@presenter.views_per_visit, stats_views_per_visits_path(search_params), "Views per Visit", :number_with_delimiter) %>
11
+ <%= render stats_container(@presenter.bounce_rate, stats_bounce_rates_path(search_params), "Bounce Rate", :number_with_delimiter) %>
12
+ <%= render stats_container(@presenter.visit_duration, stats_visit_durations_url(search_params), "Visit Duration", :number_to_duration) %>
13
+ <% end %>
14
+ </div>
12
15
  <% end %>
data/config/routes.rb CHANGED
@@ -12,14 +12,19 @@ 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
+ namespace :locations do
16
+ resource :map, only: [:show]
17
+ resources :countries, only: [:index]
18
+ resources :regions, only: [:index]
19
+ resources :cities, only: [:index]
20
+ end
21
+
22
+ resources :properties, only: [:index, :show]
15
23
  resource :export, only: [:show]
16
24
  resource :realtime, only: [:show]
17
25
  resources :funnels, only: [:show]
18
26
  resources :goals, only: [:index]
19
27
  resource :stats, only: [:show]
20
- resources :countries, only: [:index]
21
- resources :regions, only: [:index]
22
- resources :cities, only: [:index]
23
28
  resources :campaigns, only: [:index]
24
29
  resources :sources, only: [:index]
25
30
  resources :exit_pages, only: [:index]
@@ -48,6 +53,7 @@ AhoyCaptain::Engine.routes.draw do
48
53
  resources :values, only: [:index]
49
54
  end
50
55
 
56
+ resources :goals, only: [:index]
51
57
  resources :sources, only: [:index]
52
58
  resources :screens, only: [:index]
53
59
  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
@@ -19,8 +21,11 @@ module AhoyCaptain
19
21
  scope :with_entry_pages, -> {
20
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(#{table_name}.id) as max_id, #{Arel.sql("#{AhoyCaptain.config.event.url_column} AS url")}").where(name: AhoyCaptain.config.event[:view_name]).group("#{table_name}.properties")).joins("INNER JOIN exit_pages ON exit_pages.max_id = #{table_name}.id")
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 :property_name_eq, ->(value) {
37
- where("properties ? :key", key: value)
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
- scope :properties_not_eq, ->(value) do
45
- where.not("properties::jsonb @> ?", value)
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", "id_property", "name", "page", "properties", "time", "url", "user_id", "visit_id", "property_name", "goal"] + self._ransackers.keys
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
@@ -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
 
@@ -24,6 +24,10 @@ module Ransack
24
24
  end
25
25
  end
26
26
 
27
+ Ransack.configure do |config|
28
+ config.add_predicate 'json_cont', arel_predicate: 'contains', formatter: proc { |v| JSON.parse(v) }
29
+ config.add_predicate 'json_eq', arel_predicate: 'eq', formatter: proc { |v| JSON.parse(v) }
30
+ end
27
31
 
28
32
  module AhoyCaptain
29
33
  class Engine < Rails::Engine
@@ -30,12 +30,16 @@ module AhoyCaptain
30
30
  filter column: :os_version, label: "OS Version", url: :filters_versions_path, predicates: [:in, :not_in]
31
31
  end
32
32
 
33
- config.register("UTM Tag") do
34
- filter column: :utm_medium, label: "UTM Medium", url: :filters_utm_mediums_path, predicates: [:in, :not_in]
35
- filter column: :utm_source, label: "UTM Source", url: :filters_utm_sources_path, predicates: [:in, :not_in]
36
- filter column: :utm_campaign, label: "UTM Campaign", url: :filters_utm_campaigns_path, predicates: [:in, :not_in]
37
- filter column: :utm_term, label: "UTM Term", url: :filters_utm_terms_path, predicates: [:in, :not_in]
38
- filter column: :utm_content, label: "UTM Content", url: :filters_utm_contents_path, predicates: [:in, :not_in]
33
+ config.register("UTM Tags") do
34
+ filter column: :utm_medium, label: "UTM Medium", url: :filters_utm_mediums_path, predicates: [:in, :not_in, :cont]
35
+ filter column: :utm_source, label: "UTM Source", url: :filters_utm_sources_path, predicates: [:in, :not_in, :cont]
36
+ filter column: :utm_campaign, label: "UTM Campaign", url: :filters_utm_campaigns_path, predicates: [:in, :not_in, :cont]
37
+ filter column: :utm_term, label: "UTM Term", url: :filters_utm_terms_path, predicates: [:in, :not_in, :cont]
38
+ filter column: :utm_content, label: "UTM Content", url: :filters_utm_contents_path, predicates: [:in, :not_in, :cont]
39
+ end
40
+
41
+ config.register("Goal") do
42
+ filter column: :goal, label: "Goal", url: :filters_goals_path, predicates: [:in]
39
43
  end
40
44
  end
41
45
  end
@@ -1,3 +1,3 @@
1
1
  module AhoyCaptain
2
- VERSION = "0.91"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/ahoy_captain.rb CHANGED
@@ -28,11 +28,13 @@ module AhoyCaptain
28
28
  pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
29
29
  pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
30
30
  pin "application", to: "ahoy_captain/application.js", preload: true
31
- pin "slim-select", to: "https://ga.jspm.io/npm:slim-select@2.6.0/dist/slimselect.es.js", preload: true
32
31
  pin "chartkick", to: "chartkick.js"
33
32
  pin "Chart.bundle", to: "Chart.bundle.js"
34
33
  pin "chartjs-plugin-datalabels", to: "https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2", preload: true
34
+ pin "classnames", to: "https://cdnjs.cloudflare.com/ajax/libs/classnames/2.3.2/index.min.js", preload: true
35
+ pin "chartjs-chart-geo", to: "https://unpkg.com/chartjs-chart-geo@4", preload: true
35
36
  pin_all_from AhoyCaptain::Engine.root.join("app/assets/javascript/ahoy_captain/controllers"), under: "controllers", to: "ahoy_captain/controllers"
37
+ pin_all_from AhoyCaptain::Engine.root.join("app/assets/javascript/ahoy_captain/helpers"), under: "helpers", to: "ahoy_captain/helpers"
36
38
  end
37
39
  end
38
40
 
@@ -51,5 +53,9 @@ module AhoyCaptain
51
53
  def visit
52
54
  @visit ||= config.models[:visit].constantize
53
55
  end
56
+
57
+ def none
58
+ @none ||= OpenStruct.new(text: "(none)", value: "!none!")
59
+ end
54
60
  end
55
61
  end
@@ -80,6 +80,8 @@ AhoyCaptain.configure do |config|
80
80
  #
81
81
  # Set to false to disable custom ranges
82
82
  # config.ranges.custom = true
83
+ #
84
+ # For an interval to be considered "realtime" it must not have a secondary item in the range
83
85
 
84
86
  # ==> Filters
85
87
  #
@@ -160,4 +162,9 @@ AhoyCaptain.configure do |config|
160
162
  # goal :appointment_created
161
163
  # goal :appointment_paid
162
164
  # end
165
+ #
166
+ # => Realtime interval
167
+ # config.realtime_interval = 30.seconds
168
+ #
169
+ # How frequently the page should refresh if the interval is realtime
163
170
  end