Implementing Web Anayltics(webtrends) in Streamlit

Hello!
I am trying to add webtrends javascripts to track anayltics in an streamlit app.
I used 4 different methods

1- using st.markdown.

st.markdown(
    """
<script text/javascript">
    var dcsidGlobal = 
</script>
<!-- START OF SmartSource Data Collector TAG --> <!-- Copyright (c) 1996-2024 WebTrends Inc. All rights reserved. -->
<script src="js/webtrends.js" type="text/javascript"></script>
<!-- ----------------------------------------------------------------------------------- -->
<!-- Warning: The two script blocks below must remain inline. Moving them to an external -->
<!-- JavaScript include file can cause serious problems with cross-domain tracking.      -->
<!-- ----------------------------------------------------------------------------------- -->
<script type="text/javascript">
    //<![CDATA[
    var _tag = new WebTrends();
    //]]>>
</script>
<script type="text/javascript">
    //<![CDATA[
    // Add custom parameters here.
    //_tag.DCSext.param_name=param_value;
    _tag.dcsCollect();
    //]]>>
</script>
    <div><img alt="DCSIMG" id="DCSIMG" width="1" height="1"
            src="http://******" />
    </div>
""", unsafe_allow_html=True
)

Method 2 using components.v1:

java_string="""
<script src="js/webtrends.js" text/javascript">
    var dcsidGlobal = "****";

<!-- START OF SmartSource Data Collector TAG --> <!-- Copyright (c) 1996-2024 WebTrends Inc. All rights reserved. -->
<!-- ----------------------------------------------------------------------------------- -->
<!-- Warning: The two script blocks below must remain inline. Moving them to an external -->
<!-- JavaScript include file can cause serious problems with cross-domain tracking.      -->
<!-- ----------------------------------------------------------------------------------- -->
	//<![CDATA[
    var _tag = new WebTrends();
    //]]>>
    //<![CDATA[
    // Add custom parameters here.
    //_tag.DCSext.param_name=param_value;
    _tag.dcsCollect();
    //]]>>
</script>
"""

html_div= """
    <div><img alt="DCSIMG" id="DCSIMG" width="1" height="1"
            src="" />
    </div>
"""
x=comp.html(java_string+html_div)

Finally, I tried to make sure JS is in the streamlit static file as follows:

STREAMLIT_STATIC_PATH = pathlib.Path(st.__path__[0]) / 'static'/'static'
VIDEOS_PATH = (STREAMLIT_STATIC_PATH / "js")
if not VIDEOS_PATH.is_dir():
    VIDEOS_PATH.mkdir()
print(VIDEOS_PATH)
wildlife_video = VIDEOS_PATH / "webtrends.js"
if not wildlife_video.exists():
    shutil.copy("webtrends.js", wildlife_video)  # For newer Python.

Yet, None is working.
I cant see it triggered in network tab. Any adivce/help is really appreciate it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.