ahoy_panel 0.0.5 β†’ 0.0.7

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: 84e7f7e4d1cb11801db2816bc4e4f448ef4322276139bb44afac6806581fe2c3
4
- data.tar.gz: 2b05fbfac068ba5013f983301ae008f2e13be362567c85110ccfa31b904ac187
3
+ metadata.gz: 30ad1497fbf5bf2457d257333673b84c928df34e620669bdd54139f6e08139ef
4
+ data.tar.gz: 0edb2465e6c4780691b4ccdac95e26eaafe9d2e2b083396664fb8e05f2c7dc96
5
5
  SHA512:
6
- metadata.gz: de0b39d73b7cee4a3a7378d9a05e1c0f281191680f770b755bacb9eb04e7835db44cb48ce268fafc288a48b36888b0f52eb9a2797b8e48fb4585c512efe4ed67
7
- data.tar.gz: 154b5cc04a47ae153126cd86b686b1e24c78f89250d48241ad37bd535d8e2eee6ea4452c4deca2eca23cb520c414d8653096b1839a5185e29b51384a6703a566
6
+ metadata.gz: a66637704dab635875a85244c19f2937c3ca54d85e5df9fbe079516def52dc27d991c94db4714f41796cfe4290967719002fb37e49e7e3321a0e9bcc5e8565d3
7
+ data.tar.gz: b1e106a8825fd6f90db2eb52dd37dbd1f51c37bdb9e94a8ceb98d37f0030584a550cb75c0afa28e7c9ab2f0cd9de6d53c98e2ece401b7e0bf188c4a01a8b2580
data/README.md CHANGED
@@ -1,28 +1,96 @@
1
- # AhoyPanel
2
- Short description and motivation.
1
+ # Ahoy Panel
3
2
 
4
- ## Usage
5
- How to use my plugin.
3
+ [![Gem Version](https://badge.fury.io/rb/ahoy_panel.svg)](https://badge.fury.io/rb/ahoy_panel)
4
+
5
+ **Ahoy Panel** is a companion gem for the [Ahoy Panel](https://www.ahoypanel.com) web app – a modern, hosted dashboard for your [Ahoy](https://github.com/ankane/ahoy) analytics data.
6
+
7
+ It enables your Rails app to stream Ahoy events to the Ahoy Panel API for real-time analytics and beautiful insights.
8
+
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - πŸ”Œ Simple integration with your existing Ahoy setup
14
+ - πŸ“Š Centralized dashboard at [ahoypanel.com](https://www.ahoypanel.com)
15
+ - πŸš€ Lightweight and configurable
16
+ - πŸ” Secure API key-based authentication
17
+
18
+ ---
6
19
 
7
20
  ## Installation
8
- Add this line to your application's Gemfile:
21
+
22
+ Add this line to your Rails application's Gemfile:
9
23
 
10
24
  ```ruby
11
25
  gem "ahoy_panel"
12
26
  ```
13
27
 
14
28
  And then execute:
29
+
15
30
  ```bash
16
- $ bundle
31
+ bundle install
17
32
  ```
18
33
 
19
- Or install it yourself as:
34
+ ---
35
+
36
+ ## Configuration
37
+
38
+ After installing the gem, you'll need to configure it to connect to your Ahoy Panel account. This gem assumes that you already have `ahoy_matey` gem installed, configured, and in usage.
39
+
40
+ Create an initializer file:
41
+
42
+ ```ruby
43
+ # config/initializers/ahoy_panel.rb
44
+ AhoyPanel.configure do |config|
45
+ # Your project’s API key from https://www.ahoypanel.com/settings
46
+ config.api_key = ENV.fetch("AHOY_PANEL_API_KEY")
47
+ end
48
+ ```
49
+
50
+ Add your API key to your environment variables:
51
+
20
52
  ```bash
21
- $ gem install ahoy_panel
53
+ # .env
54
+ AHOY_PANEL_API_KEY=your-api-key-here
22
55
  ```
23
56
 
57
+ ---
58
+
59
+ ## Usage
60
+
61
+ Once configured, anytime you load your dashboard in [Ahoy Panel](https://www.ahoypanel.com), your `ahoy_panel` will send the data that's needed `Ahoy::Visit` and `Ahoy::Event` to [Ahoy Panel](https://www.ahoypanel.com) to build the dashboard.
62
+
63
+ No extra setup required – just install, configure, and you're done! πŸŽ‰
64
+
65
+ ---
66
+
67
+ ## Requirements
68
+
69
+ - Rails 6+
70
+ - [Ahoy](https://github.com/ankane/ahoy) gem installed and configured
71
+
72
+ ---
73
+
74
+ ## Privacy & Performance
75
+
76
+ - Events are batched and sent asynchronously to minimize request overhead
77
+ - Only relevant event data (like `name`, `properties`, `user_id`, and timestamps) is sent
78
+ - You retain full control over what data is tracked
79
+
80
+ ---
81
+
82
+ ## Troubleshooting
83
+
84
+ - Ensure your API key is correct and the base_url configured in your [Ahoy Panel](https://www.ahoypanel.com) account is correct. Any issues, reach out.
85
+
86
+ ---
87
+
24
88
  ## Contributing
25
- Contribution directions go here.
89
+
90
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/typefastco/ahoy_panel](https://github.com/typefastco/ahoy_panel).
91
+
92
+ ---
26
93
 
27
94
  ## License
95
+
28
96
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,4 +1,29 @@
1
1
  module AhoyPanel
2
2
  class ApplicationController < ActionController::Base
3
+ before_action :authenticate_api_key!
4
+
5
+ protected
6
+
7
+ def authenticate_api_key!
8
+ api_key = request.headers["Ahoy-Panel-Api-Key"]
9
+
10
+ return true if Rails.env.development?
11
+
12
+ ahoy_panel_root_url = "https://www.ahoypanel.com"
13
+
14
+ client = Faraday.new(url: ahoy_panel_root_url) do |conn|
15
+ conn.headers["Ahoy-Panel-Api-Key"] = "#{api_key}"
16
+ conn.request :json
17
+ conn.response :json
18
+ end
19
+
20
+ response = client.get("/api_key_verify")
21
+
22
+ client = Faraday.new(url: ahoy_panel_root_url)
23
+
24
+ if !response.body["verified"]
25
+ client.get("/invalid_api_key")
26
+ end
27
+ end
3
28
  end
4
29
  end
@@ -0,0 +1,12 @@
1
+ module AhoyPanel
2
+ class ViewsDataController < ApplicationController
3
+ def index
4
+ @start_date = params[:start_date].to_date
5
+ @end_date = params[:end_date].to_date
6
+
7
+ @visits = ::Ahoy::Visit.where(started_at: @start_date..@end_date)
8
+
9
+ render json: @visits
10
+ end
11
+ end
12
+ end
@@ -1,9 +1,13 @@
1
1
  module AhoyPanel
2
2
  class VisitsController < ApplicationController
3
- def index
4
- @visits = ::Ahoy::Visit.all
3
+ def all_time_dates
4
+ start_date = ::Ahoy::Visit.order(started_at: :asc).first.started_at.to_date
5
+ end_date = ::Ahoy::Visit.order(started_at: :desc).first.started_at.to_date
5
6
 
6
- render json: @visits
7
+ render json: {
8
+ start_date: start_date,
9
+ end_date: end_date
10
+ }
7
11
  end
8
12
  end
9
13
  end
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  AhoyPanel::Engine.routes.draw do
2
- resources :visits
2
+ get "all_time_dates", to: "visits#all_time_dates"
3
+
4
+ get "views_data", to: "views_data#index"
3
5
  end
@@ -1,3 +1,3 @@
1
1
  module AhoyPanel
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/ahoy_panel.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "ahoy_panel/version"
2
2
  require "ahoy_panel/engine"
3
- require 'dry-configurable'
3
+ require "dry-configurable"
4
+ require "faraday"
4
5
 
5
6
  module AhoyPanel
6
7
  extend Dry::Configurable
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_panel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Jeon
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-26 00:00:00.000000000 Z
10
+ date: 2025-03-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '7'
18
+ version: '6'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '7'
25
+ version: '6'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: ahoy_matey
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +51,20 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '1.3'
54
+ - !ruby/object:Gem::Dependency
55
+ name: faraday
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '2.12'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '2.12'
54
68
  description: Ahoy is a great analytics tracking gem. AhoyPanel is a great dashboard
55
69
  for the data collected by Ahoy.
56
70
  email:
@@ -64,6 +78,7 @@ files:
64
78
  - Rakefile
65
79
  - app/assets/stylesheets/ahoy_panel/application.css
66
80
  - app/controllers/ahoy_panel/application_controller.rb
81
+ - app/controllers/ahoy_panel/views_data_controller.rb
67
82
  - app/controllers/ahoy_panel/visits_controller.rb
68
83
  - app/helpers/ahoy_panel/application_helper.rb
69
84
  - app/jobs/ahoy_panel/application_job.rb