ahoy_captain 0.83 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -13
- data/Rakefile +23 -2
- data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +20 -0
- data/app/assets/javascript/ahoy_captain/controllers/combobox_controller.js +371 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter/item_controller.js +12 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter_modal_controller.js +45 -0
- data/app/assets/javascript/ahoy_captain/controllers/frame_link_controller.js +20 -0
- data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +58 -16
- data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +5 -0
- data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +236 -22
- data/app/assets/javascript/ahoy_captain/controllers/map_controller.js +47 -0
- data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +1 -1
- data/app/assets/javascript/ahoy_captain/controllers/properties_controller.js +8 -0
- data/app/assets/javascript/ahoy_captain/controllers/property_filter_controller.js +45 -0
- data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +4 -2
- data/app/assets/javascript/ahoy_captain/controllers/tile_controller.js +33 -0
- data/app/assets/javascript/ahoy_captain/controllers/toggle_controller.js +17 -0
- data/app/assets/javascript/ahoy_captain/helpers/chart_utils.js +156 -0
- data/app/assets/javascript/ahoy_captain/helpers/countries.js +2261 -0
- data/app/assets/javascript/ahoy_captain/helpers/number_formatters.js +55 -0
- data/app/components/ahoy_captain/combobox_component.html.erb +33 -0
- data/app/components/ahoy_captain/combobox_component.rb +13 -0
- data/app/components/ahoy_captain/comparison_link_component.html.erb +17 -0
- data/app/components/ahoy_captain/comparison_link_component.rb +44 -0
- data/app/components/ahoy_captain/dropdown_button_component.html.erb +5 -5
- data/app/components/ahoy_captain/dropdown_link_component.html.erb +5 -7
- data/app/components/ahoy_captain/dropdown_link_component.rb +4 -0
- data/app/components/ahoy_captain/filter/dropdown_component.html.erb +50 -0
- data/app/components/ahoy_captain/filter/dropdown_component.rb +51 -0
- data/app/components/ahoy_captain/filter/modal_component.html.erb +7 -5
- data/app/components/ahoy_captain/filter/select_component.html.erb +23 -21
- data/app/components/ahoy_captain/filter/select_component.rb +24 -9
- data/app/components/ahoy_captain/filter/tag_component.html.erb +8 -4
- data/app/components/ahoy_captain/filter/tag_component.rb +6 -30
- data/app/components/ahoy_captain/filter/tag_container_component.html.erb +2 -3
- data/app/components/ahoy_captain/filter/tag_container_component.rb +1 -8
- data/app/components/ahoy_captain/previous_next_component.html.erb +8 -0
- data/app/components/ahoy_captain/previous_next_component.rb +11 -0
- data/app/components/ahoy_captain/stats/comparable_container_component.html.erb +25 -0
- data/app/components/ahoy_captain/stats/comparable_container_component.rb +86 -0
- data/app/components/ahoy_captain/stats/container_component.html.erb +15 -0
- data/app/components/ahoy_captain/stats/container_component.rb +26 -0
- data/app/components/ahoy_captain/sticky_nav_component.html.erb +28 -33
- data/app/components/ahoy_captain/sticky_nav_component.rb +19 -0
- data/app/components/ahoy_captain/table_component.html.erb +2 -2
- data/app/components/ahoy_captain/table_component.rb +15 -3
- data/app/components/ahoy_captain/tables/devices_table_component.rb +11 -0
- data/app/components/ahoy_captain/tables/dynamic_table.rb +13 -0
- data/app/components/ahoy_captain/tables/dynamic_table_component.rb +204 -0
- data/app/components/ahoy_captain/tables/goals_table_component.rb +17 -0
- data/app/components/ahoy_captain/tables/header_component.html.erb +5 -0
- data/app/components/ahoy_captain/tables/header_component.rb +18 -0
- data/app/components/ahoy_captain/tables/headers/header_component.html.erb +1 -1
- data/app/components/ahoy_captain/tables/headers/header_component.rb +4 -0
- data/app/components/ahoy_captain/tables/properties_table_component.rb +27 -0
- data/app/components/ahoy_captain/tables/row_component.html.erb +4 -0
- data/app/components/ahoy_captain/tables/rows/row_component.rb +2 -3
- data/app/components/ahoy_captain/tile_component.html.erb +21 -10
- data/app/components/ahoy_captain/tile_component.rb +10 -2
- data/app/components/ahoy_captain/tooltip_component.html.erb +2 -2
- data/app/controllers/ahoy_captain/application_controller.rb +7 -16
- data/app/controllers/ahoy_captain/exports_controller.rb +1 -2
- data/app/controllers/ahoy_captain/filters/base_controller.rb +1 -3
- data/app/controllers/ahoy_captain/filters/goals_controller.rb +9 -0
- data/app/controllers/ahoy_captain/filters/pages/actions_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +4 -4
- data/app/controllers/ahoy_captain/filters/sources_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/utms_controller.rb +1 -1
- data/app/controllers/ahoy_captain/locations/cities_controller.rb +22 -0
- data/app/controllers/ahoy_captain/locations/countries_controller.rb +22 -0
- data/app/controllers/ahoy_captain/locations/maps_controller.rb +24 -0
- data/app/controllers/ahoy_captain/locations/regions_controller.rb +22 -0
- data/app/controllers/ahoy_captain/properties_controller.rb +41 -0
- data/app/controllers/ahoy_captain/stats/base_controller.rb +86 -5
- data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +1 -1
- 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 +2 -1
- data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +1 -10
- data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -1
- data/app/helpers/ahoy_captain/application_helper.rb +60 -3
- data/app/models/ahoy_captain/comparison_mode.rb +72 -0
- data/app/models/ahoy_captain/filter_parser.rb +82 -0
- data/app/models/ahoy_captain/range_from_params.rb +78 -0
- data/app/models/ahoy_captain/rangeable.rb +0 -3
- data/app/models/concerns/ahoy_captain/compare_mode.rb +19 -0
- data/app/models/concerns/ahoy_captain/limitable.rb +17 -0
- data/app/models/concerns/ahoy_captain/range_options.rb +1 -14
- data/app/presenters/ahoy_captain/dashboard_presenter.rb +18 -54
- data/app/presenters/ahoy_captain/goals_presenter.rb +3 -2
- data/app/queries/ahoy_captain/application_query.rb +74 -10
- data/app/queries/ahoy_captain/event_query.rb +7 -2
- data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +11 -4
- data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +14 -2
- data/app/queries/ahoy_captain/stats/base_query.rb +18 -0
- data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +15 -1
- data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +2 -2
- 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 +1 -1
- data/app/queries/ahoy_captain/stats/visit_duration_query.rb +3 -3
- data/app/queries/ahoy_captain/visit_query.rb +1 -2
- data/app/queries/concerns/ahoy_captain/comparable_queries.rb +25 -0
- data/app/queries/concerns/ahoy_captain/comparable_query.rb +138 -0
- data/app/queries/concerns/ahoy_captain/lazy_comparable_query.rb +42 -0
- data/app/views/ahoy_captain/devices/_table.html.erb +1 -4
- data/app/views/ahoy_captain/funnels/show.html.erb +5 -2
- data/app/views/ahoy_captain/goals/index.html.erb +1 -4
- data/app/views/ahoy_captain/layouts/application.html.erb +3 -4
- data/app/views/ahoy_captain/layouts/shared/_tile_loader.html.erb +12 -0
- data/app/views/ahoy_captain/locations/maps/show.html.erb +3 -0
- data/app/views/ahoy_captain/properties/_form.html.erb +6 -0
- data/app/views/ahoy_captain/properties/index.html.erb +3 -0
- data/app/views/ahoy_captain/properties/show.html.erb +6 -0
- data/app/views/ahoy_captain/realtimes/show.html.erb +1 -1
- data/app/views/ahoy_captain/roots/_filters.html.erb +80 -0
- data/app/views/ahoy_captain/roots/show.html.erb +113 -122
- data/app/views/ahoy_captain/stats/base/index.html.erb +37 -8
- data/app/views/ahoy_captain/stats/show.html.erb +14 -56
- data/config/routes.rb +9 -3
- data/lib/ahoy_captain/ahoy/event_methods.rb +21 -14
- data/lib/ahoy_captain/ahoy/visit_methods.rb +1 -1
- data/lib/ahoy_captain/configuration.rb +18 -7
- data/lib/ahoy_captain/engine.rb +21 -0
- data/lib/ahoy_captain/filter_configuration/filter.rb +16 -0
- data/lib/ahoy_captain/filter_configuration/filter_collection.rb +48 -0
- data/lib/ahoy_captain/filters_configuration.rb +77 -0
- data/lib/ahoy_captain/goals.rb +1 -1
- data/lib/ahoy_captain/predicate_label.rb +7 -0
- data/lib/ahoy_captain/version.rb +1 -1
- data/lib/ahoy_captain.rb +8 -1
- data/lib/generators/ahoy_captain/templates/config.rb.tt +32 -0
- metadata +149 -22
- data/app/assets/javascript/ahoy_captain/controllers/active_links_controller.js +0 -15
- data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +0 -20
- data/app/assets/javascript/ahoy_captain/controllers/search_select_controller.js +0 -65
- data/app/components/ahoy_captain/tables/headers/devices_header_component.html.erb +0 -3
- data/app/components/ahoy_captain/tables/headers/devices_header_component.rb +0 -9
- data/app/components/ahoy_captain/tables/headers/goals_header_component.html.erb +0 -6
- data/app/components/ahoy_captain/tables/headers/goals_header_component.rb +0 -9
- data/app/components/ahoy_captain/tables/rows/devices_row_component.html.erb +0 -5
- data/app/components/ahoy_captain/tables/rows/devices_row_component.rb +0 -12
- data/app/components/ahoy_captain/tables/rows/goals_row_component.html.erb +0 -11
- data/app/components/ahoy_captain/tables/rows/goals_row_component.rb +0 -12
- data/app/controllers/ahoy_captain/cities_controller.rb +0 -20
- data/app/controllers/ahoy_captain/countries_controller.rb +0 -20
- data/app/controllers/ahoy_captain/regions_controller.rb +0 -20
- /data/app/views/ahoy_captain/{cities → locations/cities}/index.html+details.erb +0 -0
- /data/app/views/ahoy_captain/{cities → locations/cities}/index.html.erb +0 -0
- /data/app/views/ahoy_captain/{countries → locations/countries}/index.html+details.erb +0 -0
- /data/app/views/ahoy_captain/{countries → locations/countries}/index.html.erb +0 -0
- /data/app/views/ahoy_captain/{regions → locations/regions}/index.html+details.erb +0 -0
- /data/app/views/ahoy_captain/{regions → locations/regions}/index.html.erb +0 -0
@@ -0,0 +1,156 @@
|
|
1
|
+
import { numberFormatter, durationFormatter, percentageFormatter } from "helpers/number_formatters";
|
2
|
+
|
3
|
+
export const getCSS = (varname, alpha = 1) => {
|
4
|
+
const value = getComputedStyle(document.documentElement).getPropertyValue(varname);
|
5
|
+
if(value.includes("em") || value.includes("px")) {
|
6
|
+
return value
|
7
|
+
}
|
8
|
+
return `hsl(${getComputedStyle(document.documentElement).getPropertyValue(varname)} / ${alpha})`
|
9
|
+
}
|
10
|
+
|
11
|
+
const buildTooltipData = (controller, tooltip) => {
|
12
|
+
return controller.extractTooltipData(tooltip)
|
13
|
+
}
|
14
|
+
|
15
|
+
export const metricFormatter = {
|
16
|
+
"ActiveSupport::Duration": durationFormatter,
|
17
|
+
"BigDecimal": numberFormatter,
|
18
|
+
"Float": percentageFormatter,
|
19
|
+
"Integer": numberFormatter
|
20
|
+
}
|
21
|
+
|
22
|
+
export const dateFormatter = {
|
23
|
+
month: (value, type = 'short') => {
|
24
|
+
if(type === 'short') {
|
25
|
+
return new Date(value).toLocaleString(
|
26
|
+
'en-US',
|
27
|
+
{ month: 'short', day: 'numeric', hour: 'numeric' }
|
28
|
+
)
|
29
|
+
} else {
|
30
|
+
return new Date(value).toLocaleString(
|
31
|
+
'en-US',
|
32
|
+
{ year: "numeric", month: 'short', day: 'numeric', hour: 'numeric' }
|
33
|
+
)
|
34
|
+
}
|
35
|
+
},
|
36
|
+
week: (value, type = 'short') => {
|
37
|
+
return new Date(value).toLocaleString(
|
38
|
+
'en-US',
|
39
|
+
{ month: 'short', day: 'numeric', hour: 'numeric' }
|
40
|
+
)
|
41
|
+
},
|
42
|
+
day: (value, type = 'short') => {
|
43
|
+
return new Date(value).toLocaleString(
|
44
|
+
'en-US',
|
45
|
+
{ month: 'short', day: 'numeric', hour: 'numeric' }
|
46
|
+
)
|
47
|
+
},
|
48
|
+
hour: (value, type = 'short') => {
|
49
|
+
if(type == 'long') {
|
50
|
+
return new Date(value).toLocaleString(
|
51
|
+
'en-US',
|
52
|
+
{ year: 'numeric', hour: 'numeric' }
|
53
|
+
)
|
54
|
+
} else {
|
55
|
+
return new Date(value).toLocaleString(
|
56
|
+
'en-US',
|
57
|
+
{ hour: 'numeric' }
|
58
|
+
)
|
59
|
+
}
|
60
|
+
},
|
61
|
+
minute: (value, type = 'short') => {
|
62
|
+
if(type == 'short') {
|
63
|
+
return new Date(value).toLocaleString(
|
64
|
+
'en-US',
|
65
|
+
{ minute: 'numeric', hour: 'numeric' }
|
66
|
+
)
|
67
|
+
} else {
|
68
|
+
return new Date(value).toLocaleString(
|
69
|
+
'en-US',
|
70
|
+
{ year: 'numeric', minute: 'numeric', hour: 'numeric' }
|
71
|
+
)
|
72
|
+
}
|
73
|
+
},
|
74
|
+
}
|
75
|
+
|
76
|
+
export const externalTooltipHandler = (controller) => {
|
77
|
+
|
78
|
+
return ({chart, tooltip}) => {
|
79
|
+
const offset = controller.chart.canvas.getBoundingClientRect()
|
80
|
+
let tooltipEl = document.getElementById('chartjs-tooltip')
|
81
|
+
|
82
|
+
if (!tooltipEl) {
|
83
|
+
tooltipEl = document.createElement('div')
|
84
|
+
tooltipEl.id = 'chartjs-tooltip'
|
85
|
+
tooltipEl.style.background = getCSS('--n', );
|
86
|
+
tooltipEl.style.borderRadius = getCSS('--rounded-btn');
|
87
|
+
tooltipEl.style.opacity = 1;
|
88
|
+
tooltipEl.style.pointerEvents = 'none';
|
89
|
+
tooltipEl.style.position = 'absolute';
|
90
|
+
tooltipEl.style.transform = 'translate(-50%, 50%)';
|
91
|
+
tooltipEl.style.transition = 'all .1s ease';
|
92
|
+
tooltipEl.style.minWidth = '250px'
|
93
|
+
|
94
|
+
chart.canvas.parentNode.appendChild(tooltipEl);
|
95
|
+
}
|
96
|
+
|
97
|
+
if (tooltipEl && offset && window.innerWidth < 768) {
|
98
|
+
tooltipEl.style.top = offset.y + offset.height + window.scrollY + 15 + 'px'
|
99
|
+
tooltipEl.style.left = offset.x + 'px'
|
100
|
+
tooltipEl.style.right = null
|
101
|
+
tooltipEl.style.opacity = 1
|
102
|
+
}
|
103
|
+
|
104
|
+
if (tooltip.opacity === 0) {
|
105
|
+
tooltipEl.style.display = 'none'
|
106
|
+
return
|
107
|
+
}
|
108
|
+
|
109
|
+
if (tooltip.body) {
|
110
|
+
const tooltipData = buildTooltipData(controller, tooltip)
|
111
|
+
|
112
|
+
tooltipEl.innerHTML = `
|
113
|
+
<aside class="flex flex-col text-neutral-content">
|
114
|
+
<div class="flex justify-between items-center">
|
115
|
+
<span class="text-sm font-bold uppercase whitespace-nowrap flex mr-4">${tooltipData.metric}</span>
|
116
|
+
${tooltipData.comparison && tooltipData.comparisonDifference ?
|
117
|
+
`<div class="inline-flex items-center space-x-1">
|
118
|
+
${tooltipData.comparisonDifference > 0 ? `<span class="font-semibold text-sm text-green-500">↑</span><span>${tooltipData.comparisonDifference}%</span>` : ""}
|
119
|
+
${tooltipData.comparisonDifference < 0 ? `<span class="font-semibold text-sm text-red-400">↓</span><span>${tooltipData.comparisonDifference * -1}%</span>` : ""}
|
120
|
+
${tooltipData.comparisonDifference == 0 ? `<span class="font-semibold text-sm">〰 0%</span>` : ""}
|
121
|
+
</div>` : ''}
|
122
|
+
</div>
|
123
|
+
|
124
|
+
${tooltipData.label ?
|
125
|
+
`<div class="flex flex-col">
|
126
|
+
<div class="flex flex-row justify-between items-center">
|
127
|
+
<span class="badge relative badge-xs" style="background-color: ${tooltipData.labelBackgroundColor}"></span>
|
128
|
+
<span class="flex items-center grow ml-4 mr-4">
|
129
|
+
<span>${tooltipData.label}</span>
|
130
|
+
</span>
|
131
|
+
<span class="font-bold">${tooltipData.formattedValue}</span>
|
132
|
+
</div>` : ''}
|
133
|
+
|
134
|
+
${tooltipData.comparison ?
|
135
|
+
`<div class="flex flex-row justify-between items-center">
|
136
|
+
<span class="badge relative badge-xs" style="background-color: ${tooltipData.comparisonLabelBackgroundColor}"></span>
|
137
|
+
<span class="flex items-center grow ml-4 mr-4">
|
138
|
+
<span>${tooltipData.comparisonLabel}</span>
|
139
|
+
</span>
|
140
|
+
<span class="font-bold">${tooltipData.formattedComparisonValue}</span>
|
141
|
+
</div>` : ""}
|
142
|
+
</div>
|
143
|
+
</aside>
|
144
|
+
`
|
145
|
+
}
|
146
|
+
const {offsetLeft: positionX, offsetTop: positionY} = chart.canvas;
|
147
|
+
|
148
|
+
// Display, position, and set styles for font
|
149
|
+
tooltipEl.style.opacity = 1;
|
150
|
+
tooltipEl.style.display = null;
|
151
|
+
tooltipEl.style.left = positionX + tooltip._eventPosition.x + 'px';
|
152
|
+
tooltipEl.style.top = positionY + tooltip._eventPosition.y + 'px';
|
153
|
+
tooltipEl.style.font = tooltip.options.bodyFont.string;
|
154
|
+
tooltipEl.style.padding = tooltip.options.padding + 'px ' + tooltip.options.padding + 'px';
|
155
|
+
}
|
156
|
+
};
|