Track & visualize user interactions with your streamlit app
Project description
streamlit-analytics 👀
Track & visualize user interactions with your streamlit app.
This is a small extension for the fantastic streamlit framework. With just one line of code, it counts page views, tracks all user interactions with your app, and visualizes the results directly in your browser. Think Google Analytics but for streamlit.
Installation
pip install streamlit-analytics
How to use it
import streamlit as st
import streamlit_analytics
with streamlit_analytics.track():
st.text_input("Write something")
st.button("Click me")
That's it! 🎈 All page views and user inputs are now tracked and counted. Of course,
you can also use any other streamlit widget
in the with
block (both from st.
and st.sidebar.
).
Note: One thing that doesn't work (yet) is tracking widgets created directly from
containers, expanders, or columns (e.g. st.beta_expander().button("foo")
). Instead,
please use a with statement, e.g. with st.beta_expander(): st.button("foo")
.
To view the results, open your app like normal and append ?analytics=on
to the URL
(e.g. http://localhost:8501/?analytics=on). The results are then shown directly below
your app (see image above).
More options
-
You can password-protect your analytics results with
streamlit_analytics.track(unsafe_password=...)
. The streamlit app will then ask you for this password. Do not choose an important password here – it is sent without encryption. -
If you don't want a huge
with
block, you can also do:import streamlit_analytics streamlit_analytics.start_tracking() # your streamlit code here streamlit_analytics.stop_tracking()
-
Experimental: You can store analytics results as a json file by passing
save_to_json="path/to/file.json"
tostreamlit_analytics.track
orstreamlit_analytics.stop_tracking
. At the moment, this may lead to problems with concurrency if many users access the site at the same time.
Next steps
PRs are welcome! If you want to work on any of these things, please open an issue to coordinate.
- enable tracking on widgets created directly from beta_container, beta_expander, beta_columns
- persist results after re-starting app
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for streamlit-analytics-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7576aeda0985e40762295e291b2c9f853f0e33c8e57bc6b54164ac861a1d9347 |
|
MD5 | 9f58c76a1e2051a0ed67ceab7a20d6da |
|
BLAKE2b-256 | 6ed632ebb8dc47d3ff2b09a9dc8c943987cd508a0766806d3b61b8da4200293b |
Hashes for streamlit_analytics-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a18dfb6a3f528a9e98fb3d03fefff4f0ce851c4a1a4169ca8c759e4698d969a0 |
|
MD5 | 5cba61e21e5161ef6a45a119a85ed069 |
|
BLAKE2b-256 | a44af804f82e042c6cc6f710750af5d833f96c53503c667fde5f2056370d5284 |