Can someone please help me get Google Analytics to pick up how many people are using my app. I already have a Google Analytics account and I also already received my tracking ID. Give me an example How I should incorporate the tracking ID into my code.
Currently, there is no native integration of GA with Streamlit. You can use our analytics functionality, which is available for free when you deploy your apps on Streamlit Community Cloud. More info about it here.
Now if you really want to add GA to your app, as far as I know, the only way is to add the tracking code in an HTML file and embed it into your app using Streamlit’s components.html() function.
You need an HTML file (e.g., google_analytics.html) in the same directory as your Streamlit app.
Your HTML code should look like this:
<!-- Google Analytics tracking code -->
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_TRACKING_ID"></script>
window.dataLayer = window.dataLayer || ;
gtag('js', new Date());
Here’s what the streamlit/Python file may look like:
import streamlit as st
import streamlit.components.v1 as components
# Include Google Analytics tracking code
with open("google_analytics.html", "r") as f:
html_code = f.read()
st.title("My Streamlit App")
Remember to replace YOUR_TRACKING_ID with your Google Analytics tracking ID!
Note that I have not personally tried this, but I suggest you give it a try and provide feedback to us here so that we can potentially investigate further.
Thank you very much for coming back to me on this. I have been struggling for almost three days to get it to work. I have tried your suggestions and it still doesn’t work. here is my GitHub repo, maybe you can have a look at what I am trying to do. GitHub - arnoldtRealph/lesson-planafr
I was looking for an alternative, because Workspace Analytics isn’t appearing on my dashboard header. If I had Workspace Analytics, it would suit my needs.
Thank you for giving attention to my concern.