How to add Google Analytics or JS code in a Streamlit app?

Hi @ozgurdugmeci

I am trying to implement the statcounter code. Does it look something like this?

        <!-- Default Statcounter code for product-tour-with-analytics -->
        <script type="text/javascript">
        var sc_project=AAAAAAA; 
        var sc_invisible=0; 
        var sc_security="BBBBB"; 
        var scJsHost = "https://";
        document.write("<sc"+"ript type='text/javascript' src='" + scJsHost+
        <noscript><div class="statcounter"><a title="Web Analytics Made Easy -
        Statcounter" href="" target="_blank"><img
        class="statcounter" src=""
        alt="Web Analytics Made Easy - Statcounter"
        <!-- End of Statcounter Code -->
""", unsafe_allow_html=True

I insert the above code before I render any widgets (buttons, forms, expanders etc.)

Is that correct?

1 Like