I created a tiny package to enable multi app page analytics

Hello community!

I built streamlit-fyr a small analytics library for multi app streamlit deployments. This package allows you to set up either a SQLite backend or a shared Postgres db where you can keep track of multiple pages and allows you to set your own page analytics.

This package it is heavily inspired on Streamlit-analytics and Stremlit-page-analytics. But instead of relying on auto instrumentation it gives you a “open” (where open means manual :sweat_smile: ) way to define your own events.

This solves the problem that my team had both for defining custom analytics to keep track on their app and for having a centralized way to track their events.

Some cool things that the package does:

  • Allow explicit named events with a JSON payload. Do what you want with the payload!
  • Gets a “visitor_id” that it is embedded in a cookie (using Streamlit-extra-components) that persist through sessions to “identify” a browser instance.
  • Gets “session_id” to keep track of the interactions.
  • Allows a “user_id” field that can be plugged into your verification process if you have one.
  • Dashboard included. If you don’t want to think about the metrics and just see the data, import the dashboard, the package will take care of it :slight_smile:

Getting started it’s super easy:

from streamlit_fyr import Tracker, SQLiteBackend

backend = SQLiteBackend("telemetry.db")
tracker = Tracker(app_name="my_app", backend=backend)

tracker.init()

...
# Emit a page change!
tracker.page("home")

# Emit a simple event
if st.button("Export"):
    tracker.event("export_clicked", {"format": "csv"})

# Want to look to the dashboard?
pg = st.navigation({
      "App": [...],
      "Analytics": [st.Page(make_dashboard_page(backend), title="Page analytics!", icon=":material/analytics:")],
})

The dashboard looks something like this:

And you have multiple ways of installing the package:

  pip install streamlit-fyr                 # core (SQLite + raw query)
  pip install 'streamlit-fyr[dashboard]'    # adds the Plotly dashboard
  pip install 'streamlit-fyr[postgres]'     # adds Postgres support
  pip install 'streamlit-fyr[all]'          # everything

Would love some feedback on it, so feel free to try it, test it and hope you make a good usage of it!

1 Like