-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google analytics Support for the Gradio Application Hosted on HF Space #5954
Comments
Not at the moment, but we'll look into this @ravishk007! |
Hi @ravishk007 this should now be possible in Gradio 4.0. In Gradio 4.0, you can set the E.g. ga_script = """
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DNJN1PF3CS"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>
"""
with gr.Blocks(head=ga_script):
... |
Hi, it looks like this approach doesn't actually work, checking with https://tagassistant.google.com/. It detects the tags shipped with gradio but not the one added with head=. |
Hi @jonathanasdf can you inspect the source of the page yourself? Is the script being added as expected? I'm wondering if the issue is that Hugging Face Spaces runs Gradio apps inside of an iframe and perhaps Google Analytics doesn't work inside of iframes. |
Ah this was something I started with demo.launch(share=True) not something on spaces so that shouldn't be the issue. Looking at the source and testing this a bit more, it seems like only the first script tag from the head is being applied
Additionally, in this case it seems like the script tag is added to the head section after the page already loads, so it never gets executed? The console output is empty. |
Hmm super weird, but yeah I can reproduce -- @jonathanasdf would you be able to create a new issue with your findings regarding the |
Here is a workaround specifically for google analytics
|
Thanks so much @jonathanasdf! We'll work on getting the underlying issue fixed as well (cc @dawoodkhan82) |
@abidlabs @jonathanasdf I got the standard approach working in 4.10.0. I'm looking to also implement Tag Manager. It requires script in the header:
Is this possible? i.e. is there a body param for blocks? i.e. "with gr.Blocks(body=gtm_script):" |
@dwipper So we don't have a |
@dawoodkhan82 I assigned this to a gr.HTML component in my UI:
When I tested the page with the Google Tag Manager, it said "tag not found". I have a feeling it may have to do with the multiple levels of iFrames that make up the Gradio page structure? I may try adding the head script to the Block head script in the app, and see if that helps. I'll still have to add the body noscript to the gr.HTML component value. |
@dawoodkhan82 Actually, looks like moving the head script to the Block header worked (at least the site test came back Ok.) Now I will need to try to implement an Element Id tag to see if the data actually flows through...... |
@dawoodkhan82 Bingo! It worked with the header script in the head, and the body noscript iframe in the body of the gr.HTML component. While I can gather data about what is displayed in the gr.HTML component, next I'm going to see if I can access other Gradio components like gr.Textbox or gr.Dropdown...... |
@dawoodkhan82 The good news is that if I add an elem_id to the Gradio component, I can access the component it in the Tag Manager, i.e. get the label of the component, but it doesn't find the actual value of the component. I'm not a DOM expert, but I don't see any representation of the actual value of the dropdown or textbox when I inspect the page, so it makes sense that the Tag Manager can't read the value. Any ideas? |
@dwipper Maybe you're reading the value before it's actually updated in the DOM? |
Is there any way to integrate our own Google Analytics HTML tags with the application developed via Gradio and hosted on HuggingFace Spaces?
The text was updated successfully, but these errors were encountered: