I would like to track in Google Analytics a UI I built with Streamlit. According to Google Analytics, the following needs to be added into the <head> section of the HTML.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-**********"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-**********');
</script>
As I do not have any html file in my code architecture, I included the following Streamlit line in my main .py file:
google_analytics_js = '[previous_html_code]'
st.components.v1.html(google_analytics_js)
The website is unfortunately not tracked. Any help on this would be greatly appreciated.