Courses / Creating A Fullstack Linktree Clone (Legacy)

Track And Graph Daily Views

This lesson covers setting up Ahoy for daily views, which is done through Events. Because each Event is a model, we can then query based on the time of its creation. This is much more powerful than a simple integer view counter, for obvious reasons, but it goes a bit further. Ahoy gives us access to a wide variety of analytics that we can explore, many of which are in use by Linktree itself.


Here is the code snippet for the Ahoy query if you're interested!

def get_daily_profile_views
daily_views = Ahoy::Event.where("json_extract(properties, '$.user.id') LIKE '#{id}'")
.where(name: 'Viewed Dashboard')
daily_views.group_by_day(:time).count
end
Fig. 1 - A preview of the stacked layout available with ApexCharts.

References:
https://github.com/ankane/ahoy
https://github.com/styd/apexcharts.rb#options 
https://apexcharts.com/docs/ 
https://youtu.be/G_T17DopsOk

Exercises

No exercises in this lesson yet.