active_analytics 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -6
  3. data/app/assets/images/active_analytics.png +0 -0
  4. data/app/assets/images/active_analytics_screenshot.png +0 -0
  5. data/app/assets/javascripts/active_analytics/application.js +13 -0
  6. data/app/assets/stylesheets/active_analytics/application.css +1 -19
  7. data/app/assets/stylesheets/active_analytics/charts.css +80 -2262
  8. data/app/assets/stylesheets/active_analytics/style.css +161 -0
  9. data/app/controllers/active_analytics/application_controller.rb +12 -0
  10. data/app/controllers/active_analytics/pages_controller.rb +10 -7
  11. data/app/controllers/active_analytics/referrers_controller.rb +6 -4
  12. data/app/controllers/active_analytics/sites_controller.rb +5 -2
  13. data/app/helpers/active_analytics/application_helper.rb +3 -0
  14. data/app/helpers/active_analytics/sites_helper.rb +3 -0
  15. data/app/models/active_analytics/views_per_day.rb +26 -7
  16. data/app/views/active_analytics/pages/_table.html.erb +31 -19
  17. data/app/views/active_analytics/pages/index.html.erb +4 -7
  18. data/app/views/active_analytics/pages/show.html.erb +18 -15
  19. data/app/views/active_analytics/referrers/_table.html.erb +21 -14
  20. data/app/views/active_analytics/referrers/index.html.erb +4 -3
  21. data/app/views/active_analytics/referrers/show.html.erb +14 -9
  22. data/app/views/active_analytics/sites/_histogram.html.erb +15 -19
  23. data/app/views/active_analytics/sites/index.html.erb +12 -7
  24. data/app/views/active_analytics/sites/show.html.erb +12 -12
  25. data/app/views/layouts/active_analytics/_footer.html.erb +45 -3
  26. data/app/views/layouts/active_analytics/_header.html.erb +47 -21
  27. data/app/views/layouts/active_analytics/application.html.erb +15 -14
  28. data/db/migrate/20210303094108_create_active_analytics_views_per_days.rb +1 -1
  29. data/lib/active_analytics.rb +2 -4
  30. data/lib/active_analytics/version.rb +1 -1
  31. metadata +7 -4
@@ -1,14 +1,21 @@
1
- <table>
2
- <% for referrer in referrers %>
3
- <tr>
4
- <td>
5
- <% if referrer.host %>
6
- <%= link_to referrer.host, referrer_path(site: params[:site], referrer: referrer.host) %>
7
- <% else %>
8
- <%= referrer.host %>
9
- <% end %>
10
- </td>
11
- <td><%= referrer.total %></td>
12
- </tr>
13
- <% end %>
14
- </table>
1
+ <% if referrers.empty? %>
2
+ <div class="is-empty">
3
+ <span>no data</span>
4
+ </div>
5
+ <% else %>
6
+ <table>
7
+ <% for referrer in referrers %>
8
+ <tr>
9
+ <td>
10
+ <% if referrer.host %>
11
+ <%= site_icon referrer.host %>
12
+ <%= link_to referrer.host, referrer_path(site: params[:site], referrer: referrer.host, from: params[:from], to: params[:to]) %>
13
+ <% else %>
14
+ <%= referrer.host %>
15
+ <% end %>
16
+ </td>
17
+ <td class="number"><%= format_view_count referrer.total %></td>
18
+ </tr>
19
+ <% end %>
20
+ </table>
21
+ <% end %>
@@ -1,8 +1,9 @@
1
- <section>
2
- <h2>Referrers</h2>
1
+ <section class="card">
2
+ <h3><%= format_view_count @histogram.total %> views</h3>
3
3
  <%= render "/active_analytics/sites/histogram", histogram: @histogram %>
4
4
  </section>
5
5
 
6
- <section>
6
+ <section class="card">
7
+ <h3>Top sources</h3>
7
8
  <%= render "table", referrers: @referrers %>
8
9
  </section>
@@ -1,14 +1,19 @@
1
1
  <section>
2
- <h2>Referrer <%= params[:referrer] %></h2>
3
- <%= render "/active_analytics/sites/histogram", histogram: @histogram %>
2
+ <h2>Source: <%= params[:referrer] %></h2>
4
3
  </section>
5
4
 
6
- <section>
7
- <h3>Sources</h3>
8
- <%= render "/active_analytics/pages/table", pages: @previous_pages %>
5
+ <section class="card">
6
+ <h3><%= format_view_count @histogram.total %> views</h3>
7
+ <%= render "/active_analytics/sites/histogram", histogram: @histogram %>
9
8
  </section>
9
+ <ul class="grid-auto">
10
+ <li class="card">
11
+ <h3>Source page</h3>
12
+ <%= render "/active_analytics/pages/table", pages: @previous_pages %>
13
+ </li>
10
14
 
11
- <section>
12
- <h3>Destinations</h3>
13
- <%= render "/active_analytics/pages/table", pages: @next_pages %>
14
- </section>
15
+ <li class="card">
16
+ <h3>Destination page</h3>
17
+ <%= render "/active_analytics/pages/table", pages: @next_pages %>
18
+ </li>
19
+ </ul>
@@ -1,19 +1,15 @@
1
- <table class="charts-css column show-5-secondary-axes show-data-on-hover show-labels" style="height: calc(var(--space-2x) * 10);">
2
- <thead>
3
- <tr>
4
- <th scope="col">Day</th>
5
- <th scope="col">Views</th>
6
- </tr>
7
- </thead>
8
-
9
- <tbody>
10
- <% for bar in histogram.bars %>
11
- <tr>
12
- <th scope="row"><%= l bar.label, format: :short %></td>
13
- <td style="--size: <%= bar.height %>; --color: rgb(240,241,243);">
14
- <span class="data"><%= bar.value.to_i %></span>
15
- </td>
16
- </tr>
17
- <% end %>
18
- </tbody>
19
- </table>
1
+ <% if histogram.bars.count > 1 %>
2
+ <table class="charts-css column show-primary-axis show-5-secondary-axes hide-data <%= "show-labels" if histogram.bars.count < 32 %>" style="height: calc(var(--space-2x) * 8);">
3
+ <tbody>
4
+ <% for bar in histogram.bars %>
5
+ <tr>
6
+ <th scope="row"><%= bar.label.day %></td>
7
+ <td style="--size: <%= bar.height %>; --color: rgba(var(--color-grey-100), 1);">
8
+ <span class="data"><%= bar.value.to_i %></span>
9
+ <span class="tooltip"><small class="tooltip-date"><%= l bar.label, format: :long%></small><br/><%= format_view_count bar.value %> views</span>
10
+ </td>
11
+ </tr>
12
+ <% end %>
13
+ </tbody>
14
+ </table>
15
+ <% end %>
@@ -1,7 +1,12 @@
1
- <h1>Sites</h1>
2
-
3
- <ul>
4
- <% for site in @sites %>
5
- <li><%= link_to site.host, site_path(site: site.host) %> <%= site.total %></li>
6
- <% end %>
7
- </ul>
1
+ <h2>Site views in the last 30 days</h2>
2
+ <div class="card">
3
+ <table>
4
+ </tr>
5
+ <% for site in @sites %>
6
+ <tr>
7
+ <td><%= link_to site.host, site_path(site: site.host) %></td>
8
+ <td class="number"><%= format_view_count site.total %></td>
9
+ </tr>
10
+ <% end %>
11
+ </table>
12
+ </div>
@@ -1,16 +1,16 @@
1
- <section>
2
- <h3>Views per day</h3>
1
+ <section class="card">
2
+ <h3><%= format_view_count @histogram.total %> views</h3>
3
3
  <%= render "/active_analytics/sites/histogram", histogram: @histogram %>
4
4
  </section>
5
5
 
6
- <section>
7
- <h3>Top Pages</h3>
8
- <%= render "/active_analytics/pages/table", pages: @pages %>
9
- <p style="text-align: center;"><br/><%= link_to "More pages", pages_path, role: "button"%></p>
10
- </section>
6
+ <ul class="grid-auto">
7
+ <li class="card">
8
+ <h3>Top sources <%= link_to "view all", referrers_path(from: params[:from], to: params[:to]) %></h3>
9
+ <%= render "/active_analytics/referrers/table", referrers: @referrers %>
10
+ </li>
11
11
 
12
- <section>
13
- <h3>Top referrers</h3>
14
- <%= render "/active_analytics/referrers/table", referrers: @referrers %>
15
- <p style="text-align: center;"><br/><%= link_to "More referrers", referrers_path, role: "button" %></p>
16
- </section>
12
+ <li class="card">
13
+ <h3>Top pages <%= link_to "view all", pages_path(from: params[:from], to: params[:to]) %></h3>
14
+ <%= render "/active_analytics/pages/table", pages: @pages %>
15
+ </li>
16
+ </ul>
@@ -1,6 +1,48 @@
1
1
  <footer>
2
2
  <p>
3
- Made in <a href="https://www.basesecrete.com">Base Secrète</a> |
4
- <%= link_to "Source code", "https://github.com/BaseSecrete/active_analytics" %>
3
+ Made in <a href="https://www.basesecrete.com" target="_blank" rel="noopener">Base Secrète</a> | <%= link_to "Source code", "https://github.com/BaseSecrete/active_analytics", target: "_blank", rel: "noopener" %> | <%= link_to "Twitter", "https://twitter.com/base_secrete", target: "_blank", rel: "noopener" %>
5
4
  </p>
6
- </footer>
5
+
6
+ <div class="card">
7
+ <ul class="grid-auto">
8
+ <li>
9
+ <a href="https://github.com/BaseSecrete/rorvswild" target="_blank" rel="noopener">RoRvsWild</a>
10
+ <p>Ruby on Rails application performances and exceptions monitoring.</p>
11
+ </li>
12
+ <li>
13
+ <a href="https://github.com/BaseSecrete/redis_dashboard" target="_blank" rel="noopener">Redis Dashboard</a>
14
+ <p>Sinatra app to monitor Redis servers.</p>
15
+ </li>
16
+ <li>
17
+ <a href="https://github.com/BaseSecrete/type_scopes" target="_blank" rel="noopener">Type Scopes</a>
18
+ <p>Automatic scopes for ActiveRecord models.</p>
19
+ </li>
20
+ <li>
21
+ <a href="https://github.com/BaseSecrete/secure_attribute" target="_blank" rel="noopener">Secure Attribute</a>
22
+ <p>Encrypt attributes of any Ruby object or ActiveRecord model.</p>
23
+ </li>
24
+ <li>
25
+ <a href="https://github.com/BaseSecrete/teamodoro" target="_blank" rel="noopener">Teamodoro</a>
26
+ <p>Synchronize pomodoros with your coworkers.</p>
27
+ </li>
28
+ <li>
29
+ <a href="https://github.com/BaseSecrete/ariato" target="_blank" rel="noopener">Ariato</a>
30
+ <p>Web UI framework to improve accessibility.</p>
31
+ </li>
32
+ </ul>
33
+ </div>
34
+ </footer>
35
+
36
+ <div role="dialog" hidden="true" id="custom-date-range" aria-labelledby="custom-range-title" aria-modal="true">
37
+ <header id="custom-range-title">Custom range</header>
38
+ <%= form_tag url_for(params.except(:from, :to).to_unsafe_hash), method: "get", id: "dateRangeForm" do %>
39
+ <div role="group" class="is-block">
40
+ <label>From <%= text_field_tag :from, params[:from] %></label>
41
+ <label>To <%= text_field_tag :to, params[:to] %></label>
42
+ </div>
43
+ <% end %>
44
+ <footer>
45
+ <%= submit_tag "Change date range", form: "dateRangeForm" %>
46
+ <button type="reset" onclick="Ariato.Dialog.close(this)">Close</button>
47
+ </footer>
48
+ </div>
@@ -1,25 +1,51 @@
1
- <header>
1
+ <header data-ariato="ActiveAnalytics.Header">
2
2
  <nav aria-label="site"> <!-- implicit role="navigation", aria label "site" is announced = "site navigation" -->
3
- <div role="toolbar" data-ariato="Application.Toolbar">
4
- <div role="group">
5
- <%= link_to "Analytics", active_analytics_path, role: "button" %>
6
- <% if params[:site] %>
7
- <div class="menubutton">
8
- <button type="button" id="site-menu-button" aria-haspopup="true" aria-controls="site-menu"><%= params[:site] %></button>
9
- <ul id="site-menu" role="menu" aria-labelledby="site-menu-button">
10
- <li role="none">
11
- <%= link_to "Site", site_path(params[:site]), role: "menuitem", tabindex: -1 %>
12
- </li>
13
- <li role="none">
14
- <%= link_to "Pages", pages_path, role: "menuitem", tabindex: -1 %>
15
- </li>
16
- <li role="none">
17
- <%= link_to "Referrers", referrers_path, role: "menuitem", tabindex: -1 %>
18
- </li>
19
- </ul>
20
- </div>
21
- <% end %>
3
+
4
+ <%#= link_to "Analytics", active_analytics_path, role: "button" %>
5
+ <%= link_to active_analytics_path, class: 'logo' do %>
6
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 11">
7
+ <path class="a" d="M.5,5.5s0,2,1,2,1-2,1-2,0-2,1-2,1,2,1,2,0,2,1,2,1-2,1-2,0-2,1-2,1,2,1,2,0,2,1,2,1-2,1-2"/>
8
+ <circle class="a" cx="5.5" cy="5.5" r="5"/>
9
+ <line class="a" x1="0.5" y1="5.5" x2="10.5" y2="5.5"/>
10
+ </svg>
11
+ <% end %>
12
+
13
+ <% if params[:site] %>
14
+ <%= link_to params[:site], site_path(params[:site], from: params[:from], to: params[:to]) %>
15
+
16
+ <% if controller_name == "pages" %>
17
+ &nbsp;/&nbsp;<%= link_to "pages", pages_path(params[:site], from: params[:from], to: params[:to]) %>
18
+ <% end %>
19
+
20
+ <% if controller_name == "referrers" %>
21
+ &nbsp;/&nbsp;<%= link_to "referrers", referrers_path(params[:site], from: params[:from], to: params[:to]) %>
22
+ <% end %>
23
+
24
+ <div class="menubutton">
25
+ <button type="button" id="date-range" aria-haspopup="true" aria-controls="date-range-menu">
26
+ <%= l params[:from].to_date, format: :long %>
27
+ <% if params[:to].to_date != params[:from].to_date %> → <%= l params[:to].to_date, format: :long %><% end%>
28
+ </button>
29
+ <ul id="date-range-menu" role="menu" aria-labelledby="date-range">
30
+ <li role="none">
31
+ <%= link_to "Today", url_for(params.merge(from: Date.today, to: Date.today).to_unsafe_hash), role: "menuitem", tabindex: "-1" %>
32
+ </li>
33
+ <li role="none">
34
+ <%= link_to "Yesterday", url_for(params.merge(from: Date.yesterday, to: Date.yesterday).to_unsafe_hash), role: "menuitem", tabindex: "-1" %>
35
+ </li>
36
+ <li role="none">
37
+ <%= link_to "Last 7 days", url_for(params.merge(from: 7.days.ago.to_date, to: Date.today).to_unsafe_hash), role: "menuitem", tabindex: "-1" %>
38
+ </li>
39
+ <li role="none">
40
+ <%= link_to "Last 30 days", url_for(params.merge(from: 30.days.ago.to_date, to: Date.today).to_unsafe_hash), role: "menuitem", tabindex: "-1" %>
41
+ </li>
42
+ <li role="none">
43
+ <button type="button" onclick="Ariato.Dialog.open('custom-date-range')" tabindex="-1" class="is-link">
44
+ Custom range
45
+ </button>
46
+ </li>
47
+ </ul>
22
48
  </div>
23
- </div>
49
+ <% end %>
24
50
  </nav>
25
51
  </header>
@@ -1,19 +1,20 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Active analytics</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
3
+ <head>
4
+ <title>Active analytics</title>
5
+ <meta name=viewport content="width=device-width, initial-scale=1">
6
+ <%= csrf_meta_tags %>
7
+ <%= csp_meta_tag %>
7
8
 
8
- <%= stylesheet_link_tag "active_analytics/application", media: "all" %>
9
- <%= javascript_include_tag "active_analytics/application" %>
10
- </head>
9
+ <%= stylesheet_link_tag "active_analytics/application", media: "all" %>
10
+ <%= javascript_include_tag "active_analytics/application" %>
11
+ </head>
11
12
 
12
- <body>
13
- <%= render "/layouts/active_analytics/header" %>
14
- <main aria-label="Content">
15
- <%= yield %>
16
- </main>
17
- <%= render "/layouts/active_analytics/footer" %>
18
- </body>
13
+ <body>
14
+ <%= render "/layouts/active_analytics/header" %>
15
+ <main aria-label="Content">
16
+ <%= yield %>
17
+ </main>
18
+ <%= render "/layouts/active_analytics/footer" %>
19
+ </body>
19
20
  </html>
@@ -10,7 +10,7 @@ class CreateActiveAnalyticsViewsPerDays < ActiveRecord::Migration[5.2]
10
10
  t.timestamps
11
11
  end
12
12
  add_index :active_analytics_views_per_days, :date
13
- add_index :active_analytics_views_per_days, [:site, :page, :date]
13
+ add_index :active_analytics_views_per_days, [:site, :page, :date], name: "index_active_analytics_views_per_days_on_site_and_date"
14
14
  add_index :active_analytics_views_per_days, [:referrer_host, :referrer_path, :date], name: "index_active_analytics_views_per_days_on_referrer_and_date"
15
15
  end
16
16
 
@@ -2,21 +2,19 @@ require "active_analytics/version"
2
2
  require "active_analytics/engine"
3
3
 
4
4
  module ActiveAnalytics
5
- VERSION = "0.1.0"
6
-
7
5
  def self.record_request(request)
8
6
  params = {
9
7
  site: request.host,
10
8
  page: request.path,
11
9
  date: Date.today,
12
10
  }
13
- if request.referer.present?
11
+ if request.referrer.present?
14
12
  referrer_uri = URI(request.referrer)
15
13
  params[:referrer_host] = referrer_uri.host
16
14
  params[:referrer_path] = referrer_uri.path
17
15
  end
18
16
  ViewsPerDay.append(params)
19
17
  rescue => ex
20
- raise if Rails.env.development?
18
+ raise if Rails.env.development? || Rails.env.test?
21
19
  end
22
20
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveAnalytics
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-24 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 5.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.2.0
27
27
  description: NO cookies, NO JavaScript, NO third parties and NO bullshit
@@ -35,11 +35,14 @@ files:
35
35
  - README.md
36
36
  - Rakefile
37
37
  - app/assets/config/active_analytics_manifest.js
38
+ - app/assets/images/active_analytics.png
39
+ - app/assets/images/active_analytics_screenshot.png
38
40
  - app/assets/javascripts/active_analytics/application.js
39
41
  - app/assets/javascripts/active_analytics/ariato.js
40
42
  - app/assets/stylesheets/active_analytics/application.css
41
43
  - app/assets/stylesheets/active_analytics/ariato.css
42
44
  - app/assets/stylesheets/active_analytics/charts.css
45
+ - app/assets/stylesheets/active_analytics/style.css
43
46
  - app/controllers/active_analytics/application_controller.rb
44
47
  - app/controllers/active_analytics/pages_controller.rb
45
48
  - app/controllers/active_analytics/referrers_controller.rb