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.

Regards
Niklas

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

@st.cache
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))
conn.commit()
conn.close()

count_visitor()

st.header(“Welcome to my website”)

1 Like

Hey!

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!

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](https://shields-io-visitor-counter.herokuapp.com/badge?page=https://share.streamlit.io/your_deployed_app_link&label=VisitorsCount&labelColor=000000&logo=GitHub&logoColor=FFFFFF&color=1D70B8&style=for-the-badge)')
1 Like

Thank you for your badge counter method.