rails_analytics 1.0.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee326c377ebf066fc7c66a085fb07592ddf2fa39f30179eb909d48c65ee33915
4
- data.tar.gz: 61f43990d112ed3dd22c4476dd6ededc70a5f765c405231810f644ba2f4487d5
3
+ metadata.gz: 20ebdf5f4a45c3f8cad6c9e607be2d5eeaccb7669311c6f86b619aa2f76992dd
4
+ data.tar.gz: 36b3978273cb8d054fec49443cc5f7ea5e3cb83c18a2c63f3a60a706dd402616
5
5
  SHA512:
6
- metadata.gz: 7e54ba03c1edd581608b4e486549b850946ff71b84aa8efa08f9e304fb42decd48e8e701029adb582177c385ccffd939b2cee37f2b751bf6a076f6fd82609632
7
- data.tar.gz: 6acf884e9a7a3e831b90f77ff05c605e5e8322f81b4858d11867aedcb86f072f8e3cf219c5ead4248c560264bd39ec73793ab9c741f5adf5d347f00cecf77399
6
+ metadata.gz: 15d271dfdeae4344ed730fcc9bf467f962180e6093d219152d2d863f4556e6f1df113b9a91b0bab7b61e0011823a3b3a39890fd953905e7ecccf2e1a761758dc
7
+ data.tar.gz: 9347e3775bec41f15af5a827ee148da0fd2fbbf91c3429b0cbf6807fc5da4f3208e1fed835a78ba79e9fabc44b66042aec0963d296a62ff6f5a1fec881a37c66
data/README.md CHANGED
@@ -42,8 +42,8 @@ dependencies.
42
42
  3. The engine verifies the token, **masks the IP** (before anything hits disk),
43
43
  derives a **daily anonymity key**, and stores a `Visit` row. Custom events are
44
44
  stored as `Event` rows linked to the visit.
45
- 4. The **dashboard** in `/rails_analytics` shows aggregated metrics from pure SQL
46
- queries in three views: overview, events, and visits.
45
+ 4. The **dashboard** at `/analytics` (default `mount_path`) shows aggregated metrics from
46
+ pure SQL queries in three views: overview, events, and visits.
47
47
 
48
48
  ## Requirements
49
49
 
@@ -88,20 +88,25 @@ Done — collection is automatic and the dashboard lives at **`/analytics`** (or
88
88
 
89
89
  ## Mounting
90
90
 
91
- You can mount the engine at any path:
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 endpoint: "/analytics" %>
104
+ <%= rails_analytics_tracker_tag %>
101
105
  ```
102
106
 
103
- > The `endpoint:` passed to the helper must match the path the engine is mounted at.
104
- > You can also set a global default via `RailsAnalytics.configure { |c| c.mount_path = "/analytics" }`.
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
 
@@ -236,7 +241,8 @@ cd test/dummy
236
241
  bin/rails server
237
242
  ```
238
243
 
239
- Then open:
244
+ Then open (the bundled dummy mounts the engine at **`/rails_analytics`** as an example of a
245
+ custom mount — the gem's default is `/analytics`):
240
246
 
241
247
  | URL | What you'll see |
242
248
  |-----|-----------------|
@@ -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
- endpoint = options[:endpoint] || RailsAnalytics.config.mount_path
7
- tag.script(src: "#{endpoint}/tracker.js",
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 => RailsAnalytics.config.mount_path)
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: RailsAnalytics.config.mount_path + "/tracker.js"\n)
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="<%= RailsAnalytics.config.mount_path %>/tracker.js" defer></script>), :yellow
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 #{RailsAnalytics.config.mount_path}"
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,9 +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 será montado no routes.rb.
9
- config.mount_path = "/analytics"
10
-
11
8
  # Período padrão para as consultas do dashboard (ex: 30.days).
12
9
  config.since_default = 30.days
13
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAnalytics
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - br4zz4