I built Freshlytics using PipelineDB (Postgres extension) - https://github.com/sheshbabu/freshlytics
It uses continuous aggregations so you don't need to manually run rollups every few mins/hours. You don't need to store individual events so it's better for user's privacy.
Here's the link to the sql - https://github.com/sheshbabu/freshlytics/blob/master/src/ser...