PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

I recently read the wonderful article Homemade Analytics with Elixir and Ecto by @josevalim and decided on using the described approach in a couple of my projects. I didn’t want to copy&paste the code into every project and decided on creating a library instead.

Disclaimer: I absolutely do not want to take credit for José’s code, so I tried to reference his blog article everywhere I could. This library is simply meant as a helper for using his code in your project.

AnalyticsEx

GitHub: GitHub - PJUllrich/analytics_ex · GitHub
Hex: API Reference — analytics_ex v0.2.2

A library tracking how many visitors a Phoenix-based application receives per day without collecting any data from the user. It encapsulates the Homemade Analytics code of José Valim and simply counts the page-requests per path per day. The collected data is stored in a configurable Ecto-repository.

I hope that you find this helpful. My next steps will be to create a nice UI for the collected data. Feel free to help and contribute :slight_smile:

Showing Posts 1 to 8

josevalim

josevalim

Creator of Elixir

Awesome work!

After I announced the blog post, I learned about Plausible.io, which is an open source analytics focused on privacy that is written in Elixir. We are using them since then and we are very happy with it, so I definitely recommend them.

So between analytics_ex and plausible, it seems we are well served in the analytics area. :slight_smile:

17
Post #1
gordoneliel

gordoneliel

This was really helpful but I found that using it with liveview won’t work on routes that go though the socket connection on push_patches. Is there an idiomatic way of doing this that tracks all routes going through the router in a liveview project? @josevalim

PJUllrich

PJUllrich OP

Author of Building Table Views with Phoenix LiveView

I just released a small addition, which is bump_with_uri/1. You can now bump the metrics whenever you have a URI like in the handle_params/3 function of your LiveView. Simply call:

def handle_params(params, uri, socket) do
  AnalyticsEx.Metrics.bump_with_uri(uri)

  # Do other stuff here
end

If you really want to be sure that the metric was bumped, you can check the return value of bump_with_uri/1, which is either :ok or {:error, :path_not_found}, if URI.parse/1 doesn’t return a value for path.

If you want to use this functionality, simply update AnalyticsEx to 0.1.1.

@gordoneliel I hope this solves your problem as well. Sorry, I didn’t see your message until now.

PJUllrich

PJUllrich OP

Author of Building Table Views with Phoenix LiveView

I added a LiveDashboard-page to AnalyticsEx which gives you a quick overview of the counted requests per day, week, and month.

Simply update AnalyticsEx to 0.2.1 and include this in the live_dashboard route in your router.ex.

live_dashboard "/dashboard",
      additional_pages: [
        {:analytics, AnalyticsEx.LiveDashboard.AnalyticsPage}
      ]

You will then have a Tab called Analytics in your LiveDashboard!

If you want to always ignore certain routes in the overview, add them to the live_dashboard-route:

live_dashboard "/dashboard",
      additional_pages: [
        {:analytics, {AnalyticsEx.LiveDashboard.AnalyticsPage, ignore: ["/this-route", "/and-this-route-including-subpaths"]}
      ]

It’s been a bit tricky to add this tab to LiveDashboard using the predefined components, mostly because LiveDashboard was not yet refactored enough in order support adding custom pages with ease. I will create a GitHub ticket for the issues I had with adding this page, but in general, it only took me 1 day to include this page and that is without having any examples! So, it certainly is possible :slight_smile:

11
Post #4
KristerV

KristerV

hey. this looks like a cool tool. you said you’re using Plausible now. Plausible is great. but i want a lib to install on random projects without having to worry about an extra service. so my question is how are you using Plausible, are you hosting your own server and then intergrating to the server? is it easy to set up for every project?

PJUllrich

PJUllrich OP

Author of Building Table Views with Phoenix LiveView

thanks! I pay for Plausible, but you can also self-host it. Otherwise, here’s a promising new library that could satisfy you needs too: GitHub - lalabuy948/PhoenixAnalytics: 📊 Plug and play analytics for Phoenix applications. · GitHub

KristerV

KristerV

oh wow, what an interesting project. I’m glad I asked. and it looks like DuckDB doesn’t need separate hosting. okay, i’ll give it a go. thanks a lot.

how did you even find this project?

edit: yeah, easy install, just works. didn’t even have to config DuckDB. deployed to fly and there are errors, but for v0.2 that’s expected :smiley:

KristerV

KristerV

yeah, several rabbit holes later, I was unable to deploy this to fly.io. here’s my issue.

https://github.com/lalabuy948/PhoenixAnalytics/issues/31

— All posts loaded —

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews