matey 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/devcontainer.json +1 -1
  3. data/COLOR_SCHEMES.md +24 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +133 -114
  6. data/README.md +8 -3
  7. data/app/components/matey/active_users_component.html.erb +1 -1
  8. data/app/components/matey/active_users_component.rb +5 -3
  9. data/app/components/{application_component.rb → matey/application_component.rb} +3 -1
  10. data/app/components/matey/bounce_rate_component.html.erb +2 -2
  11. data/app/components/matey/bounce_rate_component.rb +5 -3
  12. data/app/components/matey/browser_os_breakdown_component.html.erb +38 -0
  13. data/app/components/matey/browser_os_breakdown_component.rb +11 -0
  14. data/app/components/matey/daily_active_users_component.html.erb +15 -0
  15. data/app/components/matey/daily_active_users_component.rb +11 -0
  16. data/app/components/matey/new_activity_component.html.erb +1 -1
  17. data/app/components/matey/new_activity_component.rb +5 -3
  18. data/app/components/matey/new_users_component.html.erb +1 -1
  19. data/app/components/matey/new_users_component.rb +5 -3
  20. data/app/components/matey/top_events_component.html.erb +2 -2
  21. data/app/components/matey/top_events_component.rb +4 -2
  22. data/app/components/matey/top_visited_pages_table_component.html.erb +2 -2
  23. data/app/components/matey/top_visited_pages_table_component.rb +4 -2
  24. data/app/components/matey/user_engagement_component.html.erb +2 -2
  25. data/app/components/matey/user_engagement_component.rb +4 -2
  26. data/app/components/matey/visits_by_day_of_week_component.html.erb +26 -0
  27. data/app/components/matey/visits_by_day_of_week_component.rb +24 -0
  28. data/images/colorSchemeBlue.png +0 -0
  29. data/images/colorSchemeNeutral.png +0 -0
  30. data/lib/helpers.rb +12 -0
  31. data/lib/matey/version.rb +1 -1
  32. data/lib/matey.rb +4 -1
  33. data/matey.gemspec +1 -1
  34. metadata +16 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5991529e6b95d161fa55e0b72a16fb4d22afd2f1d3fd3e657e6c834b5baca48f
4
- data.tar.gz: 7764c92bd83d7d7796b7e8737af3c8a6c5007b444238d4307f82790413da249c
3
+ metadata.gz: 12a21ea4053dc459c4b23e8e3d2aba0f1214929392c281d40d7055e5a4de26e0
4
+ data.tar.gz: c2784dda2825209d14dfe8ee9bac7963236caf786a440d980ca1c40d66fcd3e2
5
5
  SHA512:
6
- metadata.gz: 2cdb414b9eef61de45dc70babff6c441ff54cceebe2c3b6f515c79c52c8b3f4678f8e65bd41d3ca03f00317f21d634c5780263e9004eedcb607ecbdc7260cb65
7
- data.tar.gz: 91e809d70fead673bfa1d308db1edefb5872da969f322f2ac813569de19d18d08657beb21cd31789fbb6e41f04466dad9b054ceecd36cf785b33c3bdb051f243
6
+ metadata.gz: 02a283bbedef06f95cdbdfe30b00c803b35bd0e94f163921166eb82ab3cd53273fe3ac91776c0596d06c83f7c70a19687cd8611e183bb601bbb23811bdb60e57
7
+ data.tar.gz: b4488783a6edbf40c39b1eea8e181a7bad5788eb7246586f44a81a4f4dbdd88e3b9988be3de78b2b37806981422eff0e3a45510a7b2f8835fcf2b8639ac6e161
@@ -8,7 +8,7 @@
8
8
  // Update 'VARIANT' to pick a Ruby version: 3, 3.1, 3.0, 2, 2.7, 2.6
9
9
  // Append -bullseye or -buster to pin to an OS version.
10
10
  // Use -bullseye variants on local on arm64/Apple Silicon.
11
- "VARIANT": "3.1",
11
+ "VARIANT": "3.2",
12
12
  // Options
13
13
  "NODE_VERSION": "lts/*"
14
14
  }
data/COLOR_SCHEMES.md ADDED
@@ -0,0 +1,24 @@
1
+ # Color Schemes
2
+
3
+ ## Available Colors
4
+
5
+ - [Neutral](#neutral) _(default)_
6
+ - [Blue](#blue)
7
+
8
+ ### Neutral _(default)_
9
+
10
+ ![Neutral Color Scheme](./images/colorSchemeNeutral.png)
11
+
12
+ ```ruby
13
+ <%= render Matey::[ComponentType].new(..., color_scheme: "neutral") %>
14
+ ```
15
+
16
+ Note: If `color_scheme` argument is omitted, color scheme value defaults to `neutral`
17
+
18
+ ### Blue
19
+
20
+ ![Blue Color Scheme](./images/colorSchemeBlue.png)
21
+
22
+ ```ruby
23
+ <%= render Matey::[ComponentType].new(..., color_scheme: 'blue') %>
24
+ ```
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  rails_version = (ENV["RAILS_VERSION"] || "~> 7").to_s
7
- gem "rails", rails_version == "main" ? {git: "https://github.com/rails/rails", ref: "main"} : rails_version
7
+ gem "rails", (rails_version == "main") ? {git: "https://github.com/rails/rails", ref: "main"} : rails_version
8
8
 
9
9
  gem "debug", platforms: %i[mri mingw x64_mingw]
10
10
 
data/Gemfile.lock CHANGED
@@ -1,173 +1,183 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- matey (0.1.3)
4
+ matey (0.1.4)
5
5
  ahoy_matey (~> 4.0)
6
- view_component (~> 2.74.1)
6
+ view_component (~> 2.74)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.0.4)
12
- actionpack (= 7.0.4)
13
- activesupport (= 7.0.4)
11
+ actioncable (7.0.5)
12
+ actionpack (= 7.0.5)
13
+ activesupport (= 7.0.5)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.4)
17
- actionpack (= 7.0.4)
18
- activejob (= 7.0.4)
19
- activerecord (= 7.0.4)
20
- activestorage (= 7.0.4)
21
- activesupport (= 7.0.4)
16
+ actionmailbox (7.0.5)
17
+ actionpack (= 7.0.5)
18
+ activejob (= 7.0.5)
19
+ activerecord (= 7.0.5)
20
+ activestorage (= 7.0.5)
21
+ activesupport (= 7.0.5)
22
22
  mail (>= 2.7.1)
23
23
  net-imap
24
24
  net-pop
25
25
  net-smtp
26
- actionmailer (7.0.4)
27
- actionpack (= 7.0.4)
28
- actionview (= 7.0.4)
29
- activejob (= 7.0.4)
30
- activesupport (= 7.0.4)
26
+ actionmailer (7.0.5)
27
+ actionpack (= 7.0.5)
28
+ actionview (= 7.0.5)
29
+ activejob (= 7.0.5)
30
+ activesupport (= 7.0.5)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  net-imap
33
33
  net-pop
34
34
  net-smtp
35
35
  rails-dom-testing (~> 2.0)
36
- actionpack (7.0.4)
37
- actionview (= 7.0.4)
38
- activesupport (= 7.0.4)
39
- rack (~> 2.0, >= 2.2.0)
36
+ actionpack (7.0.5)
37
+ actionview (= 7.0.5)
38
+ activesupport (= 7.0.5)
39
+ rack (~> 2.0, >= 2.2.4)
40
40
  rack-test (>= 0.6.3)
41
41
  rails-dom-testing (~> 2.0)
42
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.4)
44
- actionpack (= 7.0.4)
45
- activerecord (= 7.0.4)
46
- activestorage (= 7.0.4)
47
- activesupport (= 7.0.4)
43
+ actiontext (7.0.5)
44
+ actionpack (= 7.0.5)
45
+ activerecord (= 7.0.5)
46
+ activestorage (= 7.0.5)
47
+ activesupport (= 7.0.5)
48
48
  globalid (>= 0.6.0)
49
49
  nokogiri (>= 1.8.5)
50
- actionview (7.0.4)
51
- activesupport (= 7.0.4)
50
+ actionview (7.0.5)
51
+ activesupport (= 7.0.5)
52
52
  builder (~> 3.1)
53
53
  erubi (~> 1.4)
54
54
  rails-dom-testing (~> 2.0)
55
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.4)
57
- activesupport (= 7.0.4)
56
+ activejob (7.0.5)
57
+ activesupport (= 7.0.5)
58
58
  globalid (>= 0.3.6)
59
- activemodel (7.0.4)
60
- activesupport (= 7.0.4)
61
- activerecord (7.0.4)
62
- activemodel (= 7.0.4)
63
- activesupport (= 7.0.4)
64
- activestorage (7.0.4)
65
- actionpack (= 7.0.4)
66
- activejob (= 7.0.4)
67
- activerecord (= 7.0.4)
68
- activesupport (= 7.0.4)
59
+ activemodel (7.0.5)
60
+ activesupport (= 7.0.5)
61
+ activerecord (7.0.5)
62
+ activemodel (= 7.0.5)
63
+ activesupport (= 7.0.5)
64
+ activestorage (7.0.5)
65
+ actionpack (= 7.0.5)
66
+ activejob (= 7.0.5)
67
+ activerecord (= 7.0.5)
68
+ activesupport (= 7.0.5)
69
69
  marcel (~> 1.0)
70
70
  mini_mime (>= 1.1.0)
71
- activesupport (7.0.4)
71
+ activesupport (7.0.5)
72
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
73
73
  i18n (>= 1.6, < 2)
74
74
  minitest (>= 5.1)
75
75
  tzinfo (~> 2.0)
76
- ahoy_matey (4.1.0)
76
+ ahoy_matey (4.2.1)
77
77
  activesupport (>= 5.2)
78
78
  device_detector
79
79
  safely_block (>= 0.2.1)
80
80
  ast (2.4.2)
81
81
  builder (3.2.4)
82
- concurrent-ruby (1.1.10)
82
+ concurrent-ruby (1.2.2)
83
83
  crass (1.0.6)
84
- debug (1.6.3)
85
- irb (>= 1.3.6)
84
+ date (3.3.3)
85
+ debug (1.8.0)
86
+ irb (>= 1.5.0)
86
87
  reline (>= 0.3.1)
87
- device_detector (1.0.7)
88
+ device_detector (1.1.0)
88
89
  diff-lcs (1.5.0)
89
- errbase (0.2.2)
90
- erubi (1.11.0)
90
+ erubi (1.12.0)
91
91
  factory_bot (6.2.1)
92
92
  activesupport (>= 5.0.0)
93
93
  factory_bot_rails (6.2.0)
94
94
  factory_bot (~> 6.2.0)
95
95
  railties (>= 5.0.0)
96
- globalid (1.0.0)
96
+ globalid (1.1.0)
97
97
  activesupport (>= 5.0)
98
- i18n (1.12.0)
98
+ i18n (1.14.1)
99
99
  concurrent-ruby (~> 1.0)
100
- io-console (0.5.11)
101
- irb (1.4.2)
100
+ io-console (0.6.0)
101
+ irb (1.7.0)
102
102
  reline (>= 0.3.0)
103
- json (2.6.2)
104
- loofah (2.19.0)
103
+ json (2.6.3)
104
+ language_server-protocol (3.17.0.3)
105
+ lint_roller (1.0.0)
106
+ loofah (2.21.3)
105
107
  crass (~> 1.0.2)
106
- nokogiri (>= 1.5.9)
107
- mail (2.7.1)
108
+ nokogiri (>= 1.12.0)
109
+ mail (2.8.1)
108
110
  mini_mime (>= 0.1.1)
111
+ net-imap
112
+ net-pop
113
+ net-smtp
109
114
  marcel (1.0.2)
110
115
  method_source (1.0.0)
111
116
  mini_mime (1.1.2)
112
- minitest (5.16.3)
113
- net-imap (0.3.1)
117
+ minitest (5.18.1)
118
+ net-imap (0.3.6)
119
+ date
114
120
  net-protocol
115
121
  net-pop (0.1.2)
116
122
  net-protocol
117
- net-protocol (0.1.3)
123
+ net-protocol (0.2.1)
118
124
  timeout
119
125
  net-smtp (0.3.3)
120
126
  net-protocol
121
- nio4r (2.5.8)
122
- nokogiri (1.13.9-x86_64-darwin)
127
+ nio4r (2.5.9)
128
+ nokogiri (1.15.2-aarch64-linux)
129
+ racc (~> 1.4)
130
+ nokogiri (1.15.2-x86_64-darwin)
123
131
  racc (~> 1.4)
124
- nokogiri (1.13.9-x86_64-linux)
132
+ nokogiri (1.15.2-x86_64-linux)
125
133
  racc (~> 1.4)
126
- parallel (1.22.1)
127
- parser (3.1.2.1)
134
+ parallel (1.23.0)
135
+ parser (3.2.2.3)
128
136
  ast (~> 2.4.1)
129
- racc (1.6.0)
130
- rack (2.2.4)
131
- rack-test (2.0.2)
137
+ racc
138
+ racc (1.7.1)
139
+ rack (2.2.7)
140
+ rack-test (2.1.0)
132
141
  rack (>= 1.3)
133
- rails (7.0.4)
134
- actioncable (= 7.0.4)
135
- actionmailbox (= 7.0.4)
136
- actionmailer (= 7.0.4)
137
- actionpack (= 7.0.4)
138
- actiontext (= 7.0.4)
139
- actionview (= 7.0.4)
140
- activejob (= 7.0.4)
141
- activemodel (= 7.0.4)
142
- activerecord (= 7.0.4)
143
- activestorage (= 7.0.4)
144
- activesupport (= 7.0.4)
142
+ rails (7.0.5)
143
+ actioncable (= 7.0.5)
144
+ actionmailbox (= 7.0.5)
145
+ actionmailer (= 7.0.5)
146
+ actionpack (= 7.0.5)
147
+ actiontext (= 7.0.5)
148
+ actionview (= 7.0.5)
149
+ activejob (= 7.0.5)
150
+ activemodel (= 7.0.5)
151
+ activerecord (= 7.0.5)
152
+ activestorage (= 7.0.5)
153
+ activesupport (= 7.0.5)
145
154
  bundler (>= 1.15.0)
146
- railties (= 7.0.4)
155
+ railties (= 7.0.5)
147
156
  rails-dom-testing (2.0.3)
148
157
  activesupport (>= 4.2.0)
149
158
  nokogiri (>= 1.6)
150
- rails-html-sanitizer (1.4.3)
151
- loofah (~> 2.3)
152
- railties (7.0.4)
153
- actionpack (= 7.0.4)
154
- activesupport (= 7.0.4)
159
+ rails-html-sanitizer (1.6.0)
160
+ loofah (~> 2.21)
161
+ nokogiri (~> 1.14)
162
+ railties (7.0.5)
163
+ actionpack (= 7.0.5)
164
+ activesupport (= 7.0.5)
155
165
  method_source
156
166
  rake (>= 12.2)
157
167
  thor (~> 1.0)
158
168
  zeitwerk (~> 2.5)
159
169
  rainbow (3.1.1)
160
170
  rake (13.0.6)
161
- regexp_parser (2.6.0)
162
- reline (0.3.1)
171
+ regexp_parser (2.8.1)
172
+ reline (0.3.5)
163
173
  io-console (~> 0.5)
164
174
  rexml (3.2.5)
165
- rspec-core (3.12.0)
175
+ rspec-core (3.12.2)
166
176
  rspec-support (~> 3.12.0)
167
- rspec-expectations (3.12.0)
177
+ rspec-expectations (3.12.3)
168
178
  diff-lcs (>= 1.2.0, < 2.0)
169
179
  rspec-support (~> 3.12.0)
170
- rspec-mocks (3.12.0)
180
+ rspec-mocks (3.12.5)
171
181
  diff-lcs (>= 1.2.0, < 2.0)
172
182
  rspec-support (~> 3.12.0)
173
183
  rspec-rails (5.1.2)
@@ -179,51 +189,60 @@ GEM
179
189
  rspec-mocks (~> 3.10)
180
190
  rspec-support (~> 3.10)
181
191
  rspec-support (3.12.0)
182
- rubocop (1.35.1)
192
+ rubocop (1.52.1)
183
193
  json (~> 2.3)
184
194
  parallel (~> 1.10)
185
- parser (>= 3.1.2.1)
195
+ parser (>= 3.2.2.3)
186
196
  rainbow (>= 2.2.2, < 4.0)
187
197
  regexp_parser (>= 1.8, < 3.0)
188
198
  rexml (>= 3.2.5, < 4.0)
189
- rubocop-ast (>= 1.20.1, < 2.0)
199
+ rubocop-ast (>= 1.28.0, < 2.0)
190
200
  ruby-progressbar (~> 1.7)
191
- unicode-display_width (>= 1.4.0, < 3.0)
192
- rubocop-ast (1.23.0)
193
- parser (>= 3.1.1.0)
194
- rubocop-performance (1.14.3)
201
+ unicode-display_width (>= 2.4.0, < 3.0)
202
+ rubocop-ast (1.29.0)
203
+ parser (>= 3.2.1.0)
204
+ rubocop-performance (1.18.0)
195
205
  rubocop (>= 1.7.0, < 2.0)
196
206
  rubocop-ast (>= 0.4.0)
197
- ruby-progressbar (1.11.0)
198
- safely_block (0.3.0)
199
- errbase (>= 0.1.1)
200
- sprockets (4.1.1)
207
+ ruby-progressbar (1.13.0)
208
+ safely_block (0.4.0)
209
+ sprockets (4.2.0)
201
210
  concurrent-ruby (~> 1.0)
202
- rack (> 1, < 3)
211
+ rack (>= 2.2.4, < 4)
203
212
  sprockets-rails (3.2.2)
204
213
  actionpack (>= 4.0)
205
214
  activesupport (>= 4.0)
206
215
  sprockets (>= 3.0.0)
207
- sqlite3 (1.5.3-x86_64-darwin)
208
- sqlite3 (1.5.3-x86_64-linux)
209
- standard (1.16.1)
210
- rubocop (= 1.35.1)
211
- rubocop-performance (= 1.14.3)
212
- thor (1.2.1)
213
- timeout (0.3.0)
214
- tzinfo (2.0.5)
216
+ sqlite3 (1.6.3-aarch64-linux)
217
+ sqlite3 (1.6.3-x86_64-darwin)
218
+ sqlite3 (1.6.3-x86_64-linux)
219
+ standard (1.29.0)
220
+ language_server-protocol (~> 3.17.0.2)
221
+ lint_roller (~> 1.0)
222
+ rubocop (~> 1.52.0)
223
+ standard-custom (~> 1.0.0)
224
+ standard-performance (~> 1.1.0)
225
+ standard-custom (1.0.1)
226
+ lint_roller (~> 1.0)
227
+ standard-performance (1.1.0)
228
+ lint_roller (~> 1.0)
229
+ rubocop-performance (~> 1.18.0)
230
+ thor (1.2.2)
231
+ timeout (0.3.2)
232
+ tzinfo (2.0.6)
215
233
  concurrent-ruby (~> 1.0)
216
- unicode-display_width (2.3.0)
217
- view_component (2.74.1)
218
- activesupport (>= 5.0.0, < 8.0)
234
+ unicode-display_width (2.4.2)
235
+ view_component (2.82.0)
236
+ activesupport (>= 5.2.0, < 8.0)
219
237
  concurrent-ruby (~> 1.0)
220
238
  method_source (~> 1.0)
221
239
  websocket-driver (0.7.5)
222
240
  websocket-extensions (>= 0.1.0)
223
241
  websocket-extensions (0.1.5)
224
- zeitwerk (2.6.4)
242
+ zeitwerk (2.6.8)
225
243
 
226
244
  PLATFORMS
245
+ aarch64-linux
227
246
  x86_64-darwin-21
228
247
  x86_64-linux
229
248
 
@@ -242,4 +261,4 @@ DEPENDENCIES
242
261
  standard (~> 1.3)
243
262
 
244
263
  BUNDLED WITH
245
- 2.3.7
264
+ 2.4.10
data/README.md CHANGED
@@ -45,6 +45,8 @@ the `time_window`, which is the period to report on.
45
45
 
46
46
  It is that simple! There should now be a card displaying the number of active users within the past week.
47
47
 
48
+ View the available component color schemes [here](COLOR_SCHEMES.md).
49
+
48
50
  View the list of available components [here](COMPONENTS.md).
49
51
 
50
52
  **Note**: The more data, the more interesting the components will be. A common and helpful pattern is to capture events on all controller actions. Details on doing this can be found [here](https://github.com/ankane/ahoy#ruby).
@@ -55,10 +57,13 @@ After checking out the repository, run the following commands to get started:
55
57
 
56
58
  ```bash
57
59
  # install required packages
58
- bin/setup
60
+ bin/setup
61
+
62
+ # install spec/sample packages
63
+ bundle install --gemfile spec/sample/Gemfile
59
64
 
60
65
  # run test cases and ensure everything is passing
61
- rake spec
66
+ rake spec
62
67
 
63
68
  # an interactive prompt that will allow you to experiment with matey (currently broken!)
64
69
  bin/console
@@ -74,7 +79,7 @@ To use the sample application:
74
79
 
75
80
  1. `cd spec/sample`
76
81
  2. `bundle`
77
- 3. `rails s`
82
+ 3. `bundle exec rails s`
78
83
  4. Open a browser to `localhost:3000`
79
84
 
80
85
  ## Testing
@@ -1,4 +1,4 @@
1
- <div class="card bg-primary text-light">
1
+ <div class="card <%= @color_scheme %>">
2
2
  <div class="card-body">
3
3
  <div class="row">
4
4
  <div class="col">
@@ -1,7 +1,7 @@
1
1
  require "ahoy_matey"
2
2
 
3
- class Matey::ActiveUsersComponent < ApplicationComponent
4
- def initialize(events:, time_window: 1.week)
3
+ class Matey::ActiveUsersComponent < Matey::ApplicationComponent
4
+ def initialize(events:, time_window: 1.week, color_scheme: "neutral")
5
5
  raise ArgumentError unless events.is_a?(ActiveRecord::Relation)
6
6
  raise ArgumentError unless time_window.is_a?(Integer)
7
7
 
@@ -9,8 +9,10 @@ class Matey::ActiveUsersComponent < ApplicationComponent
9
9
  previous_period = events.where(time: (2 * time_window).ago..time_window.ago).pluck(:user_id).uniq.count
10
10
 
11
11
  @change_active_number = @current_period - previous_period
12
- @change_active_percent = ((@change_active_number.to_f / (previous_period == 0 ? 1 : previous_period)) * 100).truncate(2)
12
+ @change_active_percent = ((@change_active_number.to_f / ((previous_period == 0) ? 1 : previous_period)) * 100).truncate(2)
13
13
 
14
14
  @time_window = time_window
15
+
16
+ @color_scheme = color_scheme(scheme: color_scheme)
15
17
  end
16
18
  end
@@ -1,8 +1,10 @@
1
1
  require "view_component"
2
2
  require "ahoy_matey"
3
+ require_relative "../../../lib/helpers"
3
4
 
4
- class ApplicationComponent < ViewComponent::Base
5
+ class Matey::ApplicationComponent < ViewComponent::Base
5
6
  include ActiveModel::Validations
7
+ include ColorSchemeHelper
6
8
 
7
9
  def before_render
8
10
  validate!
@@ -1,4 +1,4 @@
1
- <div class="card bg-primary text-light">
1
+ <div class="card <%= @color_scheme %>">
2
2
  <div class="card-body">
3
3
  <h5 class = "text-center"><strong>The Bounce Rate of your Application is: <u><%= @percentage_of_visits_that_were_bounced %>%</u></strong></h5>
4
4
  <div>
@@ -21,7 +21,7 @@
21
21
  <th class="text-end">Bounce Count</th>
22
22
  </tr>
23
23
  </thead>
24
- <tbody class="text-light">
24
+ <tbody class="text-dark border-dark">
25
25
  <% @most_bounced_pages.each do |controller_name_and_action, count| %>
26
26
  <tr>
27
27
  <td><%= controller_name_and_action %></td>
@@ -1,7 +1,7 @@
1
1
  require "ahoy_matey"
2
2
 
3
- class Matey::BounceRateComponent < ApplicationComponent
4
- def initialize(events:, visits:, limit: 5)
3
+ class Matey::BounceRateComponent < Matey::ApplicationComponent
4
+ def initialize(events:, visits:, limit: 5, color_scheme: "neutral")
5
5
  # Determine the total number of user sessions to the website
6
6
  @total_number_of_user_visits = events.pluck(:visit_id).uniq.count
7
7
 
@@ -17,6 +17,8 @@ class Matey::BounceRateComponent < ApplicationComponent
17
17
  @most_bounced_pages = @single_event_visits_landing_page_count.sort_by { |controller_name_and_action, count| count }.last(limit).reverse
18
18
 
19
19
  # Get the percentage as #-One-Page-Visits / Total-#-Of-Visits
20
- @percentage_of_visits_that_were_bounced = ((@total_number_of_single_event_visits.to_f / (@total_number_of_user_visits == 0 ? 1 : @total_number_of_user_visits)) * 100).round(1)
20
+ @percentage_of_visits_that_were_bounced = ((@total_number_of_single_event_visits.to_f / ((@total_number_of_user_visits == 0) ? 1 : @total_number_of_user_visits)) * 100).round(1)
21
+
22
+ @color_scheme = color_scheme(scheme: color_scheme)
21
23
  end
22
24
  end
@@ -0,0 +1,38 @@
1
+ <div class="card <%= @color_scheme %>">
2
+ <div class="card-body">
3
+ <div class="row">
4
+ <h5 class="text-center">Browser and OS Breakdown</h5>
5
+ <div class="col">
6
+ <p class="text-center">Since <%= time_ago_in_words(@time_window.ago).titleize %> Ago</p>
7
+ <table class='table table-hover table-borderless'>
8
+ <thead class='table-dark'>
9
+ <th>Browser</th>
10
+ <th class='text-center'>Visitor Count</th>
11
+ </thead>
12
+ <tbody class='text-dark border-dark'>
13
+ <% @browsers.each do |browser_name, visitor_count| %>
14
+ <tr>
15
+ <td><%= browser_name %></td>
16
+ <td class='text-center'><%= visitor_count %></td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
21
+ <table class='table table-hover table-borderless'>
22
+ <thead class='table-dark'>
23
+ <th>OS</th>
24
+ <th class='text-center'>Visitor Count</th>
25
+ </thead>
26
+ <tbody class='text-dark border-dark'>
27
+ <% @operating_systems.each do |operating_system, visitor_count| %>
28
+ <tr>
29
+ <td><%= operating_system %></td>
30
+ <td class='text-center'><%= visitor_count %></td>
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </div>
@@ -0,0 +1,11 @@
1
+ class Matey::BrowserOsBreakdownComponent < Matey::ApplicationComponent
2
+ def initialize(visits:, time_window:, color_scheme: "neutral")
3
+ visits_in_time_window = visits.where(started_at: time_window.ago..)
4
+ @visits_in_time_window = visits_in_time_window.count
5
+ @browsers = visits_in_time_window.group(:browser).count
6
+ @operating_systems = visits_in_time_window.group(:os).count
7
+ @time_window = time_window
8
+
9
+ @color_scheme = color_scheme(scheme: color_scheme)
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ <div class="card <%= @color_scheme %>">
2
+ <div class="card-body">
3
+ <div class="col">
4
+ <div class="col">
5
+ <h5>Daily Active Users</h5>
6
+ </div>
7
+ <div class="col-auto">
8
+ <p>Since <%= time_ago_in_words(@time_window.ago).titleize %> Ago</p>
9
+ <p><%= @distinct_user_visits_by_day %></p>
10
+ <p><%# @distinct_user_visits_by_day2 %></p>
11
+ <%# @visits.each {|e| e} %>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ </div>
@@ -0,0 +1,11 @@
1
+ class Matey::DailyActiveUsersComponent < Matey::ApplicationComponent
2
+ def initialize(visits:, time_window:, color_scheme: "neutral")
3
+ @visits = visits
4
+ @time_window = time_window
5
+ visits_in_time_window = visits.where(started_at: time_window.ago..)
6
+ @distinct_user_visits_by_day = visits_in_time_window.order(:day).group(:day).uniq.count
7
+ # @distinct_user_visits_by_day2 = visits_in_time_window.order(:day).group("DATE(started_at)").map { |k, v| [k, v] }.sort
8
+
9
+ @color_scheme = color_scheme(scheme: color_scheme)
10
+ end
11
+ end
@@ -1,4 +1,4 @@
1
- <div class="card bg-primary text-light">
1
+ <div class="card <%= @color_scheme %>">
2
2
  <div class="card-body">
3
3
  <div class="row">
4
4
  <div class="col">
@@ -1,5 +1,5 @@
1
- class Matey::NewActivityComponent < ApplicationComponent
2
- def initialize(events:, time_window: 1.week)
1
+ class Matey::NewActivityComponent < Matey::ApplicationComponent
2
+ def initialize(events:, time_window: 1.week, color_scheme: "neutral")
3
3
  raise ArgumentError unless events.is_a?(ActiveRecord::Relation)
4
4
  raise ArgumentError unless time_window.is_a?(Integer)
5
5
 
@@ -7,8 +7,10 @@ class Matey::NewActivityComponent < ApplicationComponent
7
7
  previous_period = events.where(time: (2 * time_window).ago..time_window.ago).pluck(:user_id).count
8
8
 
9
9
  @change_active_number = @current_period - previous_period
10
- @change_active_percent = ((@change_active_number.to_f / (previous_period == 0 ? 1 : previous_period)) * 100).truncate(2)
10
+ @change_active_percent = ((@change_active_number.to_f / ((previous_period == 0) ? 1 : previous_period)) * 100).truncate(2)
11
11
 
12
12
  @time_window = time_window
13
+
14
+ @color_scheme = color_scheme(scheme: color_scheme)
13
15
  end
14
16
  end
@@ -1,4 +1,4 @@
1
- <div class="card bg-primary text-light">
1
+ <div class="card <%= @color_scheme %>">
2
2
  <div class="card-body">
3
3
  <div class="row">
4
4
  <div class="col">
@@ -1,11 +1,13 @@
1
- class Matey::NewUsersComponent < ApplicationComponent
2
- def initialize(users:, time_window: 1.week)
1
+ class Matey::NewUsersComponent < Matey::ApplicationComponent
2
+ def initialize(users:, time_window: 1.week, color_scheme: "neutral")
3
3
  @current_period = users.where(created_at: time_window.ago..Time.current).count
4
4
  previous_period = users.where(created_at: (2 * time_window).ago..time_window.ago).count
5
5
 
6
6
  @change_new_number = @current_period - previous_period
7
- @change_new_percent = ((@change_new_number.to_f / (previous_period == 0 ? 1 : previous_period)) * 100).truncate(2)
7
+ @change_new_percent = ((@change_new_number.to_f / ((previous_period == 0) ? 1 : previous_period)) * 100).truncate(2)
8
8
 
9
9
  @time_window = time_window
10
+
11
+ @color_scheme = color_scheme(scheme: color_scheme)
10
12
  end
11
13
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- <div class="card bg-primary text-light">
3
+ <div class="card <%= @color_scheme %>">
4
4
  <div class="card-body">
5
5
  <h5>Top Events Since <%= time_ago_in_words(@time_window.ago).titleize %> Ago (<%= @time_window.ago.strftime("%m/%d/%Y") %>)</h5>
6
6
  <div>
@@ -11,7 +11,7 @@
11
11
  <th>Count</th>
12
12
  </tr>
13
13
  </thead>
14
- <tbody class="text-light">
14
+ <tbody class="text-dark border-dark">
15
15
  <% @events.each do |action, count| %>
16
16
  <tr>
17
17
  <td><%= action %></td>
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Matey::TopEventsComponent < ApplicationComponent
4
- def initialize(events:, time_window: 1.week, limit: 5)
3
+ class Matey::TopEventsComponent < Matey::ApplicationComponent
4
+ def initialize(events:, time_window: 1.week, limit: 5, color_scheme: "neutral")
5
5
  raise ArgumentError unless events.is_a?(ActiveRecord::Relation)
6
6
  raise ArgumentError unless time_window.is_a?(Integer)
7
7
 
8
8
  @events = events.where(time: time_window.ago..Time.current).limit(limit).order("count(name) DESC").group(:name).count
9
9
  @time_window = time_window
10
+
11
+ @color_scheme = color_scheme(scheme: color_scheme)
10
12
  end
11
13
  end
@@ -1,4 +1,4 @@
1
- <div class="card bg-primary text-light">
1
+ <div class="card <%= @color_scheme %>">
2
2
  <div class="card-body">
3
3
  <h5>Top Landing Page Visits Since <%= time_ago_in_words(@time_window.ago).titleize %> Ago (<%= @time_window.ago.strftime("%m/%d/%Y") %>)</h5>
4
4
  <div>
@@ -9,7 +9,7 @@
9
9
  <th>Count</th>
10
10
  </tr>
11
11
  </thead>
12
- <tbody class="text-light">
12
+ <tbody class="text-dark border-dark">
13
13
  <% @user_count_by_event.each do |controller_name_and_action, count| %>
14
14
  <tr>
15
15
  <td><%= controller_name_and_action %></td>
@@ -1,5 +1,5 @@
1
- class Matey::TopVisitedPagesTableComponent < ApplicationComponent
2
- def initialize(events:, time_window: 1.week, limit: 10)
1
+ class Matey::TopVisitedPagesTableComponent < Matey::ApplicationComponent
2
+ def initialize(events:, time_window: 1.week, limit: 10, color_scheme: "neutral")
3
3
  # Group events by controller (:name) and action. Aggregate number of unique user actions
4
4
  @user_count_by_event = events.where(started_at: time_window.ago..).pluck(:landing_page).tally
5
5
 
@@ -7,5 +7,7 @@ class Matey::TopVisitedPagesTableComponent < ApplicationComponent
7
7
  @user_count_by_event = @user_count_by_event.sort_by { |controller_name_and_action, count| count }.last(limit).reverse
8
8
 
9
9
  @time_window = time_window
10
+
11
+ @color_scheme = color_scheme(scheme: color_scheme)
10
12
  end
11
13
  end
@@ -1,4 +1,4 @@
1
- <div class="card bg-primary text-light">
1
+ <div class="card <%= @color_scheme %>">
2
2
  <div class="card-body">
3
3
  <h5>User Activity for <i>user id: <%=@user_id%></i> since <i><%= time_ago_in_words(@time_window.ago).titleize %></i> ago </h5>
4
4
  <div>
@@ -9,7 +9,7 @@
9
9
  <th class="text-end">Count</th>
10
10
  </tr>
11
11
  </thead>
12
- <tbody class="text-light">
12
+ <tbody class="text-dark border-dark">
13
13
  <% @count_by_event.each do |event, count| %>
14
14
  <tr>
15
15
  <td><%= event %></td>
@@ -1,10 +1,12 @@
1
1
  require "ahoy_matey"
2
2
 
3
- class Matey::UserEngagementComponent < ApplicationComponent
4
- def initialize(events:, user_id:, time_window: 1.week, limit: 10)
3
+ class Matey::UserEngagementComponent < Matey::ApplicationComponent
4
+ def initialize(events:, user_id:, time_window: 1.week, limit: 10, color_scheme: "neutral")
5
5
  @events_for_user = events.where_props(user_id: user_id).where(time: time_window.ago..Time.current).group(:name).count
6
6
  @count_by_event = @events_for_user.sort_by { |event, count| count }.last(limit).reverse
7
7
  @time_window = time_window
8
8
  @user_id = user_id
9
+
10
+ @color_scheme = color_scheme(scheme: color_scheme)
9
11
  end
10
12
  end
@@ -0,0 +1,26 @@
1
+ <div class="card <%= @color_scheme %>">
2
+ <div class="card-header">
3
+ <h5>Visits By Day of Week since <%= time_ago_in_words(@time_window.ago).titleize %> Ago (<%= @time_window.ago.strftime("%m/%d/%Y") %>) </h5>
4
+ <% if @exclude_days %>
5
+ <p>Excluding <%= @exclude_days%>
6
+ <% end %>
7
+ </div>
8
+ <div class="card-body">
9
+ <table class="table table-hover table-borderless table-sm">
10
+ <thead class="table-dark">
11
+ <tr>
12
+ <th class="text-start">DayOfWeek</th>
13
+ <th class="text-end">Count</th>
14
+ </tr>
15
+ </thead>
16
+ <tbody class="text-dark border-dark">
17
+ <% @visits_by_day_of_week.each do |day_of_week, count| %>
18
+ <tr>
19
+ <td><%= day_of_week %></td>
20
+ <td class="text-end"><%= count %></td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+ </div><!-- .card-body -->
26
+ </div><!-- .card -->
@@ -0,0 +1,24 @@
1
+ require "ahoy_matey"
2
+
3
+ class Matey::VisitsByDayOfWeekComponent < Matey::ApplicationComponent
4
+ def initialize(visits:, time_window: 1.month, limit: 10, exclude_days: [], color_scheme: "neutral")
5
+ @time_window = time_window
6
+
7
+ # query for all the visits
8
+ all_visits = visits.where(started_at: time_window.ago..)
9
+
10
+ visits_by_day_of_week = {}
11
+
12
+ # get day of week from each visit. Incrase value of dayOfWeek key by 1 if key is already there else initialize key with value of 1
13
+ all_visits.each { |visit| visits_by_day_of_week.key?(visit.started_at.strftime("%A")) ? visits_by_day_of_week[(visit.started_at.strftime("%A"))] += 1 : visits_by_day_of_week[visit.started_at.strftime("%A")] = 1 }
14
+
15
+ # take out items from visits_by_day_of_week hashmap based on exclude_days parameter
16
+ if exclude_days.length > 0
17
+ exclude_days.each { |exclude| visits_by_day_of_week = visits_by_day_of_week.slice!(exclude) }
18
+ end
19
+
20
+ @visits_by_day_of_week = visits_by_day_of_week
21
+
22
+ @color_scheme = color_scheme(scheme: color_scheme)
23
+ end
24
+ end
Binary file
Binary file
data/lib/helpers.rb ADDED
@@ -0,0 +1,12 @@
1
+ module ColorSchemeHelper
2
+ def color_scheme(scheme: "blue")
3
+ case scheme
4
+ when "blue"
5
+ "bg-primary text-light"
6
+ when "neutral"
7
+ "bg-light text-dark border-dark"
8
+ else
9
+ "bg-light text-dark border-dark"
10
+ end
11
+ end
12
+ end
data/lib/matey/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Matey
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/matey.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "matey/version"
4
4
 
5
- require_relative "../app/components/application_component"
5
+ require_relative "../app/components/matey/application_component"
6
6
  require_relative "../app/components/matey/active_users_component"
7
7
  require_relative "../app/components/matey/bounce_rate_component"
8
8
  require_relative "../app/components/matey/new_activity_component"
@@ -10,6 +10,9 @@ require_relative "../app/components/matey/new_users_component"
10
10
  require_relative "../app/components/matey/top_events_component"
11
11
  require_relative "../app/components/matey/top_visited_pages_table_component"
12
12
  require_relative "../app/components/matey/user_engagement_component"
13
+ require_relative "../app/components/matey/daily_active_users_component"
14
+ require_relative "../app/components/matey/visits_by_day_of_week_component"
15
+ require_relative "../app/components/matey/browser_os_breakdown_component"
13
16
 
14
17
  module Matey
15
18
  class Error < StandardError; end
data/matey.gemspec CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
36
 
37
- spec.add_dependency "view_component", "~> 2.74.1"
37
+ spec.add_dependency "view_component", "~> 2.74"
38
38
  spec.add_dependency "ahoy_matey", "~> 4.0"
39
39
 
40
40
  spec.add_development_dependency "rspec-rails", "~> 5.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Loos
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-11-04 00:00:00.000000000 Z
12
+ date: 2023-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: view_component
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.74.1
20
+ version: '2.74'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 2.74.1
27
+ version: '2.74'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: ahoy_matey
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -153,17 +153,22 @@ files:
153
153
  - ".standard.yml"
154
154
  - CHANGELOG.md
155
155
  - CODE_OF_CONDUCT.md
156
+ - COLOR_SCHEMES.md
156
157
  - COMPONENTS.md
157
158
  - Gemfile
158
159
  - Gemfile.lock
159
160
  - LICENSE.txt
160
161
  - README.md
161
162
  - Rakefile
162
- - app/components/application_component.rb
163
163
  - app/components/matey/active_users_component.html.erb
164
164
  - app/components/matey/active_users_component.rb
165
+ - app/components/matey/application_component.rb
165
166
  - app/components/matey/bounce_rate_component.html.erb
166
167
  - app/components/matey/bounce_rate_component.rb
168
+ - app/components/matey/browser_os_breakdown_component.html.erb
169
+ - app/components/matey/browser_os_breakdown_component.rb
170
+ - app/components/matey/daily_active_users_component.html.erb
171
+ - app/components/matey/daily_active_users_component.rb
167
172
  - app/components/matey/new_activity_component.html.erb
168
173
  - app/components/matey/new_activity_component.rb
169
174
  - app/components/matey/new_users_component.html.erb
@@ -174,14 +179,19 @@ files:
174
179
  - app/components/matey/top_visited_pages_table_component.rb
175
180
  - app/components/matey/user_engagement_component.html.erb
176
181
  - app/components/matey/user_engagement_component.rb
182
+ - app/components/matey/visits_by_day_of_week_component.html.erb
183
+ - app/components/matey/visits_by_day_of_week_component.rb
177
184
  - docs/CONTRIBUTING.md
178
185
  - images/.DS_Store
179
186
  - images/activeUsersComponent.png
180
187
  - images/bounceRateComponent.png
188
+ - images/colorSchemeBlue.png
189
+ - images/colorSchemeNeutral.png
181
190
  - images/newActivityComponent.png
182
191
  - images/newUsersComponent.png
183
192
  - images/topEventsComponent.png
184
193
  - images/topVisitedPages.png
194
+ - lib/helpers.rb
185
195
  - lib/matey.rb
186
196
  - lib/matey/version.rb
187
197
  - matey.gemspec
@@ -208,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
218
  - !ruby/object:Gem::Version
209
219
  version: '0'
210
220
  requirements: []
211
- rubygems_version: 3.3.7
221
+ rubygems_version: 3.4.10
212
222
  signing_key:
213
223
  specification_version: 4
214
224
  summary: Track user engagement using Ahoy and ViewComponents.