Hi I have developed a streamlit application and deployed it on Heroku. I have changed the title using st.set_page_config(page_title=âMy appâ, page_icon=âmy_pictureâ,). It works good on the browser but when I check the access on google analytics still displays âStreamlitâ as title of the accessed web and when I google the application it shows again âStreamlitâ in the result of the google searcher, and the favicon is still the Streamlit favicon. Any idea why?
from bs4 import BeautifulSoup
import shutil
import pathlib
import logging
def inject_ga():
GA_ID = "google_analytics"
GA_JS = """
<!-- Global site tag (gtag.js) - Google Analytics -->
<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>
"""
analytics_id = "G-************"
# Insert the script in the head tag of the static template inside your virtual
index_path = pathlib.Path(st.__file__).parent / "static" / "index.html"
logging.info(f'editing {index_path}')
soup = BeautifulSoup(index_path.read_text(), features="html.parser")
if not soup.find(id=GA_ID):
bck_index = index_path.with_suffix('.bck')
if bck_index.exists():
shutil.copy(bck_index, index_path)
else:
shutil.copy(index_path, bck_index)
html = str(soup)
new_html = html.replace('<head>', '<head>\n' + GA_JS)
index_path.write_text(new_html)
inject_ga()
st.set_page_config(
page_title="My app",
page_icon="đŚ",
layout="wide",
initial_sidebar_state="expanded",
)
Thanks @Miguel_Gonzalez.
The st.set_page_config
function is designed to modify the page title and favicon, and the related snippet in your code seems to be correctly implemented.
However, be aware that Google Analytics may not show these changes instantly.
Q: is it displayed correctly in your browser?
If not, itâs important to note that browsers often cache favicons and title information, which can prevent immediate updates. To address this, have you tried viewing the app in incognito mode, or made sure to clear your browserâs cache?
Thanks,
Charly
Hi Charly, thanks for the response. Yes, it is displayed correctly in the browser. Thatâs why I am confused.
I implemented the new title and favicon one week ago, I wonder how long it takes to be updated in the google cloud resources.
Thank you for your update.
This suggests that itâs only a matter of time, possibly just a few days, before the title displays accurately in Google Cloud as well.
Given that this isnât my area of expertise, I recommend reaching out to Google Cloud support or consulting their docs for more specific guidance.
Best,
Charly