rails_analytics 1.0.3 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +10 -5
- data/app/helpers/rails_analytics/application_helper.rb +8 -2
- data/config/routes.rb +1 -1
- data/lib/generators/rails_analytics/install/install_generator.rb +10 -5
- data/lib/generators/rails_analytics/install/templates/initializer.rb +0 -4
- data/lib/rails_analytics/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20ebdf5f4a45c3f8cad6c9e607be2d5eeaccb7669311c6f86b619aa2f76992dd
|
|
4
|
+
data.tar.gz: 36b3978273cb8d054fec49443cc5f7ea5e3cb83c18a2c63f3a60a706dd402616
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 15d271dfdeae4344ed730fcc9bf467f962180e6093d219152d2d863f4556e6f1df113b9a91b0bab7b61e0011823a3b3a39890fd953905e7ecccf2e1a761758dc
|
|
7
|
+
data.tar.gz: 9347e3775bec41f15af5a827ee148da0fd2fbbf91c3429b0cbf6807fc5da4f3208e1fed835a78ba79e9fabc44b66042aec0963d296a62ff6f5a1fec881a37c66
|
data/README.md
CHANGED
|
@@ -88,20 +88,25 @@ Done — collection is automatic and the dashboard lives at **`/analytics`** (or
|
|
|
88
88
|
|
|
89
89
|
## Mounting
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
The engine's mount point is **a single configuration** — the `mount` line in
|
|
92
|
+
`config/routes.rb`. There is no separate `mount_path` to keep in sync: the tracker tag,
|
|
93
|
+
the dashboard CSS and the collect endpoint all derive their URLs from the engine's own
|
|
94
|
+
route helpers at runtime, so they follow whatever path you mount the engine at.
|
|
92
95
|
|
|
93
96
|
```ruby
|
|
94
97
|
# config/routes.rb
|
|
95
|
-
mount RailsAnalytics::Engine => "/analytics"
|
|
98
|
+
mount RailsAnalytics::Engine => "/analytics" # default
|
|
99
|
+
# mount RailsAnalytics::Engine => "/admin/analytics" # any custom path works
|
|
96
100
|
```
|
|
97
101
|
|
|
98
102
|
```erb
|
|
99
103
|
<!-- layout -->
|
|
100
|
-
<%= rails_analytics_tracker_tag
|
|
104
|
+
<%= rails_analytics_tracker_tag %>
|
|
101
105
|
```
|
|
102
106
|
|
|
103
|
-
>
|
|
104
|
-
>
|
|
107
|
+
> No need to pass an `endpoint:` to the helper — it resolves the mount automatically.
|
|
108
|
+
> The only exception is serving the tracker from a CDN:
|
|
109
|
+
> `<%= rails_analytics_tracker_tag endpoint: "/cdn/path" %>`.
|
|
105
110
|
|
|
106
111
|
## Authentication
|
|
107
112
|
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
module RailsAnalytics
|
|
4
4
|
module ApplicationHelper
|
|
5
|
+
# Single source of truth: the engine's mount point is whatever the host
|
|
6
|
+
# declared in routes.rb (`mount RailsAnalytics::Engine => "/..."`). We derive
|
|
7
|
+
# the tracker endpoint from the engine's own route helper, so there is no
|
|
8
|
+
# separate `mount_path` to keep in sync. `options[:endpoint]` still allows an
|
|
9
|
+
# explicit override (e.g. when serving the tracker from a CDN).
|
|
5
10
|
def rails_analytics_tracker_tag(options = {})
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
tracker = options[:tracker] || rails_analytics.tracker_path
|
|
12
|
+
endpoint = options[:endpoint] || rails_analytics.root_path.chomp("/")
|
|
13
|
+
tag.script(src: tracker,
|
|
8
14
|
data: { rails_analytics: true, endpoint: endpoint },
|
|
9
15
|
defer: true)
|
|
10
16
|
end
|
data/config/routes.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
RailsAnalytics::Engine.routes.draw do
|
|
4
|
-
get "tracker.js" => "analytics#tracker"
|
|
4
|
+
get "tracker.js" => "analytics#tracker", as: "tracker"
|
|
5
5
|
get "dashboard.css" => "analytics#dashboard_css", as: "dashboard_css"
|
|
6
6
|
post "collect" => "analytics#collect"
|
|
7
7
|
get "token" => "analytics#token"
|
|
@@ -6,6 +6,11 @@ module RailsAnalytics
|
|
|
6
6
|
source_root File.expand_path("templates", __dir__)
|
|
7
7
|
desc "Instala o rails_analytics: copia migrations, monta engine, cria initializer e pina tracker no importmap."
|
|
8
8
|
|
|
9
|
+
# The only mount configuration that matters is the `mount` line this generator
|
|
10
|
+
# writes into config/routes.rb. Changing that line is enough — the tracker and
|
|
11
|
+
# dashboard derive their URLs from the engine's route helpers at runtime.
|
|
12
|
+
DEFAULT_MOUNT_PATH = "/analytics"
|
|
13
|
+
|
|
9
14
|
def copy_migrations
|
|
10
15
|
migrations_dir = RailsAnalytics::Engine.root.join("db/migrate")
|
|
11
16
|
Dir["#{migrations_dir}/*.rb"].sort.each do |migration|
|
|
@@ -21,20 +26,20 @@ module RailsAnalytics
|
|
|
21
26
|
end
|
|
22
27
|
|
|
23
28
|
def mount_engine
|
|
24
|
-
route %(mount RailsAnalytics::Engine =>
|
|
25
|
-
say_status :ok, "Engine montada em config/routes.rb"
|
|
29
|
+
route %(mount RailsAnalytics::Engine => "#{DEFAULT_MOUNT_PATH}")
|
|
30
|
+
say_status :ok, "Engine montada em config/routes.rb (montada em #{DEFAULT_MOUNT_PATH})"
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
def pin_tracker
|
|
29
34
|
importmap_path = "config/importmap.rb"
|
|
30
35
|
if File.exist?(importmap_path)
|
|
31
36
|
unless File.read(importmap_path).include?("rails_analytics/tracker")
|
|
32
|
-
append_to_file importmap_path, %(\npin "rails_analytics/tracker", to:
|
|
37
|
+
append_to_file importmap_path, %(\npin "rails_analytics/tracker", to: "#{DEFAULT_MOUNT_PATH}/tracker.js"\n)
|
|
33
38
|
say_status :ok, "Tracker pinado em config/importmap.rb"
|
|
34
39
|
end
|
|
35
40
|
else
|
|
36
41
|
say_status :skipped, "config/importmap.rb não encontrado — adicione manualmente:", :yellow
|
|
37
|
-
say %( Adicione ao seu layout: <script src="
|
|
42
|
+
say %( Adicione ao seu layout: <script src="#{DEFAULT_MOUNT_PATH}/tracker.js" defer></script>), :yellow
|
|
38
43
|
end
|
|
39
44
|
end
|
|
40
45
|
|
|
@@ -42,7 +47,7 @@ module RailsAnalytics
|
|
|
42
47
|
say "\n✅ rails_analytics instalado! Próximos passos:", :green
|
|
43
48
|
say " 1. bin/rails db:migrate"
|
|
44
49
|
say " 2. Configure a autenticação no initializer: config/initializers/rails_analytics.rb"
|
|
45
|
-
say " 3. Acesse o dashboard em #{
|
|
50
|
+
say " 3. Acesse o dashboard em #{DEFAULT_MOUNT_PATH} (se quiser outro path, edite o mount em config/routes.rb)"
|
|
46
51
|
say ""
|
|
47
52
|
end
|
|
48
53
|
end
|
|
@@ -5,10 +5,6 @@ RailsAnalytics.configure do |config|
|
|
|
5
5
|
# Pode ser um Symbol (ex: :authenticate_admin!) ou um callable (ex: -> { current_user&.admin? }).
|
|
6
6
|
config.auth_callback = :authenticate_admin!
|
|
7
7
|
|
|
8
|
-
# Caminho onde o engine é montado (debe coincidir com el mount en config/routes.rb).
|
|
9
|
-
# Padrão: "/analytics". Puedes cambiarlo libremente (ex: "/admin/analytics").
|
|
10
|
-
config.mount_path = "/analytics"
|
|
11
|
-
|
|
12
8
|
# Período padrão para as consultas do dashboard (ex: 30.days).
|
|
13
9
|
config.since_default = 30.days
|
|
14
10
|
end
|