ahoy_captain 0.1.0 → 0.8
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 +117 -0
- data/app/assets/javascript/ahoy_captain/controllers/index.js +3 -0
- data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +10 -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 +86 -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 +67 -0
- data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +11 -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 +19 -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 +84 -0
- data/app/presenters/ahoy_captain/funnel_presenter.rb +68 -0
- data/app/presenters/ahoy_captain/goals_presenter.rb +69 -0
- data/app/queries/ahoy_captain/application_query.rb +121 -0
- data/app/queries/ahoy_captain/entry_pages_query.rb +17 -0
- data/app/queries/ahoy_captain/event_query.rb +35 -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 +11 -0
- data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +17 -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 +14 -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 +43 -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/migration_generator.rb +21 -0
- data/lib/generators/ahoy_captain/templates/config.rb.tt +138 -0
- data/lib/generators/ahoy_captain/templates/migration.rb.tt +7 -0
- metadata +410 -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,117 @@
|
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
2
|
+
import 'chartjs-plugin-datalabels';
|
3
|
+
const THOUSAND = 1000
|
4
|
+
const HUNDRED_THOUSAND = 100000
|
5
|
+
const MILLION = 1000000
|
6
|
+
const HUNDRED_MILLION = 100000000
|
7
|
+
const BILLION = 1000000000
|
8
|
+
const HUNDRED_BILLION = 100000000000
|
9
|
+
const TRILLION = 1000000000000
|
10
|
+
|
11
|
+
function numberFormatter(num) {
|
12
|
+
if (num >= THOUSAND && num < MILLION) {
|
13
|
+
const thousands = num / THOUSAND
|
14
|
+
if (thousands === Math.floor(thousands) || num >= HUNDRED_THOUSAND) {
|
15
|
+
return Math.floor(thousands) + 'k'
|
16
|
+
} else {
|
17
|
+
return (Math.floor(thousands * 10) / 10) + 'k'
|
18
|
+
}
|
19
|
+
} else if (num >= MILLION && num < BILLION) {
|
20
|
+
const millions = num / MILLION
|
21
|
+
if (millions === Math.floor(millions) || num >= HUNDRED_MILLION) {
|
22
|
+
return Math.floor(millions) + 'M'
|
23
|
+
} else {
|
24
|
+
return (Math.floor(millions * 10) / 10) + 'M'
|
25
|
+
}
|
26
|
+
} else if (num >= BILLION && num < TRILLION) {
|
27
|
+
const billions = num / BILLION
|
28
|
+
if (billions === Math.floor(billions) || num >= HUNDRED_BILLION) {
|
29
|
+
return Math.floor(billions) + 'B'
|
30
|
+
} else {
|
31
|
+
return (Math.floor(billions * 10) / 10) + 'B'
|
32
|
+
}
|
33
|
+
} else {
|
34
|
+
return num
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
export default class extends Controller {
|
39
|
+
connect() {
|
40
|
+
const funnel = JSON.parse(this.element.dataset.data);
|
41
|
+
|
42
|
+
const fontFamily = 'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"'
|
43
|
+
const labels = funnel.steps.map((step) => step.name)
|
44
|
+
const stepData = funnel.steps.map((step) => step.total_events)
|
45
|
+
const dropOffData = funnel.steps.map((step) => step.drop_off * 100)
|
46
|
+
|
47
|
+
const data = {
|
48
|
+
labels: labels,
|
49
|
+
datasets: [
|
50
|
+
{
|
51
|
+
label: 'Visitors',
|
52
|
+
data: stepData,
|
53
|
+
borderRadius: 4,
|
54
|
+
stack: 'Stack 0',
|
55
|
+
},
|
56
|
+
{
|
57
|
+
label: 'Dropoff',
|
58
|
+
data: dropOffData,
|
59
|
+
borderRadius: 4,
|
60
|
+
stack: 'Stack 0',
|
61
|
+
},
|
62
|
+
],
|
63
|
+
}
|
64
|
+
|
65
|
+
const config = {
|
66
|
+
responsive:true,
|
67
|
+
maintainAspectRatio: false,
|
68
|
+
plugins: [ChartDataLabels],
|
69
|
+
type: 'bar',
|
70
|
+
data: data,
|
71
|
+
options: {
|
72
|
+
layout: {
|
73
|
+
padding: 100,
|
74
|
+
},
|
75
|
+
plugins: {
|
76
|
+
legend: {
|
77
|
+
display: false,
|
78
|
+
},
|
79
|
+
tooltip: {
|
80
|
+
mode: 'index',
|
81
|
+
intersect: true,
|
82
|
+
position: 'average',
|
83
|
+
},
|
84
|
+
datalabels: {
|
85
|
+
anchor: 'end',
|
86
|
+
align: 'end',
|
87
|
+
borderRadius: 4,
|
88
|
+
padding: { top: 8, bottom: 8, right: 8, left: 8 },
|
89
|
+
font: { size: 12, weight: 'normal', lineHeight: 1.6, family: fontFamily },
|
90
|
+
textAlign: 'center',
|
91
|
+
},
|
92
|
+
},
|
93
|
+
scales: {
|
94
|
+
y: { display: false },
|
95
|
+
x: {
|
96
|
+
position: 'bottom',
|
97
|
+
display: true,
|
98
|
+
border: { display: false },
|
99
|
+
grid: { drawBorder: false, display: false },
|
100
|
+
ticks: {
|
101
|
+
padding: 8,
|
102
|
+
font: { weight: 'bold', family: fontFamily, size: 14 },
|
103
|
+
color: 'rgb(228, 228, 231)'
|
104
|
+
},
|
105
|
+
},
|
106
|
+
},
|
107
|
+
},
|
108
|
+
}
|
109
|
+
|
110
|
+
const visitorsData = []
|
111
|
+
|
112
|
+
new Chart(
|
113
|
+
this.element,
|
114
|
+
config
|
115
|
+
);
|
116
|
+
}
|
117
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
handleChange(event) {
|
5
|
+
const url = new URL(event.target.form.action);
|
6
|
+
const interval = event.target.value;
|
7
|
+
url.searchParams.set("interval", interval)
|
8
|
+
event.target.closest('turbo-frame').src = url.href
|
9
|
+
}
|
10
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
static targets = ["countriesLink", "top_pagesLink", "devicesLink", "top_sourcesLink"]
|
5
|
+
static classes = ["countries", "top_pages", "devices", "top_sources"]
|
6
|
+
|
7
|
+
changeCountries(event) {
|
8
|
+
console.log(...this.countriesClasses)
|
9
|
+
event.currentTarget.classList.add(...this.countriesClasses)
|
10
|
+
this.countriesLinkTargets.forEach((target) => {
|
11
|
+
if (target != event.currentTarget) {
|
12
|
+
target.classList.remove(...this.countriesClasses)
|
13
|
+
}
|
14
|
+
})
|
15
|
+
}
|
16
|
+
|
17
|
+
changeTopSources(event) {
|
18
|
+
event.currentTarget.classList.add(...this.top_sourcesClasses)
|
19
|
+
this.top_sourcesLinkTargets.forEach((target) => {
|
20
|
+
if (target != event.currentTarget) {
|
21
|
+
target.classList.remove(...this.top_sourcesClasses)
|
22
|
+
}
|
23
|
+
})
|
24
|
+
}
|
25
|
+
|
26
|
+
changeTopPages(event) {
|
27
|
+
event.currentTarget.classList.add(...this.top_pagesClasses)
|
28
|
+
this.top_pagesLinkTargets.forEach((target) => {
|
29
|
+
if (target != event.currentTarget) {
|
30
|
+
target.classList.remove(...this.top_pagesClasses)
|
31
|
+
}
|
32
|
+
})
|
33
|
+
}
|
34
|
+
|
35
|
+
changeDevices(event) {
|
36
|
+
event.currentTarget.classList.add(...this.devicesClasses)
|
37
|
+
this.devicesLinkTargets.forEach((target) => {
|
38
|
+
if (target != event.currentTarget) {
|
39
|
+
target.classList.remove(...this.devicesClasses)
|
40
|
+
}
|
41
|
+
})
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
connect() {
|
5
|
+
this.queryString = new URLSearchParams(window.location.search);
|
6
|
+
this.baseURL = window.location.pathname.replace(/\/$/, "");
|
7
|
+
}
|
8
|
+
|
9
|
+
navigate() {
|
10
|
+
const url = `${this.baseURL}?${this.queryString.toString()}`;
|
11
|
+
Turbo.visit(url, { action: "replace"})
|
12
|
+
}
|
13
|
+
|
14
|
+
addQueryParam({ detail: { paramKey, paramValue } }) {
|
15
|
+
this.queryString.append(paramKey, paramValue)
|
16
|
+
}
|
17
|
+
|
18
|
+
removeQueryParam({ detail: { paramKey, paramValue } }) {
|
19
|
+
if (!this.queryString.has(paramKey)) {
|
20
|
+
paramKey += "[]"
|
21
|
+
}
|
22
|
+
this.queryString.delete(paramKey,paramValue)
|
23
|
+
this.navigate()
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
static targets = ["label"]
|
5
|
+
|
6
|
+
connect() {
|
7
|
+
this.reload = this.reload.bind(this)
|
8
|
+
this.setLabel = this.setLabel.bind(this)
|
9
|
+
this.labelCount = 0;
|
10
|
+
|
11
|
+
}
|
12
|
+
|
13
|
+
reload() {
|
14
|
+
this.element.reload();
|
15
|
+
this.labelCount = 0;
|
16
|
+
}
|
17
|
+
|
18
|
+
setLabel() {
|
19
|
+
this.labelTarget.title = `Last updated ${this.labelCount} seconds ago`;
|
20
|
+
this.labelCount += 1
|
21
|
+
}
|
22
|
+
|
23
|
+
disconnect() {
|
24
|
+
clearInterval(this.labelInterval)
|
25
|
+
clearInterval(this.reloadInterval)
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="dropdown dropdown-end">
|
2
|
+
<label
|
3
|
+
tabindex="0"
|
4
|
+
class="btn btn-ghost dark:hover:bg-neutral flex"
|
5
|
+
>
|
6
|
+
<%= header_icon %>
|
7
|
+
<span><%= title %></span>
|
8
|
+
</label>
|
9
|
+
<ul class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52">
|
10
|
+
<% options.each do |option| %>
|
11
|
+
<li>
|
12
|
+
<%= option %>
|
13
|
+
<li>
|
14
|
+
<% end %>
|
15
|
+
</ul>
|
16
|
+
</div>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<div class="dropdown dropdown-end" data-controller='dropdown-label'>
|
2
|
+
<label
|
3
|
+
tabindex="0"
|
4
|
+
class="cursor-pointer flex <%= classes %>"
|
5
|
+
data-action='click->dropdown-label#removeHidden'
|
6
|
+
>
|
7
|
+
<span data-dropdown-label-target="label"><%= title %></span>
|
8
|
+
<svg class="h-8 w-8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
9
|
+
<path fill="currentColor" d="M16.53 8.97a.75.75 0 0 1 0 1.06l-4 4a.75.75 0 0 1-1.06 0l-4-4a.75.75 0 1 1 1.06-1.06L12 12.44l3.47-3.47a.75.75 0 0 1 1.06 0Z" clip-rule="evenodd" />
|
10
|
+
</svg>
|
11
|
+
</label>
|
12
|
+
<ul class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52" data-dropdown-label-target="close">
|
13
|
+
<% options.each do |option| %>
|
14
|
+
<li data-action="click->dropdown-label#setLabel">
|
15
|
+
<%= option %>
|
16
|
+
<li>
|
17
|
+
<% end %>
|
18
|
+
</ul>
|
19
|
+
</div>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AhoyCaptain::DropdownLinkComponent < ViewComponent::Base
|
4
|
+
renders_many :options
|
5
|
+
renders_one :header
|
6
|
+
|
7
|
+
def initialize(title:, classes: nil)
|
8
|
+
@title = title
|
9
|
+
@classes = classes
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :title, :classes
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<dialog id="<%= id %>" class="modal">
|
2
|
+
<form method="dialog" class="modal-box w-11/12 max-w-5xl" data-controller='filter' data-action="submit->filter#applyFilters reset->filter#resetFilters">
|
3
|
+
<fieldset>
|
4
|
+
<h5><%= title %></h5>
|
5
|
+
<%= modal_display %>
|
6
|
+
<button class="btn btn-primary mt-4" type="submit">Apply</button>
|
7
|
+
<button class="btn btn-primary mt-4" type="reset">Reset</button>
|
8
|
+
</fieldset>
|
9
|
+
</form>
|
10
|
+
<form method="dialog" class="modal-backdrop">
|
11
|
+
<button>close</button>
|
12
|
+
</form>
|
13
|
+
</dialog>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<fieldset class="flex space-x-4 items-end">
|
2
|
+
<div class="flex flex-col w-[20%]">
|
3
|
+
<label class="label"><%= label %></label>
|
4
|
+
<select class='select select-bordered' data-filter-target='predicate' name="<%= column %>">
|
5
|
+
<% predicates.each do |predicate| %>
|
6
|
+
<option value="<%= column %>_<%= predicate %>" <%= 'selected' if selected_predicate == "#{column}_#{predicate}" %>>
|
7
|
+
<%= predicate.to_s.humanize %>
|
8
|
+
</option>
|
9
|
+
<% end %>
|
10
|
+
</select>
|
11
|
+
</div>
|
12
|
+
<select
|
13
|
+
class='w-[50%] border-base-content border-opacity-20 rounded-lg min-h-[3rem]'
|
14
|
+
name="<%= column %>"
|
15
|
+
multiple
|
16
|
+
data-filter-target="select"
|
17
|
+
data-filter-column-value="<%= column %>"
|
18
|
+
data-filter-url-value="<%= url %>"
|
19
|
+
data-filter-selected="<%= values %>"
|
20
|
+
></select>
|
21
|
+
</fieldset>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AhoyCaptain::Filter::SelectComponent < ViewComponent::Base
|
4
|
+
def initialize(label:, column:, url:, predicates:)
|
5
|
+
@label = label
|
6
|
+
@column = column
|
7
|
+
@url = url
|
8
|
+
@predicates = predicates
|
9
|
+
end
|
10
|
+
|
11
|
+
def selected_predicate
|
12
|
+
predicate_options.detect { |option| params.dig(:q, option) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def values
|
16
|
+
predicate_options.each do |predicate|
|
17
|
+
option = params.dig(:q, predicate)
|
18
|
+
if option
|
19
|
+
return option
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
[]
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def predicate_options
|
29
|
+
@predicate_options ||= @predicates.map { |predicate| "#{@column}_#{predicate}" }
|
30
|
+
end
|
31
|
+
attr_reader :label, :column, :url, :predicates
|
32
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<div class="bg-base-100 py-2 px-4 mx-2 flex items-center" data-controller='filter-tag' data-filter-tag-category-value="<%= category %>" data-filter-tag-column-predicate-value="<%= column_predicate %>">
|
2
|
+
<%= column_with_predicate %>
|
3
|
+
<span class="font-bold mx-2"> <%= category %></span>
|
4
|
+
<a class="hover:text-primary" href="<%= url %>">
|
5
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="w-4 h-4">
|
6
|
+
<path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"></path>
|
7
|
+
</svg>
|
8
|
+
</a>
|
9
|
+
</div>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AhoyCaptain::Filter::TagComponent < ViewComponent::Base
|
4
|
+
PREDICATES = {
|
5
|
+
eq: 'equals',
|
6
|
+
not_eq: 'not equals',
|
7
|
+
cont: 'contains',
|
8
|
+
in: 'in',
|
9
|
+
not_in: 'not in',
|
10
|
+
}
|
11
|
+
def initialize(column_predicate:, category:)
|
12
|
+
@column_predicate = column_predicate
|
13
|
+
@category = category
|
14
|
+
end
|
15
|
+
|
16
|
+
def url
|
17
|
+
search_params = helpers.search_params.deep_dup
|
18
|
+
if search_params["q"][@column_predicate].is_a?(Array)
|
19
|
+
search_params["q"][@column_predicate] = search_params["q"][@column_predicate] - [@category]
|
20
|
+
else
|
21
|
+
search_params["q"].delete(@column_predicate)
|
22
|
+
end
|
23
|
+
|
24
|
+
request.path + "?" + search_params.to_query
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
attr_reader :column_predicate, :category
|
29
|
+
|
30
|
+
def column_with_predicate
|
31
|
+
PREDICATES.keys.map(&:to_s).each do |predicate|
|
32
|
+
if column_predicate.include?(predicate)
|
33
|
+
before, match, after = column_predicate.partition(predicate)
|
34
|
+
return [before.gsub('_',' '), PREDICATES[match.to_sym]].join(' ').humanize
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AhoyCaptain::Filter::TagContainerComponent < ViewComponent::Base
|
4
|
+
def initialize(filters:)
|
5
|
+
@filters = filters.to_unsafe_h.to_a.map do |key, values|
|
6
|
+
Array(values).map { |value| [key, value] }
|
7
|
+
end.flatten(1).reject { |k,v| v.blank? }
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
attr_reader :filters
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<div class="max-w-6xl flex justify-between sticky top-0 min-h-sm z-[99999] bg-base-300 py-4">
|
2
|
+
<div class="flex items-center">
|
3
|
+
<a href="/">
|
4
|
+
<img src="<%= image_path "ahoy_captain/logo.png" %>" alt="AhoyCaptainLogo" class='w-16 h-16 rounded-full'>
|
5
|
+
</a>
|
6
|
+
<% if params[:q] %>
|
7
|
+
<%= render AhoyCaptain::Filter::TagContainerComponent.new(filters: params.require(:q)) %>
|
8
|
+
<% else %>
|
9
|
+
<%= realtime_update %>
|
10
|
+
<% end %>
|
11
|
+
</div>
|
12
|
+
<div class="flex flex-row-reverse col-span-2 items-center">
|
13
|
+
<%= render AhoyCaptain::DropdownLinkComponent.new(title: params[:start_date] ? "Custom Range" : (AhoyCaptain.config.ranges.find(params[:period]).try(:label) || "Period"), classes: 'btn btn-base-100 no-underline text-base-content hover:text-base-content hover:bg-base-100') do |dropdown| %>
|
14
|
+
<% dropdown.with_option do %>
|
15
|
+
<% AhoyCaptain.config.ranges.each do |param, range| %>
|
16
|
+
<a class='link no-underline' href="<%= request.path %>?<%= request.query_parameters.except("start_date", "end_date").merge("period" => param).to_query %>"><%= range.label %></a>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<a class='link no-underline' href='#' onclick="event.preventDefault(); customRangeModal.showModal()">Custom range</a>
|
20
|
+
<% end %>
|
21
|
+
<% end %>
|
22
|
+
<%= render AhoyCaptain::DropdownButtonComponent.new(title: 'Filter') do |dropdown| %>
|
23
|
+
<% dropdown.with_header_icon do %>
|
24
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="-ml-1 mr-1 h-4 w-4 md:h-4 md:w-4">
|
25
|
+
<path fill-rule="evenodd" d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z" clip-rule="evenodd"></path>
|
26
|
+
</svg>
|
27
|
+
<% end %>
|
28
|
+
<% dropdown.with_option do %>
|
29
|
+
<button onClick="pageModal.showModal()" class='link no-underline'>Page</button>
|
30
|
+
<button onClick="countryModal.showModal()" class='link no-underline'>Geography</button>
|
31
|
+
<button onClick="screenModal.showModal()" class='link no-underline'>Screen</button>
|
32
|
+
<button onClick="osModal.showModal()" class='link no-underline'>Operating System</button>
|
33
|
+
<button onClick="utmModal.showModal()" class='link no-underline'>UTM Tags</button>
|
34
|
+
<% end %>
|
35
|
+
<% end %>
|
36
|
+
</div>
|
37
|
+
</div>
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<div class="flex flex-col min-h-[380px] w-full pt-4">
|
2
|
+
<div class="flex text-sm font-bold text-base-content mb-4">
|
3
|
+
<span class="grow"><%= category_name %></span>
|
4
|
+
<span ><%= unit_name %></span>
|
5
|
+
<% if additional_cols.include?(:percent_total) %>
|
6
|
+
<span class="w-8 ml-8 text-right">%</span>
|
7
|
+
<% end %>
|
8
|
+
<% if additional_cols.include?(:total) %>
|
9
|
+
<span class="w-8 ml-8 text-right">Total</span>
|
10
|
+
<% end %>
|
11
|
+
<% if additional_cols.include?(:conversion_rate) %>
|
12
|
+
<span class="w-8 ml-8 text-right">CR</span>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
15
|
+
<div class='min-h-[420px]'>
|
16
|
+
<div class="grow">
|
17
|
+
<% if items.respond_to?(:each) && items.any? %>
|
18
|
+
<% items.each do |item| %>
|
19
|
+
<div class='leading-10 flex relative'>
|
20
|
+
<progress class='progress-primary bg-base-100 h-8 grow' value="<%= item.unit_amount %>" max="<%= max_amount %>">
|
21
|
+
</progress>
|
22
|
+
<span class="grow text-elipsis overflow-hidden absolute left-4 bottom-3 h-8 text-base-content">
|
23
|
+
<%= item.display_name %>
|
24
|
+
</span>
|
25
|
+
<span class="w-8 ml-8 text-right">
|
26
|
+
<%= render AhoyCaptain::TooltipComponent.new(amount: item.unit_amount) %>
|
27
|
+
</span>
|
28
|
+
|
29
|
+
<% if additional_cols.include?(:percent_total) %>
|
30
|
+
<span class="w-8 ml-8 text-right"><%= percent_total(item) %></span>
|
31
|
+
<% end %>
|
32
|
+
<% if additional_cols.include?(:total) %>
|
33
|
+
<span class="w-8 ml-8 text-right">
|
34
|
+
<%= render AhoyCaptain::TooltipComponent.new(amount: item.total) %>
|
35
|
+
</span>
|
36
|
+
<% end %>
|
37
|
+
<% if additional_cols.include?(:conversion_rate) %>
|
38
|
+
<span class="w-8 ml-8 text-right">
|
39
|
+
<%= item.conversion_rate * 100.0 %>%
|
40
|
+
</span>
|
41
|
+
<% end %>
|
42
|
+
</div>
|
43
|
+
<% end %>
|
44
|
+
<% else %>
|
45
|
+
<p>No data found</p>
|
46
|
+
<% end %>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AhoyCaptain::TableComponent < ViewComponent::Base
|
4
|
+
SUPPORTED_COLS = [:percent_total, :total, :conversion_rate]
|
5
|
+
|
6
|
+
def initialize(items:, category_name:, unit_name:, additional_cols: [])
|
7
|
+
@items = items
|
8
|
+
@category_name = category_name
|
9
|
+
@unit_name = unit_name
|
10
|
+
@additional_cols = additional_cols
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :items, :category_name, :unit_name, :additional_cols
|
16
|
+
|
17
|
+
def max_amount
|
18
|
+
@max_amount ||= items.first.unit_amount
|
19
|
+
end
|
20
|
+
|
21
|
+
def total
|
22
|
+
@total ||= items.first.total_count
|
23
|
+
end
|
24
|
+
|
25
|
+
def percent_total(item)
|
26
|
+
'%.1f' % ((item.unit_amount.to_i * 1.0 / total)*100.0)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div class='<%= 'lg:col-span-2' if wide %> col-span-1 p-4 bg-base-200 rounded-md p-8 mx-4 lg:mx-0'>
|
2
|
+
<div class="flex justify-between">
|
3
|
+
<h5 class='text-lg text-accent-content'><%= title %></h5>
|
4
|
+
<div class="flex self-center gap-3">
|
5
|
+
<%= display_links %>
|
6
|
+
</div>
|
7
|
+
</div>
|
8
|
+
<%= statistic_display %>
|
9
|
+
<div class="flex justify-center">
|
10
|
+
<%= details_cta %>
|
11
|
+
</div>
|
12
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AhoyCaptain::TileComponent < ViewComponent::Base
|
4
|
+
renders_one :statistic_display
|
5
|
+
renders_one :display_links
|
6
|
+
renders_one :details_cta
|
7
|
+
|
8
|
+
def initialize(title: nil, wide: false)
|
9
|
+
@title = title
|
10
|
+
@wide = wide
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :title, :wide
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class AhoyCaptain::TooltipComponent < ViewComponent::Base
|
2
|
+
def initialize(amount:)
|
3
|
+
@amount = amount
|
4
|
+
end
|
5
|
+
|
6
|
+
def abbreviate
|
7
|
+
|
8
|
+
if amount.to_i >= 1000
|
9
|
+
number_to_human(amount, format: '%n%u', precision: 2, units: { thousand: 'k', million: 'm', billion: 'b' })
|
10
|
+
else
|
11
|
+
amount.to_s
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :amount
|
18
|
+
end
|