Spaces:
Sleeping
Sleeping
XQ commited on
Commit ·
14ab2b8
1
Parent(s): a493f04
Fix umami
Browse files- src/ui/app.py +25 -3
src/ui/app.py
CHANGED
|
@@ -264,9 +264,31 @@ elif "session_id" not in st.session_state:
|
|
| 264 |
# ---------------------------------------------------------------------------
|
| 265 |
# Analytics — Umami Cloud
|
| 266 |
# ---------------------------------------------------------------------------
|
| 267 |
-
st.html
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
)
|
| 271 |
|
| 272 |
# ---------------------------------------------------------------------------
|
|
|
|
| 264 |
# ---------------------------------------------------------------------------
|
| 265 |
# Analytics — Umami Cloud
|
| 266 |
# ---------------------------------------------------------------------------
|
| 267 |
+
# `st.html` injects via React's dangerouslySetInnerHTML, and scripts inserted
|
| 268 |
+
# through innerHTML never execute (HTML5 spec). We instead use a tiny iframe
|
| 269 |
+
# bootstrap (via components.html) that attaches the real Umami script to the
|
| 270 |
+
# parent document, so analytics track the actual Streamlit page URL.
|
| 271 |
+
import streamlit.components.v1 as components
|
| 272 |
+
|
| 273 |
+
components.html(
|
| 274 |
+
"""
|
| 275 |
+
<script>
|
| 276 |
+
(function () {
|
| 277 |
+
var doc = window.parent.document;
|
| 278 |
+
if (doc.querySelector('script[data-website-id="cf6c908e-1236-4406-8c02-88aa7c9a0db2"]')) {
|
| 279 |
+
return;
|
| 280 |
+
}
|
| 281 |
+
var s = doc.createElement('script');
|
| 282 |
+
s.async = true;
|
| 283 |
+
s.defer = true;
|
| 284 |
+
s.src = 'https://cloud.umami.is/script.js';
|
| 285 |
+
s.setAttribute('data-website-id', 'cf6c908e-1236-4406-8c02-88aa7c9a0db2');
|
| 286 |
+
doc.head.appendChild(s);
|
| 287 |
+
})();
|
| 288 |
+
</script>
|
| 289 |
+
""",
|
| 290 |
+
height=0,
|
| 291 |
+
width=0,
|
| 292 |
)
|
| 293 |
|
| 294 |
# ---------------------------------------------------------------------------
|