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.
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
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.
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
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.
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
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?