ahoy_captain 0.77 → 0.81
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascript/ahoy_captain/application.js +4 -4
- data/app/assets/javascript/ahoy_captain/controllers/application.js +5 -5
- data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +9 -10
- data/app/assets/javascript/ahoy_captain/controllers/details_modal_controller.js +5 -5
- data/app/assets/javascript/ahoy_captain/controllers/dropdown_label_controller.js +2 -2
- data/app/assets/javascript/ahoy_captain/controllers/filter_controller.js +64 -58
- data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +11 -8
- data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +77 -133
- data/app/assets/javascript/ahoy_captain/controllers/index.js +4 -3
- data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +10 -0
- data/app/assets/javascript/ahoy_captain/controllers/link_controller.js +22 -22
- data/app/assets/javascript/ahoy_captain/controllers/navigation_controller.js +10 -10
- data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +7 -8
- data/app/controllers/ahoy_captain/application_controller.rb +17 -15
- data/app/controllers/ahoy_captain/campaigns_controller.rb +2 -10
- data/app/controllers/ahoy_captain/cities_controller.rb +2 -6
- data/app/controllers/ahoy_captain/countries_controller.rb +2 -6
- data/app/controllers/ahoy_captain/devices_controller.rb +3 -6
- data/app/controllers/ahoy_captain/entry_pages_controller.rb +2 -4
- data/app/controllers/ahoy_captain/exit_pages_controller.rb +3 -4
- data/app/controllers/ahoy_captain/exports_controller.rb +15 -0
- data/app/controllers/ahoy_captain/realtimes_controller.rb +1 -1
- data/app/controllers/ahoy_captain/regions_controller.rb +3 -7
- data/app/controllers/ahoy_captain/sources_controller.rb +2 -5
- data/app/controllers/ahoy_captain/stats/base_controller.rb +61 -0
- data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +3 -2
- data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +1 -1
- data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +1 -1
- data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +1 -1
- data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +7 -6
- data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -1
- data/app/controllers/ahoy_captain/top_pages_controller.rb +2 -8
- data/app/decorators/ahoy_captain/application_decorator.rb +27 -3
- data/app/decorators/ahoy_captain/campaign_decorator.rb +8 -0
- data/app/decorators/ahoy_captain/city_decorator.rb +12 -0
- data/app/decorators/ahoy_captain/country_decorator.rb +10 -0
- data/app/decorators/ahoy_captain/device_decorator.rb +13 -2
- data/app/decorators/ahoy_captain/page_decorator.rb +11 -0
- data/app/decorators/ahoy_captain/region_decorator.rb +16 -0
- data/app/decorators/ahoy_captain/source_decorator.rb +7 -0
- data/app/models/ahoy_captain/export.rb +48 -0
- data/app/presenters/ahoy_captain/dashboard_presenter.rb +24 -16
- data/app/presenters/ahoy_captain/funnel_presenter.rb +32 -29
- data/app/presenters/ahoy_captain/goals_presenter.rb +32 -23
- data/app/queries/ahoy_captain/application_query.rb +5 -2
- data/app/queries/ahoy_captain/campaign_query.rb +14 -0
- data/app/queries/ahoy_captain/city_query.rb +11 -0
- data/app/queries/ahoy_captain/country_query.rb +10 -0
- data/app/queries/ahoy_captain/device_query.rb +10 -0
- data/app/queries/ahoy_captain/entry_pages_query.rb +3 -2
- data/app/queries/ahoy_captain/event_query.rb +16 -1
- data/app/queries/ahoy_captain/exit_pages_query.rb +6 -4
- data/app/queries/ahoy_captain/region_query.rb +11 -0
- data/app/queries/ahoy_captain/source_query.rb +10 -0
- data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +3 -7
- data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +9 -6
- data/app/queries/ahoy_captain/stats/total_visitors_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +2 -2
- data/app/queries/ahoy_captain/stats/visit_duration_query.rb +4 -4
- data/app/queries/ahoy_captain/top_page_query.rb +13 -0
- data/app/queries/ahoy_captain/visit_query.rb +12 -12
- data/app/views/ahoy_captain/goals/index.html.erb +5 -5
- data/app/views/ahoy_captain/roots/show.html.erb +1 -1
- data/app/views/ahoy_captain/stats/base/index.html.erb +9 -1
- data/app/views/ahoy_captain/stats/show.html.erb +1 -1
- data/config/routes.rb +1 -0
- data/lib/ahoy_captain/ahoy/event_methods.rb +1 -1
- data/lib/ahoy_captain/configuration.rb +2 -2
- data/lib/ahoy_captain/engine.rb +1 -0
- data/lib/ahoy_captain/goals.rb +8 -4
- data/lib/ahoy_captain/period_collection.rb +1 -1
- data/lib/ahoy_captain/version.rb +1 -1
- data/lib/generators/ahoy_captain/migration_generator.rb +21 -0
- data/lib/generators/ahoy_captain/templates/config.rb.tt +18 -3
- data/lib/generators/ahoy_captain/templates/migration.rb.tt +7 -0
- metadata +42 -4
- data/app/models/ahoy_captain/current.rb +0 -9
- data/app/models/ahoy_captain/url_helpers.rb +0 -6
@@ -1,25 +1,25 @@
|
|
1
|
-
import {Controller} from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
2
|
|
3
3
|
export default class extends Controller {
|
4
4
|
connect() {
|
5
5
|
this.queryString = new URLSearchParams(window.location.search);
|
6
|
-
this.baseURL = window.location.pathname.replace(/\/$/,
|
6
|
+
this.baseURL = window.location.pathname.replace(/\/$/, '');
|
7
7
|
}
|
8
|
-
|
8
|
+
|
9
9
|
navigate() {
|
10
10
|
const url = `${this.baseURL}?${this.queryString.toString()}`;
|
11
|
-
Turbo.visit(url, { action:
|
11
|
+
Turbo.visit(url, { action: 'replace' });
|
12
12
|
}
|
13
13
|
|
14
14
|
addQueryParam({ detail: { paramKey, paramValue } }) {
|
15
|
-
this.queryString.append(paramKey, paramValue)
|
15
|
+
this.queryString.append(paramKey, paramValue);
|
16
16
|
}
|
17
|
-
|
17
|
+
|
18
18
|
removeQueryParam({ detail: { paramKey, paramValue } }) {
|
19
19
|
if (!this.queryString.has(paramKey)) {
|
20
|
-
paramKey +=
|
20
|
+
paramKey += '[]';
|
21
21
|
}
|
22
|
-
this.queryString.delete(paramKey,paramValue)
|
23
|
-
this.navigate()
|
22
|
+
this.queryString.delete(paramKey, paramValue);
|
23
|
+
this.navigate();
|
24
24
|
}
|
25
|
-
}
|
25
|
+
}
|
@@ -1,13 +1,12 @@
|
|
1
|
-
import {Controller} from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
2
|
|
3
3
|
export default class extends Controller {
|
4
|
-
static targets = [
|
4
|
+
static targets = ['label'];
|
5
5
|
|
6
6
|
connect() {
|
7
|
-
this.reload = this.reload.bind(this)
|
8
|
-
this.setLabel = this.setLabel.bind(this)
|
7
|
+
this.reload = this.reload.bind(this);
|
8
|
+
this.setLabel = this.setLabel.bind(this);
|
9
9
|
this.labelCount = 0;
|
10
|
-
|
11
10
|
}
|
12
11
|
|
13
12
|
reload() {
|
@@ -17,11 +16,11 @@ export default class extends Controller {
|
|
17
16
|
|
18
17
|
setLabel() {
|
19
18
|
this.labelTarget.title = `Last updated ${this.labelCount} seconds ago`;
|
20
|
-
this.labelCount += 1
|
19
|
+
this.labelCount += 1;
|
21
20
|
}
|
22
21
|
|
23
22
|
disconnect() {
|
24
|
-
clearInterval(this.labelInterval)
|
25
|
-
clearInterval(this.reloadInterval)
|
23
|
+
clearInterval(this.labelInterval);
|
24
|
+
clearInterval(this.reloadInterval);
|
26
25
|
}
|
27
26
|
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module AhoyCaptain
|
4
2
|
module Limitable
|
5
3
|
private
|
@@ -22,19 +20,25 @@ module AhoyCaptain
|
|
22
20
|
|
23
21
|
layout 'ahoy_captain/layouts/application'
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
# show the details frame
|
24
|
+
before_action :use_details_frame
|
25
|
+
|
26
|
+
# act like an spa without being an spa
|
27
|
+
before_action :act_like_an_spa
|
28
|
+
|
29
|
+
rescue_from Widget::WidgetDisabled do |e|
|
30
|
+
render template: 'ahoy_captain/shared/widget_disabled', locals: { frame: e.frame }
|
27
31
|
end
|
28
32
|
|
29
|
-
|
30
|
-
|
33
|
+
private
|
34
|
+
|
35
|
+
def use_details_frame
|
31
36
|
if request.headers['Turbo-Frame'] == 'details'
|
32
37
|
request.variant = :details
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
|
-
|
37
|
-
before_action do
|
41
|
+
def act_like_an_spa
|
38
42
|
if request.format.html? && request.headers['Turbo-Frame'].blank?
|
39
43
|
if request.path != root_path
|
40
44
|
requested_params = Rails.application.routes.recognize_path(request.path).except(:controller, :action)
|
@@ -46,12 +50,6 @@ module AhoyCaptain
|
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
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
53
|
def visit_query
|
56
54
|
VisitQuery.call(params)
|
57
55
|
end
|
@@ -60,6 +58,7 @@ module AhoyCaptain
|
|
60
58
|
EventQuery.call(params)
|
61
59
|
end
|
62
60
|
|
61
|
+
# Only paginate details requests requests
|
63
62
|
def paginate(collection)
|
64
63
|
if paginate?
|
65
64
|
pagy, results = pagy(collection, page: params[:page])
|
@@ -75,7 +74,10 @@ module AhoyCaptain
|
|
75
74
|
end
|
76
75
|
|
77
76
|
def cached(*names)
|
78
|
-
AhoyCaptain.cache.
|
77
|
+
if AhoyCaptain.cache.class == ActiveSupport::Cache::NullStore
|
78
|
+
return yield
|
79
|
+
end
|
80
|
+
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
81
|
yield
|
80
82
|
end
|
81
83
|
end
|
@@ -10,17 +10,9 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:campaigns, params[:campaigns_type]) do
|
13
|
-
|
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)
|
13
|
+
CampaignQuery.call(params).limit(limit)
|
22
14
|
end
|
23
|
-
@campaigns = paginate(results).map { |campaign| CampaignDecorator.new(campaign) }
|
15
|
+
@campaigns = paginate(results).map { |campaign| CampaignDecorator.new(campaign, self) }
|
24
16
|
@campaign_type = params[:campaigns_type]&.titleize&.gsub("Utm", "UTM")
|
25
17
|
end
|
26
18
|
end
|
@@ -10,15 +10,11 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:cities) do
|
13
|
-
|
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")
|
13
|
+
CityQuery.call(params)
|
18
14
|
.limit(limit)
|
19
15
|
end
|
20
16
|
|
21
|
-
@cities = paginate(results).map { |city| CityDecorator.new(city) }
|
17
|
+
@cities = paginate(results).map { |city| CityDecorator.new(city, self) }
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
class CountriesController < ApplicationController
|
3
3
|
include Limitable
|
4
|
-
include Rangeable
|
5
4
|
|
6
5
|
before_action do
|
7
6
|
if Widget.disabled?(:locations, :countries)
|
@@ -11,14 +10,11 @@ module AhoyCaptain
|
|
11
10
|
|
12
11
|
def index
|
13
12
|
results = cached(:countries) do
|
14
|
-
|
15
|
-
.reselect("country as label, count(country) as count, sum(count(country)) OVER() as total_count")
|
16
|
-
.group("country")
|
17
|
-
.order("count(country) desc")
|
13
|
+
CountryQuery.call(params)
|
18
14
|
.limit(limit)
|
19
15
|
end
|
20
16
|
|
21
|
-
@countries = paginate(results).map { |country| CountryDecorator.new(country) }
|
17
|
+
@countries = paginate(results).map { |country| CountryDecorator.new(country, self) }
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
@@ -10,14 +10,11 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:devices, params[:devices_type]) do
|
13
|
-
|
14
|
-
|
15
|
-
.group(params[:devices_type])
|
16
|
-
.order("count(#{params[:devices_type]}) desc")
|
17
|
-
.limit(limit)
|
13
|
+
DeviceQuery.call(params)
|
14
|
+
.limit(limit)
|
18
15
|
end
|
19
16
|
|
20
|
-
@devices = results.map { |device| DeviceDecorator.new(device) }
|
17
|
+
@devices = results.map { |device| DeviceDecorator.new(device, self) }
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
@@ -10,12 +10,10 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:entry_pages) do
|
13
|
-
EntryPagesQuery.call(params
|
14
|
-
.order(Arel.sql "count(#{AhoyCaptain.config.event[:url_column]}) desc")
|
15
|
-
.limit(limit)
|
13
|
+
EntryPagesQuery.call(params).limit(limit)
|
16
14
|
end
|
17
15
|
|
18
|
-
@pages = paginate(results).map { |page| EntryPageDecorator.new(page) }
|
16
|
+
@pages = paginate(results).map { |page| EntryPageDecorator.new(page, self) }
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -10,11 +10,10 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:exit_pages) do
|
13
|
-
ExitPagesQuery.call(params
|
14
|
-
.
|
15
|
-
.limit(limit)
|
13
|
+
ExitPagesQuery.call(params)
|
14
|
+
.limit(limit)
|
16
15
|
end
|
17
|
-
@pages = paginate(results).map { |page| ExitPageDecorator.new(page) }
|
16
|
+
@pages = paginate(results).map { |page| ExitPageDecorator.new(page, self) }
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
class ExportsController < ApplicationController
|
3
|
+
skip_before_action :act_like_an_spa
|
4
|
+
include Rangeable
|
5
|
+
|
6
|
+
def show
|
7
|
+
export = Export.new(params, self).build
|
8
|
+
file = export.to_zip
|
9
|
+
send_data file.read,
|
10
|
+
type: 'application/zip',
|
11
|
+
disposition: 'attachment',
|
12
|
+
filename: "AhoyCaptain export #{request.host} #{range[0].to_date} to #{range[1].to_date}.zip"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
class RealtimesController < ApplicationController
|
3
3
|
def show
|
4
|
-
@total = event_query.where(
|
4
|
+
@total = event_query.where("#{AhoyCaptain.event.table_name}.time > ?", 1.minute.ago).distinct(:visit_id).count(:visit_id)
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
@@ -10,15 +10,11 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:regions) do
|
13
|
-
|
14
|
-
|
15
|
-
.where.not(region: nil)
|
16
|
-
.group("region, country")
|
17
|
-
.order(Arel.sql "count(concat(region, country)) desc")
|
18
|
-
.limit(limit)
|
13
|
+
RegionQuery.call(params)
|
14
|
+
.limit(limit)
|
19
15
|
end
|
20
16
|
|
21
|
-
@regions = paginate(results).map { |region| RegionDecorator.new(region) }
|
17
|
+
@regions = paginate(results).map { |region| RegionDecorator.new(region, self) }
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
@@ -10,14 +10,11 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:sources) do
|
13
|
-
|
14
|
-
.where.not(referring_domain: nil)
|
15
|
-
.group("substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')")
|
16
|
-
.order(Arel.sql "count(substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')) desc")
|
13
|
+
SourceQuery.call(params)
|
17
14
|
.limit(limit)
|
18
15
|
end
|
19
16
|
|
20
|
-
@sources = paginate(results).map { |source| AhoyCaptain::SourceDecorator.new(source) }
|
17
|
+
@sources = paginate(results).map { |source| AhoyCaptain::SourceDecorator.new(source, self) }
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
@@ -1,6 +1,67 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
module Stats
|
3
3
|
class BaseController < ApplicationController
|
4
|
+
include Rangeable
|
5
|
+
|
6
|
+
INTERVAL_PERIOD = {
|
7
|
+
"realtime" => ["minute"],
|
8
|
+
"day" => ["minute", "hour"],
|
9
|
+
"7d" => ["hour", "day"],
|
10
|
+
"month" => ["day", "week"],
|
11
|
+
"all" => ["day", "week", "month"]
|
12
|
+
}
|
13
|
+
|
14
|
+
INTERVALS = ["minute", "hour", "day", "week", "month"]
|
15
|
+
private
|
16
|
+
|
17
|
+
helper_method :selected_interval
|
18
|
+
def selected_interval
|
19
|
+
if params[:interval].in?(INTERVALS)
|
20
|
+
params[:interval]
|
21
|
+
else
|
22
|
+
default_interval_for_period
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_interval_for_period
|
27
|
+
default_interval_for_date_range(range)
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_interval_for_date_range(range)
|
31
|
+
if range[1].nil?
|
32
|
+
# assume we're in a realtime
|
33
|
+
return INTERVAL_PERIOD["realtime"][0]
|
34
|
+
end
|
35
|
+
diff = (range[1] - range[0]).seconds
|
36
|
+
if diff.in_months > 1
|
37
|
+
"month"
|
38
|
+
elsif diff.in_days > 0
|
39
|
+
"day"
|
40
|
+
else
|
41
|
+
"hour"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
helper_method :available_intervals
|
46
|
+
def available_intervals
|
47
|
+
if range
|
48
|
+
return INTERVAL_PERIOD["realtime"] if range[1].nil?
|
49
|
+
|
50
|
+
diff = (range[1] - range[0]).seconds.in_days
|
51
|
+
|
52
|
+
if diff == 0
|
53
|
+
INTERVAL_PERIOD["day"]
|
54
|
+
elsif diff <= 7
|
55
|
+
INTERVAL_PERIOD["7d"]
|
56
|
+
elsif diff <= 31
|
57
|
+
INTERVAL_PERIOD["month"]
|
58
|
+
else
|
59
|
+
INTERVAL_PERIOD["all"]
|
60
|
+
end
|
61
|
+
else
|
62
|
+
INTERVAL_PERIOD["month"]
|
63
|
+
end
|
64
|
+
end
|
4
65
|
end
|
5
66
|
end
|
6
67
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
module Stats
|
3
3
|
class BounceRatesController < BaseController
|
4
|
+
# @todo: this is lazy
|
4
5
|
def index
|
5
|
-
@stats = AhoyCaptain::Stats::BounceRatesQuery.call(params)
|
6
|
-
|
6
|
+
@stats = AhoyCaptain::Stats::BounceRatesQuery.call(params)
|
7
|
+
@stats = @stats.group_by_period(selected_interval, "daily_bounce_rate.date").average("bounce_rate")
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -2,7 +2,7 @@ module AhoyCaptain
|
|
2
2
|
module Stats
|
3
3
|
class TotalPageviewsController < BaseController
|
4
4
|
def index
|
5
|
-
@stats = AhoyCaptain::Stats::TotalPageviewsQuery.call(params).
|
5
|
+
@stats = AhoyCaptain::Stats::TotalPageviewsQuery.call(params).group_by_period(selected_interval, :time).count
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module AhoyCaptain
|
|
2
2
|
module Stats
|
3
3
|
class TotalVisitsController < BaseController
|
4
4
|
def index
|
5
|
-
@stats = AhoyCaptain::Stats::TotalVisitorsQuery.call(params).
|
5
|
+
@stats = AhoyCaptain::Stats::TotalVisitorsQuery.call(params).group_by_period(selected_interval, :started_at).count
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module AhoyCaptain
|
|
2
2
|
module Stats
|
3
3
|
class UniqueVisitorsController < BaseController
|
4
4
|
def index
|
5
|
-
@stats = AhoyCaptain::Stats::UniqueVisitorsQuery.call(params).
|
5
|
+
@stats = AhoyCaptain::Stats::UniqueVisitorsQuery.call(params).group_by_period(selected_interval, :started_at).count
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
module Stats
|
3
3
|
class ViewsPerVisitsController < BaseController
|
4
|
-
|
5
|
-
|
4
|
+
# @todo: make me a window func
|
6
5
|
def index
|
7
|
-
@stats = AhoyCaptain::Stats::ViewsPerVisitQuery.call(params).
|
8
|
-
|
9
|
-
|
10
|
-
@stats
|
6
|
+
@stats = AhoyCaptain::Stats::ViewsPerVisitQuery.call(params).group_by_period(selected_interval, 'views_per_visit_table.started_at').average(:views_per_visit)
|
7
|
+
if range[1]
|
8
|
+
(range[0].to_date..range[1].to_date).to_a.each do |date|
|
9
|
+
unless @stats.key?(date.to_date)
|
10
|
+
@stats[date.to_date] = 2
|
11
|
+
end
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -2,7 +2,7 @@ module AhoyCaptain
|
|
2
2
|
module Stats
|
3
3
|
class VisitDurationsController < BaseController
|
4
4
|
def index
|
5
|
-
@stats = AhoyCaptain::Stats::VisitDurationQuery.call(params).
|
5
|
+
@stats = AhoyCaptain::Stats::VisitDurationQuery.call(params).group_by_period(selected_interval, 'started_at').average(:duration)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -10,17 +10,11 @@ module AhoyCaptain
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
results = cached(:top_pages) do
|
13
|
-
|
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"))
|
13
|
+
TopPageQuery.call(params)
|
20
14
|
.limit(limit)
|
21
15
|
end
|
22
16
|
|
23
|
-
@pages = paginate(results).map { |page| TopPageDecorator.new(page) }
|
17
|
+
@pages = paginate(results).map { |page| TopPageDecorator.new(page, self) }
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
@@ -1,15 +1,39 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
1
3
|
module AhoyCaptain
|
2
4
|
class ApplicationDecorator
|
3
5
|
attr_reader :object
|
4
6
|
|
5
|
-
def
|
7
|
+
def self.to_csv(collection, context)
|
8
|
+
rows = collection.map { |row| new(row, context) }
|
9
|
+
CSV.generate do |csv|
|
10
|
+
csv << csv_map(context.params).keys
|
11
|
+
|
12
|
+
rows.each do |row|
|
13
|
+
items = []
|
14
|
+
csv_map.values.each do |attr|
|
15
|
+
items << row.send(attr)
|
16
|
+
end
|
17
|
+
|
18
|
+
csv << items
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.csv_map(params = {})
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
delegate_missing_to :object
|
28
|
+
def initialize(object, context)
|
6
29
|
@object = object
|
30
|
+
@context = context
|
7
31
|
end
|
8
32
|
|
9
33
|
private
|
10
34
|
|
11
35
|
def h
|
12
|
-
@h ||=
|
36
|
+
@h ||= @context.view_context
|
13
37
|
end
|
14
38
|
|
15
39
|
def params
|
@@ -28,7 +52,7 @@ module AhoyCaptain
|
|
28
52
|
end
|
29
53
|
|
30
54
|
def request
|
31
|
-
|
55
|
+
@context.request
|
32
56
|
end
|
33
57
|
end
|
34
58
|
end
|
@@ -1,10 +1,22 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
class CityDecorator < CountryDecorator
|
3
|
+
def self.csv_map(params = {})
|
4
|
+
{
|
5
|
+
"Country" => :country,
|
6
|
+
"City" => :city,
|
7
|
+
"Total" => :unit_amount
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
3
11
|
def display_name
|
4
12
|
search = search_query(country_eq: object.country, city_eq: object.city)
|
5
13
|
frame_link("#{country_emoji(object.country)} #{object.city}", search)
|
6
14
|
end
|
7
15
|
|
16
|
+
def country
|
17
|
+
"#{country_emoji(object.country)} #{object.country}"
|
18
|
+
end
|
19
|
+
|
8
20
|
def unit_amount
|
9
21
|
object.count
|
10
22
|
end
|
@@ -1,6 +1,16 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
class CountryDecorator < ApplicationDecorator
|
3
3
|
EMOJI_MAP = { "AD": "🇦🇩", "AE": "🇦🇪", "AF": "🇦🇫", "AG": "🇦🇬", "AI": "🇦🇮", "AL": "🇦🇱", "AM": "🇦🇲", "AO": "🇦🇴", "AQ": "🇦🇶", "AR": "🇦🇷", "AS": "🇦🇸", "AT": "🇦🇹", "AU": "🇦🇺", "AW": "🇦🇼", "AX": "🇦🇽", "AZ": "🇦🇿", "BA": "🇧🇦", "BB": "🇧🇧", "BD": "🇧🇩", "BE": "🇧🇪", "BF": "🇧🇫", "BG": "🇧🇬", "BH": "🇧🇭", "BI": "🇧🇮", "BJ": "🇧🇯", "BL": "🇧🇱", "BM": "🇧🇲", "BN": "🇧🇳", "BO": "🇧🇴", "BQ": "🇧🇶", "BR": "🇧🇷", "BS": "🇧🇸", "BT": "🇧🇹", "BV": "🇧🇻", "BW": "🇧🇼", "BY": "🇧🇾", "BZ": "🇧🇿", "CA": "🇨🇦", "CC": "🇨🇨", "CD": "🇨🇩", "CF": "🇨🇫", "CG": "🇨🇬", "CH": "🇨🇭", "CI": "🇨🇮", "CK": "🇨🇰", "CL": "🇨🇱", "CM": "🇨🇲", "CN": "🇨🇳", "CO": "🇨🇴", "CR": "🇨🇷", "CU": "🇨🇺", "CV": "🇨🇻", "CW": "🇨🇼", "CX": "🇨🇽", "CY": "🇨🇾", "CZ": "🇨🇿", "DE": "🇩🇪", "DJ": "🇩🇯", "DK": "🇩🇰", "DM": "🇩🇲", "DO": "🇩🇴", "DZ": "🇩🇿", "EC": "🇪🇨", "EE": "🇪🇪", "EG": "🇪🇬", "EH": "🇪🇭", "ER": "🇪🇷", "ES": "🇪🇸", "ET": "🇪🇹", "FI": "🇫🇮", "FJ": "🇫🇯", "FK": "🇫🇰", "FM": "🇫🇲", "FO": "🇫🇴", "FR": "🇫🇷", "GA": "🇬🇦", "GB": "🇬🇧", "GD": "🇬🇩", "GE": "🇬🇪", "GF": "🇬🇫", "GG": "🇬🇬", "GH": "🇬🇭", "GI": "🇬🇮", "GL": "🇬🇱", "GM": "🇬🇲", "GN": "🇬🇳", "GP": "🇬🇵", "GQ": "🇬🇶", "GR": "🇬🇷", "GS": "🇬🇸", "GT": "🇬🇹", "GU": "🇬🇺", "GW": "🇬🇼", "GY": "🇬🇾", "HK": "🇭🇰", "HM": "🇭🇲", "HN": "🇭🇳", "HR": "🇭🇷", "HT": "🇭🇹", "HU": "🇭🇺", "ID": "🇮🇩", "IE": "🇮🇪", "IL": "🇮🇱", "IM": "🇮🇲", "IN": "🇮🇳", "IO": "🇮🇴", "IQ": "🇮🇶", "IR": "🇮🇷", "IS": "🇮🇸", "IT": "🇮🇹", "JE": "🇯🇪", "JM": "🇯🇲", "JO": "🇯🇴", "JP": "🇯🇵", "KE": "🇰🇪", "KG": "🇰🇬", "KH": "🇰🇭", "KI": "🇰🇮", "KM": "🇰🇲", "KN": "🇰🇳", "KP": "🇰🇵", "KR": "🇰🇷", "KW": "🇰🇼", "KY": "🇰🇾", "KZ": "🇰🇿", "LA": "🇱🇦", "LB": "🇱🇧", "LC": "🇱🇨", "LI": "🇱🇮", "LK": "🇱🇰", "LR": "🇱🇷", "LS": "🇱🇸", "LT": "🇱🇹", "LU": "🇱🇺", "LV": "🇱🇻", "LY": "🇱🇾", "MA": "🇲🇦", "MC": "🇲🇨", "MD": "🇲🇩", "ME": "🇲🇪", "MF": "🇲🇫", "MG": "🇲🇬", "MH": "🇲🇭", "MK": "🇲🇰", "ML": "🇲🇱", "MM": "🇲🇲", "MN": "🇲🇳", "MO": "🇲🇴", "MP": "🇲🇵", "MQ": "🇲🇶", "MR": "🇲🇷", "MS": "🇲🇸", "MT": "🇲🇹", "MU": "🇲🇺", "MV": "🇲🇻", "MW": "🇲🇼", "MX": "🇲🇽", "MY": "🇲🇾", "MZ": "🇲🇿", "NA": "🇳🇦", "NC": "🇳🇨", "NE": "🇳🇪", "NF": "🇳🇫", "NG": "🇳🇬", "NI": "🇳🇮", "NL": "🇳🇱", "NO": "🇳🇴", "NP": "🇳🇵", "NR": "🇳🇷", "NU": "🇳🇺", "NZ": "🇳🇿", "OM": "🇴🇲", "PA": "🇵🇦", "PE": "🇵🇪", "PF": "🇵🇫", "PG": "🇵🇬", "PH": "🇵🇭", "PK": "🇵🇰", "PL": "🇵🇱", "PM": "🇵🇲", "PN": "🇵🇳", "PR": "🇵🇷", "PS": "🇵🇸", "PT": "🇵🇹", "PW": "🇵🇼", "PY": "🇵🇾", "QA": "🇶🇦", "RE": "🇷🇪", "RO": "🇷🇴", "RS": "🇷🇸", "RU": "🇷🇺", "RW": "🇷🇼", "SA": "🇸🇦", "SB": "🇸🇧", "SC": "🇸🇨", "SD": "🇸🇩", "SE": "🇸🇪", "SG": "🇸🇬", "SH": "🇸🇭", "SI": "🇸🇮", "SJ": "🇸🇯", "SK": "🇸🇰", "SL": "🇸🇱", "SM": "🇸🇲", "SN": "🇸🇳", "SO": "🇸🇴", "SR": "🇸🇷", "SS": "🇸🇸", "ST": "🇸🇹", "SV": "🇸🇻", "SX": "🇸🇽", "SY": "🇸🇾", "SZ": "🇸🇿", "TC": "🇹🇨", "TD": "🇹🇩", "TF": "🇹🇫", "TG": "🇹🇬", "TH": "🇹🇭", "TJ": "🇹🇯", "TK": "🇹🇰", "TL": "🇹🇱", "TM": "🇹🇲", "TN": "🇹🇳", "TO": "🇹🇴", "TR": "🇹🇷", "TT": "🇹🇹", "TV": "🇹🇻", "TW": "🇹🇼", "TZ": "🇹🇿", "UA": "🇺🇦", "UG": "🇺🇬", "UM": "🇺🇲", "US": "🇺🇸", "UY": "🇺🇾", "UZ": "🇺🇿", "VA": "🇻🇦", "VC": "🇻🇨", "VE": "🇻🇪", "VG": "🇻🇬", "VI": "🇻🇮", "VN": "🇻🇳", "VU": "🇻🇺", "WF": "🇼🇫", "WS": "🇼🇸", "YE": "🇾🇪", "YT": "🇾🇹", "ZA": "🇿🇦", "ZM": "🇿🇲", "ZW": "🇿🇼" }
|
4
|
+
def self.csv_map(params = {})
|
5
|
+
{
|
6
|
+
"Country" => :label,
|
7
|
+
"Total" => :unit_amount
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def label
|
12
|
+
"#{country_emoji(country)} #{country}"
|
13
|
+
end
|
4
14
|
|
5
15
|
def display_name
|
6
16
|
search = search_query(country_eq: object.label)
|
@@ -1,8 +1,19 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
class DeviceDecorator < ApplicationDecorator
|
3
|
+
def self.csv_map(params = {})
|
4
|
+
{
|
5
|
+
"#{params[:devices_type]}" => :label,
|
6
|
+
"Total" => :unit_amount
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
3
10
|
def display_name
|
4
|
-
search = search_query("#{params[:devices_type]}_eq" =>
|
5
|
-
frame_link(
|
11
|
+
search = search_query("#{params[:devices_type]}_eq" => label)
|
12
|
+
frame_link(label, search)
|
13
|
+
end
|
14
|
+
|
15
|
+
def label
|
16
|
+
object.label
|
6
17
|
end
|
7
18
|
|
8
19
|
def unit_amount
|
@@ -1,5 +1,16 @@
|
|
1
1
|
module AhoyCaptain
|
2
2
|
class PageDecorator < ApplicationDecorator
|
3
|
+
def self.csv_map(params = {})
|
4
|
+
{
|
5
|
+
"URL" => :label,
|
6
|
+
"Total" => :unit_amount
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
def label
|
11
|
+
object.url
|
12
|
+
end
|
13
|
+
|
3
14
|
def display_name
|
4
15
|
search = search_query(type => object.url)
|
5
16
|
frame_link(object.url, search)
|