PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

A Library for Homemade Analytics with Elixir and Ecto

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
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:

Most Liked

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 #2
PJUllrich

PJUllrich

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 #5
PJUllrich

PJUllrich

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

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.

KristerV

KristerV

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

Where Next?

Popular in Libraries Top

josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
achempion
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library. The progre...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
bryanjos
Hi, I just published version 0.23.0 of Elixirscript. Most of the changes are around JavaScript interop now that Elixirscript uses the ...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New
gjaldon
As the title states, EctoEnum has just been updated after some time of hardly any activity in the repo. Here’s the latest release: https:...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Sub Categories:

We're in Beta

About us Mission Statement