ahoy_captain 0.1.0 → 0.76
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +55 -14
- data/Rakefile +1 -10
- data/app/assets/images/ahoy_captain/apple-touch-icon.png +0 -0
- data/app/assets/images/ahoy_captain/favicon-16x16.png +0 -0
- data/app/assets/images/ahoy_captain/favicon-32x32.png +0 -0
- data/app/assets/images/ahoy_captain/logo.png +0 -0
- data/app/assets/images/ahoy_captain/safari-pinned-tab.svg +199 -0
- data/app/assets/javascript/ahoy_captain/application.js +4 -0
- data/app/assets/javascript/ahoy_captain/controllers/application.js +9 -0
- data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +14 -0
- data/app/assets/javascript/ahoy_captain/controllers/details_modal_controller.js +18 -0
- data/app/assets/javascript/ahoy_captain/controllers/dropdown_label_controller.js +14 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter_controller.js +145 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +17 -0
- data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +143 -0
- data/app/assets/javascript/ahoy_captain/controllers/index.js +3 -0
- data/app/assets/javascript/ahoy_captain/controllers/link_controller.js +43 -0
- data/app/assets/javascript/ahoy_captain/controllers/navigation_controller.js +25 -0
- data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +27 -0
- data/app/assets/manifest/ahoy_captain/manifest.js +2 -0
- data/app/components/ahoy_captain/dropdown_button_component.html.erb +16 -0
- data/app/components/ahoy_captain/dropdown_button_component.rb +14 -0
- data/app/components/ahoy_captain/dropdown_link_component.html.erb +19 -0
- data/app/components/ahoy_captain/dropdown_link_component.rb +15 -0
- data/app/components/ahoy_captain/filter/modal_component.html.erb +13 -0
- data/app/components/ahoy_captain/filter/modal_component.rb +13 -0
- data/app/components/ahoy_captain/filter/select_component.html.erb +21 -0
- data/app/components/ahoy_captain/filter/select_component.rb +32 -0
- data/app/components/ahoy_captain/filter/tag_component.html.erb +9 -0
- data/app/components/ahoy_captain/filter/tag_component.rb +38 -0
- data/app/components/ahoy_captain/filter/tag_container_component.html.erb +5 -0
- data/app/components/ahoy_captain/filter/tag_container_component.rb +13 -0
- data/app/components/ahoy_captain/sticky_nav_component.html.erb +37 -0
- data/app/components/ahoy_captain/sticky_nav_component.rb +5 -0
- data/app/components/ahoy_captain/table_component.html.erb +49 -0
- data/app/components/ahoy_captain/table_component.rb +28 -0
- data/app/components/ahoy_captain/tile_component.html.erb +12 -0
- data/app/components/ahoy_captain/tile_component.rb +16 -0
- data/app/components/ahoy_captain/tooltip_component.html.erb +3 -0
- data/app/components/ahoy_captain/tooltip_component.rb +18 -0
- data/app/controllers/ahoy_captain/application_controller.rb +83 -0
- data/app/controllers/ahoy_captain/campaigns_controller.rb +27 -0
- data/app/controllers/ahoy_captain/cities_controller.rb +24 -0
- data/app/controllers/ahoy_captain/countries_controller.rb +24 -0
- data/app/controllers/ahoy_captain/devices_controller.rb +23 -0
- data/app/controllers/ahoy_captain/entry_pages_controller.rb +21 -0
- data/app/controllers/ahoy_captain/exit_pages_controller.rb +20 -0
- data/app/controllers/ahoy_captain/filters/base_controller.rb +17 -0
- data/app/controllers/ahoy_captain/filters/locations_controller.rb +11 -0
- data/app/controllers/ahoy_captain/filters/operating_systems/names_controller.rb +13 -0
- data/app/controllers/ahoy_captain/filters/operating_systems/versions_controller.rb +13 -0
- data/app/controllers/ahoy_captain/filters/pages/actions_controller.rb +13 -0
- data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +14 -0
- data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +16 -0
- data/app/controllers/ahoy_captain/filters/screens_controller.rb +11 -0
- data/app/controllers/ahoy_captain/filters/sources_controller.rb +11 -0
- data/app/controllers/ahoy_captain/filters/utms_controller.rb +10 -0
- data/app/controllers/ahoy_captain/funnels_controller.rb +8 -0
- data/app/controllers/ahoy_captain/goals_controller.rb +7 -0
- data/app/controllers/ahoy_captain/realtimes_controller.rb +7 -0
- data/app/controllers/ahoy_captain/regions_controller.rb +24 -0
- data/app/controllers/ahoy_captain/roots_controller.rb +6 -0
- data/app/controllers/ahoy_captain/sources_controller.rb +24 -0
- data/app/controllers/ahoy_captain/stats/base_controller.rb +6 -0
- data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +10 -0
- data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +9 -0
- data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +9 -0
- data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +9 -0
- data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +16 -0
- data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +9 -0
- data/app/controllers/ahoy_captain/stats_controller.rb +7 -0
- data/app/controllers/ahoy_captain/top_pages_controller.rb +26 -0
- data/app/decorators/ahoy_captain/application_decorator.rb +34 -0
- data/app/decorators/ahoy_captain/campaign_decorator.rb +19 -0
- data/app/decorators/ahoy_captain/city_decorator.rb +12 -0
- data/app/decorators/ahoy_captain/country_decorator.rb +28 -0
- data/app/decorators/ahoy_captain/device_decorator.rb +16 -0
- data/app/decorators/ahoy_captain/entry_page_decorator.rb +7 -0
- data/app/decorators/ahoy_captain/exit_page_decorator.rb +7 -0
- data/app/decorators/ahoy_captain/page_decorator.rb +16 -0
- data/app/decorators/ahoy_captain/region_decorator.rb +12 -0
- data/app/decorators/ahoy_captain/source_decorator.rb +20 -0
- data/app/decorators/ahoy_captain/top_page_decorator.rb +7 -0
- data/app/helpers/ahoy_captain/application_helper.rb +32 -0
- data/app/models/ahoy_captain/current.rb +9 -0
- data/app/models/ahoy_captain/rangeable.rb +10 -0
- data/app/models/ahoy_captain/url_helpers.rb +6 -0
- data/app/models/ahoy_captain/widget.rb +15 -0
- data/app/models/concerns/ahoy_captain/range_options.rb +21 -0
- data/app/presenters/ahoy_captain/dashboard_presenter.rb +81 -0
- data/app/presenters/ahoy_captain/funnel_presenter.rb +65 -0
- data/app/presenters/ahoy_captain/goals_presenter.rb +60 -0
- data/app/queries/ahoy_captain/application_query.rb +118 -0
- data/app/queries/ahoy_captain/entry_pages_query.rb +17 -0
- data/app/queries/ahoy_captain/event_query.rb +20 -0
- data/app/queries/ahoy_captain/exit_pages_query.rb +17 -0
- data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +13 -0
- data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +15 -0
- data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +14 -0
- data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +9 -0
- data/app/queries/ahoy_captain/stats/total_visitors_query.rb +9 -0
- data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +9 -0
- data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +17 -0
- data/app/queries/ahoy_captain/stats/visit_duration_query.rb +16 -0
- data/app/queries/ahoy_captain/visit_query.rb +32 -0
- data/app/views/ahoy_captain/campaigns/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/campaigns/index.html.erb +3 -0
- data/app/views/ahoy_captain/cities/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/cities/index.html.erb +3 -0
- data/app/views/ahoy_captain/countries/index.html+details.erb +5 -0
- data/app/views/ahoy_captain/countries/index.html.erb +3 -0
- data/app/views/ahoy_captain/devices/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/devices/index.html.erb +3 -0
- data/app/views/ahoy_captain/entry_pages/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/entry_pages/index.html.erb +3 -0
- data/app/views/ahoy_captain/exit_pages/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/exit_pages/index.html.erb +3 -0
- data/app/views/ahoy_captain/funnels/index.html.erb +7 -0
- data/app/views/ahoy_captain/funnels/show.html.erb +6 -0
- data/app/views/ahoy_captain/goals/index.html.erb +39 -0
- data/app/views/ahoy_captain/layouts/application.html.erb +127 -0
- data/app/views/ahoy_captain/realtimes/show.html.erb +9 -0
- data/app/views/ahoy_captain/regions/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/regions/index.html.erb +3 -0
- data/app/views/ahoy_captain/roots/show.html.erb +179 -0
- data/app/views/ahoy_captain/sources/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/sources/index.html.erb +3 -0
- data/app/views/ahoy_captain/stats/base/index.html.erb +3 -0
- data/app/views/ahoy_captain/stats/show.html.erb +57 -0
- data/app/views/ahoy_captain/top_pages/index.html+details.erb +4 -0
- data/app/views/ahoy_captain/top_pages/index.html.erb +3 -0
- data/config/routes.rb +56 -0
- data/lib/ahoy_captain/active_record.rb +108 -0
- data/lib/ahoy_captain/ahoy/event_methods.rb +114 -0
- data/lib/ahoy_captain/ahoy/visit_methods.rb +23 -0
- data/lib/ahoy_captain/configuration.rb +43 -0
- data/lib/ahoy_captain/engine.rb +24 -0
- data/lib/ahoy_captain/funnels.rb +44 -0
- data/lib/ahoy_captain/goals.rb +39 -0
- data/lib/ahoy_captain/period_collection.rb +115 -0
- data/lib/ahoy_captain/railtie.rb +7 -0
- data/lib/ahoy_captain/version.rb +1 -3
- data/lib/ahoy_captain.rb +50 -4
- data/lib/generators/ahoy_captain/install_generator.rb +18 -0
- data/lib/generators/ahoy_captain/templates/config.rb.tt +123 -0
- metadata +393 -17
- data/.rspec +0 -3
- data/.rubocop.yml +0 -13
- data/CHANGELOG.md +0 -5
- data/Gemfile +0 -12
- data/ahoy_captain.gemspec +0 -37
- data/sig/ahoy_captain.rbs +0 -4
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module AhoyCaptain
|
4
|
+
module Limitable
|
5
|
+
private
|
6
|
+
|
7
|
+
def limit
|
8
|
+
if request.variant.include?(:details)
|
9
|
+
nil
|
10
|
+
else
|
11
|
+
if params[:limit]
|
12
|
+
params[:limit].to_i
|
13
|
+
else
|
14
|
+
10
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ApplicationController < ActionController::Base
|
21
|
+
include Pagy::Backend
|
22
|
+
|
23
|
+
layout 'ahoy_captain/layouts/application'
|
24
|
+
|
25
|
+
before_action do
|
26
|
+
Current.request = self
|
27
|
+
end
|
28
|
+
|
29
|
+
# show the details frame
|
30
|
+
before_action do
|
31
|
+
if request.headers['Turbo-Frame'] == 'details'
|
32
|
+
request.variant = :details
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# act like an spa without being an spa
|
37
|
+
before_action do
|
38
|
+
if request.format.html? && request.headers['Turbo-Frame'].blank?
|
39
|
+
if request.path != root_path
|
40
|
+
requested_params = Rails.application.routes.recognize_path(request.path).except(:controller, :action)
|
41
|
+
params.merge!(requested_params)
|
42
|
+
unless params[:debug]
|
43
|
+
render template: 'ahoy_captain/roots/show'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
rescue_from Widget::WidgetDisabled do |e|
|
50
|
+
render template: 'ahoy_captain/shared/widget_disabled', locals: { frame: e.frame }
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def visit_query
|
56
|
+
VisitQuery.call(params)
|
57
|
+
end
|
58
|
+
|
59
|
+
def event_query
|
60
|
+
EventQuery.call(params)
|
61
|
+
end
|
62
|
+
|
63
|
+
def paginate(collection)
|
64
|
+
if paginate?
|
65
|
+
pagy, results = pagy(collection, page: params[:page])
|
66
|
+
@pagination = pagy
|
67
|
+
return results
|
68
|
+
end
|
69
|
+
|
70
|
+
collection
|
71
|
+
end
|
72
|
+
|
73
|
+
def paginate?
|
74
|
+
request.variant.include?(:details)
|
75
|
+
end
|
76
|
+
|
77
|
+
def cached(*names)
|
78
|
+
AhoyCaptain.cache.fetch("ahoy_captain:#{names.join(":")}:#{request.query_parameters.sort.map { |k,v| "#{k}-#{v}" }.join(":")}", expire_in: AhoyCaptain.config.cache.ttl) do
|
79
|
+
yield
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class CampaignsController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:campaigns, params[:campaigns_type])
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :sources)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:campaigns, params[:campaigns_type]) do
|
13
|
+
visit_query
|
14
|
+
.select(
|
15
|
+
"COALESCE(#{params[:campaigns_type]}, 'Direct/None') as label",
|
16
|
+
"count(COALESCE(#{params[:campaigns_type]}, 'Direct/None')) as count",
|
17
|
+
"sum(count(COALESCE(#{params[:campaigns_type]}, 'Direct/None'))) OVER() as total_count"
|
18
|
+
)
|
19
|
+
.group("COALESCE(#{params[:campaigns_type]}, 'Direct/None')")
|
20
|
+
.order(Arel.sql("count(COALESCE(#{params[:campaigns_type]}, 'Direct/None')) desc"))
|
21
|
+
.limit(limit)
|
22
|
+
end
|
23
|
+
@campaigns = paginate(results).map { |campaign| CampaignDecorator.new(campaign) }
|
24
|
+
@campaign_type = params[:campaigns_type]&.titleize&.gsub("Utm", "UTM")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class CitiesController < ApplicationController
|
3
|
+
include AhoyCaptain::Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:locations, :cities)
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :geography)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:cities) do
|
13
|
+
visit_query
|
14
|
+
.select("city, country, count(concat(city, region, country)) as count, sum(count(concat(city, region, country))) over() as total_count")
|
15
|
+
.where.not(city: nil)
|
16
|
+
.group("city, region, country")
|
17
|
+
.order(Arel.sql "count(concat(city, region, country)) desc")
|
18
|
+
.limit(limit)
|
19
|
+
end
|
20
|
+
|
21
|
+
@cities = paginate(results).map { |city| CityDecorator.new(city) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class CountriesController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
include Rangeable
|
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
|
+
visit_query
|
15
|
+
.reselect("country as label, count(country) as count, sum(count(country)) OVER() as total_count")
|
16
|
+
.group("country")
|
17
|
+
.order("count(country) desc")
|
18
|
+
.limit(limit)
|
19
|
+
end
|
20
|
+
|
21
|
+
@countries = paginate(results).map { |country| CountryDecorator.new(country) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class DevicesController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:devices, params[:devices_type])
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :devices)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:devices, params[:devices_type]) do
|
13
|
+
visit_query
|
14
|
+
.select("#{params[:devices_type]} as label", "count(#{params[:devices_type]}) as count", "sum(count(#{params[:devices_type]})) over() as total_count")
|
15
|
+
.group(params[:devices_type])
|
16
|
+
.order("count(#{params[:devices_type]}) desc")
|
17
|
+
.limit(limit)
|
18
|
+
end
|
19
|
+
|
20
|
+
@devices = results.map { |device| DeviceDecorator.new(device) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class EntryPagesController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:entry_pages)
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :pages)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:entry_pages) do
|
13
|
+
EntryPagesQuery.call(params, event_query)
|
14
|
+
.order(Arel.sql "count(#{AhoyCaptain.config.event[:url_column]}) desc")
|
15
|
+
.limit(limit)
|
16
|
+
end
|
17
|
+
|
18
|
+
@pages = paginate(results).map { |page| EntryPageDecorator.new(page) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class ExitPagesController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:exit_pages)
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :pages)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:exit_pages) do
|
13
|
+
ExitPagesQuery.call(params, event_query)
|
14
|
+
.order(Arel.sql "count(#{AhoyCaptain.config.event[:url_column]}) desc")
|
15
|
+
.limit(limit)
|
16
|
+
end
|
17
|
+
@pages = paginate(results).map { |page| ExitPageDecorator.new(page) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
class LocationsController < BaseController
|
4
|
+
def index
|
5
|
+
query = visit_query.all
|
6
|
+
|
7
|
+
render json: query.select("distinct #{params[:type]}").where.not(params[:type] => nil).group(params[:type]).order(Arel.sql "count(*) desc").limit(50).pluck(params[:type]).map { |city| serialize(city) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
module OperatingSystems
|
4
|
+
class NamesController < BaseController
|
5
|
+
def index
|
6
|
+
query = visit_query.all
|
7
|
+
|
8
|
+
render json: query.select("distinct os").where.not(os: nil).group(:os).order(Arel.sql "count(*) desc").pluck(:os).map { |city| serialize(city) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
module OperatingSystems
|
4
|
+
class VersionsController < BaseController
|
5
|
+
def index
|
6
|
+
query = visit_query.all
|
7
|
+
|
8
|
+
render json: query.select("distinct os_version").where.not(os_version: nil).group(:os_version).order(Arel.sql "count(*) desc").pluck(:os_version).map { |city| serialize(city) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
module Pages
|
4
|
+
# TODO: ACCOMODATE EXIT_PAGES
|
5
|
+
class EntryPagesController < BaseController
|
6
|
+
def index
|
7
|
+
query = event_query.all.with_url.distinct_url
|
8
|
+
render json: query.map { |row| { text: row.url } }
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
module Pages
|
4
|
+
# TODO: ACCOMODATE ENTRY_PAGES
|
5
|
+
class ExitPagesController < BaseController
|
6
|
+
def index
|
7
|
+
query = event_query.with_url.distinct_url
|
8
|
+
|
9
|
+
render json: query.map { |row| { text: row.url } }
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
class ScreensController < BaseController
|
4
|
+
def index
|
5
|
+
query = visit_query.all
|
6
|
+
|
7
|
+
render json: query.select("distinct device_type").where.not(device_type: nil).group(:device_type).order(Arel.sql "count(*) desc").pluck(:device_type).map { |city| serialize(city) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
class SourcesController < BaseController
|
4
|
+
def index
|
5
|
+
query = visit_query.all
|
6
|
+
|
7
|
+
render json: query.result.select("distinct referring_domain").where.not(referring_domain: nil).group(:referring_domain).order(Arel.sql "count(*) desc").pluck(:referring_domain).map { |city| serialize(city) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Filters
|
3
|
+
class UtmsController < BaseController
|
4
|
+
def index
|
5
|
+
query = visit_query.select("#{params[:type]}", "count(#{params[:type]}) as total").group(params[:type]).order(Arel.sql "count(#{params[:type]}) desc").pluck(params[:type]).map { |city| serialize(city || "Direct/none") }
|
6
|
+
render json: query
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class RegionsController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:locations, :regions)
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :geography)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:regions) do
|
13
|
+
visit_query
|
14
|
+
.reselect("region, country, count(concat(region, country)) as count, sum(count(region)) over() as total_count")
|
15
|
+
.where.not(region: nil)
|
16
|
+
.group("region, country")
|
17
|
+
.order(Arel.sql "count(concat(region, country)) desc")
|
18
|
+
.limit(limit)
|
19
|
+
end
|
20
|
+
|
21
|
+
@regions = paginate(results).map { |region| RegionDecorator.new(region) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class SourcesController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:sources)
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :sources)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:sources) do
|
13
|
+
visit_query.select("substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)') as referring_domain, count(substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')) as count, sum(count(substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)'))) OVER() as total_count")
|
14
|
+
.where.not(referring_domain: nil)
|
15
|
+
.group("substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')")
|
16
|
+
.order(Arel.sql "count(substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')) desc")
|
17
|
+
.limit(limit)
|
18
|
+
end
|
19
|
+
|
20
|
+
@sources = paginate(results).map { |source| AhoyCaptain::SourceDecorator.new(source) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Stats
|
3
|
+
class BounceRatesController < BaseController
|
4
|
+
def index
|
5
|
+
@stats = AhoyCaptain::Stats::BounceRatesQuery.call(params).group_by_day("ahoy_visits.started_at").average("num_events * 100")
|
6
|
+
#.group_by_day("ahoy_visits.started_at").average("total_events")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Stats
|
3
|
+
class ViewsPerVisitsController < BaseController
|
4
|
+
include Rangeable
|
5
|
+
|
6
|
+
def index
|
7
|
+
@stats = AhoyCaptain::Stats::ViewsPerVisitQuery.call(params).group_by_day('views_per_visit_table.started_at').average(:views_per_visit)
|
8
|
+
(range[0]..range[1]).to_a.each do |date|
|
9
|
+
unless @stats.key?(date.to_date)
|
10
|
+
@stats[date.to_date] = 2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class TopPagesController < ApplicationController
|
3
|
+
include Limitable
|
4
|
+
|
5
|
+
before_action do
|
6
|
+
if Widget.disabled?(:top_pages)
|
7
|
+
raise Widget::WidgetDisabled.new("Widget disabled", :pages)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
results = cached(:top_pages) do
|
13
|
+
event_query.with_routes.select(
|
14
|
+
"#{AhoyCaptain.config.event[:url_column]} as url",
|
15
|
+
"count(*) as count",
|
16
|
+
"sum(count(*)) over() as total_count"
|
17
|
+
)
|
18
|
+
.group(Arel.sql ("(#{AhoyCaptain.config.event[:url_column]})"))
|
19
|
+
.order(Arel.sql("count(#{AhoyCaptain.config.event[:url_column]}) desc"))
|
20
|
+
.limit(limit)
|
21
|
+
end
|
22
|
+
|
23
|
+
@pages = paginate(results).map { |page| TopPageDecorator.new(page) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class ApplicationDecorator
|
3
|
+
attr_reader :object
|
4
|
+
|
5
|
+
def initialize(object)
|
6
|
+
@object = object
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def h
|
12
|
+
@h ||= Current.request.view_context
|
13
|
+
end
|
14
|
+
|
15
|
+
def params
|
16
|
+
h.params
|
17
|
+
end
|
18
|
+
|
19
|
+
def search_query(args = {})
|
20
|
+
query = h.search_params.dup
|
21
|
+
query[:q] ||= {}
|
22
|
+
args.each { |k,v| query[:q]["#{k}"] = v }
|
23
|
+
query.to_query
|
24
|
+
end
|
25
|
+
|
26
|
+
def frame_link(label, search)
|
27
|
+
h.link_to(label, "#{AhoyCaptain::Engine.routes.url_helpers.root_path}?#{search}", data: { turbo_frame: "_top" }).html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
def request
|
31
|
+
Current.request.request
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class CampaignDecorator < ApplicationDecorator
|
3
|
+
def display_name
|
4
|
+
if object.label == "Direct/None"
|
5
|
+
value = ""
|
6
|
+
else
|
7
|
+
value = object.label
|
8
|
+
end
|
9
|
+
|
10
|
+
search = search_query("#{params[:campaigns_type]}_eq" => value)
|
11
|
+
|
12
|
+
frame_link(object.label, search)
|
13
|
+
end
|
14
|
+
|
15
|
+
def unit_amount
|
16
|
+
object.count
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class CityDecorator < CountryDecorator
|
3
|
+
def display_name
|
4
|
+
search = search_query(country_eq: object.country, city_eq: object.city)
|
5
|
+
frame_link("#{country_emoji(object.country)} #{object.city}", search)
|
6
|
+
end
|
7
|
+
|
8
|
+
def unit_amount
|
9
|
+
object.count
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|