Get views statistics from my app

I want to get get views-statistics from my app. Saw some older posts on this, but isn’t there a functions for this now? Searched in the docs but could not find it.


Quick’n dirty fix could be to write to a database when the page is loaded (and possible using st.cache to avoid an artificial number of visitors evertime the user clicks a widget) :

import streamlit as st
import sqlite3

def count_visitor():
conn = sqlite3.connect("/path/to/database.db")
cur = conn.cursor()
cur.execute("UPDATE name_of_table SET total_visitors = total_visitors + " + str(1))


st.header(“Welcome to my website”)

1 Like


Do try the Streamlit Analytics library, however, this may throw some errors while deploying on Streamlit Cloud with the updated latest Streamlit version.

Reference: streamlit-analytics · PyPI

Hope this helps!

1 Like


Thanks! I don’t have a database for this application though. I could work just update a file instead I guess.

Yes, that would probably work

1 Like

@niklas_ema You can try a simple badge counter.

 st.sidebar.markdown('![Visitor count](')
1 Like

Thank you for your badge counter method.