Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lalabuy948/PhoenixAnalytics
📊 Plug and play analytics for Phoenix applications.
https://github.com/lalabuy948/PhoenixAnalytics
analytics dashboard elixir liveview phoenix
Last synced: about 2 months ago
JSON representation
📊 Plug and play analytics for Phoenix applications.
- Host: GitHub
- URL: https://github.com/lalabuy948/PhoenixAnalytics
- Owner: lalabuy948
- License: apache-2.0
- Created: 2024-08-16T12:38:28.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-09-16T08:55:57.000Z (about 2 months ago)
- Last Synced: 2024-09-18T16:36:34.284Z (about 2 months ago)
- Topics: analytics, dashboard, elixir, liveview, phoenix
- Language: Elixir
- Homepage: https://theindiestack.com/analytics
- Size: 1.11 MB
- Stars: 182
- Watchers: 4
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-duckdb - Phoenix Analytics - Plug and play analytics for Phoenix applications, powered by DuckDB. (Tools Powered by DuckDB)
README
# 📊 Phoenix Analytics
![](/github/hero.png)
Phoenix Analytics is embedded plug and play tool designed for Phoenix applications. It provides a simple and efficient way to track and analyze user behavior and application performance without impacting your main application's performance and database.
Key features:
- ⚡️ Lightweight and fast analytics tracking
- ⛓️💥 Separate storage using DuckDB to avoid affecting your main database
- 🔌 Easy integration with Phoenix applications
- 📊 Minimalistic dashboard for data visualization> The decision to use [DuckDB](https://duckdb.org) as the storage was made to ensure that the analytics data collection process does not interfere with or degrade the performance of your application's primary transactional database. This separation allows for efficient data storage and querying specifically optimized for analytics purposes, while keeping your main database focused on serving your application's core functionality.
https://github.com/user-attachments/assets/66ee00d4-3928-46ec-bfca-c03e2569bc0a
## Installation
If [available in Hex](https://hex.pm/packages/phoenix_analytics), the package can be installed
by adding `phoenix_analytics` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:phoenix_analytics, "~> 0.1.3"}
]
end
```Update `config/config.exs`
```exs
config :phoenix_analytics,
database_path: System.get_env("DUCK_PATH") || "analytics.duckdb",
app_domain: System.get_env("PHX_HOST") || "example.com"
```Add migration file
> In case you have ecto less / no migrations project you can do the following:
> `iex -S mix` `PhoenixAnalytics.Migration.up()`
```sh
mix ecto.gen.migration add_phoenix_analytics
``````elixir
defmodule MyApp.Repo.Migrations.AddPhoenixAnalytics do
def up, do: PhoenixAnalytics.Migration.up()
def down, do: PhoenixAnalytics.Migration.down()
end
``````sh
mix ecto.migrate
```Add plug to enable tracking to `endpoint.ex`, ‼️ add it straight after your `Plug.Static`
```elixir
plug PhoenixAnalytics.Plugs.RequestTracker
```Add dashboard route to your `router.ex`
```elixir
use PhoenixAnalytics.Web, :routerphoenix_analytics_dashboard "/analytics"
```Update your `.gitignore`
```.gitignore
*.duckdb
*.duckdb.*
```> ‼️ Please test thoroughly before proceeding to production!
## Documentation
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm/phoenix_analytics). Once published, the docs can
be found at .Shortcuts:
- `t` -> today
- `ctrl+t` -> yesterday
- `w` -> last_week
- `m` -> last_30_days
- `q` -> last_90_days
- `y` -> last_12_month
- `ctrl+w` -> previous_week
- `ctrl+m` -> previous_month
- `ctrl+q` -> previous_quarter
- `ctrl+y` -> previous_year
- `a` -> all_time### Development
If you would like to contribute, first you would need to install deps, assets and then compile css and js.
I put everything under next mix command:```sh
mix setup
```Then you would need some database with seeds. Here is command for this:
```sh
DUCK_PATH="dev.duckdb" mix run priv/repo/seeds.exs
```Lastly you can start dev server:
```sh
DUCK_PATH="dev.duckdb" elixir priv/repo/dev.exs
```or
```sh
DUCK_PATH="dev.duckdb" iex priv/repo/dev.exs
```You can navigate to `http://localhost:4000/dev/analytics`
## Performance test
I performed [vegeta](https://github.com/tsenart/vegeta) test on basic Macbook Air M2, to see if plug will affect application performance.
Script can be found here: `vegeta/vegeta.sh`| With plug | Without |
| ---------------------- | ---------------------- |
| ![with](/github/vegeta-with.png) | ![without](/github/vegeta-without.png) |## For whom this library
- [x] Single instance Phoenix app
- [x] Multiple instances of Phoenix app without auto scaling group- [ ] Multiple instances of Phoenix app **with** auto scaling group
There is a plan to build a separate backend to be powered by ClickHouse in order to track requests across multiple nodes in orchestrated scenarios.
### Heavily inspired by
- [https://github.com/elixir-error-tracker/error-tracker](https://github.com/elixir-error-tracker/error-tracker)
- [https://plausible.io](https://plausible.io)