{"id":15063591,"url":"https://github.com/lalabuy948/phoenixanalytics","last_synced_at":"2025-05-15T12:03:36.635Z","repository":{"id":255646670,"uuid":"843400835","full_name":"lalabuy948/PhoenixAnalytics","owner":"lalabuy948","description":"📊 Plug and play analytics for Phoenix applications.","archived":false,"fork":false,"pushed_at":"2025-03-14T11:21:33.000Z","size":1820,"stargazers_count":382,"open_issues_count":12,"forks_count":18,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-15T12:03:32.558Z","etag":null,"topics":["analytics","dashboard","elixir","liveview","phoenix"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lalabuy948.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-16T12:38:28.000Z","updated_at":"2025-05-14T23:48:46.000Z","dependencies_parsed_at":"2024-09-13T01:29:38.796Z","dependency_job_id":"165bea2a-5409-42e4-8332-ef2c6f59000b","html_url":"https://github.com/lalabuy948/PhoenixAnalytics","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"6b94e9d5970371c097413f0fbe4cf388a3523cba"},"previous_names":["lalabuy948/phoenixanalytics"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lalabuy948%2FPhoenixAnalytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lalabuy948%2FPhoenixAnalytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lalabuy948%2FPhoenixAnalytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lalabuy948%2FPhoenixAnalytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lalabuy948","download_url":"https://codeload.github.com/lalabuy948/PhoenixAnalytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","dashboard","elixir","liveview","phoenix"],"created_at":"2024-09-25T00:04:40.426Z","updated_at":"2025-05-15T12:03:36.607Z","avatar_url":"https://github.com/lalabuy948.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📊 Phoenix Analytics\n\n\u003cp align=\"center\"\u003e\n  \u003ca title=\"GitHub CI\" href=\"https://github.com/lalabuy948/PhoenixAnalytics/actions\"\u003e\u003cimg src=\"https://github.com/lalabuy948/PhoenixAnalytics/actions/workflows/tests.yml/badge.svg\" alt=\"GitHub CI\" /\u003e\u003c/a\u003e\n  \u003ca title=\"Latest release\" href=\"https://hex.pm/packages/phoenix_analytics\"\u003e\u003cimg src=\"https://img.shields.io/hexpm/v/phoenix_analytics.svg\" alt=\"Latest release\" /\u003e\u003c/a\u003e\n  \u003ca title=\"View documentation\" href=\"https://hexdocs.pm/phoenix_analytics\"\u003e\u003cimg src=\"https://img.shields.io/badge/hex.pm-docs-blue.svg\" alt=\"View documentation\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n![](https://raw.githubusercontent.com/lalabuy948/PhoenixAnalytics/master/github/hero.png)\n\n![](https://raw.githubusercontent.com/lalabuy948/PhoenixAnalytics/master/github/screenshot.png)\n\nPhoenix 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.\n\nKey features:\n- ⚡️ Lightweight and fast analytics tracking\n- ⛓️‍💥 Separate storage using DuckDB to avoid affecting your main database\n- 🔌 Easy integration with Phoenix applications\n- 📊 Minimalistic dashboard for data visualization\n\n\u003e 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.\n\n\nhttps://github.com/user-attachments/assets/66ee00d4-3928-46ec-bfca-c03e2569bc0a\n\n\n## Installation\n\nIf [available in Hex](https://hex.pm/packages/phoenix_analytics), the package can be installed\nby adding `phoenix_analytics` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:phoenix_analytics, \"~\u003e 0.3\"}\n  ]\nend\n```\n\nUpdate `config/config.exs`\n\n```elixir\nconfig :phoenix_analytics,\n  duckdb_path: System.get_env(\"DUCKDB_PATH\") || \"analytics.duckdb\",\n  app_domain: System.get_env(\"PHX_HOST\") || \"example.com\"\n```\n\n\u003e [!IMPORTANT]\n\u003e In case you have dynamic cluster, you can use your PostgresDB as backend.\n\n```elixir\nconfig :phoenix_analytics,\n  duckdb_path: System.get_env(\"DUCKDB_PATH\") || \"analytics.duckdb\",\n  app_domain: System.get_env(\"PHX_HOST\") || \"example.com\",\n  postgres_conn: System.get_env(\"POSTGRES_CONN\") || \"dbname=postgres user=phoenix password=analytics host=localhost\"\n```\n\n\u003e [!IMPORTANT]\n\u003e In case you would like to proceed with Postgres option, consider enabling caching.\n\n```elixir\nconfig :phoenix_analytics,\n  duckdb_path: System.get_env(\"DUCKDB_PATH\") || \"analytics.duckdb\",\n  app_domain: System.get_env(\"PHX_HOST\") || \"example.com\",\n  postgres_conn: System.get_env(\"POSTGRES_CONN\") || \"dbname=postgres user=phoenix password=analytics host=localhost\",\n  cache_ttl: System.get_env(\"CACHE_TTL\") || 120 # seconds\n```\n\n\u003e [!IMPORTANT]\n\u003e In case you are hosting your app on fly.io or heroku which doesn't let to persist data on the disk,\n\u003e you can add `in_memory: true` into :phoenix_analytics config.\n\u003e And don't forget to remove `duckdb_path` from the config, otherwise PA will try to create duckdb on the disk.\n\n```elixir\nconfig :phoenix_analytics,\n  app_domain: System.get_env(\"PHX_HOST\") || \"example.com\",\n  postgres_conn: System.get_env(\"POSTGRES_CONN\") || \"dbname=postgres user=phoenix password=analytics host=localhost\",\n  in_memory: true\n```\n\nAdd migration file\n\n\u003e In case you have ecto less / no migrations project you can do the following:\n\n\u003e `iex -S mix` `PhoenixAnalytics.Migration.up()`\n\n```sh\nmix ecto.gen.migration add_phoenix_analytics\n```\n\n\u003e [!TIP]\n\u003e Based on your configuration migration will be run in appropriate database.\n\u003e If only `duckdb_path` then in duckdb file.\n\u003e If `duckdb_path` and `postgres_conn` provided then in your Postgres database.\n\n```elixir\ndefmodule MyApp.Repo.Migrations.AddPhoenixAnalytics do\n  use Ecto.Migration\n\n  def up, do: PhoenixAnalytics.Migration.up()\n  def down, do: PhoenixAnalytics.Migration.down()\nend\n```\n\n```sh\nmix ecto.migrate\n```\n\nAdd plug to enable tracking to `endpoint.ex`, ‼️ add it straight after your `Plug.Static`\n\n```elixir\nplug PhoenixAnalytics.Plugs.RequestTracker\n```\n\nAdd dashboard route to your `router.ex`\n\n```elixir\nuse PhoenixAnalytics.Web, :router\n\nphoenix_analytics_dashboard \"/analytics\"\n```\n\nUpdate your `.gitignore`\n\n```.gitignore\n*.duckdb\n*.duckdb.*\n```\n\n\u003e [!WARNING]\n\u003e ‼️ Please test thoroughly before proceeding to production!\n\n## Documentation\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm/phoenix_analytics). Once published, the docs can\nbe found at \u003chttps://hexdocs.pm/phoenix_analytics\u003e.\n\nShortcuts:\n\n- `t` -\u003e today\n- `ctrl+t` -\u003e yesterday\n- `w` -\u003e last_week\n- `m` -\u003e last_30_days\n- `q` -\u003e last_90_days\n- `y` -\u003e last_12_month\n- `ctrl+w` -\u003e previous_week\n- `ctrl+m` -\u003e previous_month\n- `ctrl+q` -\u003e previous_quarter\n- `ctrl+y` -\u003e previous_year\n- `a` -\u003e all_time\n\n### Development\n\nIf you would like to contribute, first you would need to install deps, assets and then compile css and js.\nI put everything under next mix command:\n\n```sh\nmix setup\n```\n\nThen you would need some database with seeds. Here is command for this:\n\n```sh\nDUCKDB_PATH=\"analytics.duckdb\" mix run priv/repo/seeds.exs\n```\n\nor if you would like to test with Postgres backend:\n\n```sh\ncd examples/duck_postgres/\n\ndocker compose -f postgres-compose.yml up\n\n# from project root\nmix run priv/repo/seeds_postgres.exs\n```\n\n\u003e [!NOTE]\n\u003e Move database with seeds to example project which you going to use.\n\nLastly you can use one of example applications to start server.\n\n```sh\ncd examples/duck_only/\n\nmix deps.get\n\nmix phx.server\n```\n\nYou can navigate to `http://localhost:4000/dev/analytics`\n\n## Performance test\n\nI performed [vegeta](https://github.com/tsenart/vegeta) test on basic Macbook Air M2, to see if plug will affect application performance.\nScript can be found here: `vegeta/vegeta.sh`\n\n| With plug              | Without                |\n| ---------------------- | ---------------------- |\n| ![with](/github/vegeta-with.png) | ![without](/github/vegeta-without.png) |\n\n## For whom this library\n\n- [x] Single instance Phoenix app (duckdb only recommended)\n- [x] Multiple instances of Phoenix app **without** auto scaling group (duckdb or postgres option can be used)\n- [x] Multiple instances of Phoenix app **with** auto scaling group (only postgres powered apps supported at the moment)\n\n### Heavily inspired by\n\n- [error-tracker](https://github.com/elixir-error-tracker/error-tracker)\n- [plausible.io](https://plausible.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flalabuy948%2Fphoenixanalytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flalabuy948%2Fphoenixanalytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flalabuy948%2Fphoenixanalytics/lists"}